Skip to content

Commit

Permalink
SQL: [Tests] Add tests for fixed issues (#52335)
Browse files Browse the repository at this point in the history
Add tests to verify behaviour for
fixed issues: #33724 & #38306

(cherry picked from commit 89fb675)
  • Loading branch information
matriv committed Feb 14, 2020
1 parent 6cd4292 commit 51e74be
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions x-pack/plugin/sql/qa/src/main/resources/agg.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,19 @@ SELECT HISTOGRAM(YEAR(birth_date), 2) AS h, COUNT(*) as c FROM test_emp GROUP BY
null |10
;

histogramDateTimeWithScalars
schema::h:ts|c:l
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;

h | c
------------------------+---------------
1957-09-06T00:00:00.000Z|31
1953-07-29T00:00:00.000Z|24
1961-10-15T00:00:00.000Z|20
1949-06-20T00:00:00.000Z|15
null |10
;

histogramYearOnDateTimeWithScalars
schema::year:i|c:l
SELECT YEAR(CAST(birth_date + INTERVAL 5 YEARS AS DATE) + INTERVAL 20 MONTHS) AS year, COUNT(*) as c FROM test_emp GROUP BY 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ public void testGroupByHavingNonGrouped() {
public void testGroupByAggregate() {
assertEquals("1:36: Cannot use an aggregate [AVG] for grouping",
error("SELECT AVG(int) FROM test GROUP BY AVG(int)"));
assertEquals("1:65: Cannot use an aggregate [AVG] for grouping",
error("SELECT ROUND(AVG(int),2), AVG(int), COUNT(*) FROM test GROUP BY AVG(int) ORDER BY AVG(int)"));
}

public void testStarOnNested() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,21 @@ public void testGroupByHistogramQueryTranslator() {
+ "\"fixed_interval\":\"62208000000ms\",\"time_zone\":\"Z\"}}}]}"));
}

public void testGroupByHistogramWithScalarsQueryTranslator() {
PhysicalPlan p = optimizeAndPlan("SELECT MAX(int), HISTOGRAM(date, INTERVAL 5 YEARS - INTERVAL 6 MONTHS) AS h " +
"FROM test GROUP BY h");
assertEquals(EsQueryExec.class, p.getClass());
EsQueryExec eqe = (EsQueryExec) p;
assertEquals(2, eqe.output().size());
assertEquals("MAX(int)", eqe.output().get(0).qualifiedName());
assertEquals(INTEGER, eqe.output().get(0).dataType());
assertEquals("h", eqe.output().get(1).qualifiedName());
assertEquals(DATETIME, eqe.output().get(1).dataType());
assertThat(eqe.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
containsString("\"date_histogram\":{\"field\":\"date\",\"missing_bucket\":true,\"value_type\":\"date\"," +
"\"order\":\"asc\",\"fixed_interval\":\"139968000000ms\",\"time_zone\":\"Z\"}}}]}"));
}

public void testGroupByYearQueryTranslator() {
PhysicalPlan p = optimizeAndPlan("SELECT YEAR(date) FROM test GROUP BY YEAR(date)");
assertEquals(EsQueryExec.class, p.getClass());
Expand Down

0 comments on commit 51e74be

Please sign in to comment.