org.apache.calcite.sql.type.SqlOperandTypeChecker Java Examples

The following examples show how to use org.apache.calcite.sql.type.SqlOperandTypeChecker. 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: SqlOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an operator.
 */
protected SqlOperator(
    String name,
    SqlKind kind,
    int leftPrecedence,
    int rightPrecedence,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  assert kind != null;
  this.name = name;
  this.kind = kind;
  this.leftPrec = leftPrecedence;
  this.rightPrec = rightPrecedence;
  this.returnTypeInference = returnTypeInference;
  this.operandTypeInference = operandTypeInference;
  this.operandTypeChecker = operandTypeChecker;
}
 
Example #2
Source File: SqlInfixOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
protected SqlInfixOperator(
    String[] names,
    SqlKind kind,
    int precedence,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      names[0],
      kind,
      precedence,
      true,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
  assert names.length > 1;
  this.names = names;
}
 
Example #3
Source File: SqlPrefixOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
public SqlPrefixOperator(
    String name,
    SqlKind kind,
    int prec,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      leftPrec(prec, true),
      rightPrec(prec, true),
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #4
Source File: StandardConvertletTable.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Converts a {@link SqlCall} to a {@link RexCall} with a perhaps different
 * operator. */
private RexNode convertCall(
    SqlRexContext cx,
    SqlCall call,
    SqlOperator op) {
  final List<SqlNode> operands = call.getOperandList();
  final RexBuilder rexBuilder = cx.getRexBuilder();
  final SqlOperandTypeChecker.Consistency consistency =
      op.getOperandTypeChecker() == null
          ? SqlOperandTypeChecker.Consistency.NONE
          : op.getOperandTypeChecker().getConsistency();
  final List<RexNode> exprs =
      convertExpressionList(cx, operands, consistency);
  RelDataType type = rexBuilder.deriveReturnType(op, exprs);
  return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
}
 
Example #5
Source File: StandardConvertletTable.java    From Bats with Apache License 2.0 6 votes vote down vote up
private static List<RexNode> convertExpressionList(SqlRexContext cx,
    List<SqlNode> nodes, SqlOperandTypeChecker.Consistency consistency) {
  final List<RexNode> exprs = new ArrayList<>();
  for (SqlNode node : nodes) {
    exprs.add(cx.convertExpression(node));
  }
  if (exprs.size() > 1) {
    final RelDataType type =
        consistentType(cx, consistency, RexUtil.types(exprs));
    if (type != null) {
      final List<RexNode> oldExprs = Lists.newArrayList(exprs);
      exprs.clear();
      for (RexNode expr : oldExprs) {
        exprs.add(cx.getRexBuilder().ensureType(type, expr, true));
      }
    }
  }
  return exprs;
}
 
Example #6
Source File: SqlBinaryOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SqlBinaryOperator.
 *
 * @param name                 Name of operator
 * @param kind                 Kind
 * @param prec                 Precedence
 * @param leftAssoc            Left-associativity
 * @param returnTypeInference  Strategy to infer return type
 * @param operandTypeInference Strategy to infer operand types
 * @param operandTypeChecker   Validator for operand types
 */
public SqlBinaryOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean leftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      leftPrec(prec, leftAssoc),
      rightPrec(prec, leftAssoc),
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #7
Source File: SqlSpecialOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
public SqlSpecialOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean leftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      prec,
      leftAssoc,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #8
Source File: SqlSetOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
public SqlSetOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean all,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      prec,
      true,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
  this.all = all;
}
 
Example #9
Source File: SqlPostfixOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
public SqlPostfixOperator(
    String name,
    SqlKind kind,
    int prec,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      leftPrec(prec, true),
      rightPrec(prec, true),
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #10
Source File: SqlInternalOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
public SqlInternalOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean isLeftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      prec,
      isLeftAssoc,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #11
Source File: SqlMonotonicBinaryOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
public SqlMonotonicBinaryOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean isLeftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      prec,
      isLeftAssoc,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #12
Source File: SqlPrefixOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
public SqlPrefixOperator(
    String name,
    SqlKind kind,
    int prec,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      leftPrec(prec, true),
      rightPrec(prec, true),
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #13
Source File: SqlAggFunction.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Creates a built-in or user-defined SqlAggFunction or window function.
 *
 * <p>A user-defined function will have a value for {@code sqlIdentifier}; for
 * a built-in function it will be null. */
protected SqlAggFunction(
    String name,
    SqlIdentifier sqlIdentifier,
    SqlKind kind,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker,
    SqlFunctionCategory funcType,
    boolean requiresOrder,
    boolean requiresOver,
    Optionality requiresGroupOrder) {
  super(name, sqlIdentifier, kind, returnTypeInference, operandTypeInference,
      operandTypeChecker, null, funcType);
  this.requiresOrder = requiresOrder;
  this.requiresOver = requiresOver;
  this.requiresGroupOrder = Objects.requireNonNull(requiresGroupOrder);
}
 
Example #14
Source File: SqlOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an operator.
 */
protected SqlOperator(
    String name,
    SqlKind kind,
    int leftPrecedence,
    int rightPrecedence,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  assert kind != null;
  this.name = name;
  this.kind = kind;
  this.leftPrec = leftPrecedence;
  this.rightPrec = rightPrecedence;
  this.returnTypeInference = returnTypeInference;
  this.operandTypeInference = operandTypeInference;
  this.operandTypeChecker = operandTypeChecker;
}
 
Example #15
Source File: SqlFunction.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Internal constructor.
 */
protected SqlFunction(
    String name,
    SqlIdentifier sqlIdentifier,
    SqlKind kind,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker,
    List<RelDataType> paramTypes,
    SqlFunctionCategory category) {
  super(name, kind, 100, 100, returnTypeInference, operandTypeInference,
      operandTypeChecker);

  this.sqlIdentifier = sqlIdentifier;
  this.category = Objects.requireNonNull(category);
  this.paramTypes =
      paramTypes == null ? null : ImmutableList.copyOf(paramTypes);
}
 
Example #16
Source File: StandardConvertletTable.java    From Bats with Apache License 2.0 6 votes vote down vote up
public RexNode convertFunction(
    SqlRexContext cx,
    SqlFunction fun,
    SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final List<RexNode> exprs = convertExpressionList(cx, operands,
      SqlOperandTypeChecker.Consistency.NONE);
  if (fun.getFunctionType() == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR) {
    return makeConstructorCall(cx, fun, exprs);
  }
  RelDataType returnType =
      cx.getValidator().getValidatedNodeTypeIfKnown(call);
  if (returnType == null) {
    returnType = cx.getRexBuilder().deriveReturnType(fun, exprs);
  }
  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
 
Example #17
Source File: SqlFunctionalOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
public SqlFunctionalOperator(
    String name,
    SqlKind kind,
    int pred,
    boolean isLeftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      pred,
      isLeftAssoc,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #18
Source File: ConvertletTable.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/** Converts a {@link SqlCall} to a {@link RexCall} with a perhaps different
 * operator. */
private RexNode convertCall(
    SqlRexContext cx,
    SqlCall call,
    SqlOperator op) {
  final List<SqlNode> operands = call.getOperandList();
  final RexBuilder rexBuilder = cx.getRexBuilder();
  final SqlOperandTypeChecker.Consistency consistency =
      op.getOperandTypeChecker() == null
          ? SqlOperandTypeChecker.Consistency.NONE
          : op.getOperandTypeChecker().getConsistency();
  final List<RexNode> exprs =
      convertExpressionList(cx, operands, consistency);
  RelDataType type = rexBuilder.deriveReturnType(op, exprs);
  return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
}
 
Example #19
Source File: ConvertletTable.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private static List<RexNode> convertExpressionList(SqlRexContext cx,
    List<SqlNode> nodes, SqlOperandTypeChecker.Consistency consistency) {
  final List<RexNode> exprs = Lists.newArrayList();
  for (SqlNode node : nodes) {
    exprs.add(cx.convertExpression(node));
  }
  if (exprs.size() > 1) {
    final RelDataType type =
        consistentType(cx, consistency, RexUtil.types(exprs));
    if (type != null) {
      final List<RexNode> oldExprs = Lists.newArrayList(exprs);
      exprs.clear();
      for (RexNode expr : oldExprs) {
        exprs.add(cx.getRexBuilder().ensureType(type, expr, true));
      }
    }
  }
  return exprs;
}
 
Example #20
Source File: SqlMinMaxAggFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates a SqlMinMaxAggFunction. */
public SqlMinMaxAggFunction(String funcName, SqlKind kind,
    SqlOperandTypeChecker inputTypeChecker) {
  super(funcName,
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      inputTypeChecker,
      SqlFunctionCategory.SYSTEM,
      false,
      false,
      Optionality.FORBIDDEN);
  this.argTypes = ImmutableList.of();
  this.minMaxKind = MINMAX_COMPARABLE;
  Preconditions.checkArgument(kind == SqlKind.MIN
      || kind == SqlKind.MAX);
}
 
Example #21
Source File: StandardConvertletTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RexNode convertFunction(
    SqlRexContext cx,
    SqlFunction fun,
    SqlCall call) {
  final List<SqlNode> operands = call.getOperandList();
  final List<RexNode> exprs = convertExpressionList(cx, operands,
      SqlOperandTypeChecker.Consistency.NONE);
  if (fun.getFunctionType() == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR) {
    return makeConstructorCall(cx, fun, exprs);
  }
  RelDataType returnType =
      cx.getValidator().getValidatedNodeTypeIfKnown(call);
  if (returnType == null) {
    returnType = cx.getRexBuilder().deriveReturnType(fun, exprs);
  }
  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
 
Example #22
Source File: StandardConvertletTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
public RexNode convertJsonValueFunction(
    SqlRexContext cx,
    SqlJsonValueFunction fun,
    SqlCall call) {
  // For Expression with explicit return type:
  // i.e. json_value('{"foo":"bar"}', 'lax $.foo', returning varchar(2000))
  // use the specified type as the return type.
  List<SqlNode> operands = call.getOperandList();
  boolean hasExplicitReturningType = SqlJsonValueFunction.hasExplicitTypeSpec(
      operands.toArray(SqlNode.EMPTY_ARRAY));
  if (hasExplicitReturningType) {
    operands = SqlJsonValueFunction.removeTypeSpecOperands(call);
  }
  final List<RexNode> exprs = convertExpressionList(cx, operands,
      SqlOperandTypeChecker.Consistency.NONE);
  RelDataType returnType =
      cx.getValidator().getValidatedNodeTypeIfKnown(call);
  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
 
Example #23
Source File: StandardConvertletTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static List<RexNode> convertExpressionList(SqlRexContext cx,
    List<SqlNode> nodes, SqlOperandTypeChecker.Consistency consistency) {
  final List<RexNode> exprs = new ArrayList<>();
  for (SqlNode node : nodes) {
    exprs.add(cx.convertExpression(node));
  }
  if (exprs.size() > 1) {
    final RelDataType type =
        consistentType(cx, consistency, RexUtil.types(exprs));
    if (type != null) {
      final List<RexNode> oldExprs = Lists.newArrayList(exprs);
      exprs.clear();
      for (RexNode expr : oldExprs) {
        exprs.add(cx.getRexBuilder().ensureType(type, expr, true));
      }
    }
  }
  return exprs;
}
 
Example #24
Source File: SqlInternalOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
public SqlInternalOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean isLeftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      prec,
      isLeftAssoc,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #25
Source File: SqlMonotonicBinaryOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
public SqlMonotonicBinaryOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean isLeftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      prec,
      isLeftAssoc,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #26
Source File: SqlFunctionalOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
public SqlFunctionalOperator(
    String name,
    SqlKind kind,
    int pred,
    boolean isLeftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      pred,
      isLeftAssoc,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #27
Source File: SqlAggFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates a built-in or user-defined SqlAggFunction or window function.
 *
 * <p>A user-defined function will have a value for {@code sqlIdentifier}; for
 * a built-in function it will be null. */
protected SqlAggFunction(
    String name,
    SqlIdentifier sqlIdentifier,
    SqlKind kind,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker,
    SqlFunctionCategory funcType,
    boolean requiresOrder,
    boolean requiresOver,
    Optionality requiresGroupOrder) {
  super(name, sqlIdentifier, kind, returnTypeInference, operandTypeInference,
      operandTypeChecker, null, funcType);
  this.requiresOrder = requiresOrder;
  this.requiresOver = requiresOver;
  this.requiresGroupOrder = Objects.requireNonNull(requiresGroupOrder);
}
 
Example #28
Source File: SqlPostfixOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
public SqlPostfixOperator(
    String name,
    SqlKind kind,
    int prec,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      leftPrec(prec, true),
      rightPrec(prec, true),
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #29
Source File: SqlBinaryOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SqlBinaryOperator.
 *
 * @param name                 Name of operator
 * @param kind                 Kind
 * @param prec                 Precedence
 * @param leftAssoc            Left-associativity
 * @param returnTypeInference  Strategy to infer return type
 * @param operandTypeInference Strategy to infer operand types
 * @param operandTypeChecker   Validator for operand types
 */
public SqlBinaryOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean leftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      name,
      kind,
      leftPrec(prec, leftAssoc),
      rightPrec(prec, leftAssoc),
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #30
Source File: SqlInfixOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
protected SqlInfixOperator(
    String[] names,
    SqlKind kind,
    int precedence,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  super(
      names[0],
      kind,
      precedence,
      true,
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
  assert names.length > 1;
  this.names = names;
}