private List<RexFieldCollation> getOrderKeys(OrderSpec os, RexNodeConverter converter, RowResolver inputRR) throws SemanticException { List<RexFieldCollation> oKeys = new ArrayList<RexFieldCollation>(); if (os != null) { List<OrderExpression> oExprs = os.getExpressions(); for (OrderExpression oExpr : oExprs) { TypeCheckCtx tcCtx = new TypeCheckCtx(inputRR); tcCtx.setAllowStatefulFunctions(true); ExprNodeDesc exp = genExprNodeDesc(oExpr.getExpression(), inputRR, tcCtx); RexNode ordExp = converter.convert(exp); Set<SqlKind> flags = new HashSet<SqlKind>(); if (oExpr.getOrder() == org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.Order.DESC) { flags.add(SqlKind.DESCENDING); } if (oExpr.getNullOrder() == org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.NullOrder.NULLS_FIRST) { flags.add(SqlKind.NULLS_FIRST); } else if (oExpr.getNullOrder() == org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.NullOrder.NULLS_LAST) { flags.add(SqlKind.NULLS_LAST); } else { throw new SemanticException( "Unexpected null ordering option: " + oExpr.getNullOrder()); } oKeys.add(new RexFieldCollation(ordExp, flags)); } } return oKeys; }
private List<RexFieldCollation> getOrderKeys(OrderSpec os, RexNodeConverter converter, RowResolver inputRR) throws SemanticException { List<RexFieldCollation> oKeys = new ArrayList<RexFieldCollation>(); if (os != null) { List<OrderExpression> oExprs = os.getExpressions(); for (OrderExpression oExpr : oExprs) { TypeCheckCtx tcCtx = new TypeCheckCtx(inputRR); tcCtx.setAllowStatefulFunctions(true); ExprNodeDesc exp = genExprNodeDesc(oExpr.getExpression(), inputRR, tcCtx); RexNode ordExp = converter.convert(exp); Set<SqlKind> flags = new HashSet<SqlKind>(); if (oExpr.getOrder() == org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.Order.DESC) { flags.add(SqlKind.DESCENDING); } if (oExpr.getNullOrder() == org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.NullOrder.NULLS_FIRST) { flags.add(SqlKind.NULLS_FIRST); } else if (oExpr.getNullOrder() == org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.NullOrder.NULLS_LAST) { flags.add(SqlKind.NULLS_LAST); } else { throw new SemanticException( "Unexpected null ordering option: " + oExpr.getNullOrder()); } oKeys.add(new RexFieldCollation(ordExp, flags)); } } return oKeys; }
/** * Visits each of a list of field collations and returns a list of the * results. * * @param collations List of field collations * @param update If not null, sets this to true if any of the expressions * was modified * @return Array of visited field collations */ protected List<RexFieldCollation> visitFieldCollations( List<RexFieldCollation> collations, boolean[] update) { ImmutableList.Builder<RexFieldCollation> clonedOperands = ImmutableList.builder(); for (RexFieldCollation collation : collations) { RexNode clonedOperand = collation.left.accept(this); if ((clonedOperand != collation.left) && (update != null)) { update[0] = true; collation = new RexFieldCollation(clonedOperand, collation.right); } clonedOperands.add(collation); } return clonedOperands.build(); }
/** * Visits each of a list of field collations and returns a list of the * results. * * @param collations List of field collations * @param update If not null, sets this to true if any of the expressions * was modified * @return Array of visited field collations */ protected List<RexFieldCollation> visitFieldCollations( List<RexFieldCollation> collations, boolean[] update, P arg) { ImmutableList.Builder<RexFieldCollation> clonedOperands = ImmutableList.builder(); for (RexFieldCollation collation : collations) { RexNode clonedOperand = collation.left.accept(this, arg); if ((clonedOperand != collation.left) && (update != null)) { update[0] = true; collation = new RexFieldCollation(clonedOperand, collation.right); } clonedOperands.add(collation); } return clonedOperands.build(); }
/** * Visits each of a list of field collations and returns a list of the * results. * * @param collations List of field collations * @param update If not null, sets this to true if any of the expressions * was modified * @return Array of visited field collations */ protected List<RexFieldCollation> visitFieldCollations( List<RexFieldCollation> collations, boolean[] update) { ImmutableList.Builder<RexFieldCollation> clonedOperands = ImmutableList.builder(); for (RexFieldCollation collation : collations) { RexNode clonedOperand = collation.left.accept(this); if ((clonedOperand != collation.left) && (update != null)) { update[0] = true; collation = new RexFieldCollation(clonedOperand, collation.right); } clonedOperands.add(collation); } return clonedOperands.build(); }
public RexNode makeOver( SqlAggFunction operator, List<RexNode> expressions, List<RexNode> partitionKeys ) { final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class); // TODO // This is a temporal fix to make HAWQ work with OVER + UNLIMITED BOUNDS // HAWQ requires ORDER BY if andy BOUNDS are set even unlimited upper and lower BOUNDS (which is equal to // the entire partition - e.g. not setting BOUNDs at all -- // Note that the unnecessary ORDER BY have negative performance impact and has to be remove once either HAWQ // start supporting unbounded bounds without order by or Calcite can generate shorthand OVER PARTITION BY // syntax. List<RexFieldCollation> orderKeys = expressions.stream().map( rexNode -> new RexFieldCollation(rexNode, flags)).collect(Collectors.toList()); return makeOver( operator, expressions, partitionKeys, ImmutableList.copyOf(orderKeys), RexWindowBound.create(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO), null), RexWindowBound.create(SqlWindow.createUnboundedFollowing(SqlParserPos.ZERO), null), true, true, false ); }
private List<RexFieldCollation> getOrderKeys(OrderSpec os, RexNodeConverter converter, RowResolver inputRR) throws SemanticException { List<RexFieldCollation> oKeys = new ArrayList<RexFieldCollation>(); if (os != null) { List<OrderExpression> oExprs = os.getExpressions(); for (OrderExpression oExpr : oExprs) { TypeCheckCtx tcCtx = new TypeCheckCtx(inputRR); tcCtx.setAllowStatefulFunctions(true); ExprNodeDesc exp = genExprNodeDesc(oExpr.getExpression(), inputRR, tcCtx); RexNode ordExp = converter.convert(exp); Set<SqlKind> flags = new HashSet<SqlKind>(); if (oExpr.getOrder() == org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.Order.DESC) flags.add(SqlKind.DESCENDING); oKeys.add(new RexFieldCollation(ordExp, flags)); } } return oKeys; }
break; return new RexFieldCollation(convertExpression(expr), flags);
break; return new RexFieldCollation(convertExpression(expr), flags);
flags.clear(); RexNode e = bb.convertSortExpression(order, flags); orderKeys.add(new RexFieldCollation(e, flags));
flags.clear(); RexNode e = bb.convertSortExpression(order, flags); orderKeys.add(new RexFieldCollation(e, flags));