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

The following examples show how to use org.apache.calcite.sql.type.OperandTypes. 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: SqlItemOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
private SqlSingleOperandTypeChecker getChecker(RelDataType operandType) {
  switch (operandType.getSqlTypeName()) {
  case ARRAY:
    return OperandTypes.family(SqlTypeFamily.INTEGER);
  case MAP:
    return OperandTypes.family(
        operandType.getKeyType().getSqlTypeName().getFamily());
  case ANY:
  case DYNAMIC_STAR:
    return OperandTypes.or(
        OperandTypes.family(SqlTypeFamily.INTEGER),
        OperandTypes.family(SqlTypeFamily.CHARACTER));
  default:
    throw new AssertionError(operandType.getSqlTypeName());
  }
}
 
Example #2
Source File: SqlLikeOperator.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SqlLikeOperator.
 *
 * @param name    Operator name
 * @param kind    Kind
 * @param negated Whether this is 'NOT LIKE'
 */
SqlLikeOperator(
    String name,
    SqlKind kind,
    boolean negated) {
  // LIKE is right-associative, because that makes it easier to capture
  // dangling ESCAPE clauses: "a like b like c escape d" becomes
  // "a like (b like c escape d)".
  super(
      name,
      kind,
      32,
      false,
      ReturnTypes.BOOLEAN_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.STRING_SAME_SAME_SAME);
  this.negated = negated;
}
 
Example #3
Source File: RexBuilderContext.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
public RexNode getIObject() {
    if (object == null) {
        RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
        RexBuilder b = getBuilder();
        final SqlFunction GET_IOBJECT =
                new SqlUserDefinedFunction(
                        new SqlIdentifier("GET_IOBJECT", SqlParserPos.ZERO),
                        ReturnTypes.explicit(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false)),
                        null,
                        OperandTypes.ANY_ANY,
                        ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(ISnapshot.class), false),
                                typeFactory.createJavaType(int.class)),
                        ScalarFunctionImpl.create(ISnapshotMethods.class, "getIObject"));
        object = b.makeCall(GET_IOBJECT, getSnapshot(), getIObjectId());
    }
    return object;
}
 
Example #4
Source File: ClassRowTypeCache.java    From mat-calcite-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public RexNode apply(RexBuilderContext context) {
	RelOptCluster cluster = context.getCluster();
	RelDataTypeFactory typeFactory = cluster.getTypeFactory();
	final SqlFunction UDF =
			new SqlUserDefinedFunction(
					new SqlIdentifier("RESOLVE_SIMPLE", SqlParserPos.ZERO),
					ReturnTypes.explicit(typeFactory.createJavaType(Object.class)),
					null,
					OperandTypes.ANY_ANY,
					ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false),
							typeFactory.createJavaType(int.class)),
					ScalarFunctionImpl.create(IObjectMethods.class, "resolveSimpleValue"));
	RexBuilder b = context.getBuilder();
	RexNode rexNode = b.makeCall(UDF, context.getIObject(), b.makeLiteral(name));
	return b.makeCast(dataType, rexNode);
}
 
Example #5
Source File: SqlMinMaxAggFunction.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Creates a SqlMinMaxAggFunction. */
public SqlMinMaxAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.COMPARABLE_ORDERED,
      SqlFunctionCategory.SYSTEM,
      false,
      false,
      Optionality.FORBIDDEN);
  this.argTypes = ImmutableList.of();
  this.minMaxKind = MINMAX_COMPARABLE;
  Preconditions.checkArgument(kind == SqlKind.MIN
      || kind == SqlKind.MAX);
}
 
Example #6
Source File: SqlBitOpAggFunction.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Creates a SqlBitOpAggFunction. */
public SqlBitOpAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.INTEGER,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.BIT_AND
      || kind == SqlKind.BIT_OR
      || kind == SqlKind.BIT_XOR);
}
 
Example #7
Source File: SqlHistogramAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlHistogramAggFunction(RelDataType type) {
  super(
      "$HISTOGRAM",
      null,
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.HISTOGRAM,
      null,
      OperandTypes.NUMERIC_OR_STRING,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  this.type = type;
}
 
Example #8
Source File: SqlMultisetMemberOfOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
public boolean checkOperandTypes(
    SqlCallBinding callBinding,
    boolean throwOnFailure) {
  if (!OperandTypes.MULTISET.checkSingleOperandType(
      callBinding,
      callBinding.operand(1),
      0,
      throwOnFailure)) {
    return false;
  }

  MultisetSqlType mt =
      (MultisetSqlType) callBinding.getValidator().deriveType(
          callBinding.getScope(),
          callBinding.operand(1));

  RelDataType t0 =
      callBinding.getValidator().deriveType(
          callBinding.getScope(),
          callBinding.operand(0));
  RelDataType t1 = mt.getComponentType();

  if (t0.getFamily() != t1.getFamily()) {
    if (throwOnFailure) {
      throw callBinding.newValidationError(
          RESOURCE.typeNotComparableNear(t0.toString(), t1.toString()));
    }
    return false;
  }
  return true;
}
 
Example #9
Source File: SqlRandIntegerFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlRandIntegerFunction() {
  super("RAND_INTEGER",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.INTEGER,
      null,
      OperandTypes.or(OperandTypes.NUMERIC, OperandTypes.NUMERIC_NUMERIC),
      SqlFunctionCategory.NUMERIC);
}
 
Example #10
Source File: SqlDotOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
private SqlSingleOperandTypeChecker getChecker(RelDataType operandType) {
  switch (operandType.getSqlTypeName()) {
  case ROW:
    return OperandTypes.family(SqlTypeFamily.STRING);
  default:
    throw new AssertionError(operandType.getSqlTypeName());
  }
}
 
Example #11
Source File: SqlFirstLastValueAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public SqlFirstLastValueAggFunction(SqlKind kind) {
	super(
			kind.name(),
			null,
			kind,
			ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
			null,
			OperandTypes.ANY,
			SqlFunctionCategory.NUMERIC,
			false,
			false,
			Optionality.FORBIDDEN);
	Preconditions.checkArgument(kind == SqlKind.FIRST_VALUE
			|| kind == SqlKind.LAST_VALUE);
}
 
Example #12
Source File: SqlCursorConstructor.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlCursorConstructor() {
  super(
      "CURSOR",
      SqlKind.CURSOR, MDX_PRECEDENCE,
      false,
      ReturnTypes.CURSOR,
      null,
      OperandTypes.ANY);
}
 
Example #13
Source File: SqlJsonTypeFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlJsonTypeFunction() {
  super("JSON_TYPE",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.cascade(
          ReturnTypes.explicit(SqlTypeName.VARCHAR, 20),
          SqlTypeTransforms.FORCE_NULLABLE),
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.SYSTEM);
}
 
Example #14
Source File: SqlAuxiliaryGroupAggFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public SqlAuxiliaryGroupAggFunction() {
	super("AUXILIARY_GROUP",
			null,
			SqlKind.OTHER_FUNCTION,
			ReturnTypes.ARG0,
			null,
			OperandTypes.ANY,
			SqlFunctionCategory.SYSTEM,
			false,
			false);
}
 
Example #15
Source File: SqlJsonValueFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlJsonValueFunction(String name) {
  super(name, SqlKind.OTHER_FUNCTION,
      ReturnTypes.cascade(
          opBinding -> explicitTypeSpec(opBinding).orElse(getDefaultType(opBinding)),
          SqlTypeTransforms.FORCE_NULLABLE),
      null,
      OperandTypes.family(
          ImmutableList.of(SqlTypeFamily.ANY, SqlTypeFamily.CHARACTER),
          ordinal -> ordinal > 1),
      SqlFunctionCategory.SYSTEM);
}
 
Example #16
Source File: SqlJsonPrettyFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlJsonPrettyFunction() {
  super("JSON_PRETTY",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.cascade(ReturnTypes.VARCHAR_2000, SqlTypeTransforms.FORCE_NULLABLE),
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.SYSTEM);
}
 
Example #17
Source File: SqlJsonDepthFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlJsonDepthFunction() {
  super("JSON_DEPTH",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.cascade(ReturnTypes.INTEGER,
          SqlTypeTransforms.FORCE_NULLABLE),
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.SYSTEM);
}
 
Example #18
Source File: SqlDatetimeSubtractionOperator.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlDatetimeSubtractionOperator() {
  super(
      "-",
      SqlKind.MINUS,
      40,
      true,
      ReturnTypes.ARG2_NULLABLE,
      InferTypes.FIRST_KNOWN, OperandTypes.MINUS_DATE_OPERATOR);
}
 
Example #19
Source File: SqlOverlapsOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
public boolean checkOperandTypes(SqlCallBinding callBinding,
    boolean throwOnFailure) {
  if (!OperandTypes.PERIOD.checkSingleOperandType(callBinding,
      callBinding.operand(0), 0, throwOnFailure)) {
    return false;
  }
  final SqlSingleOperandTypeChecker rightChecker;
  switch (kind) {
  case CONTAINS:
    rightChecker = OperandTypes.PERIOD_OR_DATETIME;
    break;
  default:
    rightChecker = OperandTypes.PERIOD;
    break;
  }
  if (!rightChecker.checkSingleOperandType(callBinding,
      callBinding.operand(1), 0, throwOnFailure)) {
    return false;
  }
  final RelDataType t0 = callBinding.getOperandType(0);
  final RelDataType t1 = callBinding.getOperandType(1);
  if (!SqlTypeUtil.isDatetime(t1)) {
    final RelDataType t00 = t0.getFieldList().get(0).getType();
    final RelDataType t10 = t1.getFieldList().get(0).getType();
    if (!SqlTypeUtil.sameNamedType(t00, t10)) {
      if (throwOnFailure) {
        throw callBinding.newValidationSignatureError();
      }
      return false;
    }
  }
  return true;
}
 
Example #20
Source File: SqlRandFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlRandFunction() {
  super("RAND",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.DOUBLE,
      null,
      OperandTypes.or(OperandTypes.NILADIC, OperandTypes.NUMERIC),
      SqlFunctionCategory.NUMERIC);
}
 
Example #21
Source File: SqlBitOpAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Creates a SqlBitOpAggFunction. */
public SqlBitOpAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.INTEGER,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.BIT_AND
      || kind == SqlKind.BIT_OR);
}
 
Example #22
Source File: SqlTimestampDiffFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
SqlTimestampDiffFunction() {
  super("TIMESTAMPDIFF", SqlKind.TIMESTAMP_DIFF,
      RETURN_TYPE_INFERENCE, null,
      OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.DATETIME,
          SqlTypeFamily.DATETIME),
      SqlFunctionCategory.TIMEDATE);
}
 
Example #23
Source File: SqlTimestampAddFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a SqlTimestampAddFunction. */
SqlTimestampAddFunction() {
  super("TIMESTAMPADD", SqlKind.TIMESTAMP_ADD, RETURN_TYPE_INFERENCE, null,
      OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.INTEGER,
          SqlTypeFamily.DATETIME),
      SqlFunctionCategory.TIMEDATE);
}
 
Example #24
Source File: SqlJsonPrettyFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlJsonPrettyFunction() {
  super("JSON_PRETTY",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.VARCHAR_2000,
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.SYSTEM);
}
 
Example #25
Source File: SqlThrowOperator.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlThrowOperator() {
  super(
      "$throw",
      SqlKind.OTHER,
      2,
      true,
      ReturnTypes.BOOLEAN,
      null,
      OperandTypes.CHARACTER);
}
 
Example #26
Source File: SqlNtileAggFunction.java    From calcite with Apache License 2.0 5 votes vote down vote up
public SqlNtileAggFunction() {
  super(
      "NTILE",
      null,
      SqlKind.NTILE,
      ReturnTypes.RANK,
      null,
      OperandTypes.POSITIVE_INTEGER_LITERAL,
      SqlFunctionCategory.NUMERIC,
      false,
      true,
      Optionality.FORBIDDEN);
}
 
Example #27
Source File: HyperLogLog.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public SqlHllAggFunction() {
  super("HLL",
    null,
    SqlKind.OTHER_FUNCTION,
    ReturnTypes.explicit(SqlTypeName.VARBINARY, HLL_VARBINARY_SIZE),
    null,
    OperandTypes.ANY,
    SqlFunctionCategory.USER_DEFINED_FUNCTION,
    false,
    false
  );
}
 
Example #28
Source File: ProctimeMaterializeSqlFunction.java    From flink with Apache License 2.0 5 votes vote down vote up
public ProctimeMaterializeSqlFunction() {
	super(
		"PROCTIME_MATERIALIZE",
		SqlKind.OTHER_FUNCTION,
		ReturnTypes.cascade(
				ReturnTypes.explicit(SqlTypeName.TIMESTAMP, 3),
				SqlTypeTransforms.TO_NULLABLE),
		InferTypes.RETURN_TYPE,
		OperandTypes.family(SqlTypeFamily.TIMESTAMP),
		SqlFunctionCategory.SYSTEM);
}
 
Example #29
Source File: SqlNullifFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlNullifFunction() {
  // NOTE jvs 26-July-2006:  We fill in the type strategies here,
  // but normally they are not used because the validator invokes
  // rewriteCall to convert NULLIF into CASE early.  However,
  // validator rewrite can optionally be disabled, in which case these
  // strategies are used.
  super("NULLIF",
      SqlKind.NULLIF,
      ReturnTypes.ARG0_FORCE_NULLABLE,
      null,
      OperandTypes.COMPARABLE_UNORDERED_COMPARABLE_UNORDERED,
      SqlFunctionCategory.SYSTEM);
}
 
Example #30
Source File: SqlJsonArrayAggAggFunction.java    From Bats with Apache License 2.0 5 votes vote down vote up
public SqlJsonArrayAggAggFunction(SqlKind kind,
    SqlJsonConstructorNullClause nullClause) {
  super(kind + "_" + nullClause.name(), null, kind, ReturnTypes.VARCHAR_2000, null,
      OperandTypes.family(SqlTypeFamily.ANY), SqlFunctionCategory.SYSTEM,
      false, false, Optionality.OPTIONAL);
  this.nullClause = Objects.requireNonNull(nullClause);
}