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

The following examples show how to use org.apache.calcite.sql.type.SqlReturnTypeInference. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: SqlSetOperator.java    From calcite 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 #7
Source File: SqlFunction.java    From calcite 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 #8
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 #9
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 #10
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 #11
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 #12
Source File: SqlFunction.java    From calcite with 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 #13
Source File: SqlSpecialOperator.java    From calcite 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 #14
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 #15
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 #16
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 #17
Source File: SqlFunction.java    From Bats with 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 #18
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 #19
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 #20
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;
}
 
Example #21
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 #22
Source File: SqlOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an operator specifying left/right associativity.
 */
protected SqlOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean leftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  this(
      name,
      kind,
      leftPrec(prec, leftAssoc),
      rightPrec(prec, leftAssoc),
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #23
Source File: SqlOperator.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an operator specifying left/right associativity.
 */
protected SqlOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean leftAssoc,
    SqlReturnTypeInference returnTypeInference,
    SqlOperandTypeInference operandTypeInference,
    SqlOperandTypeChecker operandTypeChecker) {
  this(
      name,
      kind,
      leftPrec(prec, leftAssoc),
      rightPrec(prec, leftAssoc),
      returnTypeInference,
      operandTypeInference,
      operandTypeChecker);
}
 
Example #24
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 #25
Source File: HiveScalarSqlFunction.java    From flink with Apache License 2.0 6 votes vote down vote up
private static SqlReturnTypeInference createReturnTypeInference(
		ScalarFunction function, FlinkTypeFactory typeFactory) {
	return opBinding -> {
		List<RelDataType> sqlTypes = opBinding.collectOperandTypes();
		LogicalType[] parameters = UserDefinedFunctionUtils.getOperandTypeArray(opBinding);

		Object[] constantArguments = new Object[sqlTypes.size()];
		for (int i = 0; i < sqlTypes.size(); i++) {
			if (!opBinding.isOperandNull(i, false) && opBinding.isOperandLiteral(i, false)) {
				constantArguments[i] = opBinding.getOperandLiteralValue(
						i, getDefaultExternalClassForType(parameters[i]));
			}
		}
		return invokeGetResultType(function, constantArguments, parameters, typeFactory);
	};
}
 
Example #26
Source File: SqlAggOperator.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public SqlAggOperator(String name, int argCountMin, int argCountMax, SqlReturnTypeInference sqlReturnTypeInference) {
  super(name,
      new SqlIdentifier(name, SqlParserPos.ZERO),
      SqlKind.OTHER_FUNCTION,
      sqlReturnTypeInference,
      null,
      Checker.getChecker(argCountMin, argCountMax),
      SqlFunctionCategory.USER_DEFINED_FUNCTION);
}
 
Example #27
Source File: TypeInferenceUtils.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Give the name and BaseFunctionHolder list, return the inference mechanism.
 */
public static SqlReturnTypeInference getSqlReturnTypeInference(
  final String name,
  final List<AbstractFunctionHolder> functions,
  final boolean isDecimalV2Enabled) {

  final String nameCap = name.toUpperCase();
  if(funcNameToInference.containsKey(nameCap)) {
    return funcNameToInference.get(nameCap);
  } else {
    return new DefaultSqlReturnTypeInference(functions, isDecimalV2Enabled);
  }
}
 
Example #28
Source File: HiveSqlFunction.java    From marble with Apache License 2.0 5 votes vote down vote up
public HiveSqlFunction(SqlIdentifier sqlIdentifier, SqlKind kind,
    SqlReturnTypeInference returnTypeInference,
    SqlFunctionCategory category) {
  super(Util.last(sqlIdentifier.names), sqlIdentifier, kind,
      returnTypeInference, null, ArgChecker.INSTANCE,
      null, category);
}
 
Example #29
Source File: GandivaOperator.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a default operator that is
 *
 * 1. deterministic i.e. same output for same input always
 * 2. not dynamic i.e. plans can be safely cached for this operator.
 * 3. is of syntax function i.e. always called with paranthesis even if no args
 *
 * @param name - name of the function
 * @param minParamCount - number of parameters to the function
 * @param maxParamCount - max number of paramters for a function with this name
 * @param returnTypeInference
 * @return
 */
public static SqlOperatorImpl getSimpleFunction(String name, int minParamCount, int
  maxParamCount, SqlReturnTypeInference returnTypeInference) {

  return new SqlOperatorImpl(
    name,
    minParamCount,
    maxParamCount,
    IS_DETERMINISTIC,
    IS_DYNAMIC,
    returnTypeInference,
    SqlSyntax.FUNCTION);

}
 
Example #30
Source File: HiveAggSqlFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
private static SqlReturnTypeInference createReturnTypeInference(
		AggregateFunction function, FlinkTypeFactory typeFactory) {
	return opBinding -> {
		List<RelDataType> sqlTypes = opBinding.collectOperandTypes();
		LogicalType[] parameters = UserDefinedFunctionUtils.getOperandTypeArray(opBinding);

		Object[] constantArguments = new Object[sqlTypes.size()];
		// Can not touch the literals, Calcite make them in previous RelNode.
		// In here, all inputs are input refs.
		return invokeGetResultType(function, constantArguments, parameters, typeFactory);
	};
}