Skip to content

[FLINK-40356][table] Add new MapFromEntries function - #28948

Open
VasShabu wants to merge 6 commits into
apache:masterfrom
VasShabu:MapFromEntriesImplementation
Open

[FLINK-40356][table] Add new MapFromEntries function#28948
VasShabu wants to merge 6 commits into
apache:masterfrom
VasShabu:MapFromEntriesImplementation

Conversation

@VasShabu

@VasShabu VasShabu commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

The Purpose of this change was to add a new builtin function, MapFromEntries Function to Flink

Brief change log

-Added mapFromEntries functionality
-Wired mapFromEntries function to flink

Verifying this change

Please make sure both new and modified tests in this PR follow the conventions for tests defined in our code quality guide.

(Please pick either of the following options)

This change is already covered by existing tests, such as the ones located in

to run test you need to run this command:
./mvnw -o -pl flink-table/flink-table-planner -Dtest='JsonFunctionsITCase' -Dsurefire.failIfNoSpecifiedTests=false -Dcheckstyle.skip=true -Dspotless.check.skip=true -Drat.skip=true -e -Denforcer.skip=true test

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): (yes / no)
  • The serializers: (don't know)
  • The runtime per-record code paths (performance sensitive): (don't know)
  • 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? (yes)
  • If yes, how is the feature documented? (sql_fuunctions.yml,javadocs,pythonDocs)

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Opus 4.8

@flinkbot

flinkbot commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

- Pre-size the map since we already know the input
- Fill the key and value arrays in one loop instead of using streams
DataTypes.ARRAY(entryType),
DataTypes.ARRAY(nestedEntryType),
DataTypes.ARRAY(entryType))
// duplicate keys: the last value wins

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole EqualityAndHashcodeProvider/ObjectContainer machinery exists for non-trivial key types, but no case has duplicate STRING, ROW or ARRAY keys - the generated equality/hashcode path is never exercised. Please add one, plus an entry with a NULL value.

@gustavodemorais

Copy link
Copy Markdown
Contributor

Thanks @VasShabu, first pass above

@VasShabu

Copy link
Copy Markdown
Contributor Author

Thanks @VasShabu, first pass above

Thankyou @gustavodemorais have made the changes as per your request, please let me know if you have any feedback.

Thanks
Vas


/** A {@link MapData} backed directly by a key array and a value array. */
@Internal
public class MapDataContainer implements MapData {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it as a separate file using only in one place?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw there are already 2 similar inner classes in other classes?
Can we reuse instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for instance: extract once and reuse

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 both MapFromArraysFunction and MapDataForMapFromArrays have the same logic.

MapFromArraysFunction needs a small adjustment. MapUnionFunction could use MapContainer as-is. I think all three could share this one util

@VasShabu VasShabu Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I should unify this MapDataContainer class for other functions in its own PR simply because one of the guidelines in the PR descriptions is that

  • Each pull request should address only one issue, not mix up code from multiple issues

So I think it is best to create a new PR to unify the Container classes

Thoughts?
@gustavodemorais @snuyanzin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do this in same PR, however different commit

@gustavodemorais gustavodemorais left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @VasShabu, thanks for working on this. Some suggestions

Comment thread docs/data/sql_functions.yml

/** A {@link MapData} backed directly by a key array and a value array. */
@Internal
public class MapDataContainer implements MapData {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 both MapFromArraysFunction and MapDataForMapFromArrays have the same logic.

MapFromArraysFunction needs a small adjustment. MapUnionFunction could use MapContainer as-is. I think all three could share this one util

@VasShabu
VasShabu force-pushed the MapFromEntriesImplementation branch from 2425e71 to 9d25cbe Compare August 24, 2026 16:18

@snuyanzin snuyanzin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the AI was used, it should be used Generated-by: instead of Co-authored-by: as mentioned in Apache recommendations https://www.apache.org/legal/generative-tooling.html

also the doc about this is in https://github.com/apache/flink/pull/27776/changes#r2979585031

@VasShabu

Copy link
Copy Markdown
Contributor Author

since the AI was used, it should be used Generated-by: instead of Co-authored-by: as mentioned in Apache recommendations https://www.apache.org/legal/generative-tooling.html

also the doc about this is in https://github.com/apache/flink/pull/27776/changes#r2979585031

I have already set it as Generated-by in the pr description

@snuyanzin

Copy link
Copy Markdown
Contributor

I have already set it as Generated-by in the pr description

look at this commit 9d25cbe
and you will see it is not true

@VasShabu

Copy link
Copy Markdown
Contributor Author

I have already set it as Generated-by in the pr description

look at this commit 9d25cbe and you will see it is not true

I see will fix that.

…pe access

- Reformat the MAP_FROM_ENTRIES docs to the fenced sql / "-- Returns" style
  across sql_functions.yml, its zh mirror, BaseExpressions javadoc and the
  pyflink docstring
- Reword the non-array argument error to quote 'input' and report the actual
  type
- Read the entry field types via DataType.getFieldDataTypes() instead of the
  generic getChildren()

Generated-By: Claude Opus 4.8 <noreply@anthropic.com>
@VasShabu
VasShabu force-pushed the MapFromEntriesImplementation branch from 9d25cbe to 0fc0fdd Compare August 25, 2026 10:04
Comment thread docs/data/sql_functions.yml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants