Remove deprecated use of "interval" method, in favor of "fixedInterval". (#45501)
(cherry picked from commit 3fef65160f9e61883e9f8f7f345b814f945e2f4b)
This commit is contained in:
parent
d6a9edea16
commit
30a0711777
|
@ -7,6 +7,7 @@ package org.elasticsearch.xpack.sql.querydsl.agg;
|
|||
|
||||
import org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.composite.DateHistogramValuesSourceBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
|
||||
import org.elasticsearch.xpack.sql.expression.gen.script.ScriptTemplate;
|
||||
import org.elasticsearch.xpack.sql.querydsl.container.Sort.Direction;
|
||||
|
||||
|
@ -45,7 +46,7 @@ public class GroupByDateHistogram extends GroupByKey {
|
|||
@Override
|
||||
protected CompositeValuesSourceBuilder<?> createSourceBuilder() {
|
||||
return new DateHistogramValuesSourceBuilder(id())
|
||||
.interval(interval)
|
||||
.fixedInterval(new DateHistogramInterval(interval + "ms"))
|
||||
.timeZone(zoneId);
|
||||
}
|
||||
|
||||
|
|
|
@ -861,6 +861,30 @@ public class QueryTranslatorTests extends ESTestCase {
|
|||
assertEquals(DataType.DATETIME, field.dataType());
|
||||
}
|
||||
|
||||
public void testGroupByHistogramQueryTranslator() {
|
||||
PhysicalPlan p = optimizeAndPlan("SELECT MAX(int) FROM test GROUP BY HISTOGRAM(date, INTERVAL 2 YEARS)");
|
||||
assertEquals(EsQueryExec.class, p.getClass());
|
||||
EsQueryExec eqe = (EsQueryExec) p;
|
||||
assertEquals(1, eqe.output().size());
|
||||
assertEquals("MAX(int)", eqe.output().get(0).qualifiedName());
|
||||
assertEquals(DataType.INTEGER, eqe.output().get(0).dataType());
|
||||
assertThat(eqe.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
|
||||
containsString("\"date_histogram\":{\"field\":\"date\",\"missing_bucket\":true,\"value_type\":\"date\",\"order\":\"asc\","
|
||||
+ "\"fixed_interval\":\"62208000000ms\",\"time_zone\":\"Z\"}}}]}"));
|
||||
}
|
||||
|
||||
public void testGroupByYearQueryTranslator() {
|
||||
PhysicalPlan p = optimizeAndPlan("SELECT YEAR(date) FROM test GROUP BY YEAR(date)");
|
||||
assertEquals(EsQueryExec.class, p.getClass());
|
||||
EsQueryExec eqe = (EsQueryExec) p;
|
||||
assertEquals(1, eqe.output().size());
|
||||
assertEquals("YEAR(date)", eqe.output().get(0).qualifiedName());
|
||||
assertEquals(DataType.INTEGER, eqe.output().get(0).dataType());
|
||||
assertThat(eqe.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
|
||||
endsWith("\"date_histogram\":{\"field\":\"date\",\"missing_bucket\":true,\"value_type\":\"date\",\"order\":\"asc\","
|
||||
+ "\"fixed_interval\":\"31536000000ms\",\"time_zone\":\"Z\"}}}]}}}"));
|
||||
}
|
||||
|
||||
public void testGroupByHistogramWithDate() {
|
||||
LogicalPlan p = plan("SELECT MAX(int) FROM test GROUP BY HISTOGRAM(CAST(date AS DATE), INTERVAL 2 MONTHS)");
|
||||
assertTrue(p instanceof Aggregate);
|
||||
|
|
Loading…
Reference in New Issue