Skip to content

[CALCITE-7689] MAP equality compares maps by insertion order - #5151

Open
mihaibudiu wants to merge 1 commit into
apache:mainfrom
mihaibudiu:issue7689
Open

[CALCITE-7689] MAP equality compares maps by insertion order#5151
mihaibudiu wants to merge 1 commit into
apache:mainfrom
mihaibudiu:issue7689

Conversation

@mihaibudiu

Copy link
Copy Markdown
Contributor

Jira Link

CALCITE-7689

Changes Proposed

Two MAP values should be equal when they have the same exact key and each key maps to the same exact value. Key and value comparisons use <=> (IS NOT DISTINCT FROM), consistent with ARRAY values.

As a side-effect this changes ordering of maps too.

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@xiedeyantu

Copy link
Copy Markdown
Member

I checked the SQL standard, and there are no constraints regarding how maps should be compared; I believe any implementation approach we choose would be justifiable. However, I have observed that both DuckDB and ClickHouse return false when executing select map('a', 1, 'b', 2) = map('b', 2, 'a', 1). I am unsure what the best approach for Calcite would be.

@mihaibudiu

Copy link
Copy Markdown
Contributor Author

Clickhouse maps are actually not even maps, since they can have duplicate keys.
They are stored as Array(Tuple(K, V)).
https://clickhouse.com/docs/reference/data-types/map
So their semantics is not a good fit for Calcite.

@xiedeyantu xiedeyantu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although the databases or query engines I am familiar with typically treat map comparisons as order-dependent, and I had previously hesitated regarding the implementation approach, I personally support the implementation in this PR. If no one raises an objection, I think it is acceptable, as it aligns better with intuition.

@mihaibudiu

Copy link
Copy Markdown
Contributor Author

Let's see if there are any other objections.

@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants