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; }
for (RexFieldCollation ok : window.orderKeys) { OrderExpression exprSpec = new OrderExpression(); Order order = ok.getDirection() == RelFieldCollation.Direction.ASCENDING ? Order.ASC : Order.DESC; NullOrder nullOrder; } else { nullOrder = ok.getDirection() == RelFieldCollation.Direction.ASCENDING ? NullOrder.NULLS_FIRST : NullOrder.NULLS_LAST;
public RelFieldCollation get(int index) { final RexFieldCollation collation = collations.get(index); return new RelFieldCollation( ((RexLocalRef) collation.left).getIndex(), collation.getDirection(), collation.getNullDirection()); }
pw.print(orderKey.toString());
public RelFieldCollation get(int index) { final RexFieldCollation collation = collations.get(index); return new RelFieldCollation( ((RexLocalRef) collation.left).getIndex(), collation.getDirection(), collation.getNullDirection()); }
pw.print(orderKey.toString());
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 SqlNode toSql(RexProgram program, RexFieldCollation rfc) { SqlNode node = toSql(program, rfc.left); switch (rfc.getDirection()) { case DESCENDING: case STRICTLY_DESCENDING: node = SqlStdOperatorTable.DESC.createCall(POS, node); } if (rfc.getNullDirection() != dialect.defaultNullDirection(rfc.getDirection())) { switch (rfc.getNullDirection()) { case FIRST: node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node); break; case LAST: node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node); break; } } return node; }
oByAst = ASTBuilder.createAST(HiveParser.TOK_ORDERBY, "TOK_ORDERBY"); for (RexFieldCollation ok : window.orderKeys) { ASTNode directionAST = ok.getDirection() == RelFieldCollation.Direction.ASCENDING ? ASTBuilder .createAST(HiveParser.TOK_TABSORTCOLNAMEASC, "TOK_TABSORTCOLNAMEASC") : ASTBuilder .createAST(HiveParser.TOK_TABSORTCOLNAMEDESC, "TOK_TABSORTCOLNAMEDESC"); } else { if (ok.getDirection() == RelFieldCollation.Direction.ASCENDING) { nullDirectionAST = ASTBuilder.createAST(HiveParser.TOK_NULLS_FIRST, "TOK_NULLS_FIRST"); directionAST.addChild(nullDirectionAST);
/** * 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(); }
private SqlNode toSql(RexProgram program, RexFieldCollation rfc) { SqlNode node = toSql(program, rfc.left); switch (rfc.getDirection()) { case DESCENDING: case STRICTLY_DESCENDING: node = SqlStdOperatorTable.DESC.createCall(POS, node); } if (rfc.getNullDirection() != dialect.defaultNullDirection(rfc.getDirection())) { switch (rfc.getNullDirection()) { case FIRST: node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node); break; case LAST: node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node); break; } } return node; }
for (RexFieldCollation ok : window.orderKeys) { OrderExpression exprSpec = new OrderExpression(); Order order = ok.getDirection() == RelFieldCollation.Direction.ASCENDING ? Order.ASC : Order.DESC; NullOrder nullOrder; } else { nullOrder = ok.getDirection() == RelFieldCollation.Direction.ASCENDING ? NullOrder.NULLS_FIRST : NullOrder.NULLS_LAST;
/** * 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(); }
new RelFieldCollation( lookupOrCreateGroupExpr(fieldCollation.left), fieldCollation.getDirection(), fieldCollation.getNullDirection())) .collect(Collectors.toList()));
oByAst = ASTBuilder.createAST(HiveParser.TOK_ORDERBY, "TOK_ORDERBY"); for (RexFieldCollation ok : window.orderKeys) { ASTNode directionAST = ok.getDirection() == RelFieldCollation.Direction.ASCENDING ? ASTBuilder .createAST(HiveParser.TOK_TABSORTCOLNAMEASC, "TOK_TABSORTCOLNAMEASC") : ASTBuilder .createAST(HiveParser.TOK_TABSORTCOLNAMEDESC, "TOK_TABSORTCOLNAMEDESC"); } else { if (ok.getDirection() == RelFieldCollation.Direction.ASCENDING) { nullDirectionAST = ASTBuilder.createAST(HiveParser.TOK_NULLS_FIRST, "TOK_NULLS_FIRST"); directionAST.addChild(nullDirectionAST);
/** * 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 RelFieldCollation.NullDirection getNullDirection() { return right.contains(SqlKind.NULLS_LAST) ? RelFieldCollation.NullDirection.LAST : right.contains(SqlKind.NULLS_FIRST) ? RelFieldCollation.NullDirection.FIRST : getDirection().defaultNullDirection(); } }
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 ); }
public RelFieldCollation.NullDirection getNullDirection() { return right.contains(SqlKind.NULLS_LAST) ? RelFieldCollation.NullDirection.LAST : right.contains(SqlKind.NULLS_FIRST) ? RelFieldCollation.NullDirection.FIRST : getDirection().defaultNullDirection(); }
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; }