org.apache.calcite.sql.SqlFunctionCategory Java Examples
The following examples show how to use
org.apache.calcite.sql.SqlFunctionCategory.
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: 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 #2
Source File: ListSqlOperatorTable.java From Bats with Apache License 2.0 | 6 votes |
public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) { for (SqlOperator operator : this.operatorList) { if (operator.getSyntax() != syntax) { continue; } if (!opName.isSimple() || !operator.isName(opName.getSimple())) { continue; } if (category != null && category != category(operator) && !category.isUserDefinedNotSpecificFunction()) { continue; } operatorList.add(operator); } }
Example #3
Source File: CalciteCatalogReader.java From Bats with Apache License 2.0 | 6 votes |
public void lookupOperatorOverloads(final SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) { if (syntax != SqlSyntax.FUNCTION) { return; } final Predicate<Function> predicate; if (category == null) { predicate = function -> true; } else if (category.isTableFunction()) { predicate = function -> function instanceof TableMacro || function instanceof TableFunction; } else { predicate = function -> !(function instanceof TableMacro || function instanceof TableFunction); } getFunctionsFrom(opName.names) .stream() .filter(predicate) .map(function -> toOp(opName, function)) .forEachOrdered(operatorList::add); }
Example #4
Source File: FunctionCatalogOperatorTable.java From flink with Apache License 2.0 | 6 votes |
@Override public void lookupOperatorOverloads( SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList, SqlNameMatcher nameMatcher) { if (!opName.isSimple()) { return; } // We lookup only user functions via CatalogOperatorTable. Built in functions should // go through BasicOperatorTable if (isNotUserFunction(category)) { return; } String name = opName.getSimple(); Optional<FunctionLookup.Result> candidateFunction = functionCatalog.lookupFunction( UnresolvedIdentifier.of(name)); candidateFunction.flatMap(lookupResult -> convertToSqlFunction(category, name, lookupResult.getFunctionDefinition()) ).ifPresent(operatorList::add); }
Example #5
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 #6
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 #7
Source File: StandardConvertletTable.java From calcite with Apache License 2.0 | 6 votes |
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 #8
Source File: SqlListAggFunction.java From flink with Apache License 2.0 | 6 votes |
public SqlListAggFunction() { super("LISTAGG", null, SqlKind.LISTAGG, ReturnTypes.ARG0_NULLABLE, null, OperandTypes.or( OperandTypes.CHARACTER, OperandTypes.sequence( "'LISTAGG(<CHARACTER>, <CHARACTER_LITERAL>)'", OperandTypes.CHARACTER, OperandTypes.and(OperandTypes.CHARACTER, OperandTypes.LITERAL) )), SqlFunctionCategory.SYSTEM, false, false); }
Example #9
Source File: StandardConvertletTable.java From Bats with Apache License 2.0 | 6 votes |
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 #10
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 #11
Source File: SqlMonotonicUnaryFunction.java From calcite with Apache License 2.0 | 5 votes |
protected SqlMonotonicUnaryFunction( String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType) { super( name, kind, returnTypeInference, operandTypeInference, operandTypeChecker, funcType); }
Example #12
Source File: SqlValidatorImpl.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public void validateCall( SqlCall call, SqlValidatorScope scope) { final SqlOperator operator = call.getOperator(); if ((call.operandCount() == 0) && (operator.getSyntax() == SqlSyntax.FUNCTION_ID) && !call.isExpanded() && !conformance.allowNiladicParentheses()) { // For example, "LOCALTIME()" is illegal. (It should be // "LOCALTIME", which would have been handled as a // SqlIdentifier.) throw handleUnresolvedFunction(call, (SqlFunction) operator, ImmutableList.of(), null); } SqlValidatorScope operandScope = scope.getOperandScope(call); if (operator instanceof SqlFunction && ((SqlFunction) operator).getFunctionType() == SqlFunctionCategory.MATCH_RECOGNIZE && !(operandScope instanceof MatchRecognizeScope)) { throw newValidationError(call, Static.RESOURCE.functionMatchRecognizeOnly(call.toString())); } // Delegate validation to the operator. operator.validateCall(call, this, scope, operandScope); }
Example #13
Source File: SqlValidatorImpl.java From flink with Apache License 2.0 | 5 votes |
public void validateCall( SqlCall call, SqlValidatorScope scope) { final SqlOperator operator = call.getOperator(); if ((call.operandCount() == 0) && (operator.getSyntax() == SqlSyntax.FUNCTION_ID) && !call.isExpanded() && !conformance.allowNiladicParentheses()) { // For example, "LOCALTIME()" is illegal. (It should be // "LOCALTIME", which would have been handled as a // SqlIdentifier.) throw handleUnresolvedFunction(call, (SqlFunction) operator, ImmutableList.of(), null); } SqlValidatorScope operandScope = scope.getOperandScope(call); if (operator instanceof SqlFunction && ((SqlFunction) operator).getFunctionType() == SqlFunctionCategory.MATCH_RECOGNIZE && !(operandScope instanceof MatchRecognizeScope)) { throw newValidationError(call, Static.RESOURCE.functionMatchRecognizeOnly(call.toString())); } // Delegate validation to the operator. operator.validateCall(call, this, scope, operandScope); }
Example #14
Source File: SqlOverlayFunction.java From calcite 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 #15
Source File: SqlUserDefinedFunction.java From calcite with Apache License 2.0 | 5 votes |
/** Constructor used internally and by derived classes. */ protected SqlUserDefinedFunction(SqlIdentifier opName, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, List<RelDataType> paramTypes, Function function, SqlFunctionCategory category) { super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION, returnTypeInference, operandTypeInference, operandTypeChecker, paramTypes, category); this.function = function; }
Example #16
Source File: SqlJsonArrayAggAggFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlJsonArrayAggAggFunction(SqlKind kind, SqlJsonConstructorNullClause nullClause) { super(kind + "_" + nullClause.name(), null, kind, ReturnTypes.VARCHAR_2000, InferTypes.ANY_NULLABLE, OperandTypes.family(SqlTypeFamily.ANY), SqlFunctionCategory.SYSTEM, false, false, Optionality.OPTIONAL); this.nullClause = Objects.requireNonNull(nullClause); }
Example #17
Source File: DrillOperatorTable.java From Bats with Apache License 2.0 | 5 votes |
@Override public void lookupOperatorOverloads(SqlIdentifier opName, SqlFunctionCategory category, SqlSyntax syntax, List<SqlOperator> operatorList) { if (isInferenceEnabled()) { populateFromTypeInference(opName, category, syntax, operatorList); } else { populateFromWithoutTypeInference(opName, category, syntax, operatorList); } }
Example #18
Source File: SqlJsonRemoveFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlJsonRemoveFunction() { super("JSON_REMOVE", SqlKind.OTHER_FUNCTION, ReturnTypes.cascade(ReturnTypes.VARCHAR_2000, SqlTypeTransforms.FORCE_NULLABLE), null, null, SqlFunctionCategory.SYSTEM); }
Example #19
Source File: SqlSumEmptyIsZeroAggFunction.java From Bats with Apache License 2.0 | 5 votes |
public SqlSumEmptyIsZeroAggFunction() { super("$SUM0", null, SqlKind.SUM0, ReturnTypes.AGG_SUM_EMPTY_IS_ZERO, null, OperandTypes.NUMERIC, SqlFunctionCategory.NUMERIC, false, false, Optionality.FORBIDDEN); }
Example #20
Source File: SqlPositionFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlPositionFunction() { super( "POSITION", SqlKind.POSITION, ReturnTypes.INTEGER_NULLABLE, null, OTC_CUSTOM, SqlFunctionCategory.NUMERIC); }
Example #21
Source File: SqlConvertFunction.java From Bats with Apache License 2.0 | 5 votes |
protected SqlConvertFunction(String name) { super( name, SqlKind.OTHER_FUNCTION, null, null, null, SqlFunctionCategory.STRING); }
Example #22
Source File: SqlJsonStorageSizeFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlJsonStorageSizeFunction() { super("JSON_STORAGE_SIZE", SqlKind.OTHER_FUNCTION, ReturnTypes.cascade(ReturnTypes.INTEGER, SqlTypeTransforms.FORCE_NULLABLE), null, OperandTypes.ANY, SqlFunctionCategory.SYSTEM); }
Example #23
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 #24
Source File: SqlAvgAggFunction.java From calcite with Apache License 2.0 | 5 votes |
SqlAvgAggFunction(String name, SqlKind kind) { super(name, null, kind, ReturnTypes.AVG_AGG_FUNCTION, null, OperandTypes.NUMERIC, SqlFunctionCategory.NUMERIC, false, false, Optionality.FORBIDDEN); Preconditions.checkArgument(SqlKind.AVG_AGG_FUNCTIONS.contains(kind), "unsupported sql kind"); }
Example #25
Source File: SqlNtileAggFunction.java From Bats 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 #26
Source File: SqlTimestampDiffFunction.java From calcite with Apache License 2.0 | 5 votes |
SqlTimestampDiffFunction() { super("TIMESTAMPDIFF", SqlKind.TIMESTAMP_DIFF, RETURN_TYPE_INFERENCE, null, OperandTypes.family(SqlTypeFamily.ANY, SqlTypeFamily.DATETIME, SqlTypeFamily.DATETIME), SqlFunctionCategory.TIMEDATE); }
Example #27
Source File: SqlTranslate3Function.java From Bats 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 #28
Source File: PigUserDefinedFunction.java From calcite with Apache License 2.0 | 5 votes |
private PigUserDefinedFunction(SqlIdentifier opName, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, List<RelDataType> paramTypes, Function function, FuncSpec funcSpec) { super(opName, returnTypeInference, operandTypeInference, operandTypeChecker, paramTypes, function, SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR); this.funcSpec = funcSpec; }
Example #29
Source File: SqlRegexpReplaceFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlRegexpReplaceFunction() { super("REGEXP_REPLACE", SqlKind.OTHER_FUNCTION, ReturnTypes.cascade(ReturnTypes.explicit(SqlTypeName.VARCHAR), SqlTypeTransforms.TO_NULLABLE), null, null, SqlFunctionCategory.STRING); }
Example #30
Source File: SqlAuxiliaryGroupAggFunction.java From flink with Apache License 2.0 | 5 votes |
public SqlAuxiliaryGroupAggFunction() { super("AUXILIARY_GROUP", null, SqlKind.OTHER_FUNCTION, ReturnTypes.ARG0, null, OperandTypes.ANY, SqlFunctionCategory.SYSTEM, false, false); }