-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-37180][table] Support running stateless PTFs #26076
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -35,7 +35,6 @@ | |||||
import java.util.HashMap; | ||||||
import java.util.List; | ||||||
import java.util.Map; | ||||||
import java.util.Objects; | ||||||
import java.util.Optional; | ||||||
import java.util.Set; | ||||||
import java.util.function.Predicate; | ||||||
|
@@ -57,10 +56,15 @@ | |||||
@Internal | ||||||
public class SystemTypeInference { | ||||||
|
||||||
private static final List<StaticArgument> PROCESS_TABLE_FUNCTION_SYSTEM_ARGS = | ||||||
public static final List<StaticArgument> PROCESS_TABLE_FUNCTION_SYSTEM_ARGS = | ||||||
List.of(StaticArgument.scalar("uid", DataTypes.STRING(), true)); | ||||||
|
||||||
/** Format of unique identifiers for {@link ProcessTableFunction}. */ | ||||||
/** | ||||||
* Format of unique identifiers for {@link ProcessTableFunction}. | ||||||
* | ||||||
* <p>Leading digits are not allowed. This also prevents that a custom PTF uid can infer with | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* {@code ExecutionConfigOptions#TABLE_EXEC_UID_FORMAT}. | ||||||
*/ | ||||||
private static final Predicate<String> UID_FORMAT = | ||||||
Pattern.compile("^[a-zA-Z_][a-zA-Z-_0-9]*$").asPredicate(); | ||||||
|
||||||
|
@@ -81,6 +85,7 @@ public static TypeInference of(FunctionKind functionKind, TypeInference origin) | |||||
return builder.build(); | ||||||
} | ||||||
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted") | ||||||
public static boolean isValidUidForProcessTableFunction(String uid) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe invert it then? |
||||||
return UID_FORMAT.test(uid); | ||||||
} | ||||||
|
@@ -114,6 +119,8 @@ private static void checkScalarArgsOnly(List<StaticArgument> defaultArgs) { | |||||
} | ||||||
|
||||||
checkReservedArgs(declaredArgs); | ||||||
checkMultipleTableArgs(declaredArgs); | ||||||
checkUpdatingPassThroughColumns(declaredArgs); | ||||||
|
||||||
final List<StaticArgument> newStaticArgs = new ArrayList<>(declaredArgs); | ||||||
newStaticArgs.addAll(PROCESS_TABLE_FUNCTION_SYSTEM_ARGS); | ||||||
|
@@ -135,6 +142,25 @@ private static void checkReservedArgs(List<StaticArgument> staticArgs) { | |||||
} | ||||||
} | ||||||
|
||||||
private static void checkMultipleTableArgs(List<StaticArgument> staticArgs) { | ||||||
if (staticArgs.stream().filter(arg -> arg.is(StaticArgumentTrait.TABLE)).count() > 1) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit: would it make sense to add limit like? |
||||||
throw new ValidationException( | ||||||
"Currently, only signatures with at most one table argument are supported."); | ||||||
} | ||||||
} | ||||||
|
||||||
private static void checkUpdatingPassThroughColumns(List<StaticArgument> staticArgs) { | ||||||
final Set<StaticArgumentTrait> traits = | ||||||
staticArgs.stream() | ||||||
.flatMap(arg -> arg.getTraits().stream()) | ||||||
.collect(Collectors.toSet()); | ||||||
if (traits.contains(StaticArgumentTrait.SUPPORT_UPDATES) | ||||||
&& traits.contains(StaticArgumentTrait.PASS_COLUMNS_THROUGH)) { | ||||||
throw new ValidationException( | ||||||
"Signatures with updating inputs must not pass columns through."); | ||||||
} | ||||||
} | ||||||
|
||||||
private static InputTypeStrategy deriveSystemInputStrategy( | ||||||
FunctionKind functionKind, | ||||||
@Nullable List<StaticArgument> staticArgs, | ||||||
|
@@ -288,7 +314,6 @@ public Optional<List<DataType>> inferInputTypes( | |||||
} | ||||||
|
||||||
checkUidArg(callContext); | ||||||
checkMultipleTableArgs(callContext); | ||||||
checkTableArgTraits(staticArgs, callContext); | ||||||
|
||||||
return Optional.of(inferredDataTypes); | ||||||
|
@@ -318,19 +343,6 @@ private static void checkUidArg(CallContext callContext) { | |||||
} | ||||||
} | ||||||
|
||||||
private static void checkMultipleTableArgs(CallContext callContext) { | ||||||
final List<DataType> args = callContext.getArgumentDataTypes(); | ||||||
|
||||||
final List<TableSemantics> tableSemantics = | ||||||
IntStream.range(0, args.size()) | ||||||
.mapToObj(pos -> callContext.getTableSemantics(pos).orElse(null)) | ||||||
.collect(Collectors.toList()); | ||||||
if (tableSemantics.stream().filter(Objects::nonNull).count() > 1) { | ||||||
throw new ValidationException( | ||||||
"Currently, only signatures with at most one table argument are supported."); | ||||||
} | ||||||
} | ||||||
|
||||||
private static void checkTableArgTraits( | ||||||
List<StaticArgument> staticArgs, CallContext callContext) { | ||||||
IntStream.range(0, staticArgs.size()) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,7 @@ public Optional<TableSemantics> getTableSemantics(int pos) { | |
return Optional.empty(); | ||
} | ||
return Optional.of( | ||
CallBindingTableSemantics.create( | ||
argumentDataTypes.get(pos), staticArguments.get(pos), sqlNode)); | ||
SqlBindingTableSemantics.create(argumentDataTypes.get(pos), staticArg, sqlNode)); | ||
} | ||
|
||
@Override | ||
|
@@ -145,15 +144,15 @@ public Optional<DataType> getOutputDataType() { | |
// TableSemantics | ||
// -------------------------------------------------------------------------------------------- | ||
|
||
private static class CallBindingTableSemantics implements TableSemantics { | ||
private static class SqlBindingTableSemantics implements TableSemantics { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I usually don't have an opinion on names, so feel free to ignore this comment. You have |
||
|
||
private final DataType dataType; | ||
private final int[] partitionByColumns; | ||
|
||
public static CallBindingTableSemantics create( | ||
public static SqlBindingTableSemantics create( | ||
DataType tableDataType, StaticArgument staticArg, SqlNode sqlNode) { | ||
checkNoOrderBy(sqlNode); | ||
return new CallBindingTableSemantics( | ||
return new SqlBindingTableSemantics( | ||
createDataType(tableDataType, staticArg), | ||
createPartitionByColumns(tableDataType, sqlNode)); | ||
} | ||
|
@@ -211,7 +210,7 @@ private static int[] createPartitionByColumns(DataType tableDataType, SqlNode sq | |
.toArray(); | ||
} | ||
|
||
private CallBindingTableSemantics(DataType dataType, int[] partitionByColumns) { | ||
private SqlBindingTableSemantics(DataType dataType, int[] partitionByColumns) { | ||
this.dataType = dataType; | ||
this.partitionByColumns = partitionByColumns; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually faced adj + noun rather than noun + noun... not sure how correct it is...