use of org.apache.flink.table.functions.FunctionDefinition in project flink by apache.
the class FunctionCatalog method registerTempSystemAggregateFunction.
/**
* @deprecated Use {@link #registerTemporarySystemFunction(String, FunctionDefinition, boolean)}
* instead.
*/
@Deprecated
public <T, ACC> void registerTempSystemAggregateFunction(String name, ImperativeAggregateFunction<T, ACC> function, TypeInformation<T> resultType, TypeInformation<ACC> accType) {
UserDefinedFunctionHelper.prepareInstance(config, function);
final FunctionDefinition definition;
if (function instanceof AggregateFunction) {
definition = new AggregateFunctionDefinition(name, (AggregateFunction<?, ?>) function, resultType, accType);
} else if (function instanceof TableAggregateFunction) {
definition = new TableAggregateFunctionDefinition(name, (TableAggregateFunction<?, ?>) function, resultType, accType);
} else {
throw new TableException("Unknown function class: " + function.getClass());
}
registerTempSystemFunction(name, definition);
}
use of org.apache.flink.table.functions.FunctionDefinition in project flink by apache.
the class OverConvertRule method convert.
@Override
public Optional<RexNode> convert(CallExpression call, ConvertContext context) {
List<Expression> children = call.getChildren();
if (call.getFunctionDefinition() == BuiltInFunctionDefinitions.OVER) {
FlinkTypeFactory typeFactory = context.getTypeFactory();
Expression agg = children.get(0);
FunctionDefinition def = ((CallExpression) agg).getFunctionDefinition();
boolean isDistinct = BuiltInFunctionDefinitions.DISTINCT == def;
SqlAggFunction aggFunc = agg.accept(new SqlAggFunctionVisitor(context.getRelBuilder()));
RelDataType aggResultType = typeFactory.createFieldTypeFromLogicalType(fromDataTypeToLogicalType(((ResolvedExpression) agg).getOutputDataType()));
// assemble exprs by agg children
List<RexNode> aggExprs = agg.getChildren().stream().map(child -> {
if (isDistinct) {
return context.toRexNode(child.getChildren().get(0));
} else {
return context.toRexNode(child);
}
}).collect(Collectors.toList());
// assemble order by key
Expression orderKeyExpr = children.get(1);
Set<SqlKind> kinds = new HashSet<>();
RexNode collationRexNode = createCollation(context.toRexNode(orderKeyExpr), RelFieldCollation.Direction.ASCENDING, null, kinds);
ImmutableList<RexFieldCollation> orderKey = ImmutableList.of(new RexFieldCollation(collationRexNode, kinds));
// assemble partition by keys
List<RexNode> partitionKeys = children.subList(4, children.size()).stream().map(context::toRexNode).collect(Collectors.toList());
// assemble bounds
Expression preceding = children.get(2);
boolean isPhysical = fromDataTypeToLogicalType(((ResolvedExpression) preceding).getOutputDataType()).is(LogicalTypeRoot.BIGINT);
Expression following = children.get(3);
RexWindowBound lowerBound = createBound(context, preceding, SqlKind.PRECEDING);
RexWindowBound upperBound = createBound(context, following, SqlKind.FOLLOWING);
// build RexOver
return Optional.of(context.getRelBuilder().getRexBuilder().makeOver(aggResultType, aggFunc, aggExprs, partitionKeys, orderKey, lowerBound, upperBound, isPhysical, true, false, isDistinct));
}
return Optional.empty();
}
use of org.apache.flink.table.functions.FunctionDefinition in project flink by apache.
the class RexNodeJsonSerializer method serializeBridgingSqlFunction.
private static void serializeBridgingSqlFunction(String summaryName, ContextResolvedFunction resolvedFunction, JsonGenerator gen, SerializerProvider serializerProvider, boolean serializeCatalogObjects) throws IOException {
final FunctionDefinition definition = resolvedFunction.getDefinition();
if (definition instanceof ScalarFunctionDefinition || definition instanceof TableFunctionDefinition || definition instanceof TableAggregateFunctionDefinition || definition instanceof AggregateFunctionDefinition) {
throw legacyException(summaryName);
}
if (definition instanceof BuiltInFunctionDefinition) {
final BuiltInFunctionDefinition builtInFunction = (BuiltInFunctionDefinition) definition;
gen.writeStringField(FIELD_NAME_INTERNAL_NAME, builtInFunction.getQualifiedName());
} else if (resolvedFunction.isAnonymous()) {
serializeInlineFunction(summaryName, definition, gen);
} else if (resolvedFunction.isTemporary()) {
serializeTemporaryFunction(resolvedFunction, gen, serializerProvider);
} else {
assert resolvedFunction.isPermanent();
serializePermanentFunction(resolvedFunction, gen, serializerProvider, serializeCatalogObjects);
}
}
use of org.apache.flink.table.functions.FunctionDefinition in project flink by apache.
the class PushWatermarkIntoTableSourceScanRuleBase method hasSourceWatermarkDeclaration.
private boolean hasSourceWatermarkDeclaration(TableSourceTable table) {
final ResolvedSchema schema = table.contextResolvedTable().getResolvedSchema();
final List<WatermarkSpec> specs = schema.getWatermarkSpecs();
// we only support one watermark spec for now
if (specs.size() != 1) {
return false;
}
final ResolvedExpression watermarkExpr = specs.get(0).getWatermarkExpression();
final FunctionDefinition function = unwrapFunctionDefinition(watermarkExpr);
return function == BuiltInFunctionDefinitions.SOURCE_WATERMARK;
}
use of org.apache.flink.table.functions.FunctionDefinition in project flink by apache.
the class FilterUtils method isRetainedAfterApplyingFilterPredicates.
public static boolean isRetainedAfterApplyingFilterPredicates(List<ResolvedExpression> predicates, Function<String, Comparable<?>> getter) {
for (ResolvedExpression predicate : predicates) {
if (predicate instanceof CallExpression) {
FunctionDefinition definition = ((CallExpression) predicate).getFunctionDefinition();
boolean result = false;
if (definition.equals(BuiltInFunctionDefinitions.OR)) {
// nested filter, such as (key1 > 2 or key2 > 3)
for (Expression expr : predicate.getChildren()) {
if (!(expr instanceof CallExpression && expr.getChildren().size() == 2)) {
throw new TableException(expr + " not supported!");
}
result = binaryFilterApplies((CallExpression) expr, getter);
if (result) {
break;
}
}
} else if (predicate.getChildren().size() == 2) {
result = binaryFilterApplies((CallExpression) predicate, getter);
} else {
throw new UnsupportedOperationException(String.format("Unsupported expr: %s.", predicate));
}
if (!result) {
return false;
}
} else {
throw new UnsupportedOperationException(String.format("Unsupported expr: %s.", predicate));
}
}
return true;
}
Aggregations