• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java RexUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: convertCall

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/** Converts a {@link SqlCall} to a {@link RexCall} with a perhaps different
 * operator. */
private RexNode convertCall(
    SqlRexContext cx,
    SqlCall call,
    SqlOperator op) {
  final List<SqlNode> operands = call.getOperandList();
  final RexBuilder rexBuilder = cx.getRexBuilder();
  final SqlOperandTypeChecker.Consistency consistency =
      op.getOperandTypeChecker() == null
          ? SqlOperandTypeChecker.Consistency.NONE
          : op.getOperandTypeChecker().getConsistency();
  final List<RexNode> exprs =
      convertExpressionList(cx, operands, consistency);
  RelDataType type = rexBuilder.deriveReturnType(op, exprs);
  return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:18,代码来源:ConvertletTable.java


示例2: convert

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
public static DrillJoinRel convert(Join join, ConversionContext context) throws InvalidRelException{
  RelNode left = context.toRel(join.getLeft());
  RelNode right = context.toRel(join.getRight());

  List<RexNode> joinConditions = new ArrayList<RexNode>();
  // right fields appear after the LHS fields.
  final int rightInputOffset = left.getRowType().getFieldCount();
  for (JoinCondition condition : join.getConditions()) {
    RelDataTypeField leftField = left.getRowType().getField(ExprHelper.getFieldName(condition.getLeft()), true, false);
    RelDataTypeField rightField = right.getRowType().getField(ExprHelper.getFieldName(condition.getRight()), true, false);
      joinConditions.add(
          context.getRexBuilder().makeCall(
              SqlStdOperatorTable.EQUALS,
              context.getRexBuilder().makeInputRef(leftField.getType(), leftField.getIndex()),
              context.getRexBuilder().makeInputRef(rightField.getType(), rightInputOffset + rightField.getIndex())
              )
              );
  }
  RexNode rexCondition = RexUtil.composeConjunction(context.getRexBuilder(), joinConditions, false);
  DrillJoinRel joinRel = new DrillJoinRel(context.getCluster(), context.getLogicalTraits(), left, right, rexCondition, join.getJoinType());

  return joinRel;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:24,代码来源:DrillJoinRel.java


示例3: 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


示例4: buildJoinCondition

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
private RexNode buildJoinCondition(RelNode convertedLeft, RelNode convertedRight, List<Integer> leftKeys,
    List<Integer> rightKeys, List<Boolean> filterNulls, RexBuilder builder) {
  List<RexNode> equijoinList = Lists.newArrayList();
  final int numLeftFields = convertedLeft.getRowType().getFieldCount();
  List<RelDataTypeField> leftTypes = convertedLeft.getRowType().getFieldList();
  List<RelDataTypeField> rightTypes = convertedRight.getRowType().getFieldList();

  for (int i=0; i < leftKeys.size(); i++) {
    int leftKeyOrdinal = leftKeys.get(i).intValue();
    int rightKeyOrdinal = rightKeys.get(i).intValue();

    equijoinList.add(builder.makeCall(
        filterNulls.get(i) ? SqlStdOperatorTable.EQUALS : SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
        builder.makeInputRef(leftTypes.get(leftKeyOrdinal).getType(), leftKeyOrdinal),
        builder.makeInputRef(rightTypes.get(rightKeyOrdinal).getType(), rightKeyOrdinal + numLeftFields)
    ));
  }
  return RexUtil.composeConjunction(builder, equijoinList, false);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:JoinRule.java


示例5: convert

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
public static JoinRel convert(Join join, ConversionContext context) throws InvalidRelException{
  RelNode left = context.toRel(join.getLeft());
  RelNode right = context.toRel(join.getRight());

  List<RexNode> joinConditions = new ArrayList<RexNode>();
  // right fields appear after the LHS fields.
  final int rightInputOffset = left.getRowType().getFieldCount();
  for (JoinCondition condition : join.getConditions()) {
    RelDataTypeField leftField = left.getRowType().getField(ExprHelper.getFieldName(condition.getLeft()), true, false);
    RelDataTypeField rightField = right.getRowType().getField(ExprHelper.getFieldName(condition.getRight()), true, false);
      joinConditions.add(
          context.getRexBuilder().makeCall(
              SqlStdOperatorTable.EQUALS,
              context.getRexBuilder().makeInputRef(leftField.getType(), leftField.getIndex()),
              context.getRexBuilder().makeInputRef(rightField.getType(), rightInputOffset + rightField.getIndex())
              )
              );
  }
  RexNode rexCondition = RexUtil.composeConjunction(context.getRexBuilder(), joinConditions, false);
  JoinRel joinRel = new JoinRel(context.getCluster(), context.getLogicalTraits(), left, right, rexCondition, join.getJoinType());

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


示例6: 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


示例7: 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


示例8: convertExpressionList

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
private static List<RexNode> convertExpressionList(SqlRexContext cx,
    List<SqlNode> nodes, SqlOperandTypeChecker.Consistency consistency) {
  final List<RexNode> exprs = Lists.newArrayList();
  for (SqlNode node : nodes) {
    exprs.add(cx.convertExpression(node));
  }
  if (exprs.size() > 1) {
    final RelDataType type =
        consistentType(cx, consistency, RexUtil.types(exprs));
    if (type != null) {
      final List<RexNode> oldExprs = Lists.newArrayList(exprs);
      exprs.clear();
      for (RexNode expr : oldExprs) {
        exprs.add(cx.getRexBuilder().ensureType(type, expr, true));
      }
    }
  }
  return exprs;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:ConvertletTable.java


示例9: convertUsing

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
 * Returns an expression for matching columns of a USING clause or inferred
 * from NATURAL JOIN. "a JOIN b USING (x, y)" becomes "a.x = b.x AND a.y =
 * b.y". Returns null if the column list is empty.
 *
 * @param leftNamespace Namespace of left input to join
 * @param rightNamespace Namespace of right input to join
 * @param nameList List of column names to join on
 * @return Expression to match columns from name list, or true if name list
 * is empty
 */
private RexNode convertUsing(SqlValidatorNamespace leftNamespace,
	SqlValidatorNamespace rightNamespace,
	List<String> nameList) {
	final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
	final List<RexNode> list = Lists.newArrayList();
	for (String name : nameList) {
		List<RexNode> operands = new ArrayList<>();
		int offset = 0;
		for (SqlValidatorNamespace n : ImmutableList.of(leftNamespace,
			rightNamespace)) {
			final RelDataType rowType = n.getRowType();
			final RelDataTypeField field = nameMatcher.field(rowType, name);
			operands.add(
				rexBuilder.makeInputRef(field.getType(),
					offset + field.getIndex()));
			offset += rowType.getFieldList().size();
		}
		list.add(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, operands));
	}
	return RexUtil.composeConjunction(rexBuilder, list, false);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:33,代码来源:SqlToRelConverter.java


示例10: buildJoinCondition

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
private RexNode buildJoinCondition(RelNode convertedLeft, RelNode convertedRight, List<Integer> leftKeys,
    List<Integer> rightKeys, List<Boolean> filterNulls, RexBuilder builder) {
  List<RexNode> equijoinList = Lists.newArrayList();
  final int numLeftFields = convertedLeft.getRowType().getFieldCount();
  List<RelDataTypeField> leftTypes = convertedLeft.getRowType().getFieldList();
  List<RelDataTypeField> rightTypes = convertedRight.getRowType().getFieldList();

  for (int i=0; i < leftKeys.size(); i++) {
    int leftKeyOrdinal = leftKeys.get(i).intValue();
    int rightKeyOrdinal = rightKeys.get(i).intValue();

    equijoinList.add(builder.makeCall(
         filterNulls.get(i) ? SqlStdOperatorTable.EQUALS : SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
         builder.makeInputRef(leftTypes.get(leftKeyOrdinal).getType(), leftKeyOrdinal),
         builder.makeInputRef(rightTypes.get(rightKeyOrdinal).getType(), rightKeyOrdinal + numLeftFields)
    ));
  }
  return RexUtil.composeConjunction(builder, equijoinList, false);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:20,代码来源:DrillJoinRule.java


示例11: convertUsing

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
 * Returns an expression for matching columns of a USING clause or inferred
 * from NATURAL JOIN. "a JOIN b USING (x, y)" becomes "a.x = b.x AND a.y =
 * b.y". Returns null if the column list is empty.
 *
 * @param leftNamespace Namespace of left input to join
 * @param rightNamespace Namespace of right input to join
 * @param nameList List of column names to join on
 * @return Expression to match columns from name list, or true if name list
 * is empty
 */
private RexNode convertUsing(SqlValidatorNamespace leftNamespace,
                             SqlValidatorNamespace rightNamespace,
                             List<String> nameList) {
  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
  final List<RexNode> list = Lists.newArrayList();
  for (String name : nameList) {
    List<RexNode> operands = new ArrayList<>();
    int offset = 0;
    for (SqlValidatorNamespace n : ImmutableList.of(leftNamespace,
        rightNamespace)) {
      final RelDataType rowType = n.getRowType();
      final RelDataTypeField field = nameMatcher.field(rowType, name);
      operands.add(
          rexBuilder.makeInputRef(field.getType(),
              offset + field.getIndex()));
      offset += rowType.getFieldList().size();
    }
    list.add(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, operands));
  }
  return RexUtil.composeConjunction(rexBuilder, list, false);
}
 
开发者ID:apache,项目名称:kylin,代码行数:33,代码来源:SqlToRelConverter.java


示例12: unionPreds

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
 * AND's two predicates together, either of which may be null, removing
 * redundant filters.
 *
 * @param rexBuilder rexBuilder used to construct AND'd RexNode
 * @param pred1      first predicate
 * @param pred2      second predicate
 * @return AND'd predicate or individual predicates if one is null
 */
public static RexNode unionPreds(
    RexBuilder rexBuilder,
    RexNode pred1,
    RexNode pred2) {
  final List<RexNode> unionList = new ArrayList<>();
  final Set<String> strings = new HashSet<>();

  for (RexNode rex : RelOptUtil.conjunctions(pred1)) {
    if (strings.add(rex.toString())) {
      unionList.add(rex);
    }
  }
  for (RexNode rex2 : RelOptUtil.conjunctions(pred2)) {
    if (strings.add(rex2.toString())) {
      unionList.add(rex2);
    }
  }

  return RexUtil.composeConjunction(rexBuilder, unionList, true);
}
 
开发者ID:apache,项目名称:calcite,代码行数:30,代码来源:RelMdUtil.java


示例13: minusPreds

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
 * Takes the difference between two predicates, removing from the first any
 * predicates also in the second
 *
 * @param rexBuilder rexBuilder used to construct AND'd RexNode
 * @param pred1      first predicate
 * @param pred2      second predicate
 * @return MINUS'd predicate list
 */
public static RexNode minusPreds(
    RexBuilder rexBuilder,
    RexNode pred1,
    RexNode pred2) {
  final List<RexNode> list1 = RelOptUtil.conjunctions(pred1);
  final List<RexNode> list2 = RelOptUtil.conjunctions(pred2);
  final List<RexNode> minusList = new ArrayList<>();

  for (RexNode rex1 : list1) {
    boolean add = true;
    for (RexNode rex2 : list2) {
      if (rex2.toString().compareTo(rex1.toString()) == 0) {
        add = false;
        break;
      }
    }
    if (add) {
      minusList.add(rex1);
    }
  }

  return RexUtil.composeConjunction(rexBuilder, minusList, true);
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:RelMdUtil.java


示例14: getSelectivity

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
public Double getSelectivity(Aggregate rel, RelMetadataQuery mq,
    RexNode predicate) {
  final List<RexNode> notPushable = new ArrayList<>();
  final List<RexNode> pushable = new ArrayList<>();
  RelOptUtil.splitFilters(
      rel.getGroupSet(),
      predicate,
      pushable,
      notPushable);
  final RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
  RexNode childPred =
      RexUtil.composeConjunction(rexBuilder, pushable, true);

  Double selectivity = mq.getSelectivity(rel.getInput(), childPred);
  if (selectivity == null) {
    return null;
  } else {
    RexNode pred =
        RexUtil.composeConjunction(rexBuilder, notPushable, true);
    return selectivity * RelMdUtil.guessSelectivity(pred);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:RelMdSelectivity.java


示例15: getPredicates

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/** Infers predicates for a {@link org.apache.calcite.rel.core.SemiJoin}. */
public RelOptPredicateList getPredicates(SemiJoin semiJoin,
    RelMetadataQuery mq) {
  RexBuilder rB = semiJoin.getCluster().getRexBuilder();
  final RelNode left = semiJoin.getInput(0);
  final RelNode right = semiJoin.getInput(1);

  final RelOptPredicateList leftInfo = mq.getPulledUpPredicates(left);
  final RelOptPredicateList rightInfo = mq.getPulledUpPredicates(right);

  JoinConditionBasedPredicateInference jI =
      new JoinConditionBasedPredicateInference(semiJoin,
          RexUtil.composeConjunction(rB, leftInfo.pulledUpPredicates, false),
          RexUtil.composeConjunction(rB, rightInfo.pulledUpPredicates, false));

  return jI.inferPredicates(false);
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:RelMdPredicates.java


示例16: onMatch

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
@Override public void onMatch(RelOptRuleCall call) {
  final Filter filter = call.rel(0);
  final RexBuilder rexBuilder = filter.getCluster().getRexBuilder();
  final String timeZone = filter.getCluster().getPlanner().getContext()
      .unwrap(CalciteConnectionConfig.class).timeZone();
  final RexNode condition =
      replaceTimeUnits(rexBuilder, filter.getCondition(), timeZone);
  if (RexUtil.eq(condition, filter.getCondition())) {
    return;
  }
  final RelBuilder relBuilder =
      relBuilderFactory.create(filter.getCluster(), null);
  relBuilder.push(filter.getInput())
      .filter(condition);
  call.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:DateRangeRules.java


示例17: apply

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) {
  final ImmutableIntList projects;
  final ImmutableList.Builder<RexNode> filters = ImmutableList.builder();
  if (scan instanceof Bindables.BindableTableScan) {
    final Bindables.BindableTableScan bindableScan =
        (Bindables.BindableTableScan) scan;
    filters.addAll(bindableScan.filters);
    projects = bindableScan.projects;
  } else {
    projects = scan.identity();
  }

  final Mapping mapping = Mappings.target(projects,
      scan.getTable().getRowType().getFieldCount());
  filters.add(
      RexUtil.apply(mapping, filter.getCondition()));

  call.transformTo(
      Bindables.BindableTableScan.create(scan.getCluster(), scan.getTable(),
          filters.build(), projects));
}
 
开发者ID:apache,项目名称:calcite,代码行数:22,代码来源:FilterTableScanRule.java


示例18: rewriteRel

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
public void rewriteRel(Sort rel) {
  RelCollation oldCollation = rel.getCollation();
  final RelNode oldChild = rel.getInput();
  final RelNode newChild = getNewForOldRel(oldChild);
  final Mappings.TargetMapping mapping =
      getNewForOldInputMapping(oldChild);

  // validate
  for (RelFieldCollation field : oldCollation.getFieldCollations()) {
    int oldInput = field.getFieldIndex();
    RelDataType sortFieldType =
        oldChild.getRowType().getFieldList().get(oldInput).getType();
    if (sortFieldType.isStruct()) {
      // TODO jvs 10-Feb-2005
      throw Util.needToImplement("sorting on structured types");
    }
  }
  RelCollation newCollation = RexUtil.apply(mapping, oldCollation);
  Sort newRel =
      LogicalSort.create(newChild, newCollation, rel.offset, rel.fetch);
  setNewForOldRel(rel, newRel);
}
 
开发者ID:apache,项目名称:calcite,代码行数:23,代码来源:RelStructuredTypeFlattener.java


示例19: convertUsing

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
 * Returns an expression for matching columns of a USING clause or inferred
 * from NATURAL JOIN. "a JOIN b USING (x, y)" becomes "a.x = b.x AND a.y =
 * b.y". Returns null if the column list is empty.
 *
 * @param leftNamespace Namespace of left input to join
 * @param rightNamespace Namespace of right input to join
 * @param nameList List of column names to join on
 * @return Expression to match columns from name list, or true if name list
 * is empty
 */
private RexNode convertUsing(SqlValidatorNamespace leftNamespace,
    SqlValidatorNamespace rightNamespace,
    List<String> nameList) {
  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
  final List<RexNode> list = Lists.newArrayList();
  for (String name : nameList) {
    List<RexNode> operands = new ArrayList<>();
    int offset = 0;
    for (SqlValidatorNamespace n : ImmutableList.of(leftNamespace,
        rightNamespace)) {
      final RelDataType rowType = n.getRowType();
      final RelDataTypeField field = nameMatcher.field(rowType, name);
      operands.add(
          rexBuilder.makeInputRef(field.getType(),
              offset + field.getIndex()));
      offset += rowType.getFieldList().size();
    }
    list.add(rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, operands));
  }
  return RexUtil.composeConjunction(rexBuilder, list, false);
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:SqlToRelConverter.java


示例20: singleton

import org.apache.calcite.rex.RexUtil; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>{@code COUNT(*)}, and {@code COUNT} applied to all NOT NULL arguments,
 * become {@code 1}; otherwise
 * {@code CASE WHEN arg0 IS NOT NULL THEN 1 ELSE 0 END}.
 */
public RexNode singleton(RexBuilder rexBuilder, RelDataType inputRowType,
    AggregateCall aggregateCall) {
  final List<RexNode> predicates = new ArrayList<>();
  for (Integer arg : aggregateCall.getArgList()) {
    final RelDataType type = inputRowType.getFieldList().get(arg).getType();
    if (type.isNullable()) {
      predicates.add(
          rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL,
              rexBuilder.makeInputRef(type, arg)));
    }
  }
  final RexNode predicate =
      RexUtil.composeConjunction(rexBuilder, predicates, true);
  if (predicate == null) {
    return rexBuilder.makeExactLiteral(BigDecimal.ONE);
  } else {
    return rexBuilder.makeCall(SqlStdOperatorTable.CASE, predicate,
        rexBuilder.makeExactLiteral(BigDecimal.ONE),
        rexBuilder.makeExactLiteral(BigDecimal.ZERO));
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:SqlSplittableAggFunction.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SQLUpdateClause类代码示例发布时间:2022-05-22
下一篇:
Java KettleAttributeInterface类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap