@Override public Void visitCall(RexCall call) { if (call.getOperator() == RexBuilder.GET_OPERATOR) { throw Util.FoundOne.NULL; } return super.visitCall(call); } });
private RexNode castNullLiteralIfNeeded(RexNode node, RelDataType type) { if (!RexLiteral.isNullLiteral(node)) { return node; } return rexBuilder.makeCast(type, node); }
public RexNode newAttributeInitializer( RelDataType type, SqlFunction constructor, int iAttribute, List<RexNode> constructorArgs) { return rexBuilder.constantNull(); } }
assert literalExpr.isA(SqlKind.CAST); RexNode child = ((RexCall) literalExpr).getOperands().get(0); assert RexLiteral.isNullLiteral(child); Comparable value = literal.getValue(); (BigDecimal) value, type.getScale()); return rexBuilder.makeExactLiteral( roundedValue, type); return rexBuilder.makeCharLiteral( new NlsString( Util.rpad(unpadded.getValue(), type.getPrecision()),
public void addGroupExpr(SqlNode expr) { RexNode convExpr = bb.convertExpression(expr); final RexNode rex = lookupGroupExpr(expr); if (rex != null) { return; // don't add duplicates, in e.g. "GROUP BY x, y, x" } groupExprs.add(expr); String name = nameMap.get(expr.toString()); addExpr(convExpr, name); final RelDataType type = convExpr.getType(); inputRefs.add(rexBuilder.makeInputRef(type, inputRefs.size())); }
/** * Adjusts the type of a reference to an input field to account for nulls * introduced by outer joins; and adjusts the offset to match the physical * implementation. * * @param bb Blackboard * @param inputRef Input ref * @return Adjusted input ref */ protected RexNode adjustInputRef( Blackboard bb, RexInputRef inputRef) { RelDataTypeField field = bb.getRootField(inputRef); if (field != null) { return rexBuilder.makeInputRef( field.getType(), inputRef.getIndex()); } return inputRef; }
@Override public Pair<RexNode, String> get(int index) { if (index < rightCount) { RelDataTypeField field = fields.get(index); return Pair.<RexNode, String>of( new RexInputRef(index, field.getType()), field.getName()); } else { return Pair.of( RexUtil.shift( extraRightExprs.get(index - rightCount), -newLeftCount), null); } } },
/** * Determines whether a RexNode corresponds to a subquery that's been * converted to a constant. * * @param rex the expression to be examined * @return true if the expression is a dynamic parameter, a literal, or * a literal that is being cast */ private boolean isConvertedSubq(RexNode rex) { if ((rex instanceof RexLiteral) || (rex instanceof RexDynamicParam)) { return true; } if (rex instanceof RexCall) { RexCall call = (RexCall) rex; if (call.getOperator() == SqlStdOperatorTable.CAST) { RexNode operand = call.getOperands().get(0); if (operand instanceof RexLiteral) { return true; } } } return false; }
@Override public Pair<RexNode, String> get(int index) { if (index < leftCount) { RelDataTypeField field = fields.get(index); return Pair.<RexNode, String>of( new RexInputRef(index, field.getType()), field.getName()); } else { return Pair.<RexNode, String>of( extraLeftExprs.get(index - leftCount), null); } } },
public RexNode apply(Pair<RexNode, SqlNode> pair) { return rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, pair.left, bb.convertExpression(pair.right)); } }),
/** * Adds an expression, deducing an appropriate name if possible. * * @param expr Expression * @param name Suggested name */ private void addExpr(RexNode expr, String name) { convertedInputExprs.add(expr); if ((name == null) && (expr instanceof RexInputRef)) { final int i = ((RexInputRef) expr).getIndex(); name = bb.root.getRowType().getFieldList().get(i).getName(); } if (convertedInputExprNames.contains(name)) { // In case like 'SELECT ... GROUP BY x, y, x', don't add // name 'x' twice. name = null; } convertedInputExprNames.add(name); }
private static boolean containsGet(RexNode node) { try { node.accept( new RexVisitorImpl<Void>(true) { @Override public Void visitCall(RexCall call) { if (call.getOperator() == RexBuilder.GET_OPERATOR) { throw Util.FoundOne.NULL; } return super.visitCall(call); } }); return false; } catch (Util.FoundOne e) { return true; } }
/** * Creates an expression with which to reference the expression whose * offset in its from-list is {@code offset}. */ RexNode lookup( int offset, LookupContext lookupContext) { Pair<RelNode, Integer> pair = lookupContext.findRel(offset); return rexBuilder.makeRangeReference( pair.left.getRowType(), pair.right, false); }
public RexDynamicParam convertDynamicParam( final SqlDynamicParam dynamicParam) { // REVIEW jvs 8-Jan-2005: dynamic params may be encountered out of // order. Should probably cross-check with the count from the parser // at the end and make sure they all got filled in. Why doesn't List // have a resize() method?!? Make this a utility. while (dynamicParam.getIndex() >= dynamicParamSqlNodes.size()) { dynamicParamSqlNodes.add(null); } dynamicParamSqlNodes.set( dynamicParam.getIndex(), dynamicParam); return rexBuilder.makeDynamicParam( getDynamicParamType(dynamicParam.getIndex()), dynamicParam.getIndex()); }
private void fix(List<RexNode> operands, int before, int after) { if (before == after) { return; } for (int i = 0; i < operands.size(); i++) { RexNode node = operands.get(i); operands.set(i, RexUtil.shift(node, before, after - before)); } }
private int lookupOrCreateGroupExpr(RexNode expr) { for (int i = 0; i < convertedInputExprs.size(); i++) { RexNode convertedInputExpr = convertedInputExprs.get(i); if (expr.toString().equals(convertedInputExpr.toString())) { return i; } } // not found -- add it int index = convertedInputExprs.size(); addExpr(expr, null); return index; }
private RelNode convertCursor(Blackboard bb, SubQuery subQuery) { final SqlCall cursorCall = (SqlCall) subQuery.node; assert cursorCall.operandCount() == 1; SqlNode query = cursorCall.operand(0); RelNode converted = convertQuery(query, false, false); int iCursor = bb.cursors.size(); bb.cursors.add(converted); subQuery.expr = new RexInputRef( iCursor, converted.getRowType()); return converted; }
RelDataTypeField getRootField(RexInputRef inputRef) { int fieldOffset = inputRef.getIndex(); for (RelNode input : inputs) { RelDataType rowType = input.getRowType(); if (rowType == null) { // TODO: remove this once leastRestrictive // is correctly implemented return null; } if (fieldOffset < rowType.getFieldCount()) { return rowType.getFieldList().get(fieldOffset); } fieldOffset -= rowType.getFieldCount(); } throw new AssertionError(); }
public RexNode newColumnDefaultValue( RelOptTable table, int iColumn) { return rexBuilder.constantNull(); }