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


Java Aggregate类代码示例

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


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

示例1: visitAggregate

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
@Override
public Void visitAggregate(Aggregate aggregate, List<Void> inputStreams) throws Exception {
  beginAggregateStage(aggregate);
  pw.println("        if (_data != null) {");
  pw.println("        List<Object> curGroupValues = getGroupValues(_data);");
  pw.println("        if (!correlatedGroupedValues.containsKey(curGroupValues)) {");
  pw.println("          correlatedGroupedValues.put(curGroupValues, new ArrayList<CorrelatedValues>());");
  pw.println("        }");
  pw.println("        correlatedGroupedValues.get(curGroupValues).add(_data);");
  pw.println("        if (!state.containsKey(curGroupValues)) {");
  pw.println("          state.put(curGroupValues, new HashMap<String, Object>());");
  pw.println("        }");
  pw.println("        Map<String, Object> accumulators = state.get(curGroupValues);");
  for (AggregateCall call : aggregate.getAggCallList()) {
    aggregate(call);
  }
  pw.println("        }");
  endStage();
  return null;
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:21,代码来源:RelNodeCompiler.java

示例2: canPush

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
private boolean canPush(Aggregate aggregate, ImmutableBitSet rCols) {
  // If the filter references columns not in the group key, we cannot push
  final ImmutableBitSet groupKeys =
      ImmutableBitSet.range(0, aggregate.getGroupSet().cardinality());
  if (!groupKeys.contains(rCols)) {
    return false;
  }

  if (aggregate.indicator) {
    // If grouping sets are used, the filter can be pushed if
    // the columns referenced in the predicate are present in
    // all the grouping sets.
    for (ImmutableBitSet groupingSet : aggregate.getGroupSets()) {
      if (!groupingSet.contains(rCols)) {
        return false;
      }
    }
  }
  return true;
}
 
开发者ID:qubole,项目名称:quark,代码行数:21,代码来源:FilterAggStarRule.java

示例3: testAggregateExtractProjectRuleWithFilter

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
@Test public void testAggregateExtractProjectRuleWithFilter() {
  final String sql = "select sum(sal) filter (where empno = 40)\n"
      + "from emp";
  HepProgram pre = new HepProgramBuilder()
      .addRuleInstance(AggregateProjectMergeRule.INSTANCE)
      .build();
  // AggregateProjectMergeRule does not merges Project with Filter.
  // Force match Aggregate on top of Project once explicitly in unit test.
  final AggregateExtractProjectRule rule =
      new AggregateExtractProjectRule(
          operand(Aggregate.class,
              operand(Project.class, null,
                  new PredicateImpl<Project>() {
                    int matchCount = 0;

                    public boolean test(@Nullable Project project) {
                      return matchCount++ == 0;
                    }
                  },
                  none())),
          RelFactories.LOGICAL_BUILDER);
  sql(sql).withPre(pre).withRule(rule).checkUnchanged();
}
 
开发者ID:apache,项目名称:calcite,代码行数:24,代码来源:RelOptRulesTest.java

示例4: setAggChildKeys

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
/**
 * Takes a bitmap representing a set of input references and extracts the
 * ones that reference the group by columns in an aggregate.
 *
 * @param groupKey the original bitmap
 * @param aggRel   the aggregate
 * @param childKey sets bits from groupKey corresponding to group by columns
 */
public static void setAggChildKeys(
    ImmutableBitSet groupKey,
    Aggregate aggRel,
    ImmutableBitSet.Builder childKey) {
  List<AggregateCall> aggCalls = aggRel.getAggCallList();
  for (int bit : groupKey) {
    if (bit < aggRel.getGroupCount()) {
      // group by column
      childKey.set(bit);
    } else {
      // aggregate column -- set a bit for each argument being
      // aggregated
      AggregateCall agg = aggCalls.get(bit
          - (aggRel.getGroupCount() + aggRel.getIndicatorCount()));
      for (Integer arg : agg.getArgList()) {
        childKey.set(arg);
      }
    }
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:RelMdUtil.java

示例5: getSelectivity

import org.apache.calcite.rel.core.Aggregate; //导入依赖的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

示例6: areColumnsUnique

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
public Boolean areColumnsUnique(RelSubset rel, RelMetadataQuery mq,
    ImmutableBitSet columns, boolean ignoreNulls) {
  int nullCount = 0;
  for (RelNode rel2 : rel.getRels()) {
    if (rel2 instanceof Aggregate
        || rel2 instanceof Filter
        || rel2 instanceof Values
        || rel2 instanceof TableScan
        || simplyProjects(rel2, columns)) {
      try {
        final Boolean unique = mq.areColumnsUnique(rel2, columns, ignoreNulls);
        if (unique != null) {
          if (unique) {
            return true;
          }
        } else {
          ++nullCount;
        }
      } catch (CyclicMetadataException e) {
        // Ignore this relational expression; there will be non-cyclic ones
        // in this set.
      }
    }
  }
  return nullCount == 0 ? false : null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:RelMdColumnUniqueness.java

示例7: createAggregateCallWithBinding

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
private AggregateCall createAggregateCallWithBinding(
    RelDataTypeFactory typeFactory,
    SqlAggFunction aggFunction,
    RelDataType operandType,
    Aggregate oldAggRel,
    AggregateCall oldCall,
    int argOrdinal) {
  final Aggregate.AggCallBinding binding =
      new Aggregate.AggCallBinding(typeFactory, aggFunction,
          ImmutableList.of(operandType), oldAggRel.getGroupCount(),
          oldCall.filterArg >= 0);
  return AggregateCall.create(aggFunction,
      oldCall.isDistinct(),
      oldCall.isApproximate(),
      ImmutableIntList.of(argOrdinal),
      oldCall.filterArg,
      aggFunction.inferReturnType(binding),
      null);
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:AggregateReduceFunctionsRule.java

示例8: onMatch

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  final Aggregate aggregate = call.rel(0);
  final RelNode input = call.rel(1);
  if (!aggregate.getAggCallList().isEmpty() || aggregate.indicator) {
    return;
  }
  final RelMetadataQuery mq = call.getMetadataQuery();
  if (!SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet()))) {
    return;
  }
  // Distinct is "GROUP BY c1, c2" (where c1, c2 are a set of columns on
  // which the input is unique, i.e. contain a key) and has no aggregate
  // functions. It can be removed.
  final RelNode newInput = convert(input, aggregate.getTraitSet().simplify());

  // If aggregate was projecting a subset of columns, add a project for the
  // same effect.
  final RelBuilder relBuilder = call.builder();
  relBuilder.push(newInput);
  if (newInput.getRowType().getFieldCount()
      > aggregate.getRowType().getFieldCount()) {
    relBuilder.project(relBuilder.fields(aggregate.getGroupSet().asList()));
  }
  call.transformTo(relBuilder.build());
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:AggregateRemoveRule.java

示例9: canPush

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
private boolean canPush(Aggregate aggregate, ImmutableBitSet rCols) {
  // If the filter references columns not in the group key, we cannot push
  final ImmutableBitSet groupKeys =
      ImmutableBitSet.range(0, aggregate.getGroupSet().cardinality());
  if (!groupKeys.contains(rCols)) {
    return false;
  }

  if (aggregate.getGroupType() != Group.SIMPLE) {
    // If grouping sets are used, the filter can be pushed if
    // the columns referenced in the predicate are present in
    // all the grouping sets.
    for (ImmutableBitSet groupingSet : aggregate.getGroupSets()) {
      if (!groupingSet.contains(rCols)) {
        return false;
      }
    }
  }
  return true;
}
 
开发者ID:apache,项目名称:calcite,代码行数:21,代码来源:FilterAggregateTransposeRule.java

示例10: AggregateNode

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
public AggregateNode(Compiler compiler, Aggregate rel) {
  super(compiler, rel);
  this.dataContext = compiler.getDataContext();

  ImmutableBitSet union = ImmutableBitSet.of();

  if (rel.getGroupSets() != null) {
    for (ImmutableBitSet group : rel.getGroupSets()) {
      union = union.union(group);
      groups.add(new Grouping(group));
    }
  }

  this.unionGroups = union;
  this.outputRowLength = unionGroups.cardinality()
      + (rel.indicator ? unionGroups.cardinality() : 0)
      + rel.getAggCallList().size();

  ImmutableList.Builder<AccumulatorFactory> builder = ImmutableList.builder();
  for (AggregateCall aggregateCall : rel.getAggCallList()) {
    builder.add(getAccumulator(aggregateCall, false));
  }
  accumulatorFactories = builder.build();
}
 
开发者ID:apache,项目名称:calcite,代码行数:25,代码来源:AggregateNode.java

示例11: testInduceGroupingType1

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
/** Tests a singleton grouping set {2}, whose power set has only two elements,
 * { {2}, {} }. */
@Test public void testInduceGroupingType1() {
  final ImmutableBitSet groupSet = ImmutableBitSet.of(2);

  // Could be ROLLUP but we prefer CUBE
  List<ImmutableBitSet> groupSets = Lists.newArrayList();
  groupSets.add(groupSet);
  groupSets.add(ImmutableBitSet.of());
  assertEquals(Aggregate.Group.CUBE,
      Aggregate.Group.induce(groupSet, groupSets));

  groupSets = Lists.newArrayList();
  groupSets.add(ImmutableBitSet.of());
  assertEquals(Aggregate.Group.OTHER,
      Aggregate.Group.induce(groupSet, groupSets));

  groupSets = Lists.newArrayList();
  groupSets.add(groupSet);
  assertEquals(Aggregate.Group.SIMPLE,
      Aggregate.Group.induce(groupSet, groupSets));

  groupSets = Lists.newArrayList();
  assertEquals(Aggregate.Group.OTHER,
      Aggregate.Group.induce(groupSet, groupSets));
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:InduceGroupingTypeTest.java

示例12: getRowCount

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
@Override
public Double getRowCount(Aggregate rel) {
  ImmutableBitSet groupKey = ImmutableBitSet.range(rel.getGroupCount());

  if (groupKey.isEmpty()) {
    return 1.0;
  } else {
    return super.getRowCount(rel);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:11,代码来源:DrillRelMdRowCount.java

示例13: copy

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
@Override
public Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
  try {
    return new DrillAggregateRel(getCluster(), traitSet, input, indicator, groupSet, groupSets, aggCalls);
  } catch (InvalidRelException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:9,代码来源:DrillAggregateRel.java

示例14: matches

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
@Override
public boolean matches(RelOptRuleCall call) {
  if (!super.matches(call)) {
    return false;
  }
  Aggregate oldAggRel = (Aggregate) call.rels[0];
  return containsAvgStddevVarCall(oldAggRel.getAggCallList());
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:9,代码来源:DrillReduceAggregatesRule.java

示例15: copy

import org.apache.calcite.rel.core.Aggregate; //导入依赖的package包/类
@Override
public Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls) {
  try {
    return new HashAggPrel(getCluster(), traitSet, input, indicator, groupSet, groupSets, aggCalls,
        this.getOperatorPhase());
  } catch (InvalidRelException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:10,代码来源:HashAggPrel.java


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