You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "xuyangzhong (via GitHub)" <gi...@apache.org> on 2024/06/05 07:51:04 UTC
[PR] [FLINK-35498][table] Fix unexpected argument name conflicts when extracting method parameter names from UDF [flink]
xuyangzhong opened a new pull request, #24890:
URL: https://github.com/apache/flink/pull/24890
## What is the purpose of the change
Currently, we depend on asm to extract method parameter names. We custom a MethodVisitor to visit local variable tables in file `.class`, and then cut the first `N` local variable names as the method parameter names.
However, if there are multi blocks about one local variable, the first `N` local variable names could be same, and then wrongly be extracted, and crashed when validating the conflict of them(the new logic added in FLINK-1.19).
This pr will use the slot index in `.class` file to extract the method parameter names, because method parameter names are always at the head in the 'slot index' list(https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-3.html)
Take the test function `ExtractionUtilsTest#MultiLocalVariableBlocksWithoutInitializationClass` as an example:
- Before fix:
1. extract parameter names from asm:
[localVariable, localVariable, localVariable, this, generic, genericFuture, listOfGenericFuture, array, localVariable]
2. get the first 4 after offset 1(expected `this` in index 0)
[localVariable, localVariable, this, generic]
This is because in local variable table, there are multi `localVariable` with different lifecycle in different blocks.
- After fix:
1. extract parameter names from asm:
[this, generic, genericFuture, listOfGenericFuture, array, localVariable]
2. get the first 4 after offset 1(expected `this` in index 0)
[generic, genericFuture, listOfGenericFuture, array]
That's what we expected.
## Brief change log
*(for example:)*
- *Fix the logic in ExtractionUtils*
- *Add tests to verify this fix*
## Verifying this change
Some tests are added to verity it.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-35498][table] Fix unexpected argument name conflicts when extracting method parameter names from UDF [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #24890:
URL: https://github.com/apache/flink/pull/24890#issuecomment-2149128429
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "8949372be348163ab172cdde89562de2f67f639f",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "8949372be348163ab172cdde89562de2f67f639f",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 8949372be348163ab172cdde89562de2f67f639f UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-35498][table] Fix unexpected argument name conflicts when extracting method parameter names from UDF [flink]
Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil commented on code in PR #24890:
URL: https://github.com/apache/flink/pull/24890#discussion_r1630981891
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/stream/sql/FunctionITCase.java:
##########
@@ -1542,6 +1542,22 @@ void testUsingAddJar() throws Exception {
"drop function lowerUdf");
}
+ @Test
+ void testUdfWithMultiLocalVariables() {
+ List<Row> sourceData = Arrays.asList(Row.of(1L, 2L), Row.of(2L, 3L));
+ TestCollectionTableFactory.reset();
+ TestCollectionTableFactory.initData(sourceData);
+
+ tEnv().executeSql(
+ "CREATE TABLE SourceTable(x BIGINT, y BIGINT) WITH ('connector' = 'COLLECTION')");
+ tEnv().executeSql(
+ "CREATE FUNCTION MultiLocalVariables AS '"
+ + MultiLocalVariableBlocksClass.class.getName()
+ + "'");
+ CollectionUtil.iteratorToList(
+ tEnv().executeSql("SELECT MultiLocalVariables(x, y) FROM SourceTable").collect());
Review Comment:
We should add the verification for the running result since it is an IT case, otherwise we can add plan test for this.
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java:
##########
@@ -844,7 +846,14 @@ private static class ParameterExtractor extends ClassVisitor {
}
List<String> getParameterNames() {
- return parameterNames;
+ // method parameters are always at the head in the 'index' list
Review Comment:
It is recommended move this description toi the class comments, and also update the example to illustrate the need to sort by index.
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java:
##########
@@ -844,7 +846,14 @@ private static class ParameterExtractor extends ClassVisitor {
}
List<String> getParameterNames() {
- return parameterNames;
+ // method parameters are always at the head in the 'index' list
+ // NOTE: the first parameter may be "this" if the function is not static
+ // See more at Chapter "3.6. Receiving Arguments" in
+ // https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-3.html
+ return parameterNamesWithIndex.entrySet().stream()
Review Comment:
We can use `TreeMap` instead of `HashMap` for `parameterNamesWithIndex` to avoid sorting operation and the use of java streams, WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-35498][table] Fix unexpected argument name conflicts when extracting method parameter names from UDF [flink]
Posted by "lincoln-lil (via GitHub)" <gi...@apache.org>.
lincoln-lil commented on code in PR #24890:
URL: https://github.com/apache/flink/pull/24890#discussion_r1630964066
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java:
##########
@@ -844,7 +846,14 @@ private static class ParameterExtractor extends ClassVisitor {
}
List<String> getParameterNames() {
- return parameterNames;
+ // method parameters are always at the head in the 'index' list
Review Comment:
It is recommended moving this description to the class comments, and also update the example to illustrate the need to sort by index.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org