-
Notifications
You must be signed in to change notification settings - Fork 25k
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
[ESQL] Add SPACE
function
#112350
[ESQL] Add SPACE
function
#112350
Conversation
When the function parameter is foldable, all checks of that parameter are done before the ExpressionEvaluator.Factory is returned.
… spaces in the result) This reverts commit aed785d.
Documentation preview: |
Pinging @elastic/es-analytical-engine (Team:Analytics) |
Hi @chrisberkhout, I've created a changelog YAML for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I've added a note about the "constant" flavor of the evaluator - I feel like you should either remove it or flip it to building the space string up front. I asked for two extra tests as well, one out of an abundance of paranoia and one for wire serialization testing.
While you are there, could you add those two tests to the guide? I'll bet they aren't in there because, well, I forgot.
...src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/SpaceTests.java
Show resolved
Hide resolved
...esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/Space.java
Show resolved
Hide resolved
a376466
to
0540423
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 🚀
Added some comments I think would simplify code a bit
...src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/SpaceTests.java
Show resolved
Hide resolved
...src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/SpaceTests.java
Outdated
Show resolved
Hide resolved
...esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/Space.java
Outdated
Show resolved
Hide resolved
@astefan Oh, good catch. Looks like a problem in the toEvaluator .fold() cast to int. It's the evaluator the one converting multivalues to null/warnings, so it's too early to blindly cast there. About the tests infra, indeed, we should add an automatic test case generator for multivalues, similar to the one we have for nulls. Created an issue here: #112396 |
Fun! I just bumped into a similar error in case. I think we're not used to dealing with multivalued fields on the folding path. |
I resolved the issue of multi-value on the fold path. The current logic is:
So that matches the general documentation regarding multi-value handling, but still gives early errors about out-of-range integers when foldable. If that's too complicated I can take out the fold path and send everything to the evaluator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's too complicated I can take out the fold path and send everything to the evaluator.
I think it's ok that way. It improves what looks like a common usecase of SPACE (constant param), so nice!
We could also throw and fail the query if it's a foldable multivalue, but I'm not sure if we're doing that in other functions, or if we want to do that at all.
Cc-ing @costin in case he has an opinion on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @chrisberkhout
Pinging @elastic/kibana-esql (ES|QL-ui) |
Hi - sorry for responding late. |
They do! The exceptions are how we signal null + warnings at runtime. We have, like, a catch list. And failing hard for invalid stuff is a thing we do all the time at parse time. So long as we can do it at parse time. |
Right - I mean the users doesn't see the underlying exception. @ivancea pointed out the foldable aspect - for this case look at the |
I wonder if we can make the |
The subtle difference between folding throwing an exception and An improvement separate from this PR is to catch the warning in foldable and bubble it up similar to how |
I tried implementing In The two functions that currently implement If validation could be done earlier or folding done later, then validation would have a chance to run, but that seems like separate work. For now it seems like the best options are still:
|
Hey @chrisberkhout! |
Thanks @ivancea! |
Adds the
SPACE(number)
function, which is equivalent toREPEAT(" ", number)
.