-
Notifications
You must be signed in to change notification settings - Fork 25.3k
SQL: Fix bug regarding histograms usage in scripting #36866
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
Changes from all commits
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 |
---|---|---|
|
@@ -262,9 +262,51 @@ SELECT HISTOGRAM(birth_date, INTERVAL 1 YEAR) AS h, COUNT(*) as c FROM test_emp | |
null |10 | ||
; | ||
|
||
histogramDateWithDateFunction-Ignore | ||
SELECT YEAR(HISTOGRAM(birth_date, INTERVAL 1 YEAR)) AS h, COUNT(*) as c FROM test_emp GROUP BY h ORDER BY h DESC; | ||
histogramDateWithMonthOnTop | ||
schema::h:i|c:l | ||
SELECT HISTOGRAM(MONTH(birth_date), 2) AS h, COUNT(*) as c FROM test_emp GROUP BY h ORDER BY h DESC; | ||
|
||
h | c | ||
---------------+--------------- | ||
12 |7 | ||
10 |17 | ||
8 |16 | ||
6 |16 | ||
4 |18 | ||
2 |10 | ||
0 |6 | ||
null |10 | ||
; | ||
|
||
histogramDateWithYearOnTop | ||
schema::h:i|c:l | ||
SELECT HISTOGRAM(YEAR(birth_date), 2) AS h, COUNT(*) as c FROM test_emp GROUP BY h ORDER BY h DESC; | ||
h | c | ||
---------------+--------------- | ||
1964 |5 | ||
1962 |13 | ||
1960 |16 | ||
1958 |16 | ||
1956 |9 | ||
1954 |12 | ||
1952 |19 | ||
null |10 | ||
; | ||
|
||
|
||
|
||
histogramNumericWithExpression | ||
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. Why do we need that, since we have this: https://github.com/elastic/elasticsearch/pull/36866/files#diff-271679983098ae41c89a482374a0e984R731 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 was a typo - the incorrect query should have had the MONTH out of the histogram - I've updated that now. 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. no I mean this and the next one are similar, emp_no instead of salary, it's only the order by. |
||
schema::h:i|c:l | ||
SELECT HISTOGRAM(emp_no % 100, 10) AS h, COUNT(*) as c FROM test_emp GROUP BY h ORDER BY h DESC; | ||
|
||
h | c | ||
---------------+--------------- | ||
90 |10 | ||
80 |10 | ||
70 |10 | ||
60 |10 | ||
50 |10 | ||
40 |10 | ||
30 |10 | ||
20 |10 | ||
10 |10 | ||
0 |10 | ||
; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.sql.expression.gen.script; | ||
|
||
import org.elasticsearch.xpack.sql.expression.function.grouping.GroupingFunctionAttribute; | ||
|
||
class Grouping extends Param<GroupingFunctionAttribute> { | ||
|
||
Grouping(GroupingFunctionAttribute groupRef) { | ||
super(groupRef); | ||
} | ||
|
||
String groupName() { | ||
return value().functionId(); | ||
} | ||
|
||
@Override | ||
public String prefix() { | ||
return "g"; | ||
} | ||
} |
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 query here is exactly the same as the one referenced in the previous section:
docs.csv-spec[expressionOnHistogramNotAllowed]
.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.