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


Java AggregateCall.isDistinct方法代码示例

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


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

示例1: addAggCall

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
/**
 * Creates a reference to an aggregate call, checking for repeated calls.
 *
 * <p>Argument types help to optimize for repeated aggregates.
 * For instance count(42) is equivalent to count(*).</p>
 *
 * @param aggCall aggregate call to be added
 * @param groupCount number of groups in the aggregate relation
 * @param indicator Whether the Aggregate has indicator (GROUPING) columns
 * @param aggCalls destination list of aggregate calls
 * @param aggCallMapping the dictionary of already added calls
 * @param aggArgTypes Argument types, not null
 *
 * @return Rex expression for the given aggregate call
 */
public RexNode addAggCall(AggregateCall aggCall, int groupCount,
    boolean indicator, List<AggregateCall> aggCalls,
    Map<AggregateCall, RexNode> aggCallMapping,
    final List<RelDataType> aggArgTypes) {
  if (aggCall.getAggregation() instanceof SqlCountAggFunction
      && !aggCall.isDistinct()) {
    final List<Integer> args = aggCall.getArgList();
    final List<Integer> nullableArgs = nullableArgs(args, aggArgTypes);
    if (!nullableArgs.equals(args)) {
      aggCall = aggCall.copy(nullableArgs, aggCall.filterArg);
    }
  }
  RexNode rex = aggCallMapping.get(aggCall);
  if (rex == null) {
    int index = aggCalls.size() + groupCount * (indicator ? 2 : 1);
    aggCalls.add(aggCall);
    rex = makeInputRef(aggCall.getType(), index);
    aggCallMapping.put(aggCall, rex);
  }
  return rex;
}
 
开发者ID:apache,项目名称:calcite,代码行数:37,代码来源:RexBuilder.java

示例2: rewriteAggCalls

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private static void rewriteAggCalls(
		List<AggregateCall> newAggCalls,
		List<Integer> argList,
		Map<Integer, Integer> sourceOf) {
	// Rewrite the agg calls. Each distinct agg becomes a non-distinct call
	// to the corresponding field from the right; for example,
	// "COUNT(DISTINCT e.sal)" becomes   "COUNT(distinct_e.sal)".
	for (int i = 0; i < newAggCalls.size(); i++) {
		final AggregateCall aggCall = newAggCalls.get(i);

		// Ignore agg calls which are not distinct or have the wrong set
		// arguments. If we're rewriting aggregates whose args are {sal}, we will
		// rewrite COUNT(DISTINCT sal) and SUM(DISTINCT sal) but ignore
		// COUNT(DISTINCT gender) or SUM(sal).
		if (!aggCall.isDistinct()) {
			continue;
		}
		if (!aggCall.getArgList().equals(argList)) {
			continue;
		}

		// Re-map arguments.
		final int argCount = aggCall.getArgList().size();
		final List<Integer> newArgs = new ArrayList<>(argCount);
		for (int j = 0; j < argCount; j++) {
			final Integer arg = aggCall.getArgList().get(j);
			newArgs.add(sourceOf.get(arg));
		}
		final AggregateCall newAggCall =
				AggregateCall.create(aggCall.getAggregation(), false, newArgs, -1,
						aggCall.getType(), aggCall.getName());
		newAggCalls.set(i, newAggCall);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:35,代码来源:FlinkAggregateExpandDistinctAggregatesRule.java

示例3: getSqlFuncName

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
static String getSqlFuncName(AggregateCall aggCall) {
    String sqlName = aggCall.getAggregation().getName();
    if (aggCall.isDistinct()) {
        sqlName = sqlName + "_DISTINCT";
    }
    return sqlName;
}
 
开发者ID:apache,项目名称:kylin,代码行数:8,代码来源:OLAPAggregateRel.java

示例4: implementOLAP

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
@Override
public void implementOLAP(OLAPImplementor implementor) {
    implementor.fixSharedOlapTableScan(this);
    implementor.visitChild(getInput(), this);

    this.context = implementor.getContext();
    this.columnRowType = buildColumnRowType();
    this.afterAggregate = this.context.afterAggregate;

    // only translate the innermost aggregation
    if (!this.afterAggregate) {
        addToContextGroupBy(this.groups);
        this.context.aggregations.addAll(this.aggregations);
        this.context.aggrOutCols
                .addAll(columnRowType.getAllColumns().subList(groups.size(), columnRowType.getAllColumns().size()));
        this.context.afterAggregate = true;

        if (this.context.afterLimit) {
            this.context.limitPrecedesAggr = true;
        }
    } else {
        for (AggregateCall aggCall : aggCalls) {
            // check if supported by kylin
            if (aggCall.isDistinct()) {
                throw new IllegalStateException("Distinct count is only allowed in innermost sub-query.");
            }
        }
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:30,代码来源:OLAPAggregateRel.java

示例5: getDistinctCalls

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
/**
 * A agg function call like <code>COUNT(DISTINCT COL)</code> in Pig is
 * achieved via two statements in a FOREACH that follows a GROUP statement:
 *
 * <blockquote>
 * <code>
 * TABLE = GROUP TABLE ALL;<br>
 * TABLE = FOREACH TABLE {<br>
 * &nbsp;&nbsp;<b>COL.DISTINCT = DISTINCT COL;<br>
 * &nbsp;&nbsp;GENERATE COUNT(COL.DISTINCT) AS C;</b><br>
 * }</code>
 * </blockquote>
 */
private List<String> getDistinctCalls(Implementor implementor) {
  final String relAlias = implementor.getPigRelationAlias(this);
  final List<String> result = new ArrayList<>();
  for (AggregateCall aggCall : aggCalls) {
    if (aggCall.isDistinct()) {
      for (int fieldIndex : aggCall.getArgList()) {
        String fieldName = getInputFieldName(fieldIndex);
        result.add("  " + fieldName + DISTINCT_FIELD_SUFFIX + " = DISTINCT " + relAlias + '.'
            + fieldName + ";\n");
      }
    }
  }
  return result;
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:PigAggregate.java

示例6: canBeUsed

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
/**
 * Returns true if and only if this <code>ComplexMetric</code>
 * can be used in the given {@link AggregateCall}.
 * */
public boolean canBeUsed(AggregateCall call) {
  switch (type) {
  case HYPER_UNIQUE:
  case THETA_SKETCH:
    return call != null
          && call.getAggregation().getKind() == SqlKind.COUNT
          && call.isDistinct();
  default:
    return false;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:16,代码来源:ComplexMetric.java

示例7: rewriteAggCalls

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private static void rewriteAggCalls(
    List<AggregateCall> newAggCalls,
    List<Integer> argList,
    Map<Integer, Integer> sourceOf) {
  // Rewrite the agg calls. Each distinct agg becomes a non-distinct call
  // to the corresponding field from the right; for example,
  // "COUNT(DISTINCT e.sal)" becomes   "COUNT(distinct_e.sal)".
  for (int i = 0; i < newAggCalls.size(); i++) {
    final AggregateCall aggCall = newAggCalls.get(i);

    // Ignore agg calls which are not distinct or have the wrong set
    // arguments. If we're rewriting aggregates whose args are {sal}, we will
    // rewrite COUNT(DISTINCT sal) and SUM(DISTINCT sal) but ignore
    // COUNT(DISTINCT gender) or SUM(sal).
    if (!aggCall.isDistinct()) {
      continue;
    }
    if (!aggCall.getArgList().equals(argList)) {
      continue;
    }

    // Re-map arguments.
    final int argCount = aggCall.getArgList().size();
    final List<Integer> newArgs = new ArrayList<>(argCount);
    for (int j = 0; j < argCount; j++) {
      final Integer arg = aggCall.getArgList().get(j);
      newArgs.add(sourceOf.get(arg));
    }
    final AggregateCall newAggCall =
        AggregateCall.create(aggCall.getAggregation(), false,
            aggCall.isApproximate(), newArgs, -1,
            aggCall.getType(), aggCall.getName());
    newAggCalls.set(i, newAggCall);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:36,代码来源:AggregateExpandDistinctAggregatesRule.java

示例8: transformAggCalls

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private List<AggregateCall> transformAggCalls(RelNode input, int groupCount,
    List<AggregateCall> origCalls) {
  final List<AggregateCall> newCalls = Lists.newArrayList();
  for (Ord<AggregateCall> ord : Ord.zip(origCalls)) {
    final AggregateCall origCall = ord.e;
    if (origCall.isDistinct()
        || !SUPPORTED_AGGREGATES.containsKey(origCall.getAggregation()
            .getClass())) {
      return null;
    }
    final SqlAggFunction aggFun;
    final RelDataType aggType;
    if (origCall.getAggregation() == SqlStdOperatorTable.COUNT) {
      aggFun = SqlStdOperatorTable.SUM0;
      // count(any) is always not null, however nullability of sum might
      // depend on the number of columns in GROUP BY.
      // Here we use SUM0 since we are sure we will not face nullable
      // inputs nor we'll face empty set.
      aggType = null;
    } else {
      aggFun = origCall.getAggregation();
      aggType = origCall.getType();
    }
    AggregateCall newCall =
        AggregateCall.create(aggFun, origCall.isDistinct(),
            origCall.isApproximate(),
            ImmutableList.of(groupCount + ord.i), -1, groupCount, input,
            aggType, origCall.getName());
    newCalls.add(newCall);
  }
  return newCalls;
}
 
开发者ID:apache,项目名称:calcite,代码行数:33,代码来源:AggregateUnionTransposeRule.java

示例9: reduceSum

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private RexNode reduceSum(
    Aggregate oldAggRel,
    AggregateCall oldCall,
    List<AggregateCall> newCalls,
    Map<AggregateCall, RexNode> aggCallMapping) {
  final int nGroups = oldAggRel.getGroupCount();
  RelDataTypeFactory typeFactory =
      oldAggRel.getCluster().getTypeFactory();
  RexBuilder rexBuilder = oldAggRel.getCluster().getRexBuilder();
  int arg = oldCall.getArgList().get(0);
  RelDataType argType =
      getFieldType(
          oldAggRel.getInput(),
          arg);
  RelDataType sumType =
      typeFactory.createTypeWithNullability(
          argType, argType.isNullable());
  SqlAggFunction sumZeroAgg = new SqlSumEmptyIsZeroAggFunction();
  AggregateCall sumZeroCall =
      new AggregateCall(
          sumZeroAgg,
          oldCall.isDistinct(),
          oldCall.getArgList(),
          sumType,
          null);
  final SqlCountAggFunction countAgg = (SqlCountAggFunction) SqlStdOperatorTable.COUNT;
  final RelDataType countType = countAgg.getReturnType(typeFactory);
  AggregateCall countCall =
      new AggregateCall(
          countAgg,
          oldCall.isDistinct(),
          oldCall.getArgList(),
          countType,
          null);

  // NOTE:  these references are with respect to the output
  // of newAggRel
  RexNode sumZeroRef =
      rexBuilder.addAggCall(
          sumZeroCall,
          nGroups,
          oldAggRel.indicator,
          newCalls,
          aggCallMapping,
          ImmutableList.of(argType));
  if (!oldCall.getType().isNullable()) {
    // If SUM(x) is not nullable, the validator must have determined that
    // nulls are impossible (because the group is never empty and x is never
    // null). Therefore we translate to SUM0(x).
    return sumZeroRef;
  }
  RexNode countRef =
      rexBuilder.addAggCall(
          countCall,
          nGroups,
          oldAggRel.indicator,
          newCalls,
          aggCallMapping,
          ImmutableList.of(argType));
  return rexBuilder.makeCall(SqlStdOperatorTable.CASE,
      rexBuilder.makeCall(SqlStdOperatorTable.EQUALS,
          countRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO)),
          rexBuilder.constantNull(),
          sumZeroRef);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:66,代码来源:DrillReduceAggregatesRule.java

示例10: KylinAggregateCall

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
public KylinAggregateCall(AggregateCall aggCall, FunctionDesc func) {
    super(aggCall.getAggregation(), aggCall.isDistinct(), aggCall.getArgList(), aggCall.type, aggCall.name);
    this.func = func;
}
 
开发者ID:apache,项目名称:kylin,代码行数:5,代码来源:KylinAggregateCall.java

示例11: getInputFieldNameForAggCall

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private String getInputFieldNameForAggCall(String relAlias, AggregateCall aggCall,
    int fieldIndex) {
  final String inputField = getInputFieldName(fieldIndex);
  return aggCall.isDistinct() ? (inputField + DISTINCT_FIELD_SUFFIX)
      : (relAlias + '.' + inputField);
}
 
开发者ID:apache,项目名称:calcite,代码行数:7,代码来源:PigAggregate.java

示例12: getJsonPostAggregation

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
public JsonPostAggregation getJsonPostAggregation(String name, RexNode rexNode, RelNode rel) {
  if (rexNode instanceof RexCall) {
    List<JsonPostAggregation> fields = new ArrayList<>();
    for (RexNode ele : ((RexCall) rexNode).getOperands()) {
      JsonPostAggregation field = getJsonPostAggregation("", ele, rel);
      if (field == null) {
        throw new RuntimeException("Unchecked types that cannot be parsed as Post Aggregator");
      }
      fields.add(field);
    }
    switch (rexNode.getKind()) {
    case PLUS:
      return new JsonArithmetic(name, "+", fields, null);
    case MINUS:
      return new JsonArithmetic(name, "-", fields, null);
    case DIVIDE:
      return new JsonArithmetic(name, "quotient", fields, null);
    case TIMES:
      return new JsonArithmetic(name, "*", fields, null);
    case CAST:
      return getJsonPostAggregation(name, ((RexCall) rexNode).getOperands().get(0),
          rel);
    default:
    }
  } else if (rexNode instanceof RexInputRef) {
    // Subtract only number of grouping columns as offset because for now only Aggregates
    // without grouping sets (i.e. indicator columns size is zero) are allowed to pushed
    // in Druid Query.
    Integer indexSkipGroup = ((RexInputRef) rexNode).getIndex()
        - ((Aggregate) rel).getGroupCount();
    AggregateCall aggCall = ((Aggregate) rel).getAggCallList().get(indexSkipGroup);
    // Use either the hyper unique estimator, or the theta sketch one.
    // Hyper unique is used by default.
    if (aggCall.isDistinct()
        && aggCall.getAggregation().getKind() == SqlKind.COUNT) {
      final String fieldName = rel.getRowType().getFieldNames()
              .get(((RexInputRef) rexNode).getIndex());

      List<String> fieldNames = ((Aggregate) rel).getInput().getRowType().getFieldNames();
      String complexName = fieldNames.get(aggCall.getArgList().get(0));
      ComplexMetric metric = druidTable.resolveComplexMetric(complexName, aggCall);

      if (metric != null) {
        switch (metric.getDruidType()) {
        case THETA_SKETCH:
          return new JsonThetaSketchEstimate("", fieldName);
        case HYPER_UNIQUE:
          return new JsonHyperUniqueCardinality("", fieldName);
        default:
          throw new AssertionError("Can not translate complex metric type: "
                  + metric.getDruidType());
        }
      }
      // Count distinct on a non-complex column.
      return new JsonHyperUniqueCardinality("", fieldName);
    }
    return new JsonFieldAccessor("",
        rel.getRowType().getFieldNames().get(((RexInputRef) rexNode).getIndex()));
  } else if (rexNode instanceof RexLiteral) {
    // Druid constant post aggregator only supports numeric value for now.
    // (http://druid.io/docs/0.10.0/querying/post-aggregations.html) Accordingly, all
    // numeric type of RexLiteral can only have BigDecimal value, so filter out unsupported
    // constant by checking the type of RexLiteral value.
    if (((RexLiteral) rexNode).getValue3() instanceof BigDecimal) {
      return new JsonConstant("",
          ((BigDecimal) ((RexLiteral) rexNode).getValue3()).doubleValue());
    }
  }
  throw new RuntimeException("Unchecked types that cannot be parsed as Post Aggregator");
}
 
开发者ID:apache,项目名称:calcite,代码行数:71,代码来源:DruidQuery.java

示例13: createUnion

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
@Override protected RelNode createUnion(RelBuilder relBuilder, RexBuilder rexBuilder,
    RelNode topProject, RelNode unionInputQuery, RelNode unionInputView) {
  // Union
  relBuilder.push(unionInputQuery);
  relBuilder.push(unionInputView);
  relBuilder.union(true);
  List<RexNode> exprList = new ArrayList<>(relBuilder.peek().getRowType().getFieldCount());
  List<String> nameList = new ArrayList<>(relBuilder.peek().getRowType().getFieldCount());
  for (int i = 0; i < relBuilder.peek().getRowType().getFieldCount(); i++) {
    // We can take unionInputQuery as it is query based.
    RelDataTypeField field = unionInputQuery.getRowType().getFieldList().get(i);
    exprList.add(
        rexBuilder.ensureType(
            field.getType(),
            rexBuilder.makeInputRef(relBuilder.peek(), i),
            true));
    nameList.add(field.getName());
  }
  relBuilder.project(exprList, nameList);
  // Rollup aggregate
  Aggregate aggregate = (Aggregate) unionInputQuery;
  final ImmutableBitSet groupSet = ImmutableBitSet.range(aggregate.getGroupCount());
  final List<AggCall> aggregateCalls = new ArrayList<>();
  for (int i = 0; i < aggregate.getAggCallList().size(); i++) {
    AggregateCall aggCall = aggregate.getAggCallList().get(i);
    if (aggCall.isDistinct()) {
      // Cannot ROLLUP distinct
      return null;
    }
    aggregateCalls.add(
        relBuilder.aggregateCall(
            SubstitutionVisitor.getRollup(aggCall.getAggregation()),
            aggCall.isDistinct(), aggCall.isApproximate(), null,
            aggCall.name,
            rexBuilder.makeInputRef(relBuilder.peek(),
                aggregate.getGroupCount() + i)));
  }
  RelNode prevNode = relBuilder.peek();
  RelNode result = relBuilder
      .aggregate(relBuilder.groupKey(groupSet, null), aggregateCalls)
      .build();
  if (prevNode == result && groupSet.cardinality() != result.getRowType().getFieldCount()) {
    // Aggregate was not inserted but we need to prune columns
    result = relBuilder
        .push(result)
        .project(relBuilder.fields(groupSet.asList()))
        .build();
  }
  if (topProject != null) {
    // Top project
    return topProject.copy(topProject.getTraitSet(), ImmutableList.of(result));
  }
  // Result
  return result;
}
 
开发者ID:apache,项目名称:calcite,代码行数:56,代码来源:AbstractMaterializedViewRule.java

示例14: rollUp

import org.apache.calcite.rel.core.AggregateCall; //导入方法依赖的package包/类
private static AggregateCall rollUp(int groupCount, RelBuilder relBuilder,
    AggregateCall aggregateCall, TileKey tileKey) {
  if (aggregateCall.isDistinct()) {
    return null;
  }
  final SqlAggFunction aggregation = aggregateCall.getAggregation();
  final Pair<SqlAggFunction, List<Integer>> seek =
      Pair.of(aggregation, aggregateCall.getArgList());
  final int offset = tileKey.dimensions.cardinality();
  final ImmutableList<Lattice.Measure> measures = tileKey.measures;

  // First, try to satisfy the aggregation by rolling up an aggregate in the
  // materialization.
  final int i = find(measures, seek);
tryRoll:
  if (i >= 0) {
    final SqlAggFunction roll = SubstitutionVisitor.getRollup(aggregation);
    if (roll == null) {
      break tryRoll;
    }
    return AggregateCall.create(roll, false,
        aggregateCall.isApproximate(), ImmutableList.of(offset + i), -1,
        groupCount, relBuilder.peek(), null, aggregateCall.name);
  }

  // Second, try to satisfy the aggregation based on group set columns.
tryGroup:
  {
    List<Integer> newArgs = Lists.newArrayList();
    for (Integer arg : aggregateCall.getArgList()) {
      int z = tileKey.dimensions.indexOf(arg);
      if (z < 0) {
        break tryGroup;
      }
      newArgs.add(z);
    }
    return AggregateCall.create(aggregation, false,
        aggregateCall.isApproximate(), newArgs, -1,
        groupCount, relBuilder.peek(), null, aggregateCall.name);
  }

  // No roll up possible.
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:45,代码来源:AggregateStarTableRule.java


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