Skip to content
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

fix:修复generateTimeFieldSqlWithFormatDateTime64ZoneShangHai toDateTime64方法转换缺失精度问题 #16

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/ly/ckibana/parser/HitsResultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private HitsOptimizedResult doOptimizeSearchTimeRange(CkRequestContext ckRequest
*/
private CkRequest getByMinuteRequest(SortType sortType, CkRequestContext ckRequestContext, Range orgTimeClause) {
CkRequest byMinuteRequest = ProxyUtils.buildRequest(ckRequestContext.getTableName(), SqlConstants.COUNT_QUERY);
String timeField = ProxyUtils.generateTimeFieldSqlWithFormatUnixTimestamp64Milli(ckRequestContext.getIndexPattern().getTimeField(), orgTimeClause.getCkFieldType());
String timeField = ProxyUtils.generateTimeFieldSqlWithFormatUnixTimestamp64(ckRequestContext.getIndexPattern().getTimeField(), orgTimeClause.getCkFieldType());
byMinuteRequest.appendSelect(String.format(SqlConstants.TIME_AGG_BY_MINUTE_TEMPLATE, timeField, SqlConstants.CK_MINUTE_NAME));
byMinuteRequest.initGroupBy(SqlConstants.CK_MINUTE_NAME);
byMinuteRequest.orderBy(SqlConstants.CK_MINUTE_NAME + " " + sortType.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public List<SqlConverter> buildSelectSqlConvertors(Range timeRange) {
FieldSqlConverter fieldAggregation = new FieldSqlConverter();
fieldAggregation.setCondition(
SqlUtils.getFunctionString(SqlConstants.TO_INT64, "(%s) / %d",
ProxyUtils.generateTimeFieldSqlWithFormatUnixTimestamp64Milli(getField(), timeRange.getCkFieldType()),
ProxyUtils.generateTimeFieldSqlWithFormatUnixTimestamp64(getField(), timeRange.getCkFieldType()),
getInterval())
);
fieldAggregation.setName(queryFieldName());
Expand Down
32 changes: 6 additions & 26 deletions src/main/java/com/ly/ckibana/util/ProxyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ public static String getErrorResponse(String message) {
/**
* 时间查询sql转换,支持字符串(耗性能,不推荐)和数值类型,DateTime, DateTime64类型.
*/
public static String generateTimeFieldSqlWithFormatUnixTimestamp64Milli(String ckFieldName, String ckFieldType) {
if (isDateTime64Ms(ckFieldType)) {
public static String generateTimeFieldSqlWithFormatUnixTimestamp64(String ckFieldName, String ckFieldType) {
if (SqlUtils.isDateTime64(ckFieldType)) {
return String.format("toUnixTimestamp64Milli(%s)", getFieldSqlPart(ckFieldName));
} else if (isDateTime(ckFieldType)) {
} else if (SqlUtils.isDateTime(ckFieldType)) {
return String.format("toUnixTimestamp(%s)*1000", getFieldSqlPart(ckFieldName));
} else {
return getFieldSqlPart(ckFieldName);
Expand Down Expand Up @@ -274,33 +274,13 @@ public static Range getRangeWrappedBySqlFunction(Range orgRange, boolean isTimeF
return rangeConverted;
}

/**
* 是否为DateTime64时间类型.
*
* @param ckFieldType ck字段类型
* @return true:是DateTime64类型
*/
public static boolean isDateTime64Ms(String ckFieldType) {
return StringUtils.startsWith(ckFieldType, SqlConstants.TYPE_DATETIME64);
}

/**
* 是否为DateTime时间类型.
*
* @param ckFieldType ck字段类型
* @return true:是DateTime类型
*/
public static boolean isDateTime(String ckFieldType) {
return StringUtils.startsWith(ckFieldType, SqlConstants.TYPE_DATETIME);
}

/**
* 时间字段转换。作为值 or 字段.
*/
public static String generateTimeFieldSqlWithFormatDateTime64ZoneShangHai(Object value, String ckFieldType) {
if (isDateTime64Ms(ckFieldType)) {
return String.format("toDateTime64(%s/1000.0)", value.toString());
} else if (isDateTime(ckFieldType)) {
if (SqlUtils.isDateTime64(ckFieldType)) {
return String.format("toDateTime64(%s/1000,%d)", value.toString(),SqlUtils.getDateTime64Scale(ckFieldType));
} else if (SqlUtils.isDateTime(ckFieldType)) {
return String.format("toDateTime(%s/1000)", value.toString());
} else {
return value.toString();
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/ly/ckibana/util/SqlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,39 @@ public static String generateIpSql(Object value, IPType ipType, boolean isQueryV
public static String getSelectTemplate(String selectSql, String table) {
return String.format("SELECT %s FROM %s", selectSql, table);
}


/**
* 是否为DateTime64时间类型.
*
* @param ckFieldType ck字段类型
* @return true:是DateTime64类型
*/
public static boolean isDateTime64(String ckFieldType) {
return StringUtils.startsWith(ckFieldType, SqlConstants.TYPE_DATETIME64);
}


/**
* DateTime64时间类型,提取精度
*
* @param ckFieldType ck字段类型,如DateTime64(3)
* @return 精度,如3
*/
public static int getDateTime64Scale(String ckFieldType) {
String scale= ckFieldType.replace(SqlConstants.TYPE_DATETIME64,StringUtils.EMPTY)
.replace(Constants.Symbol.LEFT_PARENTHESIS,StringUtils.EMPTY)
.replace(Constants.Symbol.RIGHT_PARENTHESIS,StringUtils.EMPTY);
return Integer.parseInt(scale);
}
/**
* 是否为DateTime时间类型.
*
* @param ckFieldType ck字段类型
* @return true:是DateTime类型
*/
public static boolean isDateTime(String ckFieldType) {
return StringUtils.startsWith(ckFieldType, SqlConstants.TYPE_DATETIME);
}

}
16 changes: 8 additions & 8 deletions src/test/java/com/ly/ckibana/converter/CommonAggTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class CommonAggTest extends CommonTest {
public void testFiltersAndDateHistogramAgg() {
String query = "{\"aggs\":{\"2\":{\"filters\":{\"filters\":{\"s1:\\\"s1value1\\\"\":{\"query_string\":{\"query\":\"s1:\\\"s1value1\\\"\",\"analyze_wildcard\":true,\"default_field\":\"*\"}},\"s2:\\\"s1value2\\\"\":{\"query_string\":{\"query\":\"s2:\\\"s1value2\\\"\",\"analyze_wildcard\":true,\"default_field\":\"*\"}}}},\"aggs\":{\"3\":{\"date_histogram\":{\"field\":\"@timestampDateTime\",\"interval\":\"30s\",\"time_zone\":\"Asia/Shanghai\",\"min_doc_count\":1}}}}},\"size\":0,\"_source\":{\"excludes\":[]},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[{\"field\":\"@timestampDateTime\",\"format\":\"date_time\"}],\"query\":{\"bool\":{\"must\":[{\"match_all\":{}},{\"match_all\":{}},{\"range\":{\"@timestampDateTime\":{\"gte\":1697890656331,\"lte\":1697891556331,\"format\":\"epoch_millis\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"timeout\":\"120000ms\"}";
String expectedSqls = "[\n" +
" \"SELECT toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `3_@timestampDateTime`,count(1) as `3__ckCount`,count(1) as `s1:\\\"s1value1\\\"__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697891550000/1000.0) AND `@timestampDateTime` >= toDateTime64(1697890650000/1000.0) ) AND ( ( `s1` like '%s1value1%' ) ) GROUP BY `3_@timestampDateTime` ORDER BY `3_@timestampDateTime` asc LIMIT 30000\",\n" +
" \"SELECT toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `3_@timestampDateTime`,count(1) as `3__ckCount`,count(1) as `s2:\\\"s1value2\\\"__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697891550000/1000.0) AND `@timestampDateTime` >= toDateTime64(1697890650000/1000.0) ) AND ( ( `s2` like '%s1value2%' ) ) GROUP BY `3_@timestampDateTime` ORDER BY `3_@timestampDateTime` asc LIMIT 30000\"\n" +
" \"SELECT toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `3_@timestampDateTime`,count(1) as `3__ckCount`,count(1) as `s1:\\\"s1value1\\\"__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697891550000/1000,3) AND `@timestampDateTime` >= toDateTime64(1697890650000/1000,3) ) AND ( ( `s1` like '%s1value1%' ) ) GROUP BY `3_@timestampDateTime` ORDER BY `3_@timestampDateTime` asc LIMIT 30000\",\n" +
" \"SELECT toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `3_@timestampDateTime`,count(1) as `3__ckCount`,count(1) as `s2:\\\"s1value2\\\"__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697891550000/1000,3) AND `@timestampDateTime` >= toDateTime64(1697890650000/1000,3) ) AND ( ( `s2` like '%s1value2%' ) ) GROUP BY `3_@timestampDateTime` ORDER BY `3_@timestampDateTime` asc LIMIT 30000\"\n" +
" ]";
doTest(TEST_AGGS_FILTERS_AND_DATE_HISTOGRAM_AGG, query, Boolean.FALSE, expectedSqls);
}
Expand All @@ -56,7 +56,7 @@ public void testFiltersAndDateHistogramAgg() {
public void testDateHistogramAgg() {
String query = "{\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestampDateTime\",\"interval\":\"30s\",\"time_zone\":\"Asia/Shanghai\",\"min_doc_count\":1}}},\"size\":0,\"_source\":{\"excludes\":[]},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[{\"field\":\"@timestampDateTime\",\"format\":\"date_time\"}],\"query\":{\"bool\":{\"must\":[{\"query_string\":{\"query\":\"s1:\\\"s1value\\\"\",\"analyze_wildcard\":true,\"default_field\":\"*\"}},{\"query_string\":{\"query\":\"s1:\\\"s1value\\\"\",\"analyze_wildcard\":true,\"default_field\":\"*\"}},{\"range\":{\"@timestampDateTime\":{\"gte\":1697890734041,\"lte\":1697891634041,\"format\":\"epoch_millis\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"timeout\":\"120000ms\"}";
String expectedSqls = "[\n" +
" \"SELECT toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `2_@timestampDateTime`,count(1) as `2__ckCount` FROM `table1_all` PREWHERE ( ( `s1` like '%s1value%' ) AND ( `s1` like '%s1value%' ) ) AND (( `@timestampDateTime` <= toDateTime64(1697891630000/1000.0) AND `@timestampDateTime` >= toDateTime64(1697890730000/1000.0) )) GROUP BY `2_@timestampDateTime` ORDER BY `2_@timestampDateTime` asc LIMIT 30000\"\n" +
" \"SELECT toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `2_@timestampDateTime`,count(1) as `2__ckCount` FROM `table1_all` PREWHERE ( ( `s1` like '%s1value%' ) AND ( `s1` like '%s1value%' ) ) AND (( `@timestampDateTime` <= toDateTime64(1697891630000/1000,3) AND `@timestampDateTime` >= toDateTime64(1697890730000/1000,3) )) GROUP BY `2_@timestampDateTime` ORDER BY `2_@timestampDateTime` asc LIMIT 30000\"\n" +
" ]";
doTest(TEST_AGGS_DATE_HISTOGRAM_AGG, query, Boolean.FALSE, expectedSqls);

Expand All @@ -69,7 +69,7 @@ public void testDateHistogramAgg() {
public void testTermsAgg() {
String query = "{\"aggs\":{\"2\":{\"terms\":{\"field\":\"s1\",\"size\":10,\"order\":{\"_count\":\"desc\"}}}},\"size\":0,\"_source\":{\"excludes\":[]},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[{\"field\":\"@timestampDateTime\",\"format\":\"date_time\"}],\"query\":{\"bool\":{\"must\":[{\"match_all\":{}},{\"match_all\":{}},{\"range\":{\"@timestampDateTime\":{\"gte\":1697891206239,\"lte\":1697892106239,\"format\":\"epoch_millis\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"timeout\":\"120000ms\"}";
String expectedSqls = "[\n" +
" \"SELECT `s1` as `2_s1`,count(1) as `2__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892100000/1000.0) AND `@timestampDateTime` >= toDateTime64(1697891200000/1000.0) ) AND (`2_s1` is not null AND `2_s1` != '' ) GROUP BY `2_s1` ORDER BY `2__ckCount` desc LIMIT 10\"\n" +
" \"SELECT `s1` as `2_s1`,count(1) as `2__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892100000/1000,3) AND `@timestampDateTime` >= toDateTime64(1697891200000/1000,3) ) AND (`2_s1` is not null AND `2_s1` != '' ) GROUP BY `2_s1` ORDER BY `2__ckCount` desc LIMIT 10\"\n" +
" ]";
doTest(TEST_DEMO_TERMS_AGG, query, Boolean.FALSE, expectedSqls);
}
Expand All @@ -88,7 +88,7 @@ public void testTermsAgg() {
public void testMathAndPercentAndDateHistogramAgg() {
String query = "{\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestampDateTime\",\"interval\":\"30s\",\"time_zone\":\"Asia/Shanghai\",\"min_doc_count\":1},\"aggs\":{\"3\":{\"sum\":{\"field\":\"i1\"}},\"4\":{\"min\":{\"field\":\"i2\"}},\"5\":{\"max\":{\"field\":\"i3\"}},\"6\":{\"avg\":{\"field\":\"i1\"}},\"7\":{\"percentiles\":{\"field\":\"i1\",\"percents\":[90,95,99],\"keyed\":false}},\"8\":{\"percentile_ranks\":{\"field\":\"i2\",\"values\":[100],\"keyed\":false}}}}},\"size\":0,\"_source\":{\"excludes\":[]},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[{\"field\":\"@timestampDateTime\",\"format\":\"date_time\"}],\"query\":{\"bool\":{\"must\":[{\"match_all\":{}},{\"match_all\":{}},{\"range\":{\"@timestampDateTime\":{\"gte\":1697891258636,\"lte\":1697892158636,\"format\":\"epoch_millis\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"timeout\":\"120000ms\"}";
String expectedSqls = "[\n" +
" \"SELECT SUM(`i1`) as `3_i1`,MIN(`i2`) as `4_i2`,MAX(`i3`) as `5_i3`,avg(`i1`) as `6_i1`,quantile(0.9)(`i1`) as `i1_90`,quantile(0.95)(`i1`) as `i1_95`,quantile(0.99)(`i1`) as `i1_99`,count(1) as `7__ckCount`,countIf(`i2` <= 100) as `i2_100`,count(1) as `8__ckCount`,toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `2_@timestampDateTime`,count(1) as `2__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892150000/1000.0) AND `@timestampDateTime` >= toDateTime64(1697891250000/1000.0) ) GROUP BY `2_@timestampDateTime` ORDER BY `2_@timestampDateTime` asc LIMIT 30000\"\n" +
" \"SELECT SUM(`i1`) as `3_i1`,MIN(`i2`) as `4_i2`,MAX(`i3`) as `5_i3`,avg(`i1`) as `6_i1`,quantile(0.9)(`i1`) as `i1_90`,quantile(0.95)(`i1`) as `i1_95`,quantile(0.99)(`i1`) as `i1_99`,count(1) as `7__ckCount`,countIf(`i2` <= 100) as `i2_100`,count(1) as `8__ckCount`,toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `2_@timestampDateTime`,count(1) as `2__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892150000/1000,3) AND `@timestampDateTime` >= toDateTime64(1697891250000/1000,3) ) GROUP BY `2_@timestampDateTime` ORDER BY `2_@timestampDateTime` asc LIMIT 30000\"\n" +
" ]";
doTest(TEST_DEMO_MATH_AND_PERCENTILE_DATE_HISTOGRAM_AGG, query, Boolean.FALSE, expectedSqls);
}
Expand All @@ -106,7 +106,7 @@ public void testMathAndPercentAndDateHistogramAgg() {
public void testMathAndPercentAgg() {
String query = "{\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestampDateTime\",\"interval\":\"30s\",\"time_zone\":\"Asia/Shanghai\",\"min_doc_count\":1},\"aggs\":{\"3\":{\"sum\":{\"field\":\"i1\"}},\"4\":{\"min\":{\"field\":\"i2\"}},\"5\":{\"max\":{\"field\":\"i3\"}},\"6\":{\"avg\":{\"field\":\"i1\"}},\"7\":{\"percentiles\":{\"field\":\"i1\",\"percents\":[90,95,99],\"keyed\":false}},\"8\":{\"percentile_ranks\":{\"field\":\"i2\",\"values\":[100],\"keyed\":false}}}}},\"size\":0,\"_source\":{\"excludes\":[]},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[{\"field\":\"@timestampDateTime\",\"format\":\"date_time\"}],\"query\":{\"bool\":{\"must\":[{\"match_all\":{}},{\"match_all\":{}},{\"range\":{\"@timestampDateTime\":{\"gte\":1697891258636,\"lte\":1697892158636,\"format\":\"epoch_millis\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"timeout\":\"120000ms\"}";
String expectedSqls = "[\n" +
" \"SELECT SUM(`i1`) as `3_i1`,MIN(`i2`) as `4_i2`,MAX(`i3`) as `5_i3`,avg(`i1`) as `6_i1`,quantile(0.9)(`i1`) as `i1_90`,quantile(0.95)(`i1`) as `i1_95`,quantile(0.99)(`i1`) as `i1_99`,count(1) as `7__ckCount`,countIf(`i2` <= 100) as `i2_100`,count(1) as `8__ckCount`,toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `2_@timestampDateTime`,count(1) as `2__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892150000/1000.0) AND `@timestampDateTime` >= toDateTime64(1697891250000/1000.0) ) GROUP BY `2_@timestampDateTime` ORDER BY `2_@timestampDateTime` asc LIMIT 30000\"\n" +
" \"SELECT SUM(`i1`) as `3_i1`,MIN(`i2`) as `4_i2`,MAX(`i3`) as `5_i3`,avg(`i1`) as `6_i1`,quantile(0.9)(`i1`) as `i1_90`,quantile(0.95)(`i1`) as `i1_95`,quantile(0.99)(`i1`) as `i1_99`,count(1) as `7__ckCount`,countIf(`i2` <= 100) as `i2_100`,count(1) as `8__ckCount`,toInt64((toUnixTimestamp64Milli(`@timestampDateTime`)) / 30000) as `2_@timestampDateTime`,count(1) as `2__ckCount` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892150000/1000,3) AND `@timestampDateTime` >= toDateTime64(1697891250000/1000,3) ) GROUP BY `2_@timestampDateTime` ORDER BY `2_@timestampDateTime` asc LIMIT 30000\"\n" +
" ]";
doTest(TEST_DEMO_MATH_AND_PERCENTILE_AGG, query, Boolean.FALSE, expectedSqls);
}
Expand All @@ -119,7 +119,7 @@ public void testMathAndPercentAgg() {
public void testRangeNumber() {
String query = "{\"aggs\":{\"2\":{\"range\":{\"field\":\"i1\",\"ranges\":[{\"from\":0,\"to\":1000},{\"from\":1000,\"to\":2000},{\"from\":3000}],\"keyed\":true}}},\"size\":0,\"_source\":{\"excludes\":[]},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[{\"field\":\"@timestampDateTime\",\"format\":\"date_time\"}],\"query\":{\"bool\":{\"must\":[{\"match_all\":{}},{\"match_all\":{}},{\"range\":{\"@timestampDateTime\":{\"gte\":1697891642926,\"lte\":1697892542926,\"format\":\"epoch_millis\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"timeout\":\"120000ms\"}";
String expectedSqls = " [\n" +
" \"SELECT countIf(`i1` >= 0 AND `i1` < 1000) as `0-1000`,countIf(`i1` >= 1000 AND `i1` < 2000) as `1000-2000`,countIf(`i1` >= 3000) as `3000-*` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892540000/1000.0) AND `@timestampDateTime` >= toDateTime64(1697891640000/1000.0) ) AND (`i1` != 2147483647) LIMIT 30000\"\n" +
" \"SELECT countIf(`i1` >= 0 AND `i1` < 1000) as `0-1000`,countIf(`i1` >= 1000 AND `i1` < 2000) as `1000-2000`,countIf(`i1` >= 3000) as `3000-*` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892540000/1000,3) AND `@timestampDateTime` >= toDateTime64(1697891640000/1000,3) ) AND (`i1` != 2147483647) LIMIT 30000\"\n" +
" ]";
doTest(TEST_DEMO_RANGE_NUMBER_AGG, query, Boolean.FALSE, expectedSqls);
}
Expand All @@ -131,7 +131,7 @@ public void testRangeNumber() {
public void testCardinality() {
String query = "{\"aggs\":{\"2\":{\"range\":{\"field\":\"i1\",\"ranges\":[{\"from\":0,\"to\":100},{\"from\":100,\"to\":200},{\"from\":200,\"to\":300}],\"keyed\":true}}},\"size\":0,\"_source\":{\"excludes\":[]},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[{\"field\":\"@timestampDateTime\",\"format\":\"date_time\"}],\"query\":{\"bool\":{\"must\":[{\"match_all\":{}},{\"match_all\":{}},{\"range\":{\"@timestampDateTime\":{\"gte\":1697891714119,\"lte\":1697892614119,\"format\":\"epoch_millis\"}}}],\"filter\":[],\"should\":[],\"must_not\":[]}},\"timeout\":\"120000ms\"}";
String expectedSqls = "[\n" +
" \"SELECT countIf(`i1` >= 0 AND `i1` < 100) as `0-100`,countIf(`i1` >= 100 AND `i1` < 200) as `100-200`,countIf(`i1` >= 200 AND `i1` < 300) as `200-300` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892610000/1000.0) AND `@timestampDateTime` >= toDateTime64(1697891710000/1000.0) ) AND (`i1` != 2147483647) LIMIT 30000\"\n" +
" \"SELECT countIf(`i1` >= 0 AND `i1` < 100) as `0-100`,countIf(`i1` >= 100 AND `i1` < 200) as `100-200`,countIf(`i1` >= 200 AND `i1` < 300) as `200-300` FROM `table1_all` PREWHERE ( `@timestampDateTime` <= toDateTime64(1697892610000/1000,3) AND `@timestampDateTime` >= toDateTime64(1697891710000/1000,3) ) AND (`i1` != 2147483647) LIMIT 30000\"\n" +
" ]";
doTest(TEST_DEMO_CARDINALITY_AGG, query, Boolean.FALSE, expectedSqls);
}
Expand Down
Loading