You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "raminqaf (via GitHub)" <gi...@apache.org> on 2025/08/26 10:45:37 UTC
[PR] [FLINK-38286][table] Fix: MAP function with duplicate keys produces non-deterministic results [flink]
raminqaf opened a new pull request, #26942:
URL: https://github.com/apache/flink/pull/26942
## What is the purpose of the change
This pull request fixes non-deterministic behavior in the MAP function when duplicate keys are provided. The MAP function was producing inconsistent results across different environments and test runs, causing CI failures and breaking reproducibility guarantees.
The root cause was in the code generation logic in `ScalarOperatorGens.scala`, where `groupBy` was used to deduplicate keys, but the subsequent `.keys` and `.values` extraction had non-deterministic iteration order, breaking the correspondence between key and value arrays in the generated code.
## Brief change log
- Added `groupByOrdered` utility method in `GenerateUtils` that uses `LinkedHashMap` to preserve insertion order during grouping operations
- Updated MAP function code generation in `ScalarOperatorGens.scala` to use deterministic order-preserving deduplication instead of non-deterministic `groupBy`
- Ensured "last value wins" semantics for duplicate keys by taking the last occurrence in argument order
- Fixed key-value array correspondence in generated code to prevent mismatched entries
## Verifying this change
This change is already covered by existing tests, such as:
- **MapFunctionITCase.test()** - Contains the specific failing test case `map(f0, f0, f0, f1)` that was producing non-deterministic results
- The fix makes the previously flaky test `MAP[1, 1, 1, 2] → {1=2}` consistently pass
- All existing MAP function tests continue to pass with deterministic behavior
- Manual verification shows consistent results across multiple test runs and environments
The change specifically addresses test failures that occurred when constant folding was disabled, ensuring both code paths (optimized and runtime) produce consistent results.
## 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): **yes** - affects MAP function code generation, but with minimal performance impact (same O(n) complexity)
- 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? **not applicable** - this is a bug fix that
--
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-38286][table] Fix: MAP function with duplicate keys produces non-deterministic results [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #26942:
URL: https://github.com/apache/flink/pull/26942#issuecomment-3223660919
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "216f5dc87432417af78fb789a510ec9b1977a022",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "216f5dc87432417af78fb789a510ec9b1977a022",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 216f5dc87432417af78fb789a510ec9b1977a022 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-38286][table] Fix: MAP function with duplicate keys produces non-deterministic results [flink]
Posted by "dawidwys (via GitHub)" <gi...@apache.org>.
dawidwys merged PR #26942:
URL: https://github.com/apache/flink/pull/26942
--
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-38286][table] Fix: MAP function with duplicate keys produces non-deterministic results [flink]
Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #26942:
URL: https://github.com/apache/flink/pull/26942#discussion_r2300971423
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/MapFunctionITCase.java:
##########
@@ -97,9 +97,16 @@ private Stream<TestSetSpec> mapTestCases() {
DECIMAL(10, 4).notNull(),
BOOLEAN().notNull())
.testResult(
+ resultSpec(
+ map(
+ 1, 1, 1, 2, 1, 9, 1, 3, 2, 24, 2, 29, 1, 0, 2, 22,
+ 1, 8, 2, 25, 2, 20),
+ "MAP[1, 1, 1, 2, 1, 9, 1, 3, 2, 24, 2, 29, 1, 0, 2, 22, 1, 8, 2, 25, 2, 20]",
+ Map.ofEntries(Map.entry(1, 8), Map.entry(2, 20)),
+ DataTypes.MAP(INT().notNull(), INT().notNull()).notNull()),
Review Comment:
Similar to the tests case below but the order of the kvs is mixed. If not necessary it can be removed.
--
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