Java Code Examples for org.apache.calcite.sql.SqlCall#isCountStar()

The following examples show how to use org.apache.calcite.sql.SqlCall#isCountStar() . 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: 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 2
Source File: SqlCountAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public RelDataType deriveType(
    SqlValidator validator,
    SqlValidatorScope scope,
    SqlCall call) {
  // Check for COUNT(*) function.  If it is we don't
  // want to try and derive the "*"
  if (call.isCountStar()) {
    return validator.getTypeFactory().createSqlType(
        SqlTypeName.BIGINT);
  }
  return super.deriveType(validator, scope, call);
}
 
Example 3
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);
}
 
Example 4
Source File: SqlCountAggFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelDataType deriveType(
    SqlValidator validator,
    SqlValidatorScope scope,
    SqlCall call) {
  // Check for COUNT(*) function.  If it is we don't
  // want to try and derive the "*"
  if (call.isCountStar()) {
    return validator.getTypeFactory().createSqlType(
        SqlTypeName.BIGINT);
  }
  return super.deriveType(validator, scope, call);
}
 
Example 5
Source File: PlannerTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelDataType deriveType(SqlValidator validator,
    SqlValidatorScope scope, SqlCall call) {
  // Check for COUNT(*) function.  If it is we don't
  // want to try and derive the "*"
  if (call.isCountStar()) {
    return validator.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
  }
  return super.deriveType(validator, scope, call);
}