Skip to content

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

Merged
merged 6 commits into from
Jan 3, 2019

Conversation

matriv
Copy link
Contributor

@matriv matriv commented Dec 21, 2018

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

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
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@matriv matriv changed the title SQL: Enchance message for PERCENTILE[_RANK] with field as 2nd arg SQL: Enhance message for PERCENTILE[_RANK] with field as 2nd arg Dec 24, 2018
Copy link
Member

@costin costin left a 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()) {
Copy link
Member

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.

@matriv
Copy link
Contributor Author

matriv commented Jan 3, 2019

@costin Thanks for the comment, Fixup pushed.

@matriv
Copy link
Contributor Author

matriv commented Jan 3, 2019

run the gradle build tests 2

Copy link
Contributor

@astefan astefan left a 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)?

@matriv
Copy link
Contributor Author

matriv commented Jan 3, 2019

@astefan Thanks for the comment, added a more detailed explanation there.

Copy link
Member

@costin costin left a 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 " +
Copy link
Member

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 [{}]".

@matriv matriv merged commit 3313790 into elastic:master Jan 3, 2019
@matriv matriv deleted the mt/fix-36903 branch January 3, 2019 11:55
matriv added a commit that referenced this pull request Jan 3, 2019
)

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
@matriv
Copy link
Contributor Author

matriv commented Jan 3, 2019

Backported to 6.x with 685d654

@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants