Esempio n. 1
0
 /** Creates a result based on a single relational expression. */
 public Result result(SqlNode node, Collection<Clause> clauses, RelNode rel) {
   final String alias2 = SqlValidatorUtil.getAlias(node, -1);
   final String alias3 = alias2 != null ? alias2 : "t";
   final String alias4 =
       SqlValidatorUtil.uniquify(alias3, aliasSet, SqlValidatorUtil.EXPR_SUGGESTER);
   final String alias5 = alias2 == null || !alias2.equals(alias4) ? alias4 : null;
   return new Result(
       node, clauses, alias5, Collections.singletonList(Pair.of(alias4, rel.getRowType())));
 }
Esempio n. 2
0
 /**
  * Creates a relational expression which projects an array of expressions, and optionally
  * optimizes.
  *
  * <p>The result may not be a {@link ProjectRel}. If the projection is trivial, <code>child</code>
  * is returned directly; and future versions may return other formulations of expressions, such as
  * {@link CalcRel}.
  *
  * @param child input relational expression
  * @param exprs list of expressions for the input columns
  * @param fieldNames aliases of the expressions, or null to generate
  * @param optimize Whether to return <code>child</code> unchanged if the projections are trivial.
  */
 public static RelNode createProject(
     RelNode child, List<RexNode> exprs, List<String> fieldNames, boolean optimize) {
   final RelOptCluster cluster = child.getCluster();
   final RexProgram program =
       RexProgram.create(child.getRowType(), exprs, null, fieldNames, cluster.getRexBuilder());
   final List<RelCollation> collationList = program.getCollations(child.getCollationList());
   if (DEPRECATE_PROJECT_AND_FILTER) {
     return new CalcRel(
         cluster, child.getTraitSet(), child, program.getOutputRowType(), program, collationList);
   } else {
     final RelDataType rowType =
         RexUtil.createStructType(
             cluster.getTypeFactory(),
             exprs,
             fieldNames == null
                 ? null
                 : SqlValidatorUtil.uniquify(fieldNames, SqlValidatorUtil.F_SUGGESTER));
     if (optimize && RemoveTrivialProjectRule.isIdentity(exprs, rowType, child.getRowType())) {
       return child;
     }
     return new ProjectRel(
         cluster,
         cluster.traitSetOf(
             collationList.isEmpty() ? RelCollationImpl.EMPTY : collationList.get(0)),
         child,
         exprs,
         rowType,
         ProjectRelBase.Flags.BOXED);
   }
 }
Esempio n. 3
0
 public RelDataType createTypeFromProjection(
     final RelDataType type, final List<String> columnNameList) {
   return SqlValidatorUtil.createTypeFromProjection(
       type, columnNameList, typeFactory, caseSensitive);
 }
Esempio n. 4
0
 public RelDataTypeField field(RelDataType rowType, String alias) {
   return SqlValidatorUtil.lookupField(caseSensitive, rowType, alias);
 }