Skip to content

Commit 51e74be

Browse files
committed
SQL: [Tests] Add tests for fixed issues (#52335)
Add tests to verify behaviour for fixed issues: #33724 & #38306 (cherry picked from commit 89fb675)
1 parent 6cd4292 commit 51e74be

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

x-pack/plugin/sql/qa/src/main/resources/agg.csv-spec

+13
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,19 @@ SELECT HISTOGRAM(YEAR(birth_date), 2) AS h, COUNT(*) as c FROM test_emp GROUP BY
534534
null |10
535535
;
536536

537+
histogramDateTimeWithScalars
538+
schema::h:ts|c:l
539+
SELECT HISTOGRAM(birth_date, INTERVAL 20 MONTHS + INTERVAL 30 MONTHS) AS h, COUNT(*) as c FROM test_emp GROUP BY h ORDER BY c DESC;
540+
541+
h | c
542+
------------------------+---------------
543+
1957-09-06T00:00:00.000Z|31
544+
1953-07-29T00:00:00.000Z|24
545+
1961-10-15T00:00:00.000Z|20
546+
1949-06-20T00:00:00.000Z|15
547+
null |10
548+
;
549+
537550
histogramYearOnDateTimeWithScalars
538551
schema::year:i|c:l
539552
SELECT YEAR(CAST(birth_date + INTERVAL 5 YEARS AS DATE) + INTERVAL 20 MONTHS) AS year, COUNT(*) as c FROM test_emp GROUP BY 1;

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/analysis/analyzer/VerifierErrorMessagesTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ public void testGroupByHavingNonGrouped() {
457457
public void testGroupByAggregate() {
458458
assertEquals("1:36: Cannot use an aggregate [AVG] for grouping",
459459
error("SELECT AVG(int) FROM test GROUP BY AVG(int)"));
460+
assertEquals("1:65: Cannot use an aggregate [AVG] for grouping",
461+
error("SELECT ROUND(AVG(int),2), AVG(int), COUNT(*) FROM test GROUP BY AVG(int) ORDER BY AVG(int)"));
460462
}
461463

462464
public void testStarOnNested() {

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/planner/QueryTranslatorTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,21 @@ public void testGroupByHistogramQueryTranslator() {
997997
+ "\"fixed_interval\":\"62208000000ms\",\"time_zone\":\"Z\"}}}]}"));
998998
}
999999

1000+
public void testGroupByHistogramWithScalarsQueryTranslator() {
1001+
PhysicalPlan p = optimizeAndPlan("SELECT MAX(int), HISTOGRAM(date, INTERVAL 5 YEARS - INTERVAL 6 MONTHS) AS h " +
1002+
"FROM test GROUP BY h");
1003+
assertEquals(EsQueryExec.class, p.getClass());
1004+
EsQueryExec eqe = (EsQueryExec) p;
1005+
assertEquals(2, eqe.output().size());
1006+
assertEquals("MAX(int)", eqe.output().get(0).qualifiedName());
1007+
assertEquals(INTEGER, eqe.output().get(0).dataType());
1008+
assertEquals("h", eqe.output().get(1).qualifiedName());
1009+
assertEquals(DATETIME, eqe.output().get(1).dataType());
1010+
assertThat(eqe.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
1011+
containsString("\"date_histogram\":{\"field\":\"date\",\"missing_bucket\":true,\"value_type\":\"date\"," +
1012+
"\"order\":\"asc\",\"fixed_interval\":\"139968000000ms\",\"time_zone\":\"Z\"}}}]}"));
1013+
}
1014+
10001015
public void testGroupByYearQueryTranslator() {
10011016
PhysicalPlan p = optimizeAndPlan("SELECT YEAR(date) FROM test GROUP BY YEAR(date)");
10021017
assertEquals(EsQueryExec.class, p.getClass());

0 commit comments

Comments
 (0)