Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logical vs physical schema mismatch for aliased now() #12951

Merged
merged 4 commits into from
Oct 16, 2024

Conversation

wiedld
Copy link
Contributor

@wiedld wiedld commented Oct 15, 2024

Which issue does this PR close?

Part of #12733

We found another bug for aliased now() columns.

Rationale for this change

See the reproducer in the first commit.

Both of the next two commits are required for the fix.

What changes are included in this PR?

get_field_metadata should handle aliased columns.
Also, the now() udf is not nullable.

Are these changes tested?

Yes.

Are there any user-facing changes?

Not really.
Only that the now() udf will return not-nullable (instead of the default impl).

@github-actions github-actions bot added physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt) functions labels Oct 15, 2024
@wiedld wiedld marked this pull request as ready for review October 15, 2024 21:32
Copy link
Contributor

@itsjunetime itsjunetime left a comment

Choose a reason for hiding this comment

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

Looks all good to me, thanks for figuring out this one.

@alamb alamb changed the title Fix logical vs physical schema mismatch for aliased now(). Fix logical vs physical schema mismatch for aliased now() Oct 15, 2024
@@ -84,4 +84,8 @@ impl ScalarUDFImpl for NowFunc {
ScalarValue::TimestampNanosecond(now_ts, Some("+00:00".into())),
)))
}

fn is_nullable(&self, _args: &[Expr], _schema: &dyn ExprSchema) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

now can never be nullable

Copy link
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 @wiedld and @itsjunetime

@@ -125,5 +125,21 @@ NULL NULL l_bar



query P rowsort
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

))
GROUP BY ts
ORDER BY ts
LIMIT 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I verified that without the code in this PR, this test fails like this:

External error: query failed: DataFusion error: Schema error: No field named ts. Valid fields are table_with_metadata.id, table_with_metadata.name, table_with_metadata.l_name.
[SQL] SELECT ts
FROM ((
    SELECT now() AS ts
    FROM table_with_metadata
) UNION ALL (
        SELECT ts
    FROM table_with_metadata
))
GROUP BY ts
ORDER BY ts
LIMIT 1;
at test_files/metadata.slt:128

@alamb alamb merged commit 875aaa6 into apache:main Oct 16, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
functions physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants