当前位置: 首页>>代码示例>>Java>>正文


Java RexUtil.createStructType方法代码示例

本文整理汇总了Java中org.apache.calcite.rex.RexUtil.createStructType方法的典型用法代码示例。如果您正苦于以下问题:Java RexUtil.createStructType方法的具体用法?Java RexUtil.createStructType怎么用?Java RexUtil.createStructType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.rex.RexUtil的用法示例。


在下文中一共展示了RexUtil.createStructType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addRenamedProject

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
protected DrillRel addRenamedProject(DrillRel rel, RelDataType validatedRowType) {
  RelDataType t = rel.getRowType();

  RexBuilder b = rel.getCluster().getRexBuilder();
  List<RexNode> projections = Lists.newArrayList();
  int projectCount = t.getFieldList().size();

  for (int i =0; i < projectCount; i++) {
    projections.add(b.makeInputRef(rel, i));
  }

  final List<String> fieldNames2 = SqlValidatorUtil.uniquify(validatedRowType.getFieldNames(), SqlValidatorUtil.F_SUGGESTER2);

  RelDataType newRowType = RexUtil.createStructType(rel.getCluster().getTypeFactory(), projections, fieldNames2);

  DrillProjectRel topProj = DrillProjectRel.create(rel.getCluster(), rel.getTraitSet(), rel, projections, newRowType);

  // Add a final non-trivial Project to get the validatedRowType, if child is not project.
  if (rel instanceof Project && DrillRelOptUtil.isTrivialProject(topProj, true)) {
    return rel;
  } else{
    return topProj;
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:25,代码来源:DefaultSqlHandler.java

示例2: visit

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
private Prel visit(ExchangePrel hashPrel, List<DistributionTrait.DistributionField> fields, Prel child) {
  final List<String> childFields = child.getRowType().getFieldNames();


  // Insert Project SqlOperatorImpl with new column that will be a hash for HashToRandomExchange fields
  final ProjectPrel addColumnprojectPrel = HashPrelUtil.addHashProject(fields, child, null);
  final Prel newPrel = (Prel) hashPrel.copy(addColumnprojectPrel.getTraitSet(), Collections.<RelNode>singletonList(addColumnprojectPrel));

  int validRows = newPrel.getRowType().getFieldCount() - 1;
  final List<RelDataTypeField> all = newPrel.getRowType().getFieldList();
  final List<RexNode> keptExprs = new ArrayList<>(validRows);

  final RexBuilder rexBuilder = newPrel.getCluster().getRexBuilder();
  for(int i = 0; i < validRows; i++){
    RexNode rex = rexBuilder.makeInputRef(all.get(i).getType(), i);
    keptExprs.add(rex);
  }

  // remove earlier inserted Project SqlOperatorImpl - since it creates issues down the road in HashJoin
  RelDataType removeRowType = RexUtil.createStructType(newPrel.getCluster().getTypeFactory(), keptExprs, childFields);
  return new ProjectPrel(newPrel.getCluster(), newPrel.getTraitSet(), newPrel, keptExprs, removeRowType);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:InsertHashProjectVisitor.java

示例3: insertProjUnderScreenOrWriter

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
private Prel insertProjUnderScreenOrWriter(Prel prel, RelDataType origRowType, Prel child) {

    ProjectPrel proj = null;
    List<RelNode> children = Lists.newArrayList();

    List<RexNode> exprs = Lists.newArrayList();
    for (int i = 0; i < origRowType.getFieldCount(); i++) {
      RexNode expr = child.getCluster().getRexBuilder().makeInputRef(origRowType.getFieldList().get(i).getType(), i);
      exprs.add(expr);
    }

    RelDataType newRowType = RexUtil.createStructType(child.getCluster().getTypeFactory(), exprs, origRowType.getFieldNames());

    int fieldCount = prel.getRowType().isStruct()? prel.getRowType().getFieldCount():1;

    // Insert PUS/PUW : remove the prefix and keep the original field name.
    if (fieldCount > 1) { // // no point in allowing duplicates if we only have one column
      proj = new ProjectAllowDupPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
    } else {
      proj = new ProjectPrel(child.getCluster(), child.getTraitSet(), child, exprs, newRowType);
    }

    children.add(proj);
    return (Prel) prel.copy(prel.getTraitSet(), children);
  }
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:StarColumnConverter.java

示例4: createProject

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
/**
 * Creates a relational expression which projects an array of expressions,
 * and optionally optimizes.
 *
 * <p>The result may not be a
 * {@link org.apache.calcite.rel.logical.LogicalProject}. If the
 * projection is trivial, <code>child</code> is returned directly; and future
 * versions may return other formulations of expressions, such as
 * {@link org.apache.calcite.rel.logical.LogicalCalc}.
 *
 * @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.
 * @param relBuilder     Factory to create project operators
 */
public static RelNode createProject(
    RelNode child,
    List<? extends RexNode> exprs,
    List<String> fieldNames,
    boolean optimize,
    RelBuilder relBuilder) {
  final RelOptCluster cluster = child.getCluster();
  final RelDataType rowType =
      RexUtil.createStructType(cluster.getTypeFactory(), exprs,
          fieldNames, SqlValidatorUtil.F_SUGGESTER);
  if (optimize
      && RexUtil.isIdentity(exprs, child.getRowType())) {
    if (child instanceof Project && fieldNames != null) {
      // Rename columns of child projection if desired field names are given.
      Project childProject = (Project) child;
      child = childProject.copy(childProject.getTraitSet(),
          childProject.getInput(), childProject.getProjects(), rowType);
    }
    return child;
  }
  relBuilder.push(child);
  relBuilder.project(exprs, rowType.getFieldNames(), !optimize);
  return relBuilder.build();
}
 
开发者ID:apache,项目名称:calcite,代码行数:42,代码来源:RelOptUtil.java

示例5: createProject

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
@Override
public RelNode createProject(RelNode child,
                             List<? extends RexNode> childExprs, List<String> fieldNames) {
  final RelOptCluster cluster = child.getCluster();
  final RelDataType rowType = RexUtil.createStructType(cluster.getTypeFactory(), childExprs, fieldNames);
  final RelNode project = DrillProjectRel.create(cluster, child.getTraitSet(), child, childExprs, rowType);

  return project;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:10,代码来源:DrillRelFactories.java

示例6: rename

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
private RelNode rename(RelNode input, List<RelDataTypeField> inputFields, List<String> outputFieldNames) {
  List<RexNode> exprs = Lists.newArrayList();

  for (RelDataTypeField field : inputFields) {
    RexNode expr = input.getCluster().getRexBuilder().makeInputRef(field.getType(), field.getIndex());
    exprs.add(expr);
  }

  RelDataType rowType = RexUtil.createStructType(input.getCluster().getTypeFactory(), exprs, outputFieldNames);

  ProjectPrel proj = new ProjectPrel(input.getCluster(), input.getTraitSet(), input, exprs, rowType);

  return proj;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:15,代码来源:JoinPrel.java

示例7: visitScan

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
@Override
public Prel visitScan(ScanPrel scanPrel, Void value) throws RuntimeException {
  if (StarColumnHelper.containsStarColumn(scanPrel.getRowType()) && prefixedForStar ) {

    List<RexNode> exprs = Lists.newArrayList();

    for (RelDataTypeField field : scanPrel.getRowType().getFieldList()) {
      RexNode expr = scanPrel.getCluster().getRexBuilder().makeInputRef(field.getType(), field.getIndex());
      exprs.add(expr);
    }

    List<String> fieldNames = Lists.newArrayList();

    long tableId = tableNumber.getAndIncrement();

    for (String name : scanPrel.getRowType().getFieldNames()) {
      if (StarColumnHelper.isNonPrefixedStarColumn(name)) {
        fieldNames.add("T" +  tableId + StarColumnHelper.PREFIX_DELIMITER + name);  // Add prefix to * column.
      } else {
        fieldNames.add(name);  // Keep regular column as it is.
      }
    }
    RelDataType rowType = RexUtil.createStructType(scanPrel.getCluster().getTypeFactory(), exprs, fieldNames);

    // insert a PAS.
    ProjectPrel proj = new ProjectPrel(scanPrel.getCluster(), scanPrel.getTraitSet(), scanPrel, exprs, rowType);

    return proj;
  } else {
    return visitPrel(scanPrel, value);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:33,代码来源:StarColumnConverter.java

示例8: createProject

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
@Override
public RelNode createProject(RelNode child,
                             List<? extends RexNode> childExprs, List<String> fieldNames) {
  final RelOptCluster cluster = child.getCluster();
  final RelDataType rowType = RexUtil.createStructType(cluster.getTypeFactory(), childExprs, fieldNames, SqlValidatorUtil.F_SUGGESTER);
  final RelNode project = ProjectRel.create(cluster, child.getTraitSet().plus(Rel.LOGICAL), child, childExprs, rowType);

  return project;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:10,代码来源:DremioRelFactories.java

示例9: addHashProject

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
public static ProjectPrel addHashProject(List<DistributionField> distFields, Prel input, Integer ringCount){

    // Insert Project SqlOperatorImpl with new column that will be a hash for HashToRandomExchange fields

    final List<String> outputFieldNames = Lists.newArrayList(input.getRowType().getFieldNames());
    final String fieldName = ringCount == null ? HashPrelUtil.HASH_EXPR_NAME : WriterPrel.BUCKET_NUMBER_FIELD;
    outputFieldNames.add(fieldName);

    final RexBuilder rexBuilder = input.getCluster().getRexBuilder();
    final List<RelDataTypeField> childRowTypeFields = input.getRowType().getFieldList();

    // create new hashed field.
    final HashExpressionCreatorHelper<RexNode> hashHelper = new RexNodeBasedHashExpressionCreatorHelper(rexBuilder);
    final List<RexNode> distFieldRefs = Lists.newArrayListWithExpectedSize(distFields.size());
    for(int i = 0; i < distFields.size(); i++) {
      final int fieldId = distFields.get(i).getFieldId();
      distFieldRefs.add(rexBuilder.makeInputRef(childRowTypeFields.get(fieldId).getType(), fieldId));
    }

    final List <RexNode> updatedExpr = Lists.newArrayListWithExpectedSize(childRowTypeFields.size() + 1);
    for ( RelDataTypeField field : childRowTypeFields) {
      RexNode rex = rexBuilder.makeInputRef(field.getType(), field.getIndex());
      updatedExpr.add(rex);
    }
    RexNode hashExpression = HashPrelUtil.createHashBasedPartitionExpression(distFieldRefs, hashHelper);

    if(ringCount != null){
      RelDataType intType = input.getCluster().getTypeFactory().createSqlType(SqlTypeName.INTEGER);
      hashExpression = rexBuilder.makeCall(SqlStdOperatorTable.MOD, ImmutableList.of(hashExpression, rexBuilder.makeExactLiteral(BigDecimal.valueOf(ringCount), intType)));
      hashExpression = rexBuilder.makeCall(SqlStdOperatorTable.ABS, Collections.singletonList(hashExpression));
    }
    updatedExpr.add(hashExpression);

    RelDataType rowType = RexUtil.createStructType(input.getCluster().getTypeFactory(), updatedExpr, outputFieldNames);

    ProjectPrel addColumnprojectPrel = new ProjectPrel(input.getCluster(), input.getTraitSet(), input, updatedExpr, rowType);
    return addColumnprojectPrel;
  }
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:39,代码来源:HashPrelUtil.java

示例10: visitOldScan

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
@Override
public Prel visitOldScan(OldScanPrel scanPrel, Void value) throws RuntimeException {
  if (StarColumnHelper.containsStarColumn(scanPrel.getRowType()) && prefixedForStar ) {

    List<RexNode> exprs = Lists.newArrayList();

    for (RelDataTypeField field : scanPrel.getRowType().getFieldList()) {
      RexNode expr = scanPrel.getCluster().getRexBuilder().makeInputRef(field.getType(), field.getIndex());
      exprs.add(expr);
    }

    List<String> fieldNames = Lists.newArrayList();

    long tableId = tableNumber.getAndIncrement();

    for (String name : scanPrel.getRowType().getFieldNames()) {
      if (StarColumnHelper.isNonPrefixedStarColumn(name)) {
        fieldNames.add("T" +  tableId + StarColumnHelper.PREFIX_DELIMITER + name);  // Add prefix to * column.
      } else {
        fieldNames.add(name);  // Keep regular column as it is.
      }
    }
    RelDataType rowType = RexUtil.createStructType(scanPrel.getCluster().getTypeFactory(), exprs, fieldNames);

    // insert a PAS.
    ProjectPrel proj = new ProjectPrel(scanPrel.getCluster(), scanPrel.getTraitSet(), scanPrel, exprs, rowType);

    return proj;
  } else {
    return visitPrel(scanPrel, value);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:33,代码来源:StarColumnConverter.java

示例11: visitScan

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
@Override
public Prel visitScan(ScanPrelBase scanPrel, Void value) throws RuntimeException {
  if (StarColumnHelper.containsStarColumn(scanPrel.getRowType()) && prefixedForStar ) {

    List<RexNode> exprs = Lists.newArrayList();

    for (RelDataTypeField field : scanPrel.getRowType().getFieldList()) {
      RexNode expr = scanPrel.getCluster().getRexBuilder().makeInputRef(field.getType(), field.getIndex());
      exprs.add(expr);
    }

    List<String> fieldNames = Lists.newArrayList();

    long tableId = tableNumber.getAndIncrement();

    for (String name : scanPrel.getRowType().getFieldNames()) {
      if (StarColumnHelper.isNonPrefixedStarColumn(name)) {
        fieldNames.add("T" +  tableId + StarColumnHelper.PREFIX_DELIMITER + name);  // Add prefix to * column.
      } else {
        fieldNames.add(name);  // Keep regular column as it is.
      }
    }
    RelDataType rowType = RexUtil.createStructType(scanPrel.getCluster().getTypeFactory(), exprs, fieldNames);

    // insert a PAS.
    ProjectPrel proj = new ProjectPrel(scanPrel.getCluster(), scanPrel.getTraitSet(), scanPrel, exprs, rowType);

    return proj;
  } else {
    return visitPrel(scanPrel, value);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:33,代码来源:StarColumnConverter.java

示例12: addRenamedProject

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
public static Rel addRenamedProject(SqlHandlerConfig config, Rel rel, RelDataType validatedRowType) {
  RelDataType t = rel.getRowType();

  RexBuilder b = rel.getCluster().getRexBuilder();
  List<RexNode> projections = Lists.newArrayList();
  int projectCount = t.getFieldList().size();

  for (int i =0; i < projectCount; i++) {
    projections.add(b.makeInputRef(rel, i));
  }

  final List<String> fieldNames2 = SqlValidatorUtil.uniquify(
          validatedRowType.getFieldNames(),
          SqlValidatorUtil.F_SUGGESTER,
          rel.getCluster().getTypeFactory().getTypeSystem().isSchemaCaseSensitive());

  RelDataType newRowType = RexUtil.createStructType(rel.getCluster().getTypeFactory(), projections, fieldNames2);

  ProjectRel topProj = ProjectRel.create(rel.getCluster(), rel.getTraitSet(), rel, projections, newRowType);

  final boolean hasAnyType = Iterables.find(
      validatedRowType.getFieldList(),
      new Predicate<RelDataTypeField>() {
        @Override
        public boolean apply(@Nullable RelDataTypeField input) {
          return input.getType().getSqlTypeName() == SqlTypeName.ANY;
        }
      },
      null
  ) != null;

  // Add a final non-trivial Project to get the validatedRowType, if child is not project or the input row type
  // contains at least one field of type ANY
  if (rel instanceof Project && MoreRelOptUtil.isTrivialProject(topProj, true) && !hasAnyType) {
    return rel;
  }

  return topProj;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:40,代码来源:PrelTransformer.java

示例13: addTopProjectPrel

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
/**
 * Adds top project to ensure final output field names are preserved.
 * In case of duplicated column names, will rename duplicates.
 * Top project will be added only if top project is non-trivial and
 * child physical relational node is not project.
 *
 * @param prel physical relational node
 * @param validatedRowType final output row type
 * @return physical relational node with top project if necessary
 */
private Prel addTopProjectPrel(Prel prel, RelDataType validatedRowType) {
  RelDataType rowType = prel.getRowType();
  if (rowType.getFieldCount() != validatedRowType.getFieldCount()) {
    return prel;
  }

  RexBuilder rexBuilder = prel.getCluster().getRexBuilder();
  List<RexNode> projections = new ArrayList<>();
  int projectCount = rowType.getFieldList().size();

  for (int i = 0; i < projectCount; i++) {
    projections.add(rexBuilder.makeInputRef(prel, i));
  }

  List<String> fieldNames = SqlValidatorUtil.uniquify(
      validatedRowType.getFieldNames(),
      SqlValidatorUtil.F_SUGGESTER2,
      prel.getCluster().getTypeFactory().getTypeSystem().isSchemaCaseSensitive());

  RelDataType newRowType = RexUtil.createStructType(prel.getCluster().getTypeFactory(), projections, fieldNames, null);
  ProjectPrel topProject = new ProjectPrel(prel.getCluster(),
      prel.getTraitSet(),
      prel,
      projections,
      newRowType,
      true);  //outputProj = true : NONE -> OK_NEW_SCHEMA, also handle expression with NULL type.

  if (prel instanceof Project && DrillRelOptUtil.isTrivialProject(topProject, true)) {
    return new ProjectPrel(prel.getCluster(),
        prel.getTraitSet(),
        ((Project) prel).getInput(),
        ((Project) prel).getProjects(),
        prel.getRowType(),
        true); //outputProj = true : NONE -> OK_NEW_SCHEMA, also handle expression with NULL type.
  } else {
    return topProject;
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:49,代码来源:TopProjectVisitor.java

示例14: addRenamedProject

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
protected DrillRel addRenamedProject(DrillRel rel, RelDataType validatedRowType) {
  RelDataType t = rel.getRowType();

  RexBuilder b = rel.getCluster().getRexBuilder();
  List<RexNode> projections = Lists.newArrayList();
  int projectCount = t.getFieldList().size();

  for (int i =0; i < projectCount; i++) {
    projections.add(b.makeInputRef(rel, i));
  }

  final List<String> fieldNames2 = SqlValidatorUtil.uniquify(
      validatedRowType.getFieldNames(),
      SqlValidatorUtil.F_SUGGESTER2,
      rel.getCluster().getTypeFactory().getTypeSystem().isSchemaCaseSensitive());

  RelDataType newRowType = RexUtil.createStructType(rel.getCluster().getTypeFactory(), projections, fieldNames2);

  DrillProjectRel topProj = DrillProjectRel.create(rel.getCluster(), rel.getTraitSet(), rel, projections, newRowType);

  // Add a final non-trivial Project to get the validatedRowType, if child is not project.
  if (rel instanceof Project && DrillRelOptUtil.isTrivialProject(topProj, true)) {
    return rel;
  } else{
    return topProj;
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:28,代码来源:DefaultSqlHandler.java

示例15: of

import org.apache.calcite.rex.RexUtil; //导入方法依赖的package包/类
/**
 * Creates a MutableProject.
 *
 * @param input         Input relational expression
 * @param exprList      List of expressions for the input columns
 * @param fieldNameList Aliases of the expressions, or null to generate
 */
public static MutableRel of(MutableRel input, List<RexNode> exprList,
    List<String> fieldNameList) {
  final RelDataType rowType =
      RexUtil.createStructType(input.cluster.getTypeFactory(), exprList,
          fieldNameList, SqlValidatorUtil.F_SUGGESTER);
  return of(rowType, input, exprList);
}
 
开发者ID:apache,项目名称:calcite,代码行数:15,代码来源:MutableProject.java


注:本文中的org.apache.calcite.rex.RexUtil.createStructType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。