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

The following examples show how to use org.apache.calcite.sql.type.OperandTypes. 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: SqlMinMaxAggFunction.java    License: 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 2
Source Project: Bats   Source File: SqlLikeOperator.java    License: 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 Project: Bats   Source File: SqlItemOperator.java    License: 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 4
Source Project: mat-calcite-plugin   Source File: ClassRowTypeCache.java    License: 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 Project: mat-calcite-plugin   Source File: RexBuilderContext.java    License: 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 6
Source Project: calcite   Source File: SqlBitOpAggFunction.java    License: 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 Project: calcite   Source File: SqlAnyValueAggFunction.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates a SqlAnyValueAggFunction. */
public SqlAnyValueAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      ReturnTypes.ARG0_NULLABLE_IF_EMPTY,
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.SYSTEM,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(kind == SqlKind.ANY_VALUE);
}
 
Example 8
Source Project: dremio-oss   Source File: DremioCatalogReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Rest of class is utility functions taken directly from CalciteCatalogReader. This is because that class consider these utilities to be private concerns.
 */
private SqlOperator toOp(SqlIdentifier name, final Function function) {
  List<RelDataType> argTypes = new ArrayList<>();
  List<SqlTypeFamily> typeFamilies = new ArrayList<>();
  for (FunctionParameter o : function.getParameters()) {
    final RelDataType type = o.getType(typeFactory);
    argTypes.add(type);
    typeFamilies.add(
        Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY));
  }
  final Predicate<Integer> optional =
      new Predicate<Integer>() {
        @Override
        public boolean apply(Integer input) {
          return function.getParameters().get(input).isOptional();
        }
      };
  final FamilyOperandTypeChecker typeChecker =
      OperandTypes.family(typeFamilies, optional);
  final List<RelDataType> paramTypes = toSql(argTypes);
  if (function instanceof ScalarFunction) {
    return new SqlUserDefinedFunction(name, infer((ScalarFunction) function),
        InferTypes.explicit(argTypes), typeChecker, paramTypes, function);
  } else if (function instanceof AggregateFunction) {
    return new SqlUserDefinedAggFunction(name,
        infer((AggregateFunction) function), InferTypes.explicit(argTypes),
        typeChecker, (AggregateFunction) function, false, false, typeFactory);
  } else if (function instanceof TableMacro) {
    return new SqlUserDefinedTableMacro(name, ReturnTypes.CURSOR,
        InferTypes.explicit(argTypes), typeChecker, paramTypes,
        (TableMacro) function);
  } else if (function instanceof TableFunction) {
    return new SqlUserDefinedTableFunction(name, ReturnTypes.CURSOR,
        InferTypes.explicit(argTypes), typeChecker, paramTypes,
        (TableFunction) function);
  } else {
    throw new AssertionError("unknown function type " + function);
  }
}
 
Example 9
Source Project: Bats   Source File: SqlJdbcFunctionCall.java    License: Apache License 2.0 5 votes vote down vote up
public SqlJdbcFunctionCall(String name) {
  super(
      "{fn " + name + "}",
      SqlKind.JDBC_FN,
      null,
      null,
      OperandTypes.VARIADIC,
      SqlFunctionCategory.SYSTEM);
  jdbcName = name;
  lookupMakeCallObj = JdbcToInternalLookupTable.INSTANCE.lookup(name);
  lookupCall = null;
}
 
Example 10
Source Project: Bats   Source File: SqlUnnestOperator.java    License: Apache License 2.0 5 votes vote down vote up
public SqlUnnestOperator(boolean withOrdinality) {
  super(
      "UNNEST",
      SqlKind.UNNEST,
      200,
      true,
      null,
      null,
      OperandTypes.repeat(SqlOperandCountRanges.from(1),
          OperandTypes.SCALAR_OR_RECORD_COLLECTION_OR_MAP));
  this.withOrdinality = withOrdinality;
}
 
Example 11
Source Project: Bats   Source File: SqlMultisetMemberOfOperator.java    License: 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 12
Source Project: Bats   Source File: SqlCurrentDateFunction.java    License: Apache License 2.0 5 votes vote down vote up
public SqlCurrentDateFunction() {
  super(
      "CURRENT_DATE",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.DATE,
      null,
      OperandTypes.NILADIC,
      SqlFunctionCategory.TIMEDATE);
}
 
Example 13
Source Project: calcite   Source File: SqlThrowOperator.java    License: Apache License 2.0 5 votes vote down vote up
public SqlThrowOperator() {
  super(
      "$throw",
      SqlKind.OTHER,
      2,
      true,
      ReturnTypes.BOOLEAN,
      null,
      OperandTypes.CHARACTER);
}
 
Example 14
Source Project: calcite   Source File: MockSqlOperatorTable.java    License: Apache License 2.0 5 votes vote down vote up
public MyFunction() {
  super("MYFUN",
      new SqlIdentifier("MYFUN", SqlParserPos.ZERO),
      SqlKind.OTHER_FUNCTION,
      null,
      null,
      OperandTypes.NUMERIC,
      null,
      SqlFunctionCategory.USER_DEFINED_FUNCTION);
}
 
Example 15
Source Project: Bats   Source File: SqlJsonDepthFunction.java    License: Apache License 2.0 5 votes vote down vote up
public SqlJsonDepthFunction() {
  super("JSON_DEPTH",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.INTEGER_NULLABLE,
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.SYSTEM);
}
 
Example 16
Source Project: Bats   Source File: SqlDatePartFunction.java    License: Apache License 2.0 5 votes vote down vote up
public SqlDatePartFunction(String name, TimeUnit timeUnit) {
  super(name,
      SqlKind.OTHER,
      ReturnTypes.BIGINT_NULLABLE,
      InferTypes.FIRST_KNOWN,
      OperandTypes.DATETIME,
      SqlFunctionCategory.TIMEDATE);
  this.timeUnit = timeUnit;
}
 
Example 17
Source Project: calcite   Source File: SqlTranslate3Function.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates the SqlTranslate3Function.
 */
SqlTranslate3Function() {
  super("TRANSLATE3",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.ARG0_NULLABLE_VARYING,
      null,
      OperandTypes.STRING_STRING_STRING,
      SqlFunctionCategory.STRING);
}
 
Example 18
Source Project: flink   Source File: StreamRecordTimestampSqlFunction.java    License: Apache License 2.0 5 votes vote down vote up
public StreamRecordTimestampSqlFunction() {
	super(
		"STREAMRECORD_TIMESTAMP",
		SqlKind.OTHER_FUNCTION,
		ReturnTypes.explicit(SqlTypeName.BIGINT),
		InferTypes.RETURN_TYPE,
		OperandTypes.family(SqlTypeFamily.NUMERIC),
		SqlFunctionCategory.SYSTEM);
}
 
Example 19
Source Project: calcite   Source File: SqlOverlapsOperator.java    License: 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 Project: calcite   Source File: SqlJsonStorageSizeFunction.java    License: Apache License 2.0 5 votes vote down vote up
public SqlJsonStorageSizeFunction() {
  super("JSON_STORAGE_SIZE",
      SqlKind.OTHER_FUNCTION,
      ReturnTypes.cascade(ReturnTypes.INTEGER,
          SqlTypeTransforms.FORCE_NULLABLE),
      null,
      OperandTypes.ANY,
      SqlFunctionCategory.SYSTEM);
}
 
Example 21
Source Project: calcite   Source File: SqlCovarAggFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a SqlCovarAggFunction.
 */
public SqlCovarAggFunction(SqlKind kind) {
  super(kind.name(),
      null,
      kind,
      kind == SqlKind.REGR_COUNT ? ReturnTypes.BIGINT : ReturnTypes.COVAR_REGR_FUNCTION,
      null,
      OperandTypes.NUMERIC_NUMERIC,
      SqlFunctionCategory.NUMERIC,
      false,
      false,
      Optionality.FORBIDDEN);
  Preconditions.checkArgument(SqlKind.COVAR_AVG_AGG_FUNCTIONS.contains(kind),
      "unsupported sql kind: " + kind);
}
 
Example 22
Source Project: Bats   Source File: SqlRandFunction.java    License: 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 23
Source Project: Bats   Source File: SqlTimestampAddFunction.java    License: 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 Project: calcite   Source File: SqlSetOperator.java    License: Apache License 2.0 5 votes vote down vote up
public SqlSetOperator(
    String name,
    SqlKind kind,
    int prec,
    boolean all) {
  super(
      name,
      kind,
      prec,
      true,
      ReturnTypes.LEAST_RESTRICTIVE,
      null,
      OperandTypes.SET_OP);
  this.all = all;
}
 
Example 25
Source Project: Bats   Source File: SqlTimestampDiffFunction.java    License: 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 26
Source Project: Bats   Source File: SqlNullifFunction.java    License: 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 27
Source Project: calcite   Source File: SqlRandFunction.java    License: 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 28
Source Project: Bats   Source File: SqlJsonArrayAggAggFunction.java    License: 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);
}
 
Example 29
Source Project: flink   Source File: ProctimeMaterializeSqlFunction.java    License: 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 30
Source Project: dremio-oss   Source File: HyperLogLog.java    License: 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
  );
}