Skip to content

Commit fbd011f

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 533b519 commit fbd011f

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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ public void testGroupByHavingNonGrouped() {
454454
public void testGroupByAggregate() {
455455
assertEquals("1:36: Cannot use an aggregate [AVG] for grouping",
456456
error("SELECT AVG(int) FROM test GROUP BY AVG(int)"));
457+
assertEquals("1:65: Cannot use an aggregate [AVG] for grouping",
458+
error("SELECT ROUND(AVG(int),2), AVG(int), COUNT(*) FROM test GROUP BY AVG(int) ORDER BY AVG(int)"));
457459
}
458460

459461
public void testStarOnNested() {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,21 @@ public void testGroupByHistogramQueryTranslator() {
990990
+ "\"fixed_interval\":\"62208000000ms\",\"time_zone\":\"Z\"}}}]}"));
991991
}
992992

993+
public void testGroupByHistogramWithScalarsQueryTranslator() {
994+
PhysicalPlan p = optimizeAndPlan("SELECT MAX(int), HISTOGRAM(date, INTERVAL 5 YEARS - INTERVAL 6 MONTHS) AS h " +
995+
"FROM test GROUP BY h");
996+
assertEquals(EsQueryExec.class, p.getClass());
997+
EsQueryExec eqe = (EsQueryExec) p;
998+
assertEquals(2, eqe.output().size());
999+
assertEquals("MAX(int)", eqe.output().get(0).qualifiedName());
1000+
assertEquals(DataType.INTEGER, eqe.output().get(0).dataType());
1001+
assertEquals("h", eqe.output().get(1).qualifiedName());
1002+
assertEquals(DataType.DATETIME, eqe.output().get(1).dataType());
1003+
assertThat(eqe.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
1004+
containsString("\"date_histogram\":{\"field\":\"date\",\"missing_bucket\":true,\"value_type\":\"date\"," +
1005+
"\"order\":\"asc\",\"fixed_interval\":\"139968000000ms\",\"time_zone\":\"Z\"}}}]}"));
1006+
}
1007+
9931008
public void testGroupByYearQueryTranslator() {
9941009
PhysicalPlan p = optimizeAndPlan("SELECT YEAR(date) FROM test GROUP BY YEAR(date)");
9951010
assertEquals(EsQueryExec.class, p.getClass());

0 commit comments

Comments
 (0)