Java Code Examples for org.apache.calcite.sql.SqlAggFunction#inferReturnType()

The following examples show how to use org.apache.calcite.sql.SqlAggFunction#inferReturnType() . 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: AggregateCall.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Creates an AggregateCall, inferring its type if {@code type} is null. */
public static AggregateCall create(SqlAggFunction aggFunction,
    boolean distinct, boolean approximate, List<Integer> argList,
    int filterArg, RelCollation collation, int groupCount,
    RelNode input, RelDataType type, String name) {
  if (type == null) {
    final RelDataTypeFactory typeFactory =
        input.getCluster().getTypeFactory();
    final List<RelDataType> types =
        SqlTypeUtil.projectTypes(input.getRowType(), argList);
    final Aggregate.AggCallBinding callBinding =
        new Aggregate.AggCallBinding(typeFactory, aggFunction, types,
            groupCount, filterArg >= 0);
    type = aggFunction.inferReturnType(callBinding);
  }
  return create(aggFunction, distinct, approximate, argList, filterArg,
      collation, type, name);
}
 
Example 2
Source File: AggregateCall.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates an AggregateCall, inferring its type if {@code type} is null. */
public static AggregateCall create(SqlAggFunction aggFunction,
    boolean distinct, boolean approximate, boolean ignoreNulls,
    List<Integer> argList, int filterArg, RelCollation collation,
    int groupCount,
    RelNode input, RelDataType type, String name) {
  if (type == null) {
    final RelDataTypeFactory typeFactory =
        input.getCluster().getTypeFactory();
    final List<RelDataType> types =
        SqlTypeUtil.projectTypes(input.getRowType(), argList);
    final Aggregate.AggCallBinding callBinding =
        new Aggregate.AggCallBinding(typeFactory, aggFunction, types,
            groupCount, filterArg >= 0);
    type = aggFunction.inferReturnType(callBinding);
  }
  return create(aggFunction, distinct, approximate, ignoreNulls, argList,
      filterArg, collation, type, name);
}
 
Example 3
Source File: Aggregate.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the inferred type of an {@link AggregateCall} matches the
 * type it was given when it was created.
 *
 * @param aggCall Aggregate call
 * @param litmus What to do if an error is detected (types do not match)
 * @return Whether the inferred and declared types match
 */
private boolean typeMatchesInferred(
    final AggregateCall aggCall,
    final Litmus litmus) {
  SqlAggFunction aggFunction = aggCall.getAggregation();
  AggCallBinding callBinding = aggCall.createBinding(this);
  RelDataType type = aggFunction.inferReturnType(callBinding);
  RelDataType expectedType = aggCall.type;
  return RelOptUtil.eq("aggCall type",
      expectedType,
      "inferred type",
      type,
      litmus);
}
 
Example 4
Source File: StandardConvertletTable.java    From Bats with Apache License 2.0 5 votes vote down vote up
public RexNode convertAggregateFunction(
    SqlRexContext cx,
    SqlAggFunction fun,
    SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final List<RexNode> exprs;
  if (call.isCountStar()) {
    exprs = ImmutableList.of();
  } else {
    exprs = convertExpressionList(cx, operands,
        SqlOperandTypeChecker.Consistency.NONE);
  }
  RelDataType returnType =
      cx.getValidator().getValidatedNodeTypeIfKnown(call);
  final int groupCount = cx.getGroupCount();
  if (returnType == null) {
    RexCallBinding binding =
        new RexCallBinding(cx.getTypeFactory(), fun, exprs,
            ImmutableList.of()) {
          @Override public int getGroupCount() {
            return groupCount;
          }
        };
    returnType = fun.inferReturnType(binding);
  }
  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
 
Example 5
Source File: Aggregate.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the inferred type of an {@link AggregateCall} matches the
 * type it was given when it was created.
 *
 * @param aggCall Aggregate call
 * @param litmus What to do if an error is detected (types do not match)
 * @return Whether the inferred and declared types match
 */
private boolean typeMatchesInferred(
    final AggregateCall aggCall,
    final Litmus litmus) {
  SqlAggFunction aggFunction = aggCall.getAggregation();
  AggCallBinding callBinding = aggCall.createBinding(this);
  RelDataType type = aggFunction.inferReturnType(callBinding);
  RelDataType expectedType = aggCall.type;
  return RelOptUtil.eq("aggCall type",
      expectedType,
      "inferred type",
      type,
      litmus);
}
 
Example 6
Source File: StandardConvertletTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RexNode convertAggregateFunction(
    SqlRexContext cx,
    SqlAggFunction fun,
    SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final List<RexNode> exprs;
  if (call.isCountStar()) {
    exprs = ImmutableList.of();
  } else {
    exprs = convertExpressionList(cx, operands,
        SqlOperandTypeChecker.Consistency.NONE);
  }
  RelDataType returnType =
      cx.getValidator().getValidatedNodeTypeIfKnown(call);
  final int groupCount = cx.getGroupCount();
  if (returnType == null) {
    RexCallBinding binding =
        new RexCallBinding(cx.getTypeFactory(), fun, exprs,
            ImmutableList.of()) {
          @Override public int getGroupCount() {
            return groupCount;
          }
        };
    returnType = fun.inferReturnType(binding);
  }
  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}