Skip to content

fix: Order by mentioning missing column multiple times#13158

Merged
alamb merged 3 commits intoapache:mainfrom
eejbyfeldt:i-13157
Oct 30, 2024
Merged

fix: Order by mentioning missing column multiple times#13158
alamb merged 3 commits intoapache:mainfrom
eejbyfeldt:i-13157

Conversation

@eejbyfeldt
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #13157

Rationale for this change

Previously we crashed on queries where the order by mentioned a missing
columns multiple times.

What changes are included in this PR?

Only add each missing column once.

Are these changes tested?

Yes, new sqllogictest.

Are there any user-facing changes?

Bugfix.

@github-actions github-actions bot added logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Oct 29, 2024
@eejbyfeldt eejbyfeldt marked this pull request as ready for review October 29, 2024 19:26
Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @eejbyfeldt


columns.into_iter().for_each(|c| {
if !schema.has_column(c) {
if !schema.has_column(c) && !missing_cols.contains(c) {
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.

can missing cols be a set?

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 did not try it out, but most likely yes. The change becomes slightly bigger because we currently pass missing_cols as a slice to some helper methods.

I assume you are worried about this code now being quadratic? It was not clear if that was a real case in practice that you would order by a large number of columns and none of them are part of the output. But maybe it better to go for the set as it seems safer choice.

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.

Done in 5574898

@alamb
Copy link
Copy Markdown
Contributor

alamb commented Oct 30, 2024

I restarted the failed CI check (was related to some sort of neetwork issue)

@alamb alamb merged commit 68bf7ad into apache:main Oct 30, 2024
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Oct 30, 2024

Thanks again @eejbyfeldt and @findepi

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

Labels

logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate expression errors due to column being used multiple times in order by

3 participants