本文整理汇总了Java中org.apache.calcite.sql.fun.SqlCountAggFunction类的典型用法代码示例。如果您正苦于以下问题:Java SqlCountAggFunction类的具体用法?Java SqlCountAggFunction怎么用?Java SqlCountAggFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlCountAggFunction类属于org.apache.calcite.sql.fun包,在下文中一共展示了SqlCountAggFunction类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addAggCall
import org.apache.calcite.sql.fun.SqlCountAggFunction; //导入依赖的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: reduceSum
import org.apache.calcite.sql.fun.SqlCountAggFunction; //导入依赖的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
示例3: onMatch2
import org.apache.calcite.sql.fun.SqlCountAggFunction; //导入依赖的package包/类
private void onMatch2(RelOptRuleCall call, LogicalCorrelate correlate, RelNode leftInput, LogicalProject aggOutputProject, LogicalAggregate aggregate) {
if (generatedCorRels.contains(correlate)) {
// This correlator was generated by a previous invocation of
// this rule. No further work to do.
return;
}
setCurrent(call.getPlanner().getRoot(), correlate);
// check for this pattern
// The pattern matching could be simplified if rules can be applied
// during decorrelation,
//
// CorrelateRel(left correlation, condition = true)
// LeftInputRel
// LogicalProject-A (a RexNode)
// LogicalAggregate (groupby (0), agg0(), agg1()...)
// check aggOutputProj projects only one expression
List<RexNode> aggOutputProjExprs = aggOutputProject.getProjects();
if (aggOutputProjExprs.size() != 1) {
return;
}
JoinRelType joinType = correlate.getJoinType().toJoinType();
// corRel.getCondition was here, however Correlate was updated so it
// never includes a join condition. The code was not modified for brevity.
RexNode joinCond = rexBuilder.makeLiteral(true);
if ((joinType != JoinRelType.LEFT) || (joinCond != rexBuilder.makeLiteral(true))) {
return;
}
// check that the agg is on the entire input
if (!aggregate.getGroupSet().isEmpty()) {
return;
}
List<AggregateCall> aggCalls = aggregate.getAggCallList();
Set<Integer> isCount = Sets.newHashSet();
// remember the count() positions
int i = -1;
for (AggregateCall aggCall : aggCalls) {
++i;
if (aggCall.getAggregation() instanceof SqlCountAggFunction) {
isCount.add(i);
}
}
// now rewrite the plan to
//
// Project-A' (all LHS plus transformed original projections,
// replacing references to count() with case statement)
// Correlator(left correlation, condition = true)
// LeftInputRel
// LogicalAggregate (groupby (0), agg0(), agg1()...)
//
LogicalCorrelate newCorrelate = LogicalCorrelate.create(leftInput, aggregate, correlate.getCorrelationId(), correlate.getRequiredColumns(), correlate.getJoinType());
// remember this rel so we don't fire rule on it again
// REVIEW jhyde 29-Oct-2007: rules should not save state; rule
// should recognize patterns where it does or does not need to do
// work
generatedCorRels.add(newCorrelate);
// need to update the mapCorVarToCorRel Update the output position
// for the cor vars: only pass on the cor vars that are not used in
// the join key.
if (cm.mapCorVarToCorRel.get(correlate.getCorrelationId()) == correlate) {
cm.mapCorVarToCorRel.put(correlate.getCorrelationId(), newCorrelate);
}
RelNode newOutput = aggregateCorrelatorOutput(newCorrelate, aggOutputProject, isCount);
call.transformTo(newOutput);
}
开发者ID:axbaretto,项目名称:flink,代码行数:77,代码来源:FlinkRelDecorrelator.java
注:本文中的org.apache.calcite.sql.fun.SqlCountAggFunction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论