Skip to content

fix: map() fails when keys are literals and values are column expressions#22784

Open
nathanb9 wants to merge 2 commits into
apache:mainfrom
nathanb9:fix-map-literal-keys
Open

fix: map() fails when keys are literals and values are column expressions#22784
nathanb9 wants to merge 2 commits into
apache:mainfrom
nathanb9:fix-map-literal-keys

Conversation

@nathanb9
Copy link
Copy Markdown
Contributor

@nathanb9 nathanb9 commented Jun 6, 2026

Which issue does this PR close?

Closes #22781

Rationale for this change

map(['a','b'], [col, col * 10]) fails at execution time with "map requires key and value lists to have the same length" when keys are all literals and values contain column references.

Root cause: literal keys evaluate to ColumnarValue::Scalar(FixedSizeList[N]) (length N) while column values evaluate to ColumnarValue::Array (length batch_size). The length check compares N != batch_size and errors.

What changes are included in this PR?

In make_map_batch: when one argument is scalar and the other is array, expand the scalar to match batch_size via ScalarValue::to_array_of_size(number_rows) before the length comparison.

Are these changes tested?

Yes.

  • Unit test: scalar keys + array values in map.rs
  • SLT test: SELECT map(['a','b'], [column1, column1 * 10]) FROM (VALUES (1), (2), (3))

Are there any user-facing changes?

No. Previously-failing queries now execute correctly.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Jun 6, 2026
@nathanb9 nathanb9 marked this pull request as ready for review June 6, 2026 04:47
@nathanb9
Copy link
Copy Markdown
Contributor Author

nathanb9 commented Jun 6, 2026

CI failure seems like a transient docker failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

map() fails with 'key and value lists must have the same length' when keys are literals and values are column expressions

1 participant