-
Notifications
You must be signed in to change notification settings - Fork 25.2k
SQL: Enhance message for PERCENTILE[_RANK] with field as 2nd arg #36933
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
Conversation
Enhance erro message for the case that the 2nd argument of PERCENTILE and PERCENTILE_RANK is not a foldable, as it doesn't make sense to have a dynamic value coming from a field. Fixes: elastic#36903
Pinging @elastic/es-search |
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.
The checks needs moving at resolution time (instead of in a getter).
@@ -61,6 +62,10 @@ public DataType dataType() { | |||
|
|||
@Override | |||
public String innerName() { | |||
if (!percent.foldable()) { |
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.
The check happens too late when the Percentile is going to be executed. It's better to move it up-front in the resolveType
since that's where we typically check the arguments.
This would also avoid having to create an exception and instead return a resolution message.
@costin Thanks for the comment, Fixup pushed. |
run the gradle build tests 2 |
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. Just a suggestion: does the documentation page need an improvement or is it enough to mention the second parameter as "numeric expression" (as it is now)?
@astefan Thanks for the comment, added a more detailed explanation there. |
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
@@ -41,13 +42,17 @@ public Percentile replaceChildren(List<Expression> newChildren) { | |||
|
|||
@Override | |||
protected TypeResolution resolveType() { | |||
TypeResolution resolution = super.resolveType(); | |||
if (!percent.foldable()) { | |||
throw new SqlIllegalArgumentException("2nd argument: [{}] of PERCENTILE cannot be based on " + |
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.
I would rephrase this to something shorter such as "must be a constant, received [{}]".
) Enhance error message for the case that the 2nd argument of PERCENTILE and PERCENTILE_RANK is not a foldable, as it doesn't make sense to have a dynamic value coming from a field. Fixes: #36903
Backported to |
Enhance error message for the case that the 2nd argument of PERCENTILE
and PERCENTILE_RANK is not a foldable, as it doesn't make sense to have
a dynamic value coming from a field.
Fixes: #36903