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

The following examples show how to use org.apache.calcite.sql.type.SqlOperandTypeChecker. These examples are extracted from open source projects. 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 Project: Bats   Source File: StandardConvertletTable.java    License: 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 2
Source Project: Bats   Source File: StandardConvertletTable.java    License: 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 3
Source Project: Bats   Source File: StandardConvertletTable.java    License: 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 4
Source Project: Bats   Source File: SqlSpecialOperator.java    License: 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 5
Source Project: Bats   Source File: SqlSetOperator.java    License: 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 6
Source Project: Bats   Source File: SqlInternalOperator.java    License: 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 7
Source Project: calcite   Source File: SqlFunction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new SqlFunction for a call to a builtin function.
 *
 * @param name                 Name of builtin function
 * @param kind                 kind of operator implemented by function
 * @param returnTypeInference  strategy to use for return type inference
 * @param operandTypeInference strategy to use for parameter type inference
 * @param operandTypeChecker   strategy to use for parameter type checking
 * @param category             categorization for function
 */
public SqlFunction(
    String name,
    SqlKind kind,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker,
    SqlFunctionCategory category) {
  // We leave sqlIdentifier as null to indicate
  // that this is a builtin.  Same for paramTypes.
  this(name, null, kind, returnTypeInference, operandTypeInference,
      operandTypeChecker, null, category);

  assert !((category == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR)
      && (returnTypeInference == null));
}
 
Example 8
Source Project: Bats   Source File: SqlPostfixOperator.java    License: 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 9
Source Project: Bats   Source File: SqlBinaryOperator.java    License: 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 10
Source Project: Bats   Source File: SqlInfixOperator.java    License: 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 11
Source Project: calcite   Source File: SqlPrefixOperator.java    License: 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 12
Source Project: Bats   Source File: SqlMonotonicBinaryOperator.java    License: 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 13
Source Project: Bats   Source File: SqlPrefixOperator.java    License: 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 14
Source Project: Bats   Source File: SqlAggFunction.java    License: 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 15
Source Project: calcite   Source File: SqlOperator.java    License: 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 16
Source Project: Bats   Source File: SqlFunction.java    License: 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 17
Source Project: Bats   Source File: SqlOperator.java    License: 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 18
Source Project: Bats   Source File: SqlFunctionalOperator.java    License: 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 19
Source Project: dremio-oss   Source File: ConvertletTable.java    License: 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 20
Source Project: dremio-oss   Source File: ConvertletTable.java    License: 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 21
Source Project: calcite   Source File: SqlMinMaxAggFunction.java    License: 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 22
Source Project: calcite   Source File: StandardConvertletTable.java    License: 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 23
Source Project: calcite   Source File: StandardConvertletTable.java    License: 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 24
Source Project: calcite   Source File: StandardConvertletTable.java    License: 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 25
Source Project: calcite   Source File: SqlInternalOperator.java    License: 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 26
Source Project: calcite   Source File: SqlMonotonicBinaryOperator.java    License: 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 27
Source Project: calcite   Source File: SqlFunctionalOperator.java    License: 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 28
Source Project: calcite   Source File: SqlAggFunction.java    License: 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 29
Source Project: calcite   Source File: SqlPostfixOperator.java    License: 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 30
Source Project: calcite   Source File: SqlBinaryOperator.java    License: 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);
}