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

Return scalar result when all inputs are constants in map and make_map #11461

Merged
merged 9 commits into from
Jul 15, 2024

Conversation

Rachelint
Copy link
Contributor

@Rachelint Rachelint commented Jul 14, 2024

Which issue does this PR close?

Closes #11460 #6485

Rationale for this change

See #11460

What changes are included in this PR?

See title.

Are these changes tested?

Test by new uts.

Are there any user-facing changes?

Can success to run sql like:

SELECT make_map('type', 'test') FROM test

@github-actions github-actions bot added the optimizer Optimizer rules label Jul 14, 2024
@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jul 14, 2024
@Rachelint Rachelint marked this pull request as ready for review July 14, 2024 05:41
@Rachelint
Copy link
Contributor Author

cc @alamb @goldmedal

@Rachelint Rachelint changed the title Return scalar result when all inputs are constant for map and make_map udfs Return scalar result when all inputs are constants for map and make_map udfs Jul 14, 2024
@Rachelint Rachelint changed the title Return scalar result when all inputs are constants for map and make_map udfs Return scalar result when all inputs are constants for map and make_map Jul 14, 2024
@Rachelint Rachelint changed the title Return scalar result when all inputs are constants for map and make_map Return scalar result when all inputs are constants in map and make_map Jul 14, 2024
Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

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

Thanks, @Rachelint. LGTM. I guess this PR is also related to #11436. Maybe @dharanad could take a look at it.

Comment on lines 216 to 222
query error
SELECT map(column5, column6) FROM t;
# TODO: support array value
# ----
# {k1:1, k2:2}
# {k3: 3}
# {k5: 5}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
query error
SELECT map(column5, column6) FROM t;
# TODO: support array value
# ----
# {k1:1, k2:2}
# {k3: 3}
# {k5: 5}

I think this test is the same as the above one. We can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@Rachelint
Copy link
Contributor Author

Mind taking a quick look? @dharanad

@dharanad
Copy link
Contributor

Mind taking a quick look? @dharanad

Taking a look

Copy link
Contributor

@dharanad dharanad left a comment

Choose a reason for hiding this comment

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

Thanks @Rachelint this PR LGTM.

/// SELECT make_map('type', 'test') from test
/// ```
/// We can evaluate the result of `make_map` directly.
#[inline]
Copy link
Contributor

Choose a reason for hiding this comment

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

Any specific reason for using inline over here ?

Copy link
Contributor Author

@Rachelint Rachelint Jul 15, 2024

Choose a reason for hiding this comment

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

Just a personal habit to mark the very short function, and try to reduce the function call cost(it will be really inlined or not... determinded by the compiler).
Will it cause some problems that I haven't noticed before?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since it more of a suggestion to complier, i dont think this should cause problems. TIL: Inlining small functions can provide small speed wins.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is rare case for inline. I perfer not to inline unless the benmark shows that compiler fail to do the good job for us

https://matklad.github.io/2021/07/09/inline-in-rust.html

Copy link
Contributor Author

@Rachelint Rachelint Jul 15, 2024

Choose a reason for hiding this comment

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

Seem inline here is actually unnecessary according to the article mentioned by @jayzhan211 , removed.

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

👍

@alamb alamb merged commit 0965455 into apache:main Jul 15, 2024
23 checks passed
@alamb
Copy link
Contributor

alamb commented Jul 15, 2024

Thank you @Rachelint @dharanad @goldmedal and @jayzhan211

findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
…_map` (apache#11461)

* return scalar result when all inputs are constants.

* support convert map array to scalar.

* disable the const evaluate for Map type before impl its hash calculation.

* add tests in map.slt.

* improve error return.

* fix error.

* fix remove unused import.

* remove duplicated testcase.

* remove inline.
xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jul 17, 2024
…_map` (apache#11461)

* return scalar result when all inputs are constants.

* support convert map array to scalar.

* disable the const evaluate for Map type before impl its hash calculation.

* add tests in map.slt.

* improve error return.

* fix error.

* fix remove unused import.

* remove duplicated testcase.

* remove inline.
xinlifoobar pushed a commit to xinlifoobar/datafusion that referenced this pull request Jul 18, 2024
…_map` (apache#11461)

* return scalar result when all inputs are constants.

* support convert map array to scalar.

* disable the const evaluate for Map type before impl its hash calculation.

* add tests in map.slt.

* improve error return.

* fix error.

* fix remove unused import.

* remove duplicated testcase.

* remove inline.
wiedld pushed a commit to influxdata/arrow-datafusion that referenced this pull request Jul 31, 2024
…_map` (apache#11461)

* return scalar result when all inputs are constants.

* support convert map array to scalar.

* disable the const evaluate for Map type before impl its hash calculation.

* add tests in map.slt.

* improve error return.

* fix error.

* fix remove unused import.

* remove duplicated testcase.

* remove inline.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Return scalar result when all inputs are constant for map and make_map udfs
5 participants