use of org.apache.flink.table.planner.functions.utils.AggSqlFunction in project flink by apache.
the class CommonPythonUtil method extractPythonAggregateFunctionInfosFromAggregateCall.
public static Tuple2<int[], PythonFunctionInfo[]> extractPythonAggregateFunctionInfosFromAggregateCall(AggregateCall[] aggCalls) {
Map<Integer, Integer> inputNodes = new LinkedHashMap<>();
List<PythonFunctionInfo> pythonFunctionInfos = new ArrayList<>();
for (AggregateCall aggregateCall : aggCalls) {
List<Integer> inputs = new ArrayList<>();
List<Integer> argList = aggregateCall.getArgList();
for (Integer arg : argList) {
if (inputNodes.containsKey(arg)) {
inputs.add(inputNodes.get(arg));
} else {
Integer inputOffset = inputNodes.size();
inputs.add(inputOffset);
inputNodes.put(arg, inputOffset);
}
}
PythonFunction pythonFunction = null;
SqlAggFunction aggregateFunction = aggregateCall.getAggregation();
if (aggregateFunction instanceof AggSqlFunction) {
pythonFunction = (PythonFunction) ((AggSqlFunction) aggregateFunction).aggregateFunction();
} else if (aggregateFunction instanceof BridgingSqlAggFunction) {
pythonFunction = (PythonFunction) ((BridgingSqlAggFunction) aggregateFunction).getDefinition();
}
PythonFunctionInfo pythonFunctionInfo = new PythonAggregateFunctionInfo(pythonFunction, inputs.toArray(), aggregateCall.filterArg, aggregateCall.isDistinct());
pythonFunctionInfos.add(pythonFunctionInfo);
}
int[] udafInputOffsets = inputNodes.keySet().stream().mapToInt(i -> i).toArray();
return Tuple2.of(udafInputOffsets, pythonFunctionInfos.toArray(new PythonFunctionInfo[0]));
}
use of org.apache.flink.table.planner.functions.utils.AggSqlFunction in project flink by apache.
the class SqlAggFunctionVisitor method createLegacySqlTableAggregateFunction.
private SqlAggFunction createLegacySqlTableAggregateFunction(@Nullable FunctionIdentifier identifier, TableAggregateFunctionDefinition definition) {
final TableAggregateFunction<?, ?> aggFunc = definition.getTableAggregateFunction();
final FunctionIdentifier adjustedIdentifier;
if (identifier != null) {
adjustedIdentifier = identifier;
} else {
adjustedIdentifier = FunctionIdentifier.of(generateInlineFunctionName(aggFunc));
}
return new AggSqlFunction(adjustedIdentifier, aggFunc.toString(), aggFunc, fromLegacyInfoToDataType(definition.getResultTypeInfo()), fromLegacyInfoToDataType(definition.getAccumulatorTypeInfo()), ShortcutUtils.unwrapTypeFactory(relBuilder), false, scala.Option.empty());
}
use of org.apache.flink.table.planner.functions.utils.AggSqlFunction in project flink by apache.
the class SqlAggFunctionVisitor method createLegacySqlAggregateFunction.
private SqlAggFunction createLegacySqlAggregateFunction(@Nullable FunctionIdentifier identifier, AggregateFunctionDefinition definition) {
final AggregateFunction<?, ?> aggFunc = definition.getAggregateFunction();
final FunctionIdentifier adjustedIdentifier;
if (identifier != null) {
adjustedIdentifier = identifier;
} else {
adjustedIdentifier = FunctionIdentifier.of(generateInlineFunctionName(aggFunc));
}
return new AggSqlFunction(adjustedIdentifier, aggFunc.toString(), aggFunc, fromLegacyInfoToDataType(definition.getResultTypeInfo()), fromLegacyInfoToDataType(definition.getAccumulatorTypeInfo()), ShortcutUtils.unwrapTypeFactory(relBuilder), aggFunc.getRequirements().contains(FunctionRequirement.OVER_WINDOW_ONLY), scala.Option.empty());
}
use of org.apache.flink.table.planner.functions.utils.AggSqlFunction in project flink by apache.
the class RexNodeJsonSerializer method serializeSqlOperator.
// --------------------------------------------------------------------------------------------
/**
* Logic shared with {@link AggregateCallJsonSerializer}.
*/
static void serializeSqlOperator(SqlOperator operator, JsonGenerator gen, SerializerProvider serializerProvider, boolean serializeCatalogObjects) throws IOException {
if (operator.getSyntax() != SqlSyntax.FUNCTION) {
gen.writeStringField(FIELD_NAME_SYNTAX, calciteToSerializable(operator.getSyntax()).getValue());
}
if (operator instanceof BridgingSqlFunction) {
final BridgingSqlFunction function = (BridgingSqlFunction) operator;
serializeBridgingSqlFunction(function.getName(), function.getResolvedFunction(), gen, serializerProvider, serializeCatalogObjects);
} else if (operator instanceof BridgingSqlAggFunction) {
final BridgingSqlAggFunction function = (BridgingSqlAggFunction) operator;
serializeBridgingSqlFunction(function.getName(), function.getResolvedFunction(), gen, serializerProvider, serializeCatalogObjects);
} else if (operator instanceof ScalarSqlFunction || operator instanceof TableSqlFunction || operator instanceof AggSqlFunction) {
throw legacyException(operator.toString());
} else {
// We assume that all regular SqlOperators are internal. Only the function definitions
// stack is exposed to the user and can thus be external.
gen.writeStringField(FIELD_NAME_INTERNAL_NAME, BuiltInSqlOperator.toQualifiedName(operator));
}
}
Aggregations