-
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
ES|QL: Improve type validation in aggs for UNSIGNED_LONG better support for VERSION #104911
Changes from 2 commits
901b153
564c092
527fa5f
533130d
ef0529b
dbac2e6
dd1e8a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pr: 104911 | ||
summary: "ES|QL: Improve type validation in aggs for UNSIGNED_LONG better support\ | ||
\ for VERSION" | ||
area: ES|QL | ||
type: bug | ||
issues: | ||
- 102961 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,15 +254,18 @@ private static String dataTypeToString(DataType type, Class<?> aggClass) { | |
return "Long"; | ||
} else if (type.equals(DataTypes.DOUBLE)) { | ||
return "Double"; | ||
} else if (type.equals(DataTypes.KEYWORD) || type.equals(DataTypes.IP) || type.equals(DataTypes.TEXT)) { | ||
return "BytesRef"; | ||
} else if (type.equals(GEO_POINT)) { | ||
return "GeoPoint"; | ||
} else if (type.equals(CARTESIAN_POINT)) { | ||
return "CartesianPoint"; | ||
} else { | ||
throw new EsqlIllegalArgumentException("illegal agg type: " + type.typeName()); | ||
} | ||
} else if (type.equals(DataTypes.KEYWORD) | ||
|| type.equals(DataTypes.IP) | ||
|| type.equals(DataTypes.VERSION) | ||
|| type.equals(DataTypes.TEXT)) { | ||
return "BytesRef"; | ||
} else if (type.equals(GEO_POINT)) { | ||
return "GeoPoint"; | ||
} else if (type.equals(CARTESIAN_POINT)) { | ||
return "CartesianPoint"; | ||
} else { | ||
throw new EsqlIllegalArgumentException("illegal agg type: " + type.typeName()); | ||
} | ||
Comment on lines
+262
to
+268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect indentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you, but apparently Spotless does not agree with us. |
||
} | ||
|
||
private static Expression unwrapAlias(Expression expression) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1554,6 +1554,38 @@ public void testUnresolvedMvExpand() { | |
assertThat(e.getMessage(), containsString("Unknown column [bar]")); | ||
} | ||
|
||
public void testUnsupportedTypesInStats() { | ||
verifyUnsupported( | ||
""" | ||
row x = to_unsigned_long(\"10\") | ||
| stats avg(x), count_distinct(x), max(x), median(x), median_absolute_deviation(x), min(x), percentile(x, 10), sum(x) | ||
""", | ||
"Found 8 problems\n" | ||
+ "line 2:12: argument of [avg(x)] cannot be [unsigned_long], found [x]\n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our error messages tell the user what is the expectation and what is the actual value. Instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible only for foldable expressions, but in the general case we only have the variable name, eg.
Maybe |
||
+ "line 2:20: argument of [count_distinct(x)] cannot be [unsigned_long], found [x]\n" | ||
+ "line 2:39: argument of [max(x)] cannot be [unsigned_long], found [x]\n" | ||
+ "line 2:47: argument of [median(x)] cannot be [unsigned_long], found [x]\n" | ||
+ "line 2:58: argument of [median_absolute_deviation(x)] cannot be [unsigned_long], found [x]\n" | ||
+ "line 2:88: argument of [min(x)] cannot be [unsigned_long], found [x]\n" | ||
+ "line 2:96: first argument of [percentile(x, 10)] cannot be [unsigned_long], found [x]\n" | ||
+ "line 2:115: argument of [sum(x)] cannot be [unsigned_long], found [x]" | ||
); | ||
verifyUnsupported( | ||
""" | ||
row x = to_version("1.2") | ||
| stats avg(x), max(x), median(x), median_absolute_deviation(x), min(x), percentile(x, 10), sum(x) | ||
""", | ||
"Found 7 problems\n" | ||
+ "line 2:10: argument of [avg(x)] must be [numeric], found value [x] type [version]\n" | ||
+ "line 2:18: argument of [max(x)] must be [numeric or datetime], found value [max(x)] type [version]\n" | ||
+ "line 2:26: argument of [median(x)] must be [numeric], found value [x] type [version]\n" | ||
+ "line 2:37: argument of [median_absolute_deviation(x)] must be [numeric], found value [x] type [version]\n" | ||
+ "line 2:67: argument of [min(x)] must be [numeric or datetime], found value [min(x)] type [version]\n" | ||
+ "line 2:75: first argument of [percentile(x, 10)] must be [numeric], found value [x] type [version]\n" | ||
+ "line 2:94: argument of [sum(x)] must be [numeric], found value [x] type [version]" | ||
); | ||
} | ||
|
||
private void verifyUnsupported(String query, String errorMessage) { | ||
verifyUnsupported(query, errorMessage, "mapping-multi-field-variation.json"); | ||
} | ||
|
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.
For
avg
the description of the function showswhich clearly shows
unsigned_long
. Is this type really unsupported and this must be updated as well?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.
Good catch! I didn't realize that we don't have tests for this (as we have for non-aggregate funcitons).
I'm fixing all of them
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.
#104938