org.apache.calcite.util.Optionality Java Examples
The following examples show how to use
org.apache.calcite.util.Optionality.
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: RelBuilder.java From calcite with Apache License 2.0 | 6 votes |
AggCallImpl(SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, RexNode filter, String alias, ImmutableList<RexNode> operands, ImmutableList<RexNode> orderKeys) { this.aggFunction = Objects.requireNonNull(aggFunction); // If the aggregate function ignores DISTINCT, // make the DISTINCT flag FALSE. this.distinct = distinct && aggFunction.getDistinctOptionality() != Optionality.IGNORED; this.approximate = approximate; this.ignoreNulls = ignoreNulls; this.alias = alias; this.operands = Objects.requireNonNull(operands); this.orderKeys = Objects.requireNonNull(orderKeys); if (filter != null) { if (filter.getType().getSqlTypeName() != SqlTypeName.BOOLEAN) { throw RESOURCE.filterMustBeBoolean().ex(); } if (filter.getType().isNullable()) { filter = call(SqlStdOperatorTable.IS_TRUE, filter); } } this.filter = filter; }
Example #2
Source File: SqlMinMaxAggFunction.java From calcite with Apache License 2.0 | 6 votes |
/** Creates a SqlMinMaxAggFunction. */ public SqlMinMaxAggFunction(String funcName, SqlKind kind, SqlOperandTypeChecker inputTypeChecker) { super(funcName, null, kind, ReturnTypes.ARG0_NULLABLE_IF_EMPTY, null, inputTypeChecker, SqlFunctionCategory.SYSTEM, false, false, Optionality.FORBIDDEN); this.argTypes = ImmutableList.of(); this.minMaxKind = MINMAX_COMPARABLE; Preconditions.checkArgument(kind == SqlKind.MIN || kind == SqlKind.MAX); }
Example #3
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 #4
Source File: SqlAggFunction.java From Bats with Apache License 2.0 | 6 votes |
/** 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 #5
Source File: AggregateCall.java From calcite with Apache License 2.0 | 6 votes |
/** * Creates an AggregateCall. * * @param aggFunction Aggregate function * @param distinct Whether distinct * @param approximate Whether approximate * @param argList List of ordinals of arguments * @param filterArg Ordinal of filter argument (the * {@code FILTER (WHERE ...)} clause in SQL), or -1 * @param collation How to sort values before aggregation (the * {@code WITHIN GROUP} clause in SQL) * @param type Result type * @param name Name (may be null) */ private AggregateCall(SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, List<Integer> argList, int filterArg, RelCollation collation, RelDataType type, String name) { this.type = Objects.requireNonNull(type); this.name = name; this.aggFunction = Objects.requireNonNull(aggFunction); this.argList = ImmutableList.copyOf(argList); this.filterArg = filterArg; this.collation = Objects.requireNonNull(collation); this.distinct = distinct; this.approximate = approximate; this.ignoreNulls = ignoreNulls; Preconditions.checkArgument( aggFunction.getDistinctOptionality() != Optionality.IGNORED || !distinct, "DISTINCT has no effect for this aggregate function, so must be false"); Preconditions.checkArgument(filterArg < 0 || aggFunction.allowsFilter()); }
Example #6
Source File: SqlAggFunction.java From calcite with Apache License 2.0 | 6 votes |
/** 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 #7
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 #8
Source File: SqlSingleValueAggFunction.java From Bats with Apache License 2.0 | 5 votes |
public SqlSingleValueAggFunction( RelDataType type) { super( "SINGLE_VALUE", null, SqlKind.SINGLE_VALUE, ReturnTypes.ARG0, null, OperandTypes.ANY, SqlFunctionCategory.SYSTEM, false, false, Optionality.FORBIDDEN); this.type = type; }
Example #9
Source File: FlinkAggregateExpandDistinctAggregatesRule.java From flink with Apache License 2.0 | 5 votes |
private static void rewriteAggCalls( List<AggregateCall> newAggCalls, List<Integer> argList, Map<Integer, Integer> sourceOf) { // Rewrite the agg calls. Each distinct agg becomes a non-distinct call // to the corresponding field from the right; for example, // "COUNT(DISTINCT e.sal)" becomes "COUNT(distinct_e.sal)". for (int i = 0; i < newAggCalls.size(); i++) { final AggregateCall aggCall = newAggCalls.get(i); // Ignore agg calls which are not distinct or have the wrong set // arguments. If we're rewriting aggregates whose args are {sal}, we will // rewrite COUNT(DISTINCT sal) and SUM(DISTINCT sal) but ignore // COUNT(DISTINCT gender) or SUM(sal). if (!aggCall.isDistinct() && aggCall.getAggregation().getDistinctOptionality() != Optionality.IGNORED) { continue; } if (!aggCall.getArgList().equals(argList)) { continue; } // Re-map arguments. final int argCount = aggCall.getArgList().size(); final List<Integer> newArgs = new ArrayList<>(argCount); for (int j = 0; j < argCount; j++) { final Integer arg = aggCall.getArgList().get(j); newArgs.add(sourceOf.get(arg)); } final AggregateCall newAggCall = AggregateCall.create(aggCall.getAggregation(), false, aggCall.isApproximate(), false, newArgs, -1, RelCollations.EMPTY, aggCall.getType(), aggCall.getName()); newAggCalls.set(i, newAggCall); } }
Example #10
Source File: AggregateExpandDistinctAggregatesRule.java From calcite with Apache License 2.0 | 5 votes |
private static void rewriteAggCalls( List<AggregateCall> newAggCalls, List<Integer> argList, Map<Integer, Integer> sourceOf) { // Rewrite the agg calls. Each distinct agg becomes a non-distinct call // to the corresponding field from the right; for example, // "COUNT(DISTINCT e.sal)" becomes "COUNT(distinct_e.sal)". for (int i = 0; i < newAggCalls.size(); i++) { final AggregateCall aggCall = newAggCalls.get(i); // Ignore agg calls which are not distinct or have the wrong set // arguments. If we're rewriting aggregates whose args are {sal}, we will // rewrite COUNT(DISTINCT sal) and SUM(DISTINCT sal) but ignore // COUNT(DISTINCT gender) or SUM(sal). if (!aggCall.isDistinct() && aggCall.getAggregation().getDistinctOptionality() != Optionality.IGNORED) { continue; } if (!aggCall.getArgList().equals(argList)) { continue; } // Re-map arguments. final int argCount = aggCall.getArgList().size(); final List<Integer> newArgs = new ArrayList<>(argCount); for (int j = 0; j < argCount; j++) { final Integer arg = aggCall.getArgList().get(j); newArgs.add(sourceOf.get(arg)); } final AggregateCall newAggCall = AggregateCall.create(aggCall.getAggregation(), false, aggCall.isApproximate(), aggCall.ignoreNulls(), newArgs, -1, aggCall.collation, aggCall.getType(), aggCall.getName()); newAggCalls.set(i, newAggCall); } }
Example #11
Source File: SqlUserDefinedAggFunction.java From Bats with Apache License 2.0 | 5 votes |
/** Creates a SqlUserDefinedAggFunction. */ public SqlUserDefinedAggFunction(SqlIdentifier opName, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, AggregateFunction function, boolean requiresOrder, boolean requiresOver, Optionality requiresGroupOrder, RelDataTypeFactory typeFactory) { super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION, returnTypeInference, operandTypeInference, operandTypeChecker, SqlFunctionCategory.USER_DEFINED_FUNCTION, requiresOrder, requiresOver, requiresGroupOrder); this.function = function; this.typeFactory = typeFactory; }
Example #12
Source File: AggregateCall.java From calcite with Apache License 2.0 | 5 votes |
/** Creates an AggregateCall. */ public static AggregateCall create(SqlAggFunction aggFunction, boolean distinct, boolean approximate, boolean ignoreNulls, List<Integer> argList, int filterArg, RelCollation collation, RelDataType type, String name) { final boolean distinct2 = distinct && (aggFunction.getDistinctOptionality() != Optionality.IGNORED); return new AggregateCall(aggFunction, distinct2, approximate, ignoreNulls, argList, filterArg, collation, type, name); }
Example #13
Source File: CalciteCatalogReader.java From calcite with Apache License 2.0 | 5 votes |
/** Converts a function to a {@link org.apache.calcite.sql.SqlOperator}. * * <p>The {@code typeFactory} argument is technical debt; see [CALCITE-2082] * Remove RelDataTypeFactory argument from SqlUserDefinedAggFunction * constructor. */ private static SqlOperator toOp(RelDataTypeFactory typeFactory, 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 FamilyOperandTypeChecker typeChecker = OperandTypes.family(typeFamilies, i -> function.getParameters().get(i).isOptional()); final List<RelDataType> paramTypes = toSql(typeFactory, 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, Optionality.FORBIDDEN, 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 #14
Source File: SqlUserDefinedAggFunction.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a SqlUserDefinedAggFunction. */ public SqlUserDefinedAggFunction(SqlIdentifier opName, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, AggregateFunction function, boolean requiresOrder, boolean requiresOver, Optionality requiresGroupOrder, RelDataTypeFactory typeFactory) { super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION, returnTypeInference, operandTypeInference, operandTypeChecker, SqlFunctionCategory.USER_DEFINED_FUNCTION, requiresOrder, requiresOver, requiresGroupOrder); this.function = function; this.typeFactory = typeFactory; }
Example #15
Source File: SqlCovarAggFunction.java From Bats with Apache License 2.0 | 5 votes |
/** * 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 #16
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 #17
Source File: SqlLeadLagAggFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlLeadLagAggFunction(SqlKind kind) { super(kind.name(), null, kind, RETURN_TYPE, null, OPERAND_TYPES, SqlFunctionCategory.NUMERIC, false, true, Optionality.FORBIDDEN); Preconditions.checkArgument(kind == SqlKind.LEAD || kind == SqlKind.LAG); }
Example #18
Source File: SqlCovarAggFunction.java From calcite with Apache License 2.0 | 5 votes |
/** * 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 #19
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 #20
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 #21
Source File: SqlJsonObjectAggAggFunction.java From calcite 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, (callBinding, returnType, operandTypes) -> { RelDataTypeFactory typeFactory = callBinding.getTypeFactory(); operandTypes[0] = typeFactory.createSqlType(SqlTypeName.VARCHAR); operandTypes[1] = typeFactory.createTypeWithNullability( typeFactory.createSqlType(SqlTypeName.ANY), true); }, OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.ANY), SqlFunctionCategory.SYSTEM, false, false, Optionality.FORBIDDEN); this.nullClause = Objects.requireNonNull(nullClause); }
Example #22
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 #23
Source File: SqlHistogramAggFunction.java From calcite 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 #24
Source File: SqlSingleValueAggFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlSingleValueAggFunction( RelDataType type) { super( "SINGLE_VALUE", null, SqlKind.SINGLE_VALUE, ReturnTypes.ARG0, null, OperandTypes.ANY, SqlFunctionCategory.SYSTEM, false, false, Optionality.FORBIDDEN); this.type = type; }
Example #25
Source File: SqlSumEmptyIsZeroAggFunction.java From calcite 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 #26
Source File: SqlAnyValueAggFunction.java From calcite with Apache License 2.0 | 5 votes |
/** 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 #27
Source File: SqlSumAggFunction.java From calcite with Apache License 2.0 | 5 votes |
public SqlSumAggFunction(RelDataType type) { super( "SUM", null, SqlKind.SUM, ReturnTypes.AGG_SUM, null, OperandTypes.NUMERIC, SqlFunctionCategory.NUMERIC, false, false, Optionality.FORBIDDEN); this.type = type; }
Example #28
Source File: SqlAggFunction.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a built-in SqlAggFunction. */ @Deprecated // to be removed before 2.0 protected SqlAggFunction( String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType) { // We leave sqlIdentifier as null to indicate that this is a builtin. this(name, null, kind, returnTypeInference, operandTypeInference, operandTypeChecker, funcType, false, false, Optionality.FORBIDDEN); }
Example #29
Source File: SqlAggFunction.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a user-defined SqlAggFunction. */ @Deprecated // to be removed before 2.0 protected SqlAggFunction( String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType) { this(name, sqlIdentifier, kind, returnTypeInference, operandTypeInference, operandTypeChecker, funcType, false, false, Optionality.FORBIDDEN); }
Example #30
Source File: SqlAggFunction.java From calcite with Apache License 2.0 | 5 votes |
@Deprecated // to be removed before 2.0 protected SqlAggFunction( String name, SqlIdentifier sqlIdentifier, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType, boolean requiresOrder, boolean requiresOver) { this(name, sqlIdentifier, kind, returnTypeInference, operandTypeInference, operandTypeChecker, funcType, requiresOrder, requiresOver, Optionality.FORBIDDEN); }