/** * Converts an expression from {@link SqlNode} to {@link RexNode} format, * mapping identifier references to predefined expressions. * * @param node Expression to translate * @param nameToNodeMap map from String to {@link RexNode}; when an * {@link SqlIdentifier} is encountered, it is used as a * key and translated to the corresponding value from * this map * @return Converted expression */ public RexNode convertExpression( SqlNode node, Map<String, RexNode> nameToNodeMap) { final Map<String, RelDataType> nameToTypeMap = new HashMap<>(); for (Map.Entry<String, RexNode> entry : nameToNodeMap.entrySet()) { nameToTypeMap.put(entry.getKey(), entry.getValue().getType()); } final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap); final Blackboard bb = createBlackboard(scope, nameToNodeMap, false); return bb.convertExpression(node); }
/** * Converts an expression from {@link SqlNode} to {@link RexNode} format, * mapping identifier references to predefined expressions. * * @param node Expression to translate * @param nameToNodeMap map from String to {@link RexNode}; when an * {@link SqlIdentifier} is encountered, it is used as a * key and translated to the corresponding value from * this map * @return Converted expression */ public RexNode convertExpression( SqlNode node, Map<String, RexNode> nameToNodeMap) { final Map<String, RelDataType> nameToTypeMap = new HashMap<>(); for (Map.Entry<String, RexNode> entry : nameToNodeMap.entrySet()) { nameToTypeMap.put(entry.getKey(), entry.getValue().getType()); } final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap); final Blackboard bb = createBlackboard(scope, nameToNodeMap, false); return bb.convertExpression(node); }
/** * Converts an expression from {@link SqlNode} to {@link RexNode} format, * mapping identifier references to predefined expressions. * * @param node Expression to translate * @param nameToNodeMap map from String to {@link RexNode}; when an * {@link SqlIdentifier} is encountered, it is used as a * key and translated to the corresponding value from * this map * @return Converted expression */ public RexNode convertExpression( SqlNode node, Map<String, RexNode> nameToNodeMap) { final Map<String, RelDataType> nameToTypeMap = new HashMap<>(); for (Map.Entry<String, RexNode> entry : nameToNodeMap.entrySet()) { nameToTypeMap.put(entry.getKey(), entry.getValue().getType()); } final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap); final Blackboard bb = createBlackboard(scope, nameToNodeMap, false); return bb.convertExpression(node); }
private RelNode convertUpdate(SqlUpdate call) { final SqlValidatorScope scope = validator.getWhereScope(call.getSourceSelect()); Blackboard bb = createBlackboard(scope, null, false); Builder<RexNode> rexNodeSourceExpressionListBuilder = ImmutableList.builder(); for (SqlNode n : call.getSourceExpressionList()) { RexNode rn = bb.convertExpression(n); rexNodeSourceExpressionListBuilder.add(rn); } RelOptTable targetTable = getTargetTable(call); // convert update column list from SqlIdentifier to String final List<String> targetColumnNameList = new ArrayList<>(); final RelDataType targetRowType = targetTable.getRowType(); for (SqlNode node : call.getTargetColumnList()) { SqlIdentifier id = (SqlIdentifier) node; RelDataTypeField field = SqlValidatorUtil.getTargetField( targetRowType, typeFactory, id, catalogReader, targetTable); assert field != null : "column " + id.toString() + " not found"; targetColumnNameList.add(field.getName()); } RelNode sourceRel = convertSelect(call.getSourceSelect(), false); return LogicalTableModify.create(targetTable, catalogReader, sourceRel, LogicalTableModify.Operation.UPDATE, targetColumnNameList, rexNodeSourceExpressionListBuilder.build(), false); }
/** * Converts an expression from {@link SqlNode} to {@link RexNode} format, * mapping identifier references to predefined expressions. * * @param node Expression to translate * @param nameToNodeMap map from String to {@link RexNode}; when an * {@link SqlIdentifier} is encountered, it is used as a * key and translated to the corresponding value from * this map * @return Converted expression */ public RexNode convertExpression( SqlNode node, Map<String, RexNode> nameToNodeMap) { final Map<String, RelDataType> nameToTypeMap = new HashMap<>(); for (Map.Entry<String, RexNode> entry : nameToNodeMap.entrySet()) { nameToTypeMap.put(entry.getKey(), entry.getValue().getType()); } final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap); final Blackboard bb = createBlackboard(scope, nameToNodeMap, false); return bb.convertExpression(node); }
private RelNode convertUpdate(SqlUpdate call) { final SqlValidatorScope scope = validator.getWhereScope(call.getSourceSelect()); Blackboard bb = createBlackboard(scope, null, false); Builder<RexNode> rexNodeSourceExpressionListBuilder = ImmutableList.builder(); for (SqlNode n : call.getSourceExpressionList()) { RexNode rn = bb.convertExpression(n); rexNodeSourceExpressionListBuilder.add(rn); } RelOptTable targetTable = getTargetTable(call); // convert update column list from SqlIdentifier to String final List<String> targetColumnNameList = new ArrayList<>(); final RelDataType targetRowType = targetTable.getRowType(); for (SqlNode node : call.getTargetColumnList()) { SqlIdentifier id = (SqlIdentifier) node; RelDataTypeField field = SqlValidatorUtil.getTargetField( targetRowType, typeFactory, id, catalogReader, targetTable); assert field != null : "column " + id.toString() + " not found"; targetColumnNameList.add(field.getName()); } RelNode sourceRel = convertSelect(call.getSourceSelect(), false); return LogicalTableModify.create(targetTable, catalogReader, sourceRel, LogicalTableModify.Operation.UPDATE, targetColumnNameList, rexNodeSourceExpressionListBuilder.build(), false); }
private RelNode convertUpdate(SqlUpdate call) { final SqlValidatorScope scope = validator.getWhereScope(call.getSourceSelect()); Blackboard bb = createBlackboard(scope, null, false); Builder<RexNode> rexNodeSourceExpressionListBuilder = ImmutableList.builder(); for (SqlNode n : call.getSourceExpressionList()) { RexNode rn = bb.convertExpression(n); rexNodeSourceExpressionListBuilder.add(rn); } RelOptTable targetTable = getTargetTable(call); // convert update column list from SqlIdentifier to String final List<String> targetColumnNameList = new ArrayList<>(); final RelDataType targetRowType = targetTable.getRowType(); for (SqlNode node : call.getTargetColumnList()) { SqlIdentifier id = (SqlIdentifier) node; RelDataTypeField field = SqlValidatorUtil.getTargetField( targetRowType, typeFactory, id, catalogReader, targetTable); assert field != null : "column " + id.toString() + " not found"; targetColumnNameList.add(field.getName()); } RelNode sourceRel = convertSelect(call.getSourceSelect(), false); return LogicalTableModify.create(targetTable, catalogReader, sourceRel, LogicalTableModify.Operation.UPDATE, targetColumnNameList, rexNodeSourceExpressionListBuilder.build(), false); }
private RelNode convertUpdate(SqlUpdate call) { final SqlValidatorScope scope = validator.getWhereScope(call.getSourceSelect()); Blackboard bb = createBlackboard(scope, null, false); Builder<RexNode> rexNodeSourceExpressionListBuilder = ImmutableList.builder(); for (SqlNode n : call.getSourceExpressionList()) { RexNode rn = bb.convertExpression(n); rexNodeSourceExpressionListBuilder.add(rn); } RelOptTable targetTable = getTargetTable(call); // convert update column list from SqlIdentifier to String final List<String> targetColumnNameList = new ArrayList<>(); final RelDataType targetRowType = targetTable.getRowType(); for (SqlNode node : call.getTargetColumnList()) { SqlIdentifier id = (SqlIdentifier) node; RelDataTypeField field = SqlValidatorUtil.getTargetField( targetRowType, typeFactory, id, catalogReader, targetTable); assert field != null : "column " + id.toString() + " not found"; targetColumnNameList.add(field.getName()); } RelNode sourceRel = convertSelect(call.getSourceSelect(), false); return LogicalTableModify.create(targetTable, catalogReader, sourceRel, LogicalTableModify.Operation.UPDATE, targetColumnNameList, rexNodeSourceExpressionListBuilder.build(), false); }
public int addGroupExpr(SqlNode expr) { int ref = lookupGroupExpr(expr); if (ref >= 0) { return ref; } final int index = groupExprs.size(); groupExprs.add(expr); String name = nameMap.get(expr.toString()); RexNode convExpr = bb.convertExpression(expr); addExpr(convExpr, name); if (expr instanceof SqlCall) { SqlCall call = (SqlCall) expr; for (Pair<SqlNode, AuxiliaryConverter> p : SqlStdOperatorTable.convertGroupToAuxiliaryCalls(call)) { addAuxiliaryGroupExpr(p.left, index, p.right); } } return index; }
public int addGroupExpr(SqlNode expr) { int ref = lookupGroupExpr(expr); if (ref >= 0) { return ref; } final int index = groupExprs.size(); groupExprs.add(expr); String name = nameMap.get(expr.toString()); RexNode convExpr = bb.convertExpression(expr); addExpr(convExpr, name); if (expr instanceof SqlCall) { SqlCall call = (SqlCall) expr; for (Pair<SqlNode, AuxiliaryConverter> p : SqlStdOperatorTable.convertGroupToAuxiliaryCalls(call)) { addAuxiliaryGroupExpr(p.left, index, p.right); } } return index; }
public int addGroupExpr(SqlNode expr) { int ref = lookupGroupExpr(expr); if (ref >= 0) { return ref; } final int index = groupExprs.size(); groupExprs.add(expr); String name = nameMap.get(expr.toString()); RexNode convExpr = bb.convertExpression(expr); addExpr(convExpr, name); if (expr instanceof SqlCall) { SqlCall call = (SqlCall) expr; for (Pair<SqlNode, AuxiliaryConverter> p : SqlStdOperatorTable.convertGroupToAuxiliaryCalls(call)) { addAuxiliaryGroupExpr(p.left, index, p.right); } } return index; }
public int addGroupExpr(SqlNode expr) { int ref = lookupGroupExpr(expr); if (ref >= 0) { return ref; } final int index = groupExprs.size(); groupExprs.add(expr); String name = nameMap.get(expr.toString()); RexNode convExpr = bb.convertExpression(expr); addExpr(convExpr, name); if (expr instanceof SqlCall) { SqlCall call = (SqlCall) expr; for (Pair<SqlNode, AuxiliaryConverter> p : SqlStdOperatorTable.convertGroupToAuxiliaryCalls(call)) { addAuxiliaryGroupExpr(p.left, index, p.right); } } return index; }
/** * Converts an item in an ORDER BY clause, extracting DESC, NULLS LAST * and NULLS FIRST flags first. */ public RexNode convertSortExpression(SqlNode expr, Set<SqlKind> flags) { switch (expr.getKind()) { case DESCENDING: case NULLS_LAST: case NULLS_FIRST: flags.add(expr.getKind()); final SqlNode operand = ((SqlCall) expr).operand(0); return convertSortExpression(operand, flags); default: return convertExpression(expr); } }
/** * Converts an item in an ORDER BY clause, extracting DESC, NULLS LAST * and NULLS FIRST flags first. */ public RexNode convertSortExpression(SqlNode expr, Set<SqlKind> flags) { switch (expr.getKind()) { case DESCENDING: case NULLS_LAST: case NULLS_FIRST: flags.add(expr.getKind()); final SqlNode operand = ((SqlCall) expr).operand(0); return convertSortExpression(operand, flags); default: return convertExpression(expr); } }
/** * Converts an expression from {@link SqlNode} to {@link RexNode} format. * * @param node Expression to translate * @return Converted expression */ public RexNode convertExpression( SqlNode node) { Map<String, RelDataType> nameToTypeMap = Collections.emptyMap(); final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap); final Blackboard bb = createBlackboard(scope, null, false); return bb.convertExpression(node); }
/** * Converts an expression from {@link SqlNode} to {@link RexNode} format. * * @param node Expression to translate * @return Converted expression */ public RexNode convertExpression( SqlNode node) { Map<String, RelDataType> nameToTypeMap = Collections.emptyMap(); final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap); final Blackboard bb = createBlackboard(scope, null, false); return bb.convertExpression(node); }
/** * Converts an expression from {@link SqlNode} to {@link RexNode} format. * * @param node Expression to translate * @return Converted expression */ public RexNode convertExpression( SqlNode node) { Map<String, RelDataType> nameToTypeMap = Collections.emptyMap(); final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap); final Blackboard bb = createBlackboard(scope, null, false); return bb.convertExpression(node); }
/** * Converts an expression from {@link SqlNode} to {@link RexNode} format. * * @param node Expression to translate * @return Converted expression */ public RexNode convertExpression( SqlNode node) { Map<String, RelDataType> nameToTypeMap = Collections.emptyMap(); final ParameterScope scope = new ParameterScope((SqlValidatorImpl) validator, nameToTypeMap); final Blackboard bb = createBlackboard(scope, null, false); return bb.convertExpression(node); }
public RexNode apply(Pair<RexNode, SqlNode> pair) { return rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, pair.left, ensureSqlType(pair.left.getType(), bb.convertExpression(pair.right))); } }),
public RexNode apply(Pair<RexNode, SqlNode> pair) { return rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, pair.left, ensureSqlType(pair.left.getType(), bb.convertExpression(pair.right))); } }),