org.apache.calcite.sql.fun.SqlRowOperator Java Examples
The following examples show how to use
org.apache.calcite.sql.fun.SqlRowOperator.
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: StandardConvertletTable.java From Bats with Apache License 2.0 | 6 votes |
/** * Converts a ROW. * * <p>Called automatically via reflection. */ public RexNode convertRow( SqlRexContext cx, SqlRowOperator op, SqlCall call) { if (cx.getValidator().getValidatedNodeType(call).getSqlTypeName() != SqlTypeName.COLUMN_LIST) { return convertCall(cx, call); } final RexBuilder rexBuilder = cx.getRexBuilder(); final List<RexNode> columns = new ArrayList<>(); for (SqlNode operand : call.getOperandList()) { columns.add( rexBuilder.makeLiteral( ((SqlIdentifier) operand).getSimple())); } final RelDataType type = rexBuilder.deriveReturnType(SqlStdOperatorTable.COLUMN_LIST, columns); return rexBuilder.makeCall(type, SqlStdOperatorTable.COLUMN_LIST, columns); }
Example #2
Source File: StandardConvertletTable.java From calcite with Apache License 2.0 | 6 votes |
/** * Converts a ROW. * * <p>Called automatically via reflection. */ public RexNode convertRow( SqlRexContext cx, SqlRowOperator op, SqlCall call) { if (cx.getValidator().getValidatedNodeType(call).getSqlTypeName() != SqlTypeName.COLUMN_LIST) { return convertCall(cx, call); } final RexBuilder rexBuilder = cx.getRexBuilder(); final List<RexNode> columns = new ArrayList<>(); for (SqlNode operand : call.getOperandList()) { columns.add( rexBuilder.makeLiteral( ((SqlIdentifier) operand).getSimple())); } final RelDataType type = rexBuilder.deriveReturnType(SqlStdOperatorTable.COLUMN_LIST, columns); return rexBuilder.makeCall(type, SqlStdOperatorTable.COLUMN_LIST, columns); }
Example #3
Source File: ReduceExpressionsRule.java From Bats with Apache License 2.0 | 4 votes |
private void analyzeCall(RexCall call, Constancy callConstancy) { parentCallTypeStack.push(call.getOperator()); // visit operands, pushing their states onto stack super.visitCall(call); // look for NON_CONSTANT operands int operandCount = call.getOperands().size(); List<Constancy> operandStack = Util.last(stack, operandCount); for (Constancy operandConstancy : operandStack) { if (operandConstancy == Constancy.NON_CONSTANT) { callConstancy = Constancy.NON_CONSTANT; } } // Even if all operands are constant, the call itself may // be non-deterministic. if (!call.getOperator().isDeterministic()) { callConstancy = Constancy.NON_CONSTANT; } else if (call.getOperator().isDynamicFunction()) { // We can reduce the call to a constant, but we can't // cache the plan if the function is dynamic. // For now, treat it same as non-deterministic. callConstancy = Constancy.NON_CONSTANT; } // Row operator itself can't be reduced to a literal, but if // the operands are constants, we still want to reduce those if ((callConstancy == Constancy.REDUCIBLE_CONSTANT) && (call.getOperator() instanceof SqlRowOperator)) { callConstancy = Constancy.NON_CONSTANT; } if (callConstancy == Constancy.NON_CONSTANT) { // any REDUCIBLE_CONSTANT children are now known to be maximal // reducible subtrees, so they can be added to the result // list for (int iOperand = 0; iOperand < operandCount; ++iOperand) { Constancy constancy = operandStack.get(iOperand); if (constancy == Constancy.REDUCIBLE_CONSTANT) { addResult(call.getOperands().get(iOperand)); } } // if this cast expression can't be reduced to a literal, // then see if we can remove the cast if (call.getOperator() == SqlStdOperatorTable.CAST) { reduceCasts(call); } } // pop operands off of the stack operandStack.clear(); // pop this parent call operator off the stack parentCallTypeStack.pop(); // push constancy result for this call onto stack stack.add(callConstancy); }
Example #4
Source File: ReduceExpressionsRule.java From calcite with Apache License 2.0 | 4 votes |
private void analyzeCall(RexCall call, Constancy callConstancy) { parentCallTypeStack.push(call.getOperator()); // visit operands, pushing their states onto stack super.visitCall(call); // look for NON_CONSTANT operands int operandCount = call.getOperands().size(); List<Constancy> operandStack = Util.last(stack, operandCount); for (Constancy operandConstancy : operandStack) { if (operandConstancy == Constancy.NON_CONSTANT) { callConstancy = Constancy.NON_CONSTANT; break; } } // Even if all operands are constant, the call itself may // be non-deterministic. if (!call.getOperator().isDeterministic()) { callConstancy = Constancy.NON_CONSTANT; } else if (call.getOperator().isDynamicFunction()) { // We can reduce the call to a constant, but we can't // cache the plan if the function is dynamic. // For now, treat it same as non-deterministic. callConstancy = Constancy.NON_CONSTANT; } // Row operator itself can't be reduced to a literal, but if // the operands are constants, we still want to reduce those if ((callConstancy == Constancy.REDUCIBLE_CONSTANT) && (call.getOperator() instanceof SqlRowOperator)) { callConstancy = Constancy.NON_CONSTANT; } if (callConstancy == Constancy.NON_CONSTANT) { // any REDUCIBLE_CONSTANT children are now known to be maximal // reducible subtrees, so they can be added to the result // list for (int iOperand = 0; iOperand < operandCount; ++iOperand) { Constancy constancy = operandStack.get(iOperand); if (constancy == Constancy.REDUCIBLE_CONSTANT) { addResult(call.getOperands().get(iOperand)); } } } // pop operands off of the stack operandStack.clear(); // pop this parent call operator off the stack parentCallTypeStack.pop(); // push constancy result for this call onto stack stack.add(callConstancy); }