Java Code Examples for org.apache.calcite.sql.SqlKind#SUM

The following examples show how to use org.apache.calcite.sql.SqlKind#SUM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlinkAggregateRemoveRule.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(RelOptRuleCall call) {
	final Aggregate aggregate = call.rel(0);
	final RelNode input = call.rel(1);
	if (aggregate.getGroupCount() == 0 || aggregate.indicator ||
			aggregate.getGroupType() != Aggregate.Group.SIMPLE) {
		return false;
	}
	for (AggregateCall aggCall : aggregate.getAggCallList()) {
		SqlKind aggCallKind = aggCall.getAggregation().getKind();
		// TODO supports more AggregateCalls
		boolean isAllowAggCall = aggCallKind == SqlKind.SUM ||
				aggCallKind == SqlKind.MIN ||
				aggCallKind == SqlKind.MAX ||
				aggCall.getAggregation() instanceof SqlAuxiliaryGroupAggFunction;
		if (!isAllowAggCall || aggCall.filterArg >= 0 || aggCall.getArgList().size() != 1) {
			return false;
		}
	}

	final RelMetadataQuery mq = call.getMetadataQuery();
	return SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet()));
}
 
Example 2
Source File: FlinkAggregateRemoveRule.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(RelOptRuleCall call) {
	final Aggregate aggregate = call.rel(0);
	final RelNode input = call.rel(1);
	if (aggregate.getGroupCount() == 0 || aggregate.indicator ||
			aggregate.getGroupType() != Aggregate.Group.SIMPLE) {
		return false;
	}
	for (AggregateCall aggCall : aggregate.getAggCallList()) {
		SqlKind aggCallKind = aggCall.getAggregation().getKind();
		// TODO supports more AggregateCalls
		boolean isAllowAggCall = aggCallKind == SqlKind.SUM ||
				aggCallKind == SqlKind.MIN ||
				aggCallKind == SqlKind.MAX ||
				aggCall.getAggregation() instanceof SqlAuxiliaryGroupAggFunction;
		if (!isAllowAggCall || aggCall.filterArg >= 0 || aggCall.getArgList().size() != 1) {
			return false;
		}
	}

	final RelMetadataQuery mq = call.getMetadataQuery();
	return SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet()));
}
 
Example 3
Source File: AggregateReduceFunctionsRule.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an AggregateReduceFunctionsRule with client
 * provided information on which specific functions will
 * be reduced by this rule
 * @param aggregateClass aggregate class
 * @param relBuilderFactory builder for relational expressions
 * @param functionsToReduce client provided information
 *                          on which specific functions
 *                          will be reduced by this rule
 */
public AggregateReduceFunctionsRule(Class<? extends Aggregate> aggregateClass,
    RelBuilderFactory relBuilderFactory, EnumSet<SqlKind> functionsToReduce) {
  super(operand(aggregateClass, any()), relBuilderFactory, null);
  Objects.requireNonNull(functionsToReduce,
      "Expecting a valid handle for AggregateFunctionsToReduce");
  this.functionsToReduce = EnumSet.noneOf(SqlKind.class);
  for (SqlKind function : functionsToReduce) {
    if (SqlKind.AVG_AGG_FUNCTIONS.contains(function)
        || SqlKind.COVAR_AVG_AGG_FUNCTIONS.contains(function)
        || function == SqlKind.SUM) {
      this.functionsToReduce.add(function);
    } else {
      throw new IllegalArgumentException(
        "AggregateReduceFunctionsRule doesn't support function: " + function.sql);
    }
  }
}
 
Example 4
Source File: SqlSumAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlSumAggFunction(RelDataType type) {
  super(
      "SUM",
      null,
      SqlKind.SUM,
      ReturnTypes.AGG_SUM,
      null,
      OperandTypes.NUMERIC,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  this.type = type;
}
 
Example 5
Source File: SqlSumAggFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlSumAggFunction(RelDataType type) {
  super(
      "SUM",
      null,
      SqlKind.SUM,
      ReturnTypes.AGG_SUM,
      null,
      OperandTypes.NUMERIC,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  this.type = type;
}
 
Example 6
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static boolean isAggregation(SqlKind kind) {
	return kind == SqlKind.SUM || kind == SqlKind.SUM0
		|| kind == SqlKind.AVG || kind == SqlKind.COUNT
		|| kind == SqlKind.MAX || kind == SqlKind.MIN;
}
 
Example 7
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
private static boolean isAggregation(SqlKind kind) {
	return kind == SqlKind.SUM || kind == SqlKind.SUM0
		|| kind == SqlKind.AVG || kind == SqlKind.COUNT
		|| kind == SqlKind.MAX || kind == SqlKind.MIN;
}