public int size() { return program.getProjectList().size(); } },
private static boolean hasConstants( RexProgram program ) { List<RexLocalRef> projects = program.getProjectList(); for( RexLocalRef project : projects ) { if( program.isConstant( project ) ) return true; } return false; }
public boolean isIdentity() { if( program.getCondition() != null || !program.getInputRowType().equals( program.getOutputRowType() ) ) return false; for( int i = 0; i < program.getProjectList().size(); i++ ) { RexLocalRef ref = program.getProjectList().get( i ); if( ref.getIndex() != i ) return false; } return true; } }
public static List<RexLiteral> getOutputConstantsLiterals( RexProgram program ) { List<RexNode> exprList = program.getExprList(); List<RexLiteral> literals = new ArrayList<RexLiteral>(); List<RexLocalRef> projectList = program.getProjectList(); for( RexLocalRef ref : projectList ) { if( !program.isConstant( ref ) ) continue; literals.add( (RexLiteral) exprList.get( ref.getIndex() ) ); } return literals; }
public static RelDataType getOutputConstantsRowType( RexProgram program ) { RelDataType outputRowType = program.getOutputRowType(); List<RelDataTypeField> fields = new ArrayList<RelDataTypeField>(); List<RexLocalRef> projectList = program.getProjectList(); for( int i = 0; i < projectList.size(); i++ ) { RexLocalRef ref = projectList.get( i ); if( !program.isConstant( ref ) ) continue; fields.add( outputRowType.getFieldList().get( i ) ); } return new RelRecordType( fields ); }
public RexNode get(int index) { final RexLocalRef ref = program.getProjectList().get(index); return new RexInputRef(ref.getIndex(), ref.getType()); }
/** * Translates a {@link RexProgram} to a sequence of expressions and * declarations. * * @param program Program to be translated * @param typeFactory Type factory * @param list List of statements, populated with declarations * @param inputGetter Generates expressions for inputs * @return Sequence of expressions, optional condition */ public static List<Expression> translateProjects( RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, InputGetter inputGetter) { return new RexToLixTranslator(program, typeFactory, inputGetter, list) .translateList(program.getProjectList()); }
private static boolean isStar(RexProgram program) { int i = 0; for (RexLocalRef ref : program.getProjectList()) { if (ref.getIndex() != i++) { return false; } } return i == program.getInputRowType().getFieldCount(); } }
private static boolean isStar(RexProgram program) { int i = 0; for (RexLocalRef ref : program.getProjectList()) { if (ref.getIndex() != i++) { return false; } } return i == program.getInputRowType().getFieldCount(); }
private static boolean hasFunctions( RexProgram program ) { List<RexLocalRef> projects = program.getProjectList(); RelDataType inputRowType = program.getInputRowType(); int fieldCount = inputRowType.getFieldCount(); for( RexLocalRef project : projects ) { if( !program.isConstant( project ) && project.getIndex() >= fieldCount ) return true; } return false; }
private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) { final List<RexNode> exprList = program.getExprList(); final List<RexLocalRef> projectRefList = new ArrayList<RexLocalRef>(); final RexShuttle shuttle = new RegisterOutputShuttle(exprList); // For each project, lookup the expr and expand it so it is in terms of // bottomCalc's input fields for (RexLocalRef topProject : program.getProjectList()) { final RexNode topExpr = exprList.get(topProject.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); // Remember the expr, but don't add to the project list yet. projectRefList.add(expanded); } // Similarly for the condition. final RexLocalRef topCondition = program.getCondition(); if (topCondition != null) { final RexNode topExpr = exprList.get(topCondition.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); addCondition(registerInput(expanded)); } return projectRefList; }
private List<RexLocalRef> registerProjectsAndCondition(RexProgram program) { final List<RexNode> exprList = program.getExprList(); final List<RexLocalRef> projectRefList = new ArrayList<RexLocalRef>(); final RexShuttle shuttle = new RegisterOutputShuttle(exprList); // For each project, lookup the expr and expand it so it is in terms of // bottomCalc's input fields for (RexLocalRef topProject : program.getProjectList()) { final RexNode topExpr = exprList.get(topProject.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); // Remember the expr, but don't add to the project list yet. projectRefList.add(expanded); } // Similarly for the condition. final RexLocalRef topCondition = program.getCondition(); if (topCondition != null) { final RexNode topExpr = exprList.get(topCondition.getIndex()); final RexLocalRef expanded = (RexLocalRef) topExpr.accept(shuttle); addCondition(registerInput(expanded)); } return projectRefList; }
/** * Translates a {@link RexProgram} to a sequence of expressions and * declarations. * * @param program Program to be translated * @param typeFactory Type factory * @param list List of statements, populated with declarations * @param outputPhysType Output type, or null * @param inputGetter Generates expressions for inputs * @return Sequence of expressions, optional condition */ public static List<Expression> translateProjects( RexProgram program, JavaTypeFactory typeFactory, BlockBuilder list, PhysType outputPhysType, InputGetter inputGetter) { List<Type> storageTypes = null; if (outputPhysType != null) { final RelDataType rowType = outputPhysType.getRowType(); storageTypes = new ArrayList<Type>(rowType.getFieldCount()); for (int i = 0; i < rowType.getFieldCount(); i++) { storageTypes.add(outputPhysType.getJavaFieldType(i)); } } return new RexToLixTranslator(program, typeFactory, inputGetter, list) .translateList(program.getProjectList(), storageTypes); }
private static RexProgram renameInputs( RexProgram program, RexBuilder rexBuilder, List<String> names ) { final RelDataType inputRowType = program.getInputRowType(); if( inputRowType.getFieldNames().equals( names ) ) return program; final RexProgramBuilder builder = RexProgramBuilder.create( rexBuilder, rexBuilder.getTypeFactory().createStructType( Pair.zip( names, RelOptUtil.getFieldTypeList( inputRowType ) ) ), program.getExprList(), program.getProjectList(), program.getCondition(), program.getOutputRowType(), false ); return builder.getProgram(); }
assert program.isValid(true); final RelDataType inputRowType = program.getInputRowType(); final List<RexLocalRef> projectRefs = program.getProjectList(); final RexLocalRef conditionRef = program.getCondition(); final List<RexNode> exprs = program.getExprList();
final List<RexLocalRef> projectRefs = program.getProjectList(); final RexLocalRef conditionRef = program.getCondition(); final List<RexNode> exprs = program.getExprList();
public JdbcImplementor.Result implement(JdbcImplementor implementor) { JdbcImplementor.Result x = implementor.visitChild(0, getChild()); final JdbcImplementor.Builder builder = program.getCondition() != null ? x.builder(this, JdbcImplementor.Clause.FROM, JdbcImplementor.Clause.WHERE) : x.builder(this, JdbcImplementor.Clause.FROM); if (!isStar(program)) { final List<SqlNode> selectList = new ArrayList<SqlNode>(); for (RexLocalRef ref : program.getProjectList()) { SqlNode sqlExpr = builder.context.toSql(program, ref); addSelect(selectList, sqlExpr, getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); } if (program.getCondition() != null) { builder.setWhere( builder.context.toSql(program, program.getCondition())); } return builder.result(); } }
public JdbcImplementor.Result implement(JdbcImplementor implementor) { JdbcImplementor.Result x = implementor.visitChild(0, getChild()); final JdbcImplementor.Builder builder = program.getCondition() != null ? x.builder(this, JdbcImplementor.Clause.FROM, JdbcImplementor.Clause.WHERE) : x.builder(this, JdbcImplementor.Clause.FROM); if (!isStar(program)) { final List<SqlNode> selectList = new ArrayList<SqlNode>(); for (RexLocalRef ref : program.getProjectList()) { SqlNode sqlExpr = builder.context.toSql(program, ref); addSelect(selectList, sqlExpr, getRowType()); } builder.setSelect(new SqlNodeList(selectList, POS)); } if (program.getCondition() != null) { builder.setWhere( builder.context.toSql(program, program.getCondition())); } return builder.result(); }
calcRel.getChild().getRowType(), program.getExprList(), program.getProjectList(), program.getCondition(), program.getOutputRowType(),
calcRel.getChild().getRowType(), program.getExprList(), program.getProjectList(), program.getCondition(), program.getOutputRowType(),