/** Converts a call to an aggregate function to an expression. */ public SqlNode toSql(AggregateCall aggCall) { SqlOperator op = aggCall.getAggregation(); if (op instanceof SqlSumEmptyIsZeroAggFunction) { op = SqlStdOperatorTable.SUM; } final List<SqlNode> operands = Expressions.list(); for (int arg : aggCall.getArgList()) { operands.add(field(arg)); } return op.createCall( aggCall.isDistinct() ? SqlSelectKeyword.DISTINCT.symbol(POS) : null, POS, operands.toArray(new SqlNode[0])); }
public void addOrderItem(List<SqlNode> orderByList, RelFieldCollation field) { if (field.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED) { boolean first = field.nullDirection == RelFieldCollation.NullDirection.FIRST; SqlNode nullDirectionNode = dialect.emulateNullDirection(context.field(field.getFieldIndex()), first, field.direction.isDescending()); if (nullDirectionNode != null) { orderByList.add(nullDirectionNode); field = new RelFieldCollation(field.getFieldIndex(), field.getDirection(), RelFieldCollation.NullDirection.UNSPECIFIED); } } orderByList.add(context.toSql(field)); }
void addOrderItem(List<SqlNode> orderByList, RelFieldCollation field) { if (field.nullDirection != RelFieldCollation.NullDirection.UNSPECIFIED) { final boolean first = field.nullDirection == RelFieldCollation.NullDirection.FIRST; SqlNode nullDirectionNode = dialect.emulateNullDirection(field(field.getFieldIndex()), first, field.direction.isDescending()); if (nullDirectionNode != null) { orderByList.add(nullDirectionNode); field = new RelFieldCollation(field.getFieldIndex(), field.getDirection(), RelFieldCollation.NullDirection.UNSPECIFIED); } } orderByList.add(toSql(field)); }
return field(((RexInputRef) rex).getIndex()); assert lastAccess != null; sqlIdentifier = (SqlIdentifier) correlAliasContext .field(lastAccess.getField().getIndex()); break; default: final RexPatternFieldRef ref = (RexPatternFieldRef) rex; String pv = ref.getAlpha(); SqlNode refNode = field(ref.getIndex()); final SqlIdentifier id = (SqlIdentifier) refNode; if (id.names.size() > 1) {
return field(((RexInputRef) rex).getIndex()); assert lastAccess != null; sqlIdentifier = (SqlIdentifier) correlAliasContext .field(lastAccess.getField().getIndex()); break; default: final RexPatternFieldRef ref = (RexPatternFieldRef) rex; String pv = ref.getAlpha(); SqlNode refNode = field(ref.getIndex()); final SqlIdentifier id = (SqlIdentifier) refNode; if (id.names.size() > 1) {
boolean first = fc.nullDirection == RelFieldCollation.NullDirection.FIRST; SqlNode nullDirectionNode = dialect.emulateNullDirection(context.field(fc.getFieldIndex()), first, fc.direction.isDescending()); if (nullDirectionNode != null) {
leftContext.field(op0.getIndex()), rightContext.field(op1.getIndex() - leftFieldCount)); leftContext.field(op1.getIndex()), rightContext.field(op0.getIndex() - leftFieldCount)); final RexInputRef op0 = (RexInputRef) operands.get(0); if (op0.getIndex() < leftFieldCount) { return op.createCall(POS, leftContext.field(op0.getIndex())); } else { return op.createCall(POS, rightContext.field(op0.getIndex() - leftFieldCount));
leftContext.field(op0.getIndex()), rightContext.field(op1.getIndex() - leftFieldCount)); leftContext.field(op1.getIndex()), rightContext.field(op0.getIndex() - leftFieldCount)); final RexInputRef op0 = (RexInputRef) operands.get(0); if (op0.getIndex() < leftFieldCount) { return op.createCall(POS, leftContext.field(op0.getIndex())); } else { return op.createCall(POS, rightContext.field(op0.getIndex() - leftFieldCount));
boolean first = fc.nullDirection == RelFieldCollation.NullDirection.FIRST; SqlNode nullDirectionNode = dialect.emulateNullDirection(context.field(fc.getFieldIndex()), first, fc.direction.isDescending()); if (nullDirectionNode != null) {
final List<SqlNode> selectList = new ArrayList<>(); for (int group : e.getGroupSet()) { final SqlNode field = builder.context.field(group); addSelect(selectList, field, e.getRowType()); groupByList.add(field);
final List<SqlNode> selectList = new ArrayList<>(); for (int group : e.getGroupSet()) { final SqlNode field = builder.context.field(group); addSelect(selectList, field, e.getRowType()); groupByList.add(field);
/** Converts a call to an aggregate function to an expression. */ public SqlNode toSql(AggregateCall aggCall) { final SqlOperator op = aggCall.getAggregation(); final List<SqlNode> operandList = Expressions.list(); for (int arg : aggCall.getArgList()) { operandList.add(field(arg)); } final SqlLiteral qualifier = aggCall.isDistinct() ? SqlSelectKeyword.DISTINCT.symbol(POS) : null; final SqlNode[] operands = operandList.toArray(new SqlNode[0]); List<SqlNode> orderByList = Expressions.list(); for (RelFieldCollation field : aggCall.collation.getFieldCollations()) { addOrderItem(orderByList, field); } SqlNodeList orderList = new SqlNodeList(orderByList, POS); if (op instanceof SqlSumEmptyIsZeroAggFunction) { final SqlNode node = withOrder( SqlStdOperatorTable.SUM.createCall(qualifier, POS, operands), orderList); return SqlStdOperatorTable.COALESCE.createCall(POS, node, SqlLiteral.createExactNumeric("0", POS)); } else { return withOrder(op.createCall(qualifier, POS, operands), orderList); } }
/** Converts a collation to an ORDER BY item. */ public SqlNode toSql(RelFieldCollation collation) { SqlNode node = field(collation.getFieldIndex()); switch (collation.getDirection()) { case DESCENDING: case STRICTLY_DESCENDING: node = SqlStdOperatorTable.DESC.createCall(POS, node); } if (collation.nullDirection != dialect.defaultNullDirection(collation.direction)) { switch (collation.nullDirection) { case FIRST: node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node); break; case LAST: node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node); break; } } return node; }
/** Converts a collation to an ORDER BY item. */ public SqlNode toSql(RelFieldCollation collation) { SqlNode node = field(collation.getFieldIndex()); switch (collation.getDirection()) { case DESCENDING: case STRICTLY_DESCENDING: node = SqlStdOperatorTable.DESC.createCall(POS, node); } if (collation.nullDirection != dialect.defaultNullDirection(collation.direction)) { switch (collation.nullDirection) { case FIRST: node = SqlStdOperatorTable.NULLS_FIRST.createCall(POS, node); break; case LAST: node = SqlStdOperatorTable.NULLS_LAST.createCall(POS, node); break; } } return node; }
public SqlNode get(int index) { return field(index); }
public SqlNode get(int index) { return field(index); }