org.apache.calcite.sql.type.ReturnTypes Java Examples
The following examples show how to use
org.apache.calcite.sql.type.ReturnTypes.
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: ClassRowTypeCache.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public RexNode apply(RexBuilderContext context) { RelOptCluster cluster = context.getCluster(); RelDataTypeFactory typeFactory = cluster.getTypeFactory(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("RESOLVE_REFERENCE", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createJavaType(HeapReference.class)), null, OperandTypes.ANY_ANY, ImmutableList.of(typeFactory.createTypeWithNullability(typeFactory.createJavaType(IObject.class), false), typeFactory.createJavaType(String.class)), ScalarFunctionImpl.create(IObjectMethods.class, "resolveReferenceValue")); RexBuilder b = context.getBuilder(); return b.makeCall(UDF, context.getIObject(), b.makeLiteral(name)); }
Example #2
Source File: RexBuilderContext.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
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 #3
Source File: SqlDatePartOperator.java From dremio-oss with Apache License 2.0 | 6 votes |
public SqlDatePartOperator() { super( "DATE_PART", SqlKind.OTHER_FUNCTION, ReturnTypes.BIGINT_NULLABLE, null, OperandTypes.sequence( "<PERIOD LITERAL>, <DATE or TIMESTAMP or INTERVAL>", new EnumeratedListChecker(VALID_PERIODS.keySet()), OperandTypes.or( OperandTypes.family(SqlTypeFamily.DATE), OperandTypes.family(SqlTypeFamily.TIMESTAMP), OperandTypes.family(SqlTypeFamily.DATETIME), OperandTypes.family(SqlTypeFamily.DATETIME_INTERVAL), OperandTypes.family(SqlTypeFamily.INTERVAL_DAY_TIME), OperandTypes.family(SqlTypeFamily.INTERVAL_YEAR_MONTH)) ), SqlFunctionCategory.SYSTEM); }
Example #4
Source File: SqlLikeOperator.java From Bats with Apache License 2.0 | 6 votes |
/** * 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 #5
Source File: ExecutionRexBuilderContext.java From mat-calcite-plugin with Apache License 2.0 | 6 votes |
@Override public RexNode getSnapshot() { if (snapshot == null) { RelDataTypeFactory typeFactory = getCluster().getTypeFactory(); RexBuilder b = getBuilder(); final SqlFunction UDF = new SqlUserDefinedFunction( new SqlIdentifier("GET_SNAPSHOT", SqlParserPos.ZERO), ReturnTypes.explicit(typeFactory.createTypeWithNullability(typeFactory.createJavaType(ISnapshot.class), false)), null, OperandTypes.NUMERIC, ImmutableList.of(typeFactory.createJavaType(Integer.class)), ScalarFunctionImpl.create(SnapshotHolder.class, "get")); snapshot = b.makeCall(UDF, b.makeLiteral(snapshotId, typeFactory.createSqlType(SqlTypeName.INTEGER), false)); } return snapshot; }
Example #6
Source File: SqlFloorFunction.java From Bats with Apache License 2.0 | 6 votes |
/** * Most dialects that natively support datetime floor will use this. * In those cases the call will look like TRUNC(datetime, 'year'). * * @param writer SqlWriter * @param call SqlCall * @param funName Name of the sql function to call * @param datetimeFirst Specify the order of the datetime & timeUnit * arguments */ public static void unparseDatetimeFunction(SqlWriter writer, SqlCall call, String funName, Boolean datetimeFirst) { SqlFunction func = new SqlFunction(funName, SqlKind.OTHER_FUNCTION, ReturnTypes.ARG0_NULLABLE_VARYING, null, null, SqlFunctionCategory.STRING); SqlCall call1; if (datetimeFirst) { call1 = call; } else { // switch order of operands SqlNode op1 = call.operand(0); SqlNode op2 = call.operand(1); call1 = call.getOperator().createCall(call.getParserPosition(), op2, op1); } SqlUtil.unparseFunctionSyntax(func, writer, call1); }
Example #7
Source File: SqlFloorFunction.java From calcite with Apache License 2.0 | 6 votes |
/** * Most dialects that natively support datetime floor will use this. * In those cases the call will look like TRUNC(datetime, 'year'). * * @param writer SqlWriter * @param call SqlCall * @param funName Name of the sql function to call * @param datetimeFirst Specify the order of the datetime & timeUnit * arguments */ public static void unparseDatetimeFunction(SqlWriter writer, SqlCall call, String funName, Boolean datetimeFirst) { SqlFunction func = new SqlFunction(funName, SqlKind.OTHER_FUNCTION, ReturnTypes.ARG0_NULLABLE_VARYING, null, null, SqlFunctionCategory.STRING); SqlCall call1; if (datetimeFirst) { call1 = call; } else { // switch order of operands SqlNode op1 = call.operand(0); SqlNode op2 = call.operand(1); call1 = call.getOperator().createCall(call.getParserPosition(), op2, op1); } SqlUtil.unparseFunctionSyntax(func, writer, call1); }
Example #8
Source File: SqlMinMaxAggFunction.java From Bats with Apache License 2.0 | 6 votes |
/** 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 #9
Source File: RexProgramTest.java From calcite with Apache License 2.0 | 6 votes |
@Test void testIsDeterministic() { SqlOperator ndc = new SqlSpecialOperator( "NDC", SqlKind.OTHER_FUNCTION, 0, false, ReturnTypes.BOOLEAN, null, null) { @Override public boolean isDeterministic() { return false; } }; RexNode n = rexBuilder.makeCall(ndc); assertFalse(RexUtil.isDeterministic(n)); assertEquals(0, RexUtil.retainDeterministic(RelOptUtil.conjunctions(n)).size()); }
Example #10
Source File: SqlLikeOperator.java From calcite with Apache License 2.0 | 6 votes |
/** * 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 #11
Source File: SqlBitOpAggFunction.java From calcite with Apache License 2.0 | 6 votes |
/** 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 #12
Source File: SqlDatePartFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlDatePartFunction(String name, TimeUnit timeUnit) { super(name, SqlKind.OTHER, ReturnTypes.BIGINT_NULLABLE, InferTypes.FIRST_KNOWN, OperandTypes.DATETIME, SqlFunctionCategory.TIMEDATE); this.timeUnit = timeUnit; }
Example #13
Source File: SqlTranslate3Function.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates the SqlTranslate3Function. */ SqlTranslate3Function() { super("TRANSLATE3", SqlKind.OTHER_FUNCTION, ReturnTypes.ARG0_NULLABLE_VARYING, null, OperandTypes.STRING_STRING_STRING, SqlFunctionCategory.STRING); }
Example #14
Source File: SqlBitOpAggFunction.java From Bats with Apache License 2.0 | 5 votes |
/** 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 #15
Source File: SqlFirstLastValueAggFunction.java From flink with Apache License 2.0 | 5 votes |
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 #16
Source File: FlinkSqlOperatorTable.java From flink with Apache License 2.0 | 5 votes |
private static SqlReturnTypeInference createTimeIndicatorReturnType(boolean isRowTime) { return ReturnTypes.explicit(factory -> { if (isRowTime) { return ((FlinkTypeFactory) factory).createRowtimeIndicatorType(false); } else { return ((FlinkTypeFactory) factory).createProctimeIndicatorType(false); } }); }
Example #17
Source File: SqlOverlayFunction.java From Bats with Apache License 2.0 | 5 votes |
public SqlOverlayFunction() { super( "OVERLAY", SqlKind.OTHER_FUNCTION, ReturnTypes.DYADIC_STRING_SUM_PRECISION_NULLABLE_VARYING, null, OTC_CUSTOM, SqlFunctionCategory.STRING); }
Example #18
Source File: SqlGroupedWindowFunction.java From calcite with Apache License 2.0 | 5 votes |
@Deprecated // to be removed before 2.0 public SqlGroupedWindowFunction(String name, SqlKind kind, SqlGroupedWindowFunction groupFunction, SqlOperandTypeChecker operandTypeChecker) { this(name, kind, groupFunction, ReturnTypes.ARG0, null, operandTypeChecker, SqlFunctionCategory.SYSTEM); }
Example #19
Source File: OLAPAggregateRel.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
SqlAggFunction createCustomAggFunction(String funcName, RelDataType returnType, Class<?> customAggFuncClz) { RelDataTypeFactory typeFactory = getCluster().getTypeFactory(); SqlIdentifier sqlIdentifier = new SqlIdentifier(funcName, new SqlParserPos(1, 1)); AggregateFunction aggFunction = AggregateFunctionImpl.create(customAggFuncClz); List<RelDataType> argTypes = new ArrayList<RelDataType>(); List<SqlTypeFamily> typeFamilies = new ArrayList<SqlTypeFamily>(); for (FunctionParameter o : aggFunction.getParameters()) { final RelDataType type = o.getType(typeFactory); argTypes.add(type); typeFamilies.add(Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY)); } return new SqlUserDefinedAggFunction(sqlIdentifier, ReturnTypes.explicit(returnType), InferTypes.explicit(argTypes), OperandTypes.family(typeFamilies), aggFunction, false, false, typeFactory); }
Example #20
Source File: SqlJsonKeysFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlJsonKeysFunction() { super("JSON_KEYS", SqlKind.OTHER_FUNCTION, ReturnTypes.cascade(ReturnTypes.VARCHAR_2000, SqlTypeTransforms.FORCE_NULLABLE), null, OperandTypes.or(OperandTypes.ANY, OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.CHARACTER)), SqlFunctionCategory.SYSTEM); }
Example #21
Source File: SqlCursorConstructor.java From Bats with Apache License 2.0 | 5 votes |
public SqlCursorConstructor() { super( "CURSOR", SqlKind.CURSOR, MDX_PRECEDENCE, false, ReturnTypes.CURSOR, null, OperandTypes.ANY); }
Example #22
Source File: SqlHistogramAggFunction.java From Bats with Apache License 2.0 | 5 votes |
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 #23
Source File: SqlJsonTypeFunction.java From Bats with Apache License 2.0 | 5 votes |
public SqlJsonTypeFunction() { super("JSON_TYPE", SqlKind.OTHER_FUNCTION, ReturnTypes.explicit(SqlTypeName.VARCHAR, 20), null, OperandTypes.ANY, SqlFunctionCategory.SYSTEM); }
Example #24
Source File: SqlJsonPrettyFunction.java From Bats with Apache License 2.0 | 5 votes |
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 |
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 |
public SqlNtileAggFunction() { super( "NTILE", null, SqlKind.NTILE, ReturnTypes.RANK, null, OperandTypes.POSITIVE_INTEGER_LITERAL, SqlFunctionCategory.NUMERIC, false, true, Optionality.FORBIDDEN); }
Example #27
Source File: SqlDatetimeSubtractionOperator.java From Bats with Apache License 2.0 | 5 votes |
public SqlDatetimeSubtractionOperator() { super( "-", SqlKind.MINUS, 40, true, ReturnTypes.ARG2_NULLABLE, InferTypes.FIRST_KNOWN, OperandTypes.MINUS_DATE_OPERATOR); }
Example #28
Source File: SqlFirstLastValueAggFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlFirstLastValueAggFunction(SqlKind kind) { super( kind.name(), null, kind, ReturnTypes.ARG0_NULLABLE_IF_EMPTY, null, OperandTypes.ANY, SqlFunctionCategory.NUMERIC, false, true, Optionality.FORBIDDEN); Preconditions.checkArgument(kind == SqlKind.FIRST_VALUE || kind == SqlKind.LAST_VALUE); }
Example #29
Source File: SqlGroupedWindowFunction.java From Bats with Apache License 2.0 | 5 votes |
@Deprecated // to be removed before 2.0 public SqlGroupedWindowFunction(String name, SqlKind kind, SqlGroupedWindowFunction groupFunction, SqlOperandTypeChecker operandTypeChecker) { this(name, kind, groupFunction, ReturnTypes.ARG0, null, operandTypeChecker, SqlFunctionCategory.SYSTEM); }
Example #30
Source File: SqlJsonObjectAggAggFunction.java From Bats with Apache License 2.0 | 5 votes |
/** Creates a SqlJsonObjectAggAggFunction. */ public SqlJsonObjectAggAggFunction(SqlKind kind, SqlJsonConstructorNullClause nullClause) { super(kind + "_" + nullClause.name(), null, kind, ReturnTypes.VARCHAR_2000, null, OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.ANY), SqlFunctionCategory.SYSTEM, false, false, Optionality.FORBIDDEN); this.nullClause = Objects.requireNonNull(nullClause); }