Java Code Examples for org.apache.calcite.sql.SqlOperator#createCall()
The following examples show how to use
org.apache.calcite.sql.SqlOperator#createCall() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlValidatorImpl.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private SqlNode navigationInMeasure(SqlNode node, boolean allRows) { final Set<String> prefix = node.accept(new PatternValidator(true)); Util.discard(prefix); final List<SqlNode> ops = ((SqlCall) node).getOperandList(); final SqlOperator defaultOp = allRows ? SqlStdOperatorTable.RUNNING : SqlStdOperatorTable.FINAL; final SqlNode op0 = ops.get(0); if (!isRunningOrFinal(op0.getKind()) || !allRows && op0.getKind() == SqlKind.RUNNING) { SqlNode newNode = defaultOp.createCall(SqlParserPos.ZERO, op0); node = SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, newNode, ops.get(1)); } node = new NavigationExpander().go(node); return node; }
Example 2
Source File: SqlValidatorImpl.java From flink with Apache License 2.0 | 6 votes |
private SqlNode navigationInMeasure(SqlNode node, boolean allRows) { final Set<String> prefix = node.accept(new PatternValidator(true)); Util.discard(prefix); final List<SqlNode> ops = ((SqlCall) node).getOperandList(); final SqlOperator defaultOp = allRows ? SqlStdOperatorTable.RUNNING : SqlStdOperatorTable.FINAL; final SqlNode op0 = ops.get(0); if (!isRunningOrFinal(op0.getKind()) || !allRows && op0.getKind() == SqlKind.RUNNING) { SqlNode newNode = defaultOp.createCall(SqlParserPos.ZERO, op0); node = SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, newNode, ops.get(1)); } node = new NavigationExpander().go(node); return node; }
Example 3
Source File: SqlImplementor.java From Bats with Apache License 2.0 | 5 votes |
private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) { SqlNode node = op.createCall(new SqlNodeList(nodeList.subList(0, 2), POS)); for (int i = 2; i < nodeList.size(); i++) { node = op.createCall(new SqlNodeList(ImmutableList.of(node, nodeList.get(i)), POS)); } return node; }
Example 4
Source File: SqlValidatorImpl.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override public SqlNode visit(SqlIdentifier id) { if (id.isSimple()) { return id; } SqlOperator operator = id.names.get(0).equals(alpha) ? SqlStdOperatorTable.PREV : SqlStdOperatorTable.LAST; return operator.createCall(SqlParserPos.ZERO, id, SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO)); }
Example 5
Source File: SqlValidatorImpl.java From flink with Apache License 2.0 | 5 votes |
@Override public SqlNode visit(SqlIdentifier id) { if (id.isSimple()) { return id; } SqlOperator operator = id.names.get(0).equals(alpha) ? SqlStdOperatorTable.PREV : SqlStdOperatorTable.LAST; return operator.createCall(SqlParserPos.ZERO, id, SqlLiteral.createExactNumeric("0", SqlParserPos.ZERO)); }
Example 6
Source File: SqlImplementor.java From dremio-oss with Apache License 2.0 | 5 votes |
protected SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) { if (nodeList.size() == 2) { return op.createCall(new SqlNodeList(nodeList, POS)); } final List<SqlNode> butLast = Util.skipLast(nodeList); final SqlNode last = nodeList.get(nodeList.size() - 1); final SqlNode call = createLeftCall(op, butLast); return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS)); }
Example 7
Source File: SqlImplementor.java From dremio-oss with Apache License 2.0 | 5 votes |
/** * 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])); }
Example 8
Source File: DremioRelToSqlConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
public SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) { if (nodeList.size() == 2) { return op.createCall(new SqlNodeList(nodeList, POS)); } final List<SqlNode> butLast = skipLast(nodeList); final SqlNode last = nodeList.get(nodeList.size() - 1); final SqlNode call = createLeftCall(op, butLast); return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS)); }
Example 9
Source File: RelToSqlConverter.java From quark with Apache License 2.0 | 5 votes |
private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) { if (nodeList.size() == 2) { return op.createCall(new SqlNodeList(nodeList, POS)); } final List<SqlNode> butLast = Util.skipLast(nodeList); final SqlNode last = nodeList.get(nodeList.size() - 1); final SqlNode call = createLeftCall(op, butLast); return op.createCall(new SqlNodeList(ImmutableList.of(call, last), POS)); }
Example 10
Source File: RelToSqlConverter.java From quark with Apache License 2.0 | 5 votes |
/** * Converts a call to an aggregate function to an expression. */ public SqlNode toSql(AggregateCall aggCall) { SqlOperator op = (SqlAggFunction) 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[operands.size()])); }
Example 11
Source File: SqlImplementor.java From calcite with Apache License 2.0 | 5 votes |
private SqlNode createLeftCall(SqlOperator op, List<SqlNode> nodeList) { SqlNode node = op.createCall(new SqlNodeList(nodeList.subList(0, 2), POS)); for (int i = 2; i < nodeList.size(); i++) { node = op.createCall(new SqlNodeList(ImmutableList.of(node, nodeList.get(i)), POS)); } return node; }
Example 12
Source File: SqlAbstractParserImpl.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates a call. * * @param funName Name of function * @param pos Position in source code * @param funcType Type of function * @param functionQualifier Qualifier * @param operands Operands to call * @return Call */ protected SqlCall createCall( SqlIdentifier funName, SqlParserPos pos, SqlFunctionCategory funcType, SqlLiteral functionQualifier, SqlNode[] operands) { // Create a placeholder function. Later, during // validation, it will be resolved into a real function reference. SqlOperator fun = new SqlUnresolvedFunction(funName, null, null, null, null, funcType); return fun.createCall(functionQualifier, pos, operands); }
Example 13
Source File: SqlValidatorImpl.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public SqlNode visit(SqlCall call) { SqlKind kind = call.getKind(); List<SqlNode> operands = call.getOperandList(); List<SqlNode> newOperands = new ArrayList<>(); // This code is a workaround for CALCITE-2707 if (call.getFunctionQuantifier() != null && call.getFunctionQuantifier().getValue() == SqlSelectKeyword.DISTINCT) { final SqlParserPos pos = call.getParserPosition(); throw SqlUtil.newContextException(pos, Static.RESOURCE.functionQuantifierNotAllowed(call.toString())); } // This code is a workaround for CALCITE-2707 if (isLogicalNavigation(kind) || isPhysicalNavigation(kind)) { SqlNode inner = operands.get(0); SqlNode offset = operands.get(1); // merge two straight prev/next, update offset if (isPhysicalNavigation(kind)) { SqlKind innerKind = inner.getKind(); if (isPhysicalNavigation(innerKind)) { List<SqlNode> innerOperands = ((SqlCall) inner).getOperandList(); SqlNode innerOffset = innerOperands.get(1); SqlOperator newOperator = innerKind == kind ? SqlStdOperatorTable.PLUS : SqlStdOperatorTable.MINUS; offset = newOperator.createCall(SqlParserPos.ZERO, offset, innerOffset); inner = call.getOperator().createCall(SqlParserPos.ZERO, innerOperands.get(0), offset); } } SqlNode newInnerNode = inner.accept(new NavigationExpander(call.getOperator(), offset)); if (op != null) { newInnerNode = op.createCall(SqlParserPos.ZERO, newInnerNode, this.offset); } return newInnerNode; } if (operands.size() > 0) { for (SqlNode node : operands) { if (node != null) { SqlNode newNode = node.accept(new NavigationExpander()); if (op != null) { newNode = op.createCall(SqlParserPos.ZERO, newNode, offset); } newOperands.add(newNode); } else { newOperands.add(null); } } return call.getOperator().createCall(SqlParserPos.ZERO, newOperands); } else { if (op == null) { return call; } else { return op.createCall(SqlParserPos.ZERO, call, offset); } } }
Example 14
Source File: SqlValidatorImpl.java From flink with Apache License 2.0 | 4 votes |
@Override public SqlNode visit(SqlCall call) { SqlKind kind = call.getKind(); List<SqlNode> operands = call.getOperandList(); List<SqlNode> newOperands = new ArrayList<>(); // This code is a workaround for CALCITE-2707 if (call.getFunctionQuantifier() != null && call.getFunctionQuantifier().getValue() == SqlSelectKeyword.DISTINCT) { final SqlParserPos pos = call.getParserPosition(); throw SqlUtil.newContextException(pos, Static.RESOURCE.functionQuantifierNotAllowed(call.toString())); } // This code is a workaround for CALCITE-2707 if (isLogicalNavigation(kind) || isPhysicalNavigation(kind)) { SqlNode inner = operands.get(0); SqlNode offset = operands.get(1); // merge two straight prev/next, update offset if (isPhysicalNavigation(kind)) { SqlKind innerKind = inner.getKind(); if (isPhysicalNavigation(innerKind)) { List<SqlNode> innerOperands = ((SqlCall) inner).getOperandList(); SqlNode innerOffset = innerOperands.get(1); SqlOperator newOperator = innerKind == kind ? SqlStdOperatorTable.PLUS : SqlStdOperatorTable.MINUS; offset = newOperator.createCall(SqlParserPos.ZERO, offset, innerOffset); inner = call.getOperator().createCall(SqlParserPos.ZERO, innerOperands.get(0), offset); } } SqlNode newInnerNode = inner.accept(new NavigationExpander(call.getOperator(), offset)); if (op != null) { newInnerNode = op.createCall(SqlParserPos.ZERO, newInnerNode, this.offset); } return newInnerNode; } if (operands.size() > 0) { for (SqlNode node : operands) { if (node != null) { SqlNode newNode = node.accept(new NavigationExpander()); if (op != null) { newNode = op.createCall(SqlParserPos.ZERO, newNode, offset); } newOperands.add(newNode); } else { newOperands.add(null); } } return call.getOperator().createCall(SqlParserPos.ZERO, newOperands); } else { if (op == null) { return call; } else { return op.createCall(SqlParserPos.ZERO, call, offset); } } }
Example 15
Source File: RelToSqlConverter.java From quark with Apache License 2.0 | 4 votes |
/** * Convert {@link RexNode} condition into {@link SqlNode} * * @param node condition Node * @param leftContext LeftContext * @param rightContext RightContext * @param leftFieldCount Number of field on left result * @return SqlJoin which represent the condition */ private SqlNode convertConditionToSqlNode(RexNode node, Context leftContext, Context rightContext, int leftFieldCount) { if (!(node instanceof RexCall)) { throw new AssertionError(node); } final List<RexNode> operands; final SqlOperator op; switch (node.getKind()) { case AND: case OR: operands = ((RexCall) node).getOperands(); op = ((RexCall) node).getOperator(); SqlNode sqlCondition = null; for (RexNode operand : operands) { SqlNode x = convertConditionToSqlNode(operand, leftContext, rightContext, leftFieldCount); if (sqlCondition == null) { sqlCondition = x; } else { sqlCondition = op.createCall(POS, sqlCondition, x); } } return sqlCondition; case EQUALS: case IS_NOT_DISTINCT_FROM: case NOT_EQUALS: case GREATER_THAN: case GREATER_THAN_OR_EQUAL: case LESS_THAN: case LESS_THAN_OR_EQUAL: operands = ((RexCall) node).getOperands(); op = ((RexCall) node).getOperator(); if (operands.get(0) instanceof RexInputRef && operands.get(1) instanceof RexInputRef) { final RexInputRef op0 = (RexInputRef) operands.get(0); final RexInputRef op1 = (RexInputRef) operands.get(1); if (op0.getIndex() < leftFieldCount && op1.getIndex() >= leftFieldCount) { // Arguments were of form 'op0 = op1' return op.createCall(POS, leftContext.field(op0.getIndex()), rightContext.field(op1.getIndex() - leftFieldCount)); } if (op1.getIndex() < leftFieldCount && op0.getIndex() >= leftFieldCount) { // Arguments were of form 'op1 = op0' return reverseOperatorDirection(op).createCall(POS, leftContext.field(op1.getIndex()), rightContext.field(op0.getIndex() - leftFieldCount)); } } } throw new AssertionError(node); }