diff --git a/integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java b/integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java index 325c81107f..81b2aad785 100644 --- a/integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/jdbc/CursorIT.java @@ -111,7 +111,8 @@ public void select_all_no_cursor() { var query = String.format("SELECT * FROM %s", table); ResultSet rs = stmt.executeQuery(query); int rows = 0; - while (rs.next()) rows++; + while(rs.next()) + rows++; var restResponse = executeRestQuery(query, null); assertEquals(rows, restResponse.getInt("total")); diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java index 490e9eb510..bf25c75f00 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/AggregationIT.java @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ + package org.opensearch.sql.legacy; import static org.hamcrest.Matchers.containsString; @@ -59,9 +60,8 @@ public void countTest() throws IOException { @Ignore("The distinct is not supported in new engine") public void countDistinctTest() { - JSONObject response = - executeJdbcRequest( - String.format("SELECT COUNT(distinct gender) FROM %s", TEST_INDEX_ACCOUNT)); + JSONObject response = executeJdbcRequest( + String.format("SELECT COUNT(distinct gender) FROM %s", TEST_INDEX_ACCOUNT)); verifySchema(response, schema("COUNT(DISTINCT gender)", null, "integer")); verifyDataRows(response, rows(2)); @@ -71,9 +71,8 @@ public void countDistinctTest() { public void countWithDocsHintTest() throws Exception { JSONObject result = - executeQuery( - String.format( - "SELECT /*! DOCS_WITH_AGGREGATION(10) */ count(*) from %s", TEST_INDEX_ACCOUNT)); + executeQuery(String.format("SELECT /*! DOCS_WITH_AGGREGATION(10) */ count(*) from %s", + TEST_INDEX_ACCOUNT)); JSONArray hits = (JSONArray) result.query("/hits/hits"); Assert.assertThat(hits.length(), equalTo(10)); } @@ -84,8 +83,8 @@ public void sumTest() throws IOException { JSONObject result = executeQuery(String.format("SELECT SUM(balance) FROM %s", TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); - Assert.assertThat( - getDoubleAggregationValue(result, "SUM(balance)", "value"), equalTo(25714837.0)); + Assert.assertThat(getDoubleAggregationValue(result, "SUM(balance)", "value"), + equalTo(25714837.0)); } @Test @@ -128,28 +127,23 @@ public void statsTest() throws IOException { @Test public void extendedStatsTest() throws IOException { - JSONObject result = - executeQuery(String.format("SELECT EXTENDED_STATS(age) FROM %s", TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT EXTENDED_STATS(age) FROM %s", + TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); - Assert.assertThat( - getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "min"), equalTo(20.0)); - Assert.assertThat( - getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "max"), equalTo(40.0)); - Assert.assertThat( - getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "avg"), equalTo(30.171)); - Assert.assertThat( - getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "sum"), equalTo(30171.0)); - Assert.assertThat( - getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "sum_of_squares"), + Assert + .assertThat(getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "min"), equalTo(20.0)); + Assert + .assertThat(getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "max"), equalTo(40.0)); + Assert.assertThat(getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "avg"), + equalTo(30.171)); + Assert.assertThat(getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "sum"), + equalTo(30171.0)); + Assert.assertThat(getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "sum_of_squares"), equalTo(946393.0)); - Assert.assertEquals( - 6.008640362012022, - getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "std_deviation"), - 0.0001); - Assert.assertEquals( - 36.10375899999996, - getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "variance"), - 0.0001); + Assert.assertEquals(6.008640362012022, + getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "std_deviation"), 0.0001); + Assert.assertEquals(36.10375899999996, + getDoubleAggregationValue(result, "EXTENDED_STATS(age)", "variance"), 0.0001); } @Test @@ -158,73 +152,72 @@ public void percentileTest() throws IOException { JSONObject result = executeQuery(String.format("SELECT PERCENTILES(age) FROM %s", TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); - Assert.assertEquals( - 20.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "1.0"), 0.001); - Assert.assertEquals( - 21.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "5.0"), 0.001); - Assert.assertEquals( - 25.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "25.0"), 0.001); - // All percentiles are approximations calculated by t-digest, however, P50 has the widest - // distribution (not sure why) - Assert.assertEquals( - 30.5, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "50.0"), 0.6); - Assert.assertEquals( - 35.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "75.0"), 0.6); - Assert.assertEquals( - 39.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "95.0"), 0.6); - Assert.assertEquals( - 40.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "99.0"), 0.6); + Assert + .assertEquals(20.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "1.0"), + 0.001); + Assert + .assertEquals(21.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "5.0"), + 0.001); + Assert + .assertEquals(25.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "25.0"), + 0.001); + // All percentiles are approximations calculated by t-digest, however, P50 has the widest distribution (not sure why) + Assert + .assertEquals(30.5, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "50.0"), + 0.6); + Assert + .assertEquals(35.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "75.0"), + 0.6); + Assert + .assertEquals(39.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "95.0"), + 0.6); + Assert + .assertEquals(40.0, getDoubleAggregationValue(result, "PERCENTILES(age)", "values", "99.0"), + 0.6); } @Test public void percentileTestSpecific() throws IOException { - JSONObject result = - executeQuery( - String.format("SELECT PERCENTILES(age,25.0,75.0) FROM %s", TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT PERCENTILES(age,25.0,75.0) FROM %s", + TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); - Assert.assertEquals( - 25.0, - getDoubleAggregationValue(result, "PERCENTILES(age,25.0,75.0)", "values", "25.0"), - 0.6); - Assert.assertEquals( - 35.0, - getDoubleAggregationValue(result, "PERCENTILES(age,25.0,75.0)", "values", "75.0"), - 0.6); + Assert.assertEquals(25.0, + getDoubleAggregationValue(result, "PERCENTILES(age,25.0,75.0)", "values", "25.0"), 0.6); + Assert.assertEquals(35.0, + getDoubleAggregationValue(result, "PERCENTILES(age,25.0,75.0)", "values", "75.0"), 0.6); } @Test public void aliasTest() throws IOException { - JSONObject result = - executeQuery(String.format("SELECT COUNT(*) AS mycount FROM %s", TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT COUNT(*) AS mycount FROM %s", + TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); Assert.assertThat(getIntAggregationValue(result, "mycount", "value"), equalTo(1000)); } @Test public void groupByTest() throws Exception { - JSONObject result = - executeQuery(String.format("SELECT COUNT(*) FROM %s GROUP BY gender", TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT COUNT(*) FROM %s GROUP BY gender", + TEST_INDEX_ACCOUNT)); assertResultForGroupByTest(result); } @Test public void groupByUsingTableAliasTest() throws Exception { - JSONObject result = - executeQuery( - String.format("SELECT COUNT(*) FROM %s a GROUP BY a.gender", TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT COUNT(*) FROM %s a GROUP BY a.gender", + TEST_INDEX_ACCOUNT)); assertResultForGroupByTest(result); } @Test public void groupByUsingTableNamePrefixTest() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT COUNT(*) FROM %s GROUP BY opensearch-sql_test_index_account.gender", - TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format( + "SELECT COUNT(*) FROM %s GROUP BY opensearch-sql_test_index_account.gender", + TEST_INDEX_ACCOUNT + )); assertResultForGroupByTest(result); } @@ -251,30 +244,28 @@ public void groupByHavingTest() throws Exception { JSONObject result = executeQuery( String.format( - "SELECT gender FROM %s GROUP BY gender HAVING COUNT(*) > 0", TEST_INDEX_ACCOUNT)); + "SELECT gender FROM %s GROUP BY gender HAVING COUNT(*) > 0", + TEST_INDEX_ACCOUNT)); assertResultForGroupByHavingTest(result); } @Test public void groupByHavingUsingTableAliasTest() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT a.gender FROM %s a GROUP BY a.gender HAVING COUNT(*) > 0", - TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format( + "SELECT a.gender " + + "FROM %s a " + + "GROUP BY a.gender " + + "HAVING COUNT(*) > 0", TEST_INDEX_ACCOUNT)); assertResultForGroupByHavingTest(result); } @Test public void groupByHavingUsingTableNamePrefixTest() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT opensearch-sql_test_index_account.gender " - + "FROM %s " - + "GROUP BY opensearch-sql_test_index_account.gender " - + "HAVING COUNT(*) > 0", - TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format( + "SELECT opensearch-sql_test_index_account.gender " + + "FROM %s " + + "GROUP BY opensearch-sql_test_index_account.gender " + + "HAVING COUNT(*) > 0", TEST_INDEX_ACCOUNT)); assertResultForGroupByHavingTest(result); } @@ -296,17 +287,15 @@ private void assertResultForGroupByHavingTest(JSONObject result) { Assert.assertThat(gender.query(femaleBucketPrefix + "/count_0/value"), equalTo(493)); } - @Ignore // todo VerificationException: table alias or field name missing + @Ignore //todo VerificationException: table alias or field name missing @Test public void groupBySubqueryTest() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT COUNT(*) FROM %s " - + "WHERE firstname IN (SELECT firstname FROM %s) " - + "GROUP BY gender", - TEST_INDEX_ACCOUNT, TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format( + "SELECT COUNT(*) FROM %s " + + "WHERE firstname IN (SELECT firstname FROM %s) " + + "GROUP BY gender", + TEST_INDEX_ACCOUNT, TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); JSONObject gender = getAggregation(result, "gender"); Assert.assertThat(gender.getJSONArray("buckets").length(), equalTo(2)); @@ -327,12 +316,9 @@ public void groupBySubqueryTest() throws Exception { @Test public void postFilterTest() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT /*! POST_FILTER({\\\"term\\\":" - + "{\\\"gender\\\":\\\"m\\\"}}) */ COUNT(*) FROM %s GROUP BY gender", - TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT /*! POST_FILTER({\\\"term\\\":" + + "{\\\"gender\\\":\\\"m\\\"}}) */ COUNT(*) FROM %s GROUP BY gender", + TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(507)); JSONObject gender = getAggregation(result, "gender"); Assert.assertThat(gender.getJSONArray("buckets").length(), equalTo(2)); @@ -353,12 +339,9 @@ public void postFilterTest() throws Exception { @Test public void multipleGroupByTest() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT COUNT(*) FROM %s GROUP BY gender," - + " terms('field'='age','size'=200,'alias'='age')", - TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT COUNT(*) FROM %s GROUP BY gender," + + " terms('field'='age','size'=200,'alias'='age')", + TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); JSONObject gender = getAggregation(result, "gender"); Assert.assertThat(gender.getJSONArray("buckets").length(), equalTo(2)); @@ -381,11 +364,9 @@ public void multipleGroupByTest() throws Exception { final Set actualAgesM = new HashSet<>(expectedAges.size()); final Set actualAgesF = new HashSet<>(expectedAges.size()); - mAgeBuckets - .iterator() + mAgeBuckets.iterator() .forEachRemaining(json -> actualAgesM.add(((JSONObject) json).getInt("key"))); - fAgeBuckets - .iterator() + fAgeBuckets.iterator() .forEachRemaining(json -> actualAgesF.add(((JSONObject) json).getInt("key"))); Assert.assertThat(actualAgesM, equalTo(expectedAges)); @@ -395,12 +376,9 @@ public void multipleGroupByTest() throws Exception { @Test public void multipleGroupBysWithSize() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT COUNT(*) FROM %s GROUP BY gender," - + " terms('alias'='ageAgg','field'='age','size'=3)", - TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT COUNT(*) FROM %s GROUP BY gender," + + " terms('alias'='ageAgg','field'='age','size'=3)", + TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); JSONObject gender = getAggregation(result, "gender"); Assert.assertThat(gender.getJSONArray("buckets").length(), equalTo(2)); @@ -415,12 +393,9 @@ public void multipleGroupBysWithSize() throws Exception { @Test public void termsWithSize() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT COUNT(*) FROM %s GROUP BY terms" - + "('alias'='ageAgg','field'='age','size'=3)", - TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT COUNT(*) FROM %s GROUP BY terms" + + "('alias'='ageAgg','field'='age','size'=3)", + TEST_INDEX_ACCOUNT)); Assert.assertThat(getTotalHits(result), equalTo(1000)); JSONObject gender = getAggregation(result, "ageAgg"); Assert.assertThat(gender.getJSONArray("buckets").length(), equalTo(3)); @@ -429,12 +404,9 @@ public void termsWithSize() throws Exception { @Test public void termsWithMissing() throws Exception { - JSONObject result = - executeQuery( - String.format( - "SELECT count(*) FROM %s GROUP BY terms" - + "('alias'='nick','field'='nickname','missing'='no_nickname')", - TEST_INDEX_GAME_OF_THRONES)); + JSONObject result = executeQuery(String.format("SELECT count(*) FROM %s GROUP BY terms" + + "('alias'='nick','field'='nickname','missing'='no_nickname')", + TEST_INDEX_GAME_OF_THRONES)); JSONObject nick = getAggregation(result, "nick"); Optional noNicknameBucket = Optional.empty(); @@ -455,12 +427,9 @@ public void termsWithOrder() throws Exception { final String dog1 = "snoopy"; final String dog2 = "rex"; - JSONObject result = - executeQuery( - String.format( - "SELECT count(*) FROM %s GROUP BY terms" - + "('field'='dog_name', 'alias'='dog_name', 'order'='desc')", - TEST_INDEX_DOG)); + JSONObject result = executeQuery(String.format("SELECT count(*) FROM %s GROUP BY terms" + + "('field'='dog_name', 'alias'='dog_name', 'order'='desc')", + TEST_INDEX_DOG)); JSONObject dogName = getAggregation(result, "dog_name"); String firstDog = (String) (dogName.optQuery("/buckets/0/key")); @@ -468,12 +437,8 @@ public void termsWithOrder() throws Exception { Assert.assertThat(firstDog, equalTo(dog1)); Assert.assertThat(secondDog, equalTo(dog2)); - result = - executeQuery( - String.format( - "SELECT count(*) FROM %s GROUP BY terms" - + "('field'='dog_name', 'alias'='dog_name', 'order'='asc')", - TEST_INDEX_DOG)); + result = executeQuery(String.format("SELECT count(*) FROM %s GROUP BY terms" + + "('field'='dog_name', 'alias'='dog_name', 'order'='asc')", TEST_INDEX_DOG)); dogName = getAggregation(result, "dog_name"); @@ -485,96 +450,92 @@ public void termsWithOrder() throws Exception { @Test public void orderByAscTest() { - JSONObject response = - executeJdbcRequest( - String.format( - "SELECT COUNT(*) FROM %s " + "GROUP BY gender ORDER BY COUNT(*)", - TEST_INDEX_ACCOUNT)); + JSONObject response = executeJdbcRequest(String.format("SELECT COUNT(*) FROM %s " + + "GROUP BY gender ORDER BY COUNT(*)", TEST_INDEX_ACCOUNT)); verifySchema(response, schema("COUNT(*)", null, "integer")); - verifyDataRows(response, rows(493), rows(507)); + verifyDataRows(response, + rows(493), + rows(507)); } @Test public void orderByAliasAscTest() { - JSONObject response = - executeJdbcRequest( - String.format( - "SELECT COUNT(*) as count FROM %s " + "GROUP BY gender ORDER BY count", - TEST_INDEX_ACCOUNT)); + JSONObject response = executeJdbcRequest(String.format("SELECT COUNT(*) as count FROM %s " + + "GROUP BY gender ORDER BY count", TEST_INDEX_ACCOUNT)); verifySchema(response, schema("COUNT(*)", "count", "integer")); - verifyDataRowsInOrder(response, rows(493), rows(507)); + verifyDataRowsInOrder(response, + rows(493), + rows(507)); } @Test public void orderByDescTest() throws IOException { - JSONObject response = - executeJdbcRequest( - String.format( - "SELECT COUNT(*) FROM %s " + "GROUP BY gender ORDER BY COUNT(*) DESC", - TEST_INDEX_ACCOUNT)); + JSONObject response = executeJdbcRequest(String.format("SELECT COUNT(*) FROM %s " + + "GROUP BY gender ORDER BY COUNT(*) DESC", TEST_INDEX_ACCOUNT)); verifySchema(response, schema("COUNT(*)", null, "integer")); - verifyDataRowsInOrder(response, rows(507), rows(493)); + verifyDataRowsInOrder(response, + rows(507), + rows(493)); } @Test public void orderByAliasDescTest() throws IOException { - JSONObject response = - executeJdbcRequest( - String.format( - "SELECT COUNT(*) as count FROM %s " + "GROUP BY gender ORDER BY count DESC", - TEST_INDEX_ACCOUNT)); + JSONObject response = executeJdbcRequest(String.format("SELECT COUNT(*) as count FROM %s " + + "GROUP BY gender ORDER BY count DESC", TEST_INDEX_ACCOUNT)); verifySchema(response, schema("COUNT(*)", "count", "integer")); - verifyDataRowsInOrder(response, rows(507), rows(493)); + verifyDataRowsInOrder(response, + rows(507), + rows(493)); } @Test public void orderByGroupFieldWithAlias() throws IOException { // ORDER BY field name - JSONObject response = - executeJdbcRequest( - String.format( - "SELECT gender as g, COUNT(*) as count " - + "FROM %s GROUP BY gender ORDER BY gender", - TEST_INDEX_ACCOUNT)); + JSONObject response = executeJdbcRequest(String.format("SELECT gender as g, COUNT(*) as count " + + "FROM %s GROUP BY gender ORDER BY gender", TEST_INDEX_ACCOUNT)); - verifySchema(response, schema("gender", "g", "text"), schema("COUNT(*)", "count", "integer")); - verifyDataRowsInOrder(response, rows("f", 493), rows("m", 507)); + verifySchema(response, + schema("gender", "g", "text"), + schema("COUNT(*)", "count", "integer")); + verifyDataRowsInOrder(response, + rows("f", 493), + rows("m", 507)); // ORDER BY field alias - response = - executeJdbcRequest( - String.format( - "SELECT gender as g, COUNT(*) as count " + "FROM %s GROUP BY gender ORDER BY g", - TEST_INDEX_ACCOUNT)); + response = executeJdbcRequest(String.format("SELECT gender as g, COUNT(*) as count " + + "FROM %s GROUP BY gender ORDER BY g", TEST_INDEX_ACCOUNT)); - verifySchema(response, schema("gender", "g", "text"), schema("COUNT(*)", "count", "integer")); - verifyDataRowsInOrder(response, rows("f", 493), rows("m", 507)); + verifySchema(response, + schema("gender", "g", "text"), + schema("COUNT(*)", "count", "integer")); + verifyDataRowsInOrder(response, + rows("f", 493), + rows("m", 507)); } @Test public void limitTest() throws IOException { - JSONObject response = - executeJdbcRequest( - String.format( - "SELECT COUNT(*) FROM %s " + "GROUP BY age ORDER BY COUNT(*) LIMIT 5", - TEST_INDEX_ACCOUNT)); + JSONObject response = executeJdbcRequest(String.format("SELECT COUNT(*) FROM %s " + + "GROUP BY age ORDER BY COUNT(*) LIMIT 5", TEST_INDEX_ACCOUNT)); verifySchema(response, schema("COUNT(*)", null, "integer")); - verifyDataRowsInOrder(response, rows(35), rows(39), rows(39), rows(42), rows(42)); + verifyDataRowsInOrder(response, + rows(35), + rows(39), + rows(39), + rows(42), + rows(42)); } @Test public void countGroupByRange() throws IOException { - JSONObject result = - executeQuery( - String.format( - "SELECT COUNT(age) FROM %s" + " GROUP BY range(age, 20,25,30,35,40)", - TEST_INDEX_ACCOUNT)); + JSONObject result = executeQuery(String.format("SELECT COUNT(age) FROM %s" + + " GROUP BY range(age, 20,25,30,35,40)", TEST_INDEX_ACCOUNT)); JSONObject ageAgg = getAggregation(result, "range(age,20,25,30,35,40)"); JSONArray buckets = ageAgg.getJSONArray("buckets"); Assert.assertThat(buckets.length(), equalTo(4)); @@ -583,8 +544,7 @@ public void countGroupByRange() throws IOException { for (int i = 0; i < expectedResults.length; ++i) { - Assert.assertThat( - buckets.query(String.format(Locale.ROOT, "/%d/COUNT(age)/value", i)), + Assert.assertThat(buckets.query(String.format(Locale.ROOT, "/%d/COUNT(age)/value", i)), equalTo(expectedResults[i])); } } @@ -596,58 +556,42 @@ public void countGroupByRange() throws IOException { public void countGroupByDateTest() throws IOException { String result = - explainQuery( - String.format( - "select insert_time from %s group by" - + " date_histogram('field'='insert_time','fixed_interval'='1h','format'='yyyy-MM','min_doc_count'=5)" - + " ", - TEST_INDEX_ONLINE)); - Assert.assertThat( - result.replaceAll("\\s+", ""), - containsString( - "{\"date_histogram\":{\"field\":\"insert_time\",\"format\":\"yyyy-MM\"," - + "\"fixed_interval\":\"1h\",\"offset\":0,\"order\":{\"_key\":\"asc\"},\"keyed\":false," - + "\"min_doc_count\":5}")); + explainQuery(String.format("select insert_time from %s group by date_histogram" + + "('field'='insert_time','fixed_interval'='1h','format'='yyyy-MM','min_doc_count'=5) ", + TEST_INDEX_ONLINE)); + Assert.assertThat(result.replaceAll("\\s+", ""), + containsString("{\"date_histogram\":{\"field\":\"insert_time\",\"format\":\"yyyy-MM\"," + + "\"fixed_interval\":\"1h\",\"offset\":0,\"order\":{\"_key\":\"asc\"},\"keyed\":false," + + "\"min_doc_count\":5}")); } @Test public void countGroupByDateTestWithAlias() throws IOException { String result = - explainQuery( - String.format( - "select insert_time from %s group by date_histogram" - + "('field'='insert_time','fixed_interval'='1h','format'='yyyy-MM','alias'='myAlias')", - TEST_INDEX_ONLINE)); - Assert.assertThat( - result.replaceAll("\\s+", ""), - containsString( - "myAlias\":{\"date_histogram\":{\"field\":\"insert_time\"," - + "\"format\":\"yyyy-MM\",\"fixed_interval\":\"1h\"")); - } - - /** - * - * http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html - */ - @Test - @Ignore - public void countDateRangeTest() throws IOException { - String result = - explainQuery( - String.format( - "select online from %s group by date_range(" - + "field='insert_time', 'format'='yyyy-MM-dd' ,'2014-08-18','2014-08-17', " - + "'now-8d','now-7d','now-6d','now')", - TEST_INDEX_ONLINE)); - // TODO: fix the query or fix the code for the query to work - } + explainQuery(String.format("select insert_time from %s group by date_histogram" + + "('field'='insert_time','fixed_interval'='1h','format'='yyyy-MM','alias'='myAlias')", + TEST_INDEX_ONLINE)); + Assert.assertThat(result.replaceAll("\\s+", ""), + containsString("myAlias\":{\"date_histogram\":{\"field\":\"insert_time\"," + + "\"format\":\"yyyy-MM\",\"fixed_interval\":\"1h\"")); + } + +// /** +// * http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html +// */ +// @Test +// public void countDateRangeTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException { +// String result = explainQuery(String.format("select online from %s group by date_range(field='insert_time'," + +// "'format'='yyyy-MM-dd' ,'2014-08-18','2014-08-17','now-8d','now-7d','now-6d','now')", +// TEST_INDEX_ONLINE)); +// // TODO: fix the query or fix the code for the query to work +// } @Test public void topHitTest() throws IOException { - String query = - String.format( - "select topHits('size'=3,age='desc') from %s group by gender", TEST_INDEX_ACCOUNT); + String query = String + .format("select topHits('size'=3,age='desc') from %s group by gender", TEST_INDEX_ACCOUNT); JSONObject result = executeQuery(query); JSONObject gender = getAggregation(result, "gender"); Assert.assertThat(gender.getJSONArray("buckets").length(), equalTo(2)); @@ -660,8 +604,7 @@ public void topHitTest() throws IOException { final String femaleBucketPrefix = String.format(Locale.ROOT, "/buckets/%d", femaleBucketId); Assert.assertThat(gender.query(maleBucketPrefix + "/key"), equalTo("m")); - Assert.assertThat( - gender.query(maleBucketPrefix + "/topHits(size=3,age=desc)/hits/total/value"), + Assert.assertThat(gender.query(maleBucketPrefix + "/topHits(size=3,age=desc)/hits/total/value"), equalTo(507)); Assert.assertThat( gender.query(maleBucketPrefix + "/topHits(size=3,age=desc)/hits/total/relation"), @@ -671,9 +614,9 @@ public void topHitTest() throws IOException { .length(), equalTo(3)); Assert.assertThat(gender.query(femaleBucketPrefix + "/key"), equalTo("f")); - Assert.assertThat( - gender.query(femaleBucketPrefix + "/topHits(size=3,age=desc)/hits/total/value"), - equalTo(493)); + Assert + .assertThat(gender.query(femaleBucketPrefix + "/topHits(size=3,age=desc)/hits/total/value"), + equalTo(493)); Assert.assertThat( gender.query(femaleBucketPrefix + "/topHits(size=3,age=desc)/hits/total/relation"), equalTo("eq")); @@ -687,8 +630,7 @@ public void topHitTest() throws IOException { public void topHitTest_WithInclude() throws IOException { String query = - String.format( - "select topHits('size'=3,age='desc','include'=age) from %s group by gender", + String.format("select topHits('size'=3,age='desc','include'=age) from %s group by gender", TEST_INDEX_ACCOUNT); JSONObject result = executeQuery(query); JSONObject gender = getAggregation(result, "gender"); @@ -705,41 +647,28 @@ public void topHitTest_WithInclude() throws IOException { Assert.assertThat( gender.query(maleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/total/value"), equalTo(507)); - Assert.assertThat( - gender.query( - maleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/total/relation"), + Assert.assertThat(gender + .query(maleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/total/relation"), equalTo("eq")); - Assert.assertThat( - ((JSONArray) - gender.query(maleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/hits")) - .length(), + Assert.assertThat(((JSONArray) gender.query( + maleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/hits")).length(), equalTo(3)); Assert.assertThat(gender.query(femaleBucketPrefix + "/key"), equalTo("f")); Assert.assertThat( gender.query(femaleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/total/value"), equalTo(493)); - Assert.assertThat( - gender.query( - femaleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/total/relation"), + Assert.assertThat(gender + .query(femaleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/total/relation"), equalTo("eq")); - Assert.assertThat( - ((JSONArray) - gender.query( - femaleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/hits")) - .length(), + Assert.assertThat(((JSONArray) gender.query( + femaleBucketPrefix + "/topHits(size=3,age=desc,include=age)/hits/hits")).length(), equalTo(3)); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { - JSONObject source = - (JSONObject) - gender.query( - String.format( - Locale.ROOT, - "/buckets/%d/topHits(size=3,age=desc,include=age)/hits/hits/%d/_source", - i, - j)); + JSONObject source = (JSONObject) gender.query(String.format(Locale.ROOT, + "/buckets/%d/topHits(size=3,age=desc,include=age)/hits/hits/%d/_source", i, j)); Assert.assertThat(source.length(), equalTo(1)); Assert.assertTrue(source.has("age")); Assert.assertThat(source.getInt("age"), equalTo(40)); @@ -751,24 +680,17 @@ public void topHitTest_WithInclude() throws IOException { public void topHitTest_WithIncludeTwoFields() throws IOException { String query = - String.format( - "select topHits('size'=3,'include'='age,firstname',age='desc') from %s " - + "group by gender", - TEST_INDEX_ACCOUNT); + String.format("select topHits('size'=3,'include'='age,firstname',age='desc') from %s " + + "group by gender", TEST_INDEX_ACCOUNT); JSONObject result = executeQuery(query); JSONObject gender = getAggregation(result, "gender"); Assert.assertThat(gender.getJSONArray("buckets").length(), equalTo(2)); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { - JSONObject source = - (JSONObject) - gender.query( - String.format( - Locale.ROOT, - "/buckets/%d/topHits(size=3,include=age,firstname,age=desc)/hits/hits/%d/_source", - i, - j)); + JSONObject source = (JSONObject) gender.query(String.format(Locale.ROOT, + "/buckets/%d/topHits(size=3,include=age,firstname,age=desc)/hits/hits/%d/_source", i, + j)); Assert.assertThat(source.length(), equalTo(2)); Assert.assertTrue(source.has("age")); Assert.assertThat(source.getInt("age"), equalTo(40)); @@ -782,10 +704,8 @@ public void topHitTest_WithIncludeTwoFields() throws IOException { @Test public void topHitTest_WithExclude() throws IOException { - String query = - String.format( - "select topHits('size'=3,'exclude'='lastname',age='desc') from " + "%s group by gender", - TEST_INDEX_ACCOUNT); + String query = String.format("select topHits('size'=3,'exclude'='lastname',age='desc') from " + + "%s group by gender", TEST_INDEX_ACCOUNT); JSONObject result = executeQuery(query); JSONObject gender = getAggregation(result, "gender"); Assert.assertThat(gender.getJSONArray("buckets").length(), equalTo(2)); @@ -798,61 +718,44 @@ public void topHitTest_WithExclude() throws IOException { final String femaleBucketPrefix = String.format(Locale.ROOT, "/buckets/%d", femaleBucketId); Assert.assertThat(gender.query(maleBucketPrefix + "/key"), equalTo("m")); - Assert.assertThat( - gender.query( - maleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/total/value"), + Assert.assertThat(gender + .query(maleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/total/value"), equalTo(507)); - Assert.assertThat( - gender.query( - maleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/total/relation"), + Assert.assertThat(gender + .query(maleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/total/relation"), equalTo("eq")); - Assert.assertThat( - ((JSONArray) - gender.query( - maleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/hits")) - .length(), + Assert.assertThat(((JSONArray) gender.query( + maleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/hits")).length(), equalTo(3)); Assert.assertThat(gender.query(femaleBucketPrefix + "/key"), equalTo("f")); - Assert.assertThat( - gender.query( - femaleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/total/value"), + Assert.assertThat(gender + .query(femaleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/total/value"), equalTo(493)); - Assert.assertThat( - gender.query( - femaleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/total/relation"), + Assert.assertThat(gender.query( + femaleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/total/relation"), equalTo("eq")); - Assert.assertThat( - ((JSONArray) - gender.query( - femaleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/hits")) - .length(), + Assert.assertThat(((JSONArray) gender.query( + femaleBucketPrefix + "/topHits(size=3,exclude=lastname,age=desc)/hits/hits")).length(), equalTo(3)); - final Set expectedFields = - new HashSet<>( - Arrays.asList( - "account_number", - "firstname", - "address", - "balance", - "gender", - "city", - "employer", - "state", - "age", - "email")); + final Set expectedFields = new HashSet<>(Arrays.asList( + "account_number", + "firstname", + "address", + "balance", + "gender", + "city", + "employer", + "state", + "age", + "email" + )); for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { - JSONObject source = - (JSONObject) - gender.query( - String.format( - Locale.ROOT, - "/buckets/%d/topHits(size=3,exclude=lastname,age=desc)/hits/hits/%d/_source", - i, - j)); + JSONObject source = (JSONObject) gender.query(String.format(Locale.ROOT, + "/buckets/%d/topHits(size=3,exclude=lastname,age=desc)/hits/hits/%d/_source", i, j)); Assert.assertThat(source.length(), equalTo(expectedFields.size())); Assert.assertFalse(source.has("lastname")); Assert.assertThat(source.keySet().containsAll(expectedFields), equalTo(true)); @@ -860,300 +763,254 @@ public void topHitTest_WithExclude() throws IOException { } } - // region not migrated - - // script on metric aggregation tests. uncomment if your elastic has scripts enable (disabled by - // default) - // @Test - // public void sumWithScriptTest() throws IOException, SqlParseException, - // SQLFeatureNotSupportedException { - // Aggregations result = query(String.format("SELECT - // SUM(script('','doc[\\'balance\\'].value + doc[\\'balance\\'].value')) as doubleSum FROM %s", - // TEST_INDEX)); - // Sum sum = result.get("doubleSum"); - // assertThat(sum.getValue(), equalTo(25714837.0*2)); - // } - // - // @Test - // public void sumWithImplicitScriptTest() throws IOException, SqlParseException, - // SQLFeatureNotSupportedException { - // Aggregations result = query(String.format("SELECT SUM(balance + balance) as doubleSum - // FROM %s", TEST_INDEX)); - // Sum sum = result.get("doubleSum"); - // assertThat(sum.getValue(), equalTo(25714837.0*2)); - // } - // - // @Test - // public void sumWithScriptTestNoAlias() throws IOException, SqlParseException, - // SQLFeatureNotSupportedException { - // Aggregations result = query(String.format("SELECT SUM(balance + balance) FROM %s", - // TEST_INDEX)); - // Sum sum = result.get("SUM(script=script(balance + balance,doc('balance').value + - // doc('balance').value))"); - // assertThat(sum.getValue(), equalTo(25714837.0*2)); - // } - // - // @Test - // public void scriptedMetricAggregation() throws SQLFeatureNotSupportedException, - // SqlParseException { - // Aggregations result = query ("select - // scripted_metric('map_script'='if(doc[\\'balance\\'].value > 49670){ - // if(!_agg.containsKey(\\'ages\\')) { _agg.put(\\'ages\\',doc[\\'age\\'].value); } " + - // "else { _agg.put(\\'ages\\',_agg.get(\\'ages\\')+doc[\\'age\\'].value); }}'," + - // "'reduce_script'='sumThem = 0; for (a in _aggs) { if(a.containsKey(\\'ages\\')){ - // sumThem += a.get(\\'ages\\');} }; return sumThem;') as wierdSum from " + TEST_INDEX + ""); - // ScriptedMetric metric = result.get("wierdSum"); - // Assert.assertEquals(136L,metric.aggregation()); - // } - // - // @Test - // public void scriptedMetricConcatWithStringParamAndReduceParamAggregation() throws - // SQLFeatureNotSupportedException, SqlParseException { - // String query = "select scripted_metric(\n" + - // " 'init_script' = '_agg[\"concat\"]=[] ',\n" + - // " 'map_script'='_agg.concat.add(doc[field].value)' ,\n" + - // " 'combine_script'='return _agg.concat.join(delim);',\t\t\t\t\n" + - // " 'reduce_script'='_aggs.removeAll(\"\"); return _aggs.join(delim)'," + - // "'@field' = 'name.firstname' , '@delim'=';',@reduce_delim =';' ) as - // all_characters \n" + - // "from "+TEST_INDEX+""; - // Aggregations result = query (query); - // ScriptedMetric metric = result.get("all_characters"); - // List names = Arrays.asList(metric.aggregation().toString().split(";")); - // - // - // Assert.assertEquals(4,names.size()); - // String[] expectedNames = new String[]{"brandon","daenerys","eddard","jaime"}; - // for(String name : expectedNames){ - // Assert.assertTrue("not contains:" + name,names.contains(name)); - // } - // } - // - // @Test - // public void scriptedMetricAggregationWithNumberParams() throws - // SQLFeatureNotSupportedException, SqlParseException { - // Aggregations result = query ("select - // scripted_metric('map_script'='if(doc[\\'balance\\'].value > 49670){ - // if(!_agg.containsKey(\\'ages\\')) { _agg.put(\\'ages\\',doc[\\'age\\'].value+x); } " + - // "else { _agg.put(\\'ages\\',_agg.get(\\'ages\\')+doc[\\'age\\'].value+x); }}'," - // + - // "'reduce_script'='sumThem = 0; for (a in _aggs) { if(a.containsKey(\\'ages\\')){ - // sumThem += a.get(\\'ages\\');} }; return sumThem;'" + - // ",'@x'=3) as wierdSum from " + TEST_INDEX + ""); - // ScriptedMetric metric = result.get("wierdSum"); - // Assert.assertEquals(148L,metric.aggregation()); - // } - // - - // @Test - // public void topHitTest_WithIncludeAndExclude() throws IOException, SqlParseException, - // SQLFeatureNotSupportedException { - // Aggregations result = query(String.format("select - // topHits('size'=3,'exclude'='lastname','include'='firstname,lastname',age='desc') from %s group - // by gender ", TEST_INDEX_ACCOUNT)); - // List buckets = ((Terms) (result.asList().get(0))).getBuckets(); - // for (Terms.Bucket bucket : buckets) { - // SearchHits hits = ((InternalTopHits) - // bucket.getAggregations().asList().get(0)).getHits(); - // for (SearchHit hit : hits) { - // Set fields = hit.getSourceAsMap().keySet(); - // Assert.assertEquals(1, fields.size()); - // Assert.assertTrue(fields.contains("firstname")); - // } - // } - // } - // - // private Aggregations query(String query) throws SqlParseException, - // SQLFeatureNotSupportedException { - // SqlElasticSearchRequestBuilder select = getSearchRequestBuilder(query); - // return ((SearchResponse)select.get()).getAggregations(); - // } - // - // private SqlElasticSearchRequestBuilder getSearchRequestBuilder(String query) throws - // SqlParseException, SQLFeatureNotSupportedException { - // SearchDao searchDao = MainTestSuite.getSearchDao(); - // return (SqlElasticSearchRequestBuilder) searchDao.explain(query).explain(); - // } - // - // @Test - // public void testFromSizeWithAggregations() throws Exception { - // final String query1 = String.format("SELECT /*! DOCS_WITH_AGGREGATION(0,1) */" + - // " account_number FROM %s GROUP BY gender", TEST_INDEX_ACCOUNT); - // SearchResponse response1 = (SearchResponse) getSearchRequestBuilder(query1).get(); - // - // Assert.assertEquals(1, response1.getHits().getHits().length); - // Terms gender1 = response1.getAggregations().get("gender"); - // Assert.assertEquals(2, gender1.getBuckets().size()); - // Object account1 = - // response1.getHits().getHits()[0].getSourceAsMap().get("account_number"); - // - // final String query2 = String.format("SELECT /*! DOCS_WITH_AGGREGATION(1,1) */" + - // " account_number FROM %s GROUP BY gender", TEST_INDEX_ACCOUNT); - // SearchResponse response2 = (SearchResponse) getSearchRequestBuilder(query2).get(); - // - // Assert.assertEquals(1, response2.getHits().getHits().length); - // Terms gender2 = response2.getAggregations().get("gender"); - // Assert.assertEquals(2, gender2.getBuckets().size()); - // Object account2 = - // response2.getHits().getHits()[0].getSourceAsMap().get("account_number"); - // - // Assert.assertEquals(response1.getHits().getTotalHits(), - // response2.getHits().getTotalHits()); - // Assert.assertNotEquals(account1, account2); - // } - // - // @Test - // public void testSubAggregations() throws Exception { - // Set expectedAges = new HashSet<>(ContiguousSet.create(Range.closed(20, 40), - // DiscreteDomain.integers())); - // final String query = String.format("SELECT /*! DOCS_WITH_AGGREGATION(10) */" + - // " * FROM %s GROUP BY (gender, terms('field'='age','size'=200,'alias'='age')), - // (state) LIMIT 200,200", TEST_INDEX_ACCOUNT); - // - // Map> buckets = new HashMap<>(); - // - // SqlElasticSearchRequestBuilder select = getSearchRequestBuilder(query); - // SearchResponse response = (SearchResponse) select.get(); - // Aggregations result = response.getAggregations(); - // - // Terms gender = result.get("gender"); - // for(Terms.Bucket genderBucket : gender.getBuckets()) { - // String genderKey = genderBucket.getKey().toString(); - // buckets.put(genderKey, new HashSet()); - // Terms ageBuckets = (Terms) genderBucket.getAggregations().get("age"); - // for(Terms.Bucket ageBucket : ageBuckets.getBuckets()) { - // buckets.get(genderKey).add(Integer.parseInt(ageBucket.getKey().toString())); - // } - // } - // - // Assert.assertEquals(2, buckets.keySet().size()); - // Assert.assertEquals(expectedAges, buckets.get("m")); - // Assert.assertEquals(expectedAges, buckets.get("f")); - // - // Terms state = result.get("state.keyword"); - // for(Terms.Bucket stateBucket : state.getBuckets()) { - // if(stateBucket.getKey().toString().equalsIgnoreCase("ak")) { - // Assert.assertTrue("There are 22 entries for state ak", stateBucket.getDocCount() - // == 22); - // } - // } - // - // Assert.assertEquals(response.getHits().getTotalHits(), 1000); - // Assert.assertEquals(response.getHits().getHits().length, 10); - // } - // - // @Test - // public void testSimpleSubAggregations() throws Exception { - // final String query = String.format("SELECT /*! DOCS_WITH_AGGREGATION(10) */ * FROM %s - // GROUP BY (gender), (state) ", TEST_INDEX_ACCOUNT); - // - // SqlElasticSearchRequestBuilder select = getSearchRequestBuilder(query); - // SearchResponse response = (SearchResponse) select.get(); - // Aggregations result = response.getAggregations(); - // - // Terms gender = result.get("gender"); - // for(Terms.Bucket genderBucket : gender.getBuckets()) { - // String genderKey = genderBucket.getKey().toString(); - // Assert.assertTrue("Gender should be m or f", genderKey.equals("m") || - // genderKey.equals("f")); - // } - // - // Assert.assertEquals(2, gender.getBuckets().size()); - // - // Terms state = result.get("state.keyword"); - // for(Terms.Bucket stateBucket : state.getBuckets()) { - // if(stateBucket.getKey().toString().equalsIgnoreCase("ak")) { - // Assert.assertTrue("There are 22 entries for state ak", stateBucket.getDocCount() - // == 22); - // } - // } - // - // Assert.assertEquals(response.getHits().getTotalHits(), 1000); - // Assert.assertEquals(response.getHits().getHits().length, 10); - // } - // - // @Test - // public void geoHashGrid() throws SQLFeatureNotSupportedException, SqlParseException { - // Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/location GROUP BY - // geohash_grid(field='center',precision=5) ", TEST_INDEX_LOCATION)); - // InternalGeoHashGrid grid = result.get("geohash_grid(field=center,precision=5)"); - // Collection buckets = - // grid.getBuckets(); - // for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) { - // Assert.assertTrue(bucket.getKeyAsString().equals("w2fsm") || - // bucket.getKeyAsString().equals("w0p6y") ); - // Assert.assertEquals(1,bucket.getDocCount()); - // } - // } - // - // @Test - // public void geoBounds() throws SQLFeatureNotSupportedException, SqlParseException { - // Aggregations result = query(String.format("SELECT * FROM %s/location GROUP BY - // geo_bounds(field='center',alias='bounds') ", TEST_INDEX_LOCATION)); - // InternalGeoBounds bounds = result.get("bounds"); - // Assert.assertEquals(0.5,bounds.bottomRight().getLat(),0.001); - // Assert.assertEquals(105.0,bounds.bottomRight().getLon(),0.001); - // Assert.assertEquals(5.0,bounds.topLeft().getLat(),0.001); - // Assert.assertEquals(100.5,bounds.topLeft().getLon(),0.001); - // } - // - // @Test - // public void groupByOnNestedFieldTest() throws Exception { - // Aggregations result = query(String.format("SELECT COUNT(*) FROM %s GROUP BY - // nested(message.info)", TEST_INDEX_NESTED_TYPE)); - // InternalNested nested = result.get("message.info@NESTED"); - // Terms infos = nested.getAggregations().get("message.info"); - // Assert.assertEquals(3,infos.getBuckets().size()); - // for(Terms.Bucket bucket : infos.getBuckets()) { - // String key = bucket.getKey().toString(); - // long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue(); - // if(key.equalsIgnoreCase("a")) { - // Assert.assertEquals(2, count); - // } - // else if(key.equalsIgnoreCase("c")) { - // Assert.assertEquals(2, count); - // } - // else if(key.equalsIgnoreCase("b")) { - // Assert.assertEquals(1, count); - // } - // else { - // throw new Exception(String.format("Unexpected key. expected: a OR b OR c . - // found: %s", key)); - // } - // } - // } - // - // @Test - // public void groupByTestWithFilter() throws Exception { - // Aggregations result = query(String.format("SELECT COUNT(*) FROM %s GROUP BY - // filter(gender='m'),gender", TEST_INDEX_ACCOUNT)); - // InternalFilter filter = result.get("filter(gender = 'm')@FILTER"); - // Terms gender = filter.getAggregations().get("gender"); - // - // for(Terms.Bucket bucket : gender.getBuckets()) { - // String key = bucket.getKey().toString(); - // long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue(); - // if(key.equalsIgnoreCase("m")) { - // Assert.assertEquals(507, count); - // } - // else { - // throw new Exception(String.format("Unexpected key. expected: only m. found: %s", - // key)); - // } - // } - // } - // - // - // endregion not migrated + //region not migrated + + // script on metric aggregation tests. uncomment if your elastic has scripts enable (disabled by default) +// @Test +// public void sumWithScriptTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException { +// Aggregations result = query(String.format("SELECT SUM(script('','doc[\\'balance\\'].value + doc[\\'balance\\'].value')) as doubleSum FROM %s", TEST_INDEX)); +// Sum sum = result.get("doubleSum"); +// assertThat(sum.getValue(), equalTo(25714837.0*2)); +// } +// +// @Test +// public void sumWithImplicitScriptTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException { +// Aggregations result = query(String.format("SELECT SUM(balance + balance) as doubleSum FROM %s", TEST_INDEX)); +// Sum sum = result.get("doubleSum"); +// assertThat(sum.getValue(), equalTo(25714837.0*2)); +// } +// +// @Test +// public void sumWithScriptTestNoAlias() throws IOException, SqlParseException, SQLFeatureNotSupportedException { +// Aggregations result = query(String.format("SELECT SUM(balance + balance) FROM %s", TEST_INDEX)); +// Sum sum = result.get("SUM(script=script(balance + balance,doc('balance').value + doc('balance').value))"); +// assertThat(sum.getValue(), equalTo(25714837.0*2)); +// } +// +// @Test +// public void scriptedMetricAggregation() throws SQLFeatureNotSupportedException, SqlParseException { +// Aggregations result = query ("select scripted_metric('map_script'='if(doc[\\'balance\\'].value > 49670){ if(!_agg.containsKey(\\'ages\\')) { _agg.put(\\'ages\\',doc[\\'age\\'].value); } " + +// "else { _agg.put(\\'ages\\',_agg.get(\\'ages\\')+doc[\\'age\\'].value); }}'," + +// "'reduce_script'='sumThem = 0; for (a in _aggs) { if(a.containsKey(\\'ages\\')){ sumThem += a.get(\\'ages\\');} }; return sumThem;') as wierdSum from " + TEST_INDEX + ""); +// ScriptedMetric metric = result.get("wierdSum"); +// Assert.assertEquals(136L,metric.aggregation()); +// } +// +// @Test +// public void scriptedMetricConcatWithStringParamAndReduceParamAggregation() throws SQLFeatureNotSupportedException, SqlParseException { +// String query = "select scripted_metric(\n" + +// " 'init_script' = '_agg[\"concat\"]=[] ',\n" + +// " 'map_script'='_agg.concat.add(doc[field].value)' ,\n" + +// " 'combine_script'='return _agg.concat.join(delim);',\t\t\t\t\n" + +// " 'reduce_script'='_aggs.removeAll(\"\"); return _aggs.join(delim)'," + +// "'@field' = 'name.firstname' , '@delim'=';',@reduce_delim =';' ) as all_characters \n" + +// "from "+TEST_INDEX+""; +// Aggregations result = query (query); +// ScriptedMetric metric = result.get("all_characters"); +// List names = Arrays.asList(metric.aggregation().toString().split(";")); +// +// +// Assert.assertEquals(4,names.size()); +// String[] expectedNames = new String[]{"brandon","daenerys","eddard","jaime"}; +// for(String name : expectedNames){ +// Assert.assertTrue("not contains:" + name,names.contains(name)); +// } +// } +// +// @Test +// public void scriptedMetricAggregationWithNumberParams() throws SQLFeatureNotSupportedException, SqlParseException { +// Aggregations result = query ("select scripted_metric('map_script'='if(doc[\\'balance\\'].value > 49670){ if(!_agg.containsKey(\\'ages\\')) { _agg.put(\\'ages\\',doc[\\'age\\'].value+x); } " + +// "else { _agg.put(\\'ages\\',_agg.get(\\'ages\\')+doc[\\'age\\'].value+x); }}'," + +// "'reduce_script'='sumThem = 0; for (a in _aggs) { if(a.containsKey(\\'ages\\')){ sumThem += a.get(\\'ages\\');} }; return sumThem;'" + +// ",'@x'=3) as wierdSum from " + TEST_INDEX + ""); +// ScriptedMetric metric = result.get("wierdSum"); +// Assert.assertEquals(148L,metric.aggregation()); +// } +// + +// @Test +// public void topHitTest_WithIncludeAndExclude() throws IOException, SqlParseException, SQLFeatureNotSupportedException { +// Aggregations result = query(String.format("select topHits('size'=3,'exclude'='lastname','include'='firstname,lastname',age='desc') from %s group by gender ", TEST_INDEX_ACCOUNT)); +// List buckets = ((Terms) (result.asList().get(0))).getBuckets(); +// for (Terms.Bucket bucket : buckets) { +// SearchHits hits = ((InternalTopHits) bucket.getAggregations().asList().get(0)).getHits(); +// for (SearchHit hit : hits) { +// Set fields = hit.getSourceAsMap().keySet(); +// Assert.assertEquals(1, fields.size()); +// Assert.assertTrue(fields.contains("firstname")); +// } +// } +// } +// +// private Aggregations query(String query) throws SqlParseException, SQLFeatureNotSupportedException { +// SqlElasticSearchRequestBuilder select = getSearchRequestBuilder(query); +// return ((SearchResponse)select.get()).getAggregations(); +// } +// +// private SqlElasticSearchRequestBuilder getSearchRequestBuilder(String query) throws SqlParseException, SQLFeatureNotSupportedException { +// SearchDao searchDao = MainTestSuite.getSearchDao(); +// return (SqlElasticSearchRequestBuilder) searchDao.explain(query).explain(); +// } +// +// @Test +// public void testFromSizeWithAggregations() throws Exception { +// final String query1 = String.format("SELECT /*! DOCS_WITH_AGGREGATION(0,1) */" + +// " account_number FROM %s GROUP BY gender", TEST_INDEX_ACCOUNT); +// SearchResponse response1 = (SearchResponse) getSearchRequestBuilder(query1).get(); +// +// Assert.assertEquals(1, response1.getHits().getHits().length); +// Terms gender1 = response1.getAggregations().get("gender"); +// Assert.assertEquals(2, gender1.getBuckets().size()); +// Object account1 = response1.getHits().getHits()[0].getSourceAsMap().get("account_number"); +// +// final String query2 = String.format("SELECT /*! DOCS_WITH_AGGREGATION(1,1) */" + +// " account_number FROM %s GROUP BY gender", TEST_INDEX_ACCOUNT); +// SearchResponse response2 = (SearchResponse) getSearchRequestBuilder(query2).get(); +// +// Assert.assertEquals(1, response2.getHits().getHits().length); +// Terms gender2 = response2.getAggregations().get("gender"); +// Assert.assertEquals(2, gender2.getBuckets().size()); +// Object account2 = response2.getHits().getHits()[0].getSourceAsMap().get("account_number"); +// +// Assert.assertEquals(response1.getHits().getTotalHits(), response2.getHits().getTotalHits()); +// Assert.assertNotEquals(account1, account2); +// } +// +// @Test +// public void testSubAggregations() throws Exception { +// Set expectedAges = new HashSet<>(ContiguousSet.create(Range.closed(20, 40), DiscreteDomain.integers())); +// final String query = String.format("SELECT /*! DOCS_WITH_AGGREGATION(10) */" + +// " * FROM %s GROUP BY (gender, terms('field'='age','size'=200,'alias'='age')), (state) LIMIT 200,200", TEST_INDEX_ACCOUNT); +// +// Map> buckets = new HashMap<>(); +// +// SqlElasticSearchRequestBuilder select = getSearchRequestBuilder(query); +// SearchResponse response = (SearchResponse) select.get(); +// Aggregations result = response.getAggregations(); +// +// Terms gender = result.get("gender"); +// for(Terms.Bucket genderBucket : gender.getBuckets()) { +// String genderKey = genderBucket.getKey().toString(); +// buckets.put(genderKey, new HashSet()); +// Terms ageBuckets = (Terms) genderBucket.getAggregations().get("age"); +// for(Terms.Bucket ageBucket : ageBuckets.getBuckets()) { +// buckets.get(genderKey).add(Integer.parseInt(ageBucket.getKey().toString())); +// } +// } +// +// Assert.assertEquals(2, buckets.keySet().size()); +// Assert.assertEquals(expectedAges, buckets.get("m")); +// Assert.assertEquals(expectedAges, buckets.get("f")); +// +// Terms state = result.get("state.keyword"); +// for(Terms.Bucket stateBucket : state.getBuckets()) { +// if(stateBucket.getKey().toString().equalsIgnoreCase("ak")) { +// Assert.assertTrue("There are 22 entries for state ak", stateBucket.getDocCount() == 22); +// } +// } +// +// Assert.assertEquals(response.getHits().getTotalHits(), 1000); +// Assert.assertEquals(response.getHits().getHits().length, 10); +// } +// +// @Test +// public void testSimpleSubAggregations() throws Exception { +// final String query = String.format("SELECT /*! DOCS_WITH_AGGREGATION(10) */ * FROM %s GROUP BY (gender), (state) ", TEST_INDEX_ACCOUNT); +// +// SqlElasticSearchRequestBuilder select = getSearchRequestBuilder(query); +// SearchResponse response = (SearchResponse) select.get(); +// Aggregations result = response.getAggregations(); +// +// Terms gender = result.get("gender"); +// for(Terms.Bucket genderBucket : gender.getBuckets()) { +// String genderKey = genderBucket.getKey().toString(); +// Assert.assertTrue("Gender should be m or f", genderKey.equals("m") || genderKey.equals("f")); +// } +// +// Assert.assertEquals(2, gender.getBuckets().size()); +// +// Terms state = result.get("state.keyword"); +// for(Terms.Bucket stateBucket : state.getBuckets()) { +// if(stateBucket.getKey().toString().equalsIgnoreCase("ak")) { +// Assert.assertTrue("There are 22 entries for state ak", stateBucket.getDocCount() == 22); +// } +// } +// +// Assert.assertEquals(response.getHits().getTotalHits(), 1000); +// Assert.assertEquals(response.getHits().getHits().length, 10); +// } +// +// @Test +// public void geoHashGrid() throws SQLFeatureNotSupportedException, SqlParseException { +// Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/location GROUP BY geohash_grid(field='center',precision=5) ", TEST_INDEX_LOCATION)); +// InternalGeoHashGrid grid = result.get("geohash_grid(field=center,precision=5)"); +// Collection buckets = grid.getBuckets(); +// for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) { +// Assert.assertTrue(bucket.getKeyAsString().equals("w2fsm") || bucket.getKeyAsString().equals("w0p6y") ); +// Assert.assertEquals(1,bucket.getDocCount()); +// } +// } +// +// @Test +// public void geoBounds() throws SQLFeatureNotSupportedException, SqlParseException { +// Aggregations result = query(String.format("SELECT * FROM %s/location GROUP BY geo_bounds(field='center',alias='bounds') ", TEST_INDEX_LOCATION)); +// InternalGeoBounds bounds = result.get("bounds"); +// Assert.assertEquals(0.5,bounds.bottomRight().getLat(),0.001); +// Assert.assertEquals(105.0,bounds.bottomRight().getLon(),0.001); +// Assert.assertEquals(5.0,bounds.topLeft().getLat(),0.001); +// Assert.assertEquals(100.5,bounds.topLeft().getLon(),0.001); +// } +// +// @Test +// public void groupByOnNestedFieldTest() throws Exception { +// Aggregations result = query(String.format("SELECT COUNT(*) FROM %s GROUP BY nested(message.info)", TEST_INDEX_NESTED_TYPE)); +// InternalNested nested = result.get("message.info@NESTED"); +// Terms infos = nested.getAggregations().get("message.info"); +// Assert.assertEquals(3,infos.getBuckets().size()); +// for(Terms.Bucket bucket : infos.getBuckets()) { +// String key = bucket.getKey().toString(); +// long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue(); +// if(key.equalsIgnoreCase("a")) { +// Assert.assertEquals(2, count); +// } +// else if(key.equalsIgnoreCase("c")) { +// Assert.assertEquals(2, count); +// } +// else if(key.equalsIgnoreCase("b")) { +// Assert.assertEquals(1, count); +// } +// else { +// throw new Exception(String.format("Unexpected key. expected: a OR b OR c . found: %s", key)); +// } +// } +// } +// +// @Test +// public void groupByTestWithFilter() throws Exception { +// Aggregations result = query(String.format("SELECT COUNT(*) FROM %s GROUP BY filter(gender='m'),gender", TEST_INDEX_ACCOUNT)); +// InternalFilter filter = result.get("filter(gender = 'm')@FILTER"); +// Terms gender = filter.getAggregations().get("gender"); +// +// for(Terms.Bucket bucket : gender.getBuckets()) { +// String key = bucket.getKey().toString(); +// long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue(); +// if(key.equalsIgnoreCase("m")) { +// Assert.assertEquals(507, count); +// } +// else { +// throw new Exception(String.format("Unexpected key. expected: only m. found: %s", key)); +// } +// } +// } +// +// + //endregion not migrated @Test public void groupByOnNestedFieldWithFilterTest() throws Exception { - String query = - String.format( - "SELECT COUNT(*) FROM %s GROUP BY nested(message.info)," - + "filter('myFilter',message.info = 'a')", - TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT COUNT(*) FROM %s GROUP BY nested(message.info)," + + "filter('myFilter',message.info = 'a')", TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.info@NESTED"); @@ -1169,36 +1026,29 @@ public void groupByOnNestedFieldWithFilterTest() throws Exception { @Test public void minOnNestedField() throws Exception { - String query = - String.format( - "SELECT min(nested(message.dayOfWeek)) as minDays FROM %s", TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT min(nested(message.dayOfWeek)) as minDays FROM %s", + TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.dayOfWeek@NESTED"); - Assert.assertEquals( - 1.0, ((BigDecimal) aggregation.query("/minDays/value")).doubleValue(), 0.0001); + Assert.assertEquals(1.0, ((BigDecimal) aggregation.query("/minDays/value")).doubleValue(), 0.0001); } @Test public void sumOnNestedField() throws Exception { - String query = - String.format( - "SELECT sum(nested(message.dayOfWeek)) as sumDays FROM %s", TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT sum(nested(message.dayOfWeek)) as sumDays FROM %s", + TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.dayOfWeek@NESTED"); - Assert.assertEquals( - 19.0, ((BigDecimal) aggregation.query("/sumDays/value")).doubleValue(), 0.0001); + Assert.assertEquals(19.0, ((BigDecimal) aggregation.query("/sumDays/value")).doubleValue(), 0.0001); } @Test public void histogramOnNestedField() throws Exception { - String query = - String.format( - "select count(*) from %s group by" - + " histogram('field'='message.dayOfWeek','nested'='message','interval'='2' ," - + " 'alias' = 'someAlias' )", - TEST_INDEX_NESTED_TYPE); + String query = String.format("select count(*) from %s group by histogram" + + "('field'='message.dayOfWeek','nested'='message','interval'='2' , 'alias' = 'someAlias' )", + TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message@NESTED"); @@ -1211,26 +1061,22 @@ public void histogramOnNestedField() throws Exception { JSONArray buckets = (JSONArray) aggregation.query("/someAlias/buckets"); Assert.assertThat(buckets.length(), equalTo(4)); - buckets.forEach( - obj -> { - JSONObject bucket = (JSONObject) obj; - final double key = bucket.getDouble("key"); - Assert.assertTrue(expectedCountsByKey.containsKey(key)); - Assert.assertThat( - bucket.getJSONObject("COUNT(*)").getInt("value"), - equalTo(expectedCountsByKey.get(key))); - }); + buckets.forEach(obj -> { + JSONObject bucket = (JSONObject) obj; + final double key = bucket.getDouble("key"); + Assert.assertTrue(expectedCountsByKey.containsKey(key)); + Assert.assertThat(bucket.getJSONObject("COUNT(*)").getInt("value"), + equalTo(expectedCountsByKey.get(key))); + }); } @Test public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedAndEmptyPath() throws Exception { - String query = - String.format( - "SELECT COUNT(*) FROM %s GROUP BY nested(message.info)," - + "filter('myFilter',message.info = 'a'),reverse_nested(someField,'')", - TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT COUNT(*) FROM %s GROUP BY nested(message.info)," + + "filter('myFilter',message.info = 'a'),reverse_nested(someField,'')", + TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.info@NESTED"); @@ -1251,11 +1097,8 @@ public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedAndE public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedNoPath() throws Exception { - String query = - String.format( - "SELECT COUNT(*) FROM %s GROUP BY nested(message.info),filter" - + "('myFilter',message.info = 'a'),reverse_nested(someField)", - TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT COUNT(*) FROM %s GROUP BY nested(message.info),filter" + + "('myFilter',message.info = 'a'),reverse_nested(someField)", TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.info@NESTED"); @@ -1276,12 +1119,9 @@ public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedNoPa public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedOnHistogram() throws Exception { - String query = - String.format( - "SELECT COUNT(*) FROM %s GROUP BY nested(message.info),filter('myFilter',message.info" - + " = 'a'),histogram('field'='myNum','reverse_nested'='','interval'='2', 'alias' =" - + " 'someAlias' )", - TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT COUNT(*) FROM %s GROUP BY nested(message.info)," + + "filter('myFilter',message.info = 'a'),histogram('field'='myNum','reverse_nested'='','interval'='2', " + + "'alias' = 'someAlias' )", TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.info@NESTED"); @@ -1300,26 +1140,21 @@ public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedOnHi expectedCountsByKey.put(2.0, 0); expectedCountsByKey.put(4.0, 1); - someAliasBuckets.forEach( - obj -> { - JSONObject bucket = (JSONObject) obj; - final double key = bucket.getDouble("key"); - Assert.assertTrue(expectedCountsByKey.containsKey(key)); - Assert.assertThat( - bucket.getJSONObject("COUNT(*)").getInt("value"), - equalTo(expectedCountsByKey.get(key))); - }); + someAliasBuckets.forEach(obj -> { + JSONObject bucket = (JSONObject) obj; + final double key = bucket.getDouble("key"); + Assert.assertTrue(expectedCountsByKey.containsKey(key)); + Assert.assertThat(bucket.getJSONObject("COUNT(*)").getInt("value"), + equalTo(expectedCountsByKey.get(key))); + }); } @Test public void reverseToRootGroupByOnNestedFieldWithFilterAndSumOnReverseNestedField() throws Exception { - String query = - String.format( - "SELECT sum(reverse_nested(myNum)) bla FROM %s GROUP BY " - + "nested(message.info),filter('myFilter',message.info = 'a')", - TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT sum(reverse_nested(myNum)) bla FROM %s GROUP BY " + + "nested(message.info),filter('myFilter',message.info = 'a')", TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.info@NESTED"); @@ -1337,11 +1172,9 @@ public void reverseToRootGroupByOnNestedFieldWithFilterAndSumOnReverseNestedFiel public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNestedNoPath() throws Exception { - String query = - String.format( - "SELECT COUNT(*) FROM %s GROUP BY nested(message.info)," - + "filter('myFilter',message.info = 'a'),reverse_nested(comment.data,'~comment')", - TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT COUNT(*) FROM %s GROUP BY nested(message.info)," + + "filter('myFilter',message.info = 'a'),reverse_nested(comment.data,'~comment')", + TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.info@NESTED"); @@ -1351,9 +1184,8 @@ public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNes Assert.assertThat(msgInfoBuckets.length(), equalTo(1)); JSONArray commentDataBuckets = - (JSONArray) - msgInfoBuckets.optQuery( - "/0/comment.data@NESTED_REVERSED" + "/comment.data@NESTED/comment.data/buckets"); + (JSONArray) msgInfoBuckets.optQuery("/0/comment.data@NESTED_REVERSED" + + "/comment.data@NESTED/comment.data/buckets"); Assert.assertNotNull(commentDataBuckets); Assert.assertThat(commentDataBuckets.length(), equalTo(1)); Assert.assertThat(commentDataBuckets.query("/0/key"), equalTo("ab")); @@ -1364,12 +1196,9 @@ public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNes public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNestedOnHistogram() throws Exception { - String query = - String.format( - "SELECT COUNT(*) FROM %s GROUP BY nested(message.info),filter('myFilter',message.info" - + " = 'a'),histogram('field'='comment.likes','reverse_nested'='~comment','interval'='2'" - + " , 'alias' = 'someAlias' )", - TEST_INDEX_NESTED_TYPE); + String query = String.format("SELECT COUNT(*) FROM %s GROUP BY nested(message.info),filter" + + "('myFilter',message.info = 'a'),histogram('field'='comment.likes','reverse_nested'='~comment'," + + "'interval'='2' , 'alias' = 'someAlias' )", TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.info@NESTED"); @@ -1378,10 +1207,8 @@ public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNes Assert.assertNotNull(msgInfoBuckets); Assert.assertThat(msgInfoBuckets.length(), equalTo(1)); - JSONArray someAliasBuckets = - (JSONArray) - msgInfoBuckets.optQuery( - "/0/~comment@NESTED_REVERSED/~comment@NESTED/someAlias/buckets"); + JSONArray someAliasBuckets = (JSONArray) msgInfoBuckets.optQuery( + "/0/~comment@NESTED_REVERSED/~comment@NESTED/someAlias/buckets"); Assert.assertNotNull(msgInfoBuckets); Assert.assertThat(someAliasBuckets.length(), equalTo(2)); @@ -1389,15 +1216,13 @@ public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNes expectedCountsByKey.put(0.0, 1); expectedCountsByKey.put(2.0, 1); - someAliasBuckets.forEach( - obj -> { - JSONObject bucket = (JSONObject) obj; - final double key = bucket.getDouble("key"); - Assert.assertTrue(expectedCountsByKey.containsKey(key)); - Assert.assertThat( - bucket.getJSONObject("COUNT(*)").getInt("value"), - equalTo(expectedCountsByKey.get(key))); - }); + someAliasBuckets.forEach(obj -> { + JSONObject bucket = (JSONObject) obj; + final double key = bucket.getDouble("key"); + Assert.assertTrue(expectedCountsByKey.containsKey(key)); + Assert.assertThat(bucket.getJSONObject("COUNT(*)").getInt("value"), + equalTo(expectedCountsByKey.get(key))); + }); } @Test @@ -1405,9 +1230,8 @@ public void reverseAnotherNestedGroupByOnNestedFieldWithFilterAndSumOnReverseNes throws Exception { String query = - String.format( - "SELECT sum(reverse_nested(comment.likes,'~comment')) bla FROM %s " - + "GROUP BY nested(message.info),filter('myFilter',message.info = 'a')", + String.format("SELECT sum(reverse_nested(comment.likes,'~comment')) bla FROM %s " + + "GROUP BY nested(message.info),filter('myFilter',message.info = 'a')", TEST_INDEX_NESTED_TYPE); JSONObject result = executeQuery(query); JSONObject aggregation = getAggregation(result, "message.info@NESTED"); @@ -1417,11 +1241,10 @@ public void reverseAnotherNestedGroupByOnNestedFieldWithFilterAndSumOnReverseNes Assert.assertNotNull(msgInfoBuckets); Assert.assertThat(msgInfoBuckets.length(), equalTo(1)); - Assert.assertNotNull( - msgInfoBuckets.optQuery("/0/comment.likes@NESTED_REVERSED/comment.likes@NESTED/bla/value")); - JSONObject bla = - (JSONObject) - msgInfoBuckets.query("/0/comment.likes@NESTED_REVERSED/comment.likes@NESTED/bla"); + Assert.assertNotNull(msgInfoBuckets.optQuery( + "/0/comment.likes@NESTED_REVERSED/comment.likes@NESTED/bla/value")); + JSONObject bla = (JSONObject) msgInfoBuckets + .query("/0/comment.likes@NESTED_REVERSED/comment.likes@NESTED/bla"); Assert.assertEquals(4.0, bla.getDouble("value"), 0.000001); } @@ -1434,9 +1257,8 @@ public void docsReturnedTestWithoutDocsHint() throws Exception { @Test public void docsReturnedTestWithDocsHint() throws Exception { - String query = - String.format( - "SELECT /*! DOCS_WITH_AGGREGATION(10) */ count(*) from %s", TEST_INDEX_ACCOUNT); + String query = String.format("SELECT /*! DOCS_WITH_AGGREGATION(10) */ count(*) from %s", + TEST_INDEX_ACCOUNT); JSONObject result = executeQuery(query); Assert.assertThat(getHits(result).length(), equalTo(10)); } @@ -1445,11 +1267,9 @@ public void docsReturnedTestWithDocsHint() throws Exception { @Test public void termsWithScript() throws Exception { String query = - String.format( - "select count(*), avg(all_client) from %s group by terms('alias'='asdf'," - + " substring(field, 0, 1)), date_histogram('alias'='time', 'field'='timestamp', " - + "'interval'='20d ', 'format'='yyyy-MM-dd') limit 1000", - TEST_INDEX_ONLINE); + String.format("select count(*), avg(all_client) from %s group by terms('alias'='asdf'," + + " substring(field, 0, 1)), date_histogram('alias'='time', 'field'='timestamp', " + + "'interval'='20d ', 'format'='yyyy-MM-dd') limit 1000", TEST_INDEX_ONLINE); String result = explainQuery(query); Assert.assertThat(result, containsString("\"script\":{\"source\"")); @@ -1458,10 +1278,9 @@ public void termsWithScript() throws Exception { @Test public void groupByScriptedDateHistogram() throws Exception { - String query = - String.format( - "select count(*), avg(all_client) from %s group by date_histogram('alias'='time'," - + " ceil(all_client), 'fixed_interval'='20d ', 'format'='yyyy-MM-dd') limit 1000", + String query = String + .format("select count(*), avg(all_client) from %s group by date_histogram('alias'='time'," + + " ceil(all_client), 'fixed_interval'='20d ', 'format'='yyyy-MM-dd') limit 1000", TEST_INDEX_ONLINE); String result = explainQuery(query); @@ -1471,10 +1290,9 @@ public void groupByScriptedDateHistogram() throws Exception { @Test public void groupByScriptedHistogram() throws Exception { - String query = - String.format( - "select count(*) from %s group by histogram('alias'='all_field', pow(all_client,1))", - TEST_INDEX_ONLINE); + String query = String.format( + "select count(*) from %s group by histogram('alias'='all_field', pow(all_client,1))", + TEST_INDEX_ONLINE); String result = explainQuery(query); Assert.assertThat(result, containsString("Math.pow(doc['all_client'].value, 1)")); @@ -1485,17 +1303,18 @@ public void groupByScriptedHistogram() throws Exception { public void distinctWithOneField() { Assert.assertEquals( executeQuery("SELECT DISTINCT name.lastname FROM " + TEST_INDEX_GAME_OF_THRONES, "jdbc"), - executeQuery( - "SELECT name.lastname FROM " + TEST_INDEX_GAME_OF_THRONES + " GROUP BY name.lastname", - "jdbc")); + executeQuery("SELECT name.lastname FROM " + TEST_INDEX_GAME_OF_THRONES + + " GROUP BY name.lastname", "jdbc") + ); } @Test public void distinctWithMultipleFields() { Assert.assertEquals( executeQuery("SELECT DISTINCT age, gender FROM " + TEST_INDEX_ACCOUNT, "jdbc"), - executeQuery( - "SELECT age, gender FROM " + TEST_INDEX_ACCOUNT + " GROUP BY age, gender", "jdbc")); + executeQuery("SELECT age, gender FROM " + TEST_INDEX_ACCOUNT + + " GROUP BY age, gender", "jdbc") + ); } private JSONObject getAggregation(final JSONObject queryResult, final String aggregationName) { @@ -1507,27 +1326,26 @@ private JSONObject getAggregation(final JSONObject queryResult, final String agg return aggregations.getJSONObject(aggregationName); } - private int getIntAggregationValue( - final JSONObject queryResult, final String aggregationName, final String fieldName) { + private int getIntAggregationValue(final JSONObject queryResult, final String aggregationName, + final String fieldName) { final JSONObject targetAggregation = getAggregation(queryResult, aggregationName); Assert.assertTrue(targetAggregation.has(fieldName)); return targetAggregation.getInt(fieldName); } - private double getDoubleAggregationValue( - final JSONObject queryResult, final String aggregationName, final String fieldName) { + private double getDoubleAggregationValue(final JSONObject queryResult, + final String aggregationName, + final String fieldName) { final JSONObject targetAggregation = getAggregation(queryResult, aggregationName); Assert.assertTrue(targetAggregation.has(fieldName)); return targetAggregation.getDouble(fieldName); } - private double getDoubleAggregationValue( - final JSONObject queryResult, - final String aggregationName, - final String fieldName, - final String subFieldName) { + private double getDoubleAggregationValue(final JSONObject queryResult, + final String aggregationName, + final String fieldName, final String subFieldName) { final JSONObject targetAggregation = getAggregation(queryResult, aggregationName); Assert.assertTrue(targetAggregation.has(fieldName)); diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/DateFormatIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/DateFormatIT.java index 388d900924..63d37dbad1 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/DateFormatIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/DateFormatIT.java @@ -40,9 +40,9 @@ protected void init() throws Exception { } /** - * All the following tests use UTC as their date_format timezone as this is the same timezone of - * the data being queried. This is to prevent discrepancies in the OpenSearch query and the actual - * field data that is being checked for the integration tests. + * All the following tests use UTC as their date_format timezone as this is the same timezone + * of the data being queried. This is to prevent discrepancies in the OpenSearch query and the + * actual field data that is being checked for the integration tests. * *

Large LIMIT values were given for some of these queries since the default result size of the * query is 200 and this ends up excluding some of the expected values causing the assertion to diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/MetaDataQueriesIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/MetaDataQueriesIT.java index 3accb2bb17..ba4519f607 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/MetaDataQueriesIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/MetaDataQueriesIT.java @@ -26,8 +26,6 @@ import org.opensearch.sql.legacy.utils.StringUtils; /** - * - * *

  * The following are tests for SHOW/DESCRIBE query support under Pretty Format Response protocol using JDBC format.
  * 

diff --git a/integ-test/src/test/java/org/opensearch/sql/legacy/MethodQueryIT.java b/integ-test/src/test/java/org/opensearch/sql/legacy/MethodQueryIT.java index 7589304af0..28c5886d68 100644 --- a/integ-test/src/test/java/org/opensearch/sql/legacy/MethodQueryIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/legacy/MethodQueryIT.java @@ -27,8 +27,6 @@ protected void init() throws Exception { } /** - * - * *

    * query
    * "query" : {
@@ -37,7 +35,6 @@ protected void init() throws Exception {
    *   }
    * }
    * 
- * * @throws IOException */ @Test @@ -53,8 +50,6 @@ public void queryTest() throws IOException { } /** - * - * *
    * matchQuery
    * "query" : {
@@ -66,7 +61,6 @@ public void queryTest() throws IOException {
    *   }
    * }
    * 
- * * @throws IOException */ @Test @@ -83,8 +77,6 @@ public void matchQueryTest() throws IOException { } /** - * - * *
    * matchQuery
    * {
@@ -126,7 +118,6 @@ public void matchQueryTest() throws IOException {
    *   }
    * }
    * 
- * * @throws IOException */ @Test @@ -183,8 +174,6 @@ public void negativeRegexpQueryTest() throws IOException { } /** - * - * *
    * wildcardQuery
    * l*e means leae ltae ...
@@ -194,7 +183,6 @@ public void negativeRegexpQueryTest() throws IOException {
    *   }
    * }
    * 
- * * @throws IOException */ @Test @@ -210,8 +198,6 @@ public void wildcardQueryTest() throws IOException { } /** - * - * *
    * matchPhraseQuery
    * "address" : {
@@ -219,7 +205,6 @@ public void wildcardQueryTest() throws IOException {
    *   "type" : "phrase"
    * }
    * 
- * * @throws IOException */ @Test diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java index a0749387d5..452eb9a822 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/ConvertTZFunctionIT.java @@ -1,26 +1,28 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ + /* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ package org.opensearch.sql.ppl; -import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE; -import static org.opensearch.sql.util.MatcherUtils.rows; -import static org.opensearch.sql.util.MatcherUtils.schema; -import static org.opensearch.sql.util.MatcherUtils.verifySchema; -import static org.opensearch.sql.util.MatcherUtils.verifySome; + import org.json.JSONObject; + import org.junit.Test; -import java.io.IOException; -import org.json.JSONObject; -import org.junit.Test; + import java.io.IOException; -public class ConvertTZFunctionIT extends PPLIntegTestCase { + import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_DATE; + import static org.opensearch.sql.util.MatcherUtils.rows; + import static org.opensearch.sql.util.MatcherUtils.schema; + import static org.opensearch.sql.util.MatcherUtils.verifySchema; + import static org.opensearch.sql.util.MatcherUtils.verifySome; - @Override - public void init() throws IOException { - loadIndex(Index.DATE); - } + public class ConvertTZFunctionIT extends PPLIntegTestCase { + + + @Override + public void init() throws IOException { + loadIndex(Index.DATE); + } @Test public void inRangeZeroToPositive() throws IOException { diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java index 7cc083cbb6..6f6b5cc297 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeComparisonIT.java @@ -98,6 +98,32 @@ public static Iterable compareTwoTimes() { $("TIME('19:16:03') <= TIME('04:12:42')", "lte3", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareTwoDateTimes() { + return Arrays.asList( + $$( + $("DATETIME('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", "eq1", true), + $("DATETIME('2020-09-16 10:20:30') = DATETIME('1961-04-12 09:07:00')", "eq2", false), + $("DATETIME('2020-09-16 10:20:30') != DATETIME('1984-12-15 22:15:07')", "neq1", true), + $("DATETIME('1984-12-15 22:15:08') != DATETIME('1984-12-15 22:15:07')", "neq2", true), + $("DATETIME('1961-04-12 09:07:00') != DATETIME('1961-04-12 09:07:00')", "neq3", false), + $("DATETIME('1984-12-15 22:15:07') > DATETIME('1961-04-12 22:15:07')", "gt1", true), + $("DATETIME('1984-12-15 22:15:07') > DATETIME('1984-12-15 22:15:06')", "gt2", true), + $("DATETIME('1984-12-15 22:15:07') > DATETIME('2020-09-16 10:20:30')", "gt3", false), + $("DATETIME('1961-04-12 09:07:00') < DATETIME('1984-12-15 09:07:00')", "lt1", true), + $("DATETIME('1984-12-15 22:15:07') < DATETIME('1984-12-15 22:15:08')", "lt2", true), + $("DATETIME('1984-12-15 22:15:07') < DATETIME('1961-04-12 09:07:00')", "lt3", false), + $("DATETIME('1984-12-15 22:15:07') >= DATETIME('1961-04-12 09:07:00')", "gte1", true), + $("DATETIME('1984-12-15 22:15:07') >= DATETIME('1984-12-15 22:15:07')", "gte2", true), + $("DATETIME('1984-12-15 22:15:07') >= DATETIME('2020-09-16 10:20:30')", "gte3", false), + $("DATETIME('1961-04-12 09:07:00') <= DATETIME('1984-12-15 22:15:07')", "lte1", true), + $("DATETIME('1961-04-12 09:07:00') <= DATETIME('1961-04-12 09:07:00')", "lte2", true), + $( + "DATETIME('2020-09-16 10:20:30') <= DATETIME('1961-04-12 09:07:00')", + "lte3", + false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareTwoTimestamps() { return Arrays.asList( @@ -135,6 +161,22 @@ public static Iterable compareEqTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('1961-04-12 09:07:00')", + "ts_dt_f", + false), + $( + "DATETIME('1961-04-12 09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 00:00:00') = DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') = TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') = DATE('1961-04-12')", "ts_d_f", false), @@ -145,6 +187,37 @@ public static Iterable compareEqTimestampWithOtherTypes() { $("TIME('09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareEqDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_f", + false), + $( + "TIMESTAMP('1961-04-12 09:07:00') = DATETIME('1984-12-15 22:15:07')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 00:00:00') = DATE('2020-09-16')", "dt_d_t", true), + $("DATE('2020-09-16') = DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 10:20:30') = DATE('1961-04-12')", "dt_d_f", false), + $("DATE('1961-04-12') = DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('" + today + " 10:20:30') = TIME('10:20:30')", "dt_t_t", true), + $("TIME('10:20:30') = DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('2020-09-16 10:20:30') = TIME('09:07:00')", "dt_t_f", false), + $("TIME('09:07:00') = DATETIME('1984-12-15 22:15:07')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareEqDateWithOtherTypes() { var today = LocalDate.now().toString(); @@ -154,6 +227,10 @@ public static Iterable compareEqDateWithOtherTypes() { $("TIMESTAMP('2020-09-16 00:00:00') = DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') = TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('1984-12-15 09:07:00') = DATE('1984-12-15')", "ts_d_f", false), + $("DATE('2020-09-16') = DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') = DATE('2020-09-16')", "dt_d_t", true), + $("DATE('1961-04-12') = DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('1961-04-12 10:20:30') = DATE('1961-04-12')", "dt_d_f", false), $("DATE('" + today + "') = TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') = DATE('" + today + "')", "t_d_t", true), $("DATE('2020-09-16') = TIME('09:07:00')", "d_t_f", false), @@ -165,6 +242,10 @@ public static Iterable compareEqTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('10:20:30') = DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('" + today + " 10:20:30') = TIME('10:20:30')", "dt_t_t", true), + $("TIME('09:07:00') = DATETIME('1961-04-12 09:07:00')", "t_dt_f", false), + $("DATETIME('" + today + " 09:07:00') = TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') = TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('" + today + " 10:20:30') = TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false), @@ -180,6 +261,22 @@ public static Iterable compareNeqTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('1961-04-12 09:07:00')", + "ts_dt_t", + true), + $( + "DATETIME('1961-04-12 09:07:00') != TIMESTAMP('1984-12-15 22:15:07')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('2020-09-16 10:20:30')", + "ts_dt_f", + false), + $( + "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') != DATE('1961-04-12')", "ts_d_t", true), $("DATE('1961-04-12') != TIMESTAMP('1984-12-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 00:00:00') != DATE('2020-09-16')", "ts_d_f", false), @@ -190,6 +287,37 @@ public static Iterable compareNeqTimestampWithOtherTypes() { $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareNeqDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_t", + true), + $( + "TIMESTAMP('1961-04-12 09:07:00') != DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_f", + false), + $( + "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('2020-09-16 10:20:30')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 10:20:30') != DATE('1961-04-12')", "dt_d_t", true), + $("DATE('1961-04-12') != DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') != DATE('2020-09-16')", "dt_d_f", false), + $("DATE('2020-09-16') != DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), + $("DATETIME('2020-09-16 10:20:30') != TIME('09:07:00')", "dt_t_t", true), + $("TIME('09:07:00') != DATETIME('1984-12-15 22:15:07')", "t_dt_t", true), + $("DATETIME('" + today + " 10:20:30') != TIME('10:20:30')", "dt_t_f", false), + $("TIME('10:20:30') != DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareNeqDateWithOtherTypes() { var today = LocalDate.now().toString(); @@ -199,6 +327,10 @@ public static Iterable compareNeqDateWithOtherTypes() { $("TIMESTAMP('1984-12-15 09:07:00') != DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') != TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('2020-09-16 00:00:00') != DATE('2020-09-16')", "ts_d_f", false), + $("DATE('1961-04-12') != DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('1961-04-12 10:20:30') != DATE('1961-04-12')", "dt_d_t", true), + $("DATE('2020-09-16') != DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), + $("DATETIME('2020-09-16 00:00:00') != DATE('2020-09-16')", "dt_d_f", false), $("DATE('2020-09-16') != TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') != DATE('" + today + "')", "t_d_t", true), $("DATE('" + today + "') != TIME('00:00:00')", "d_t_f", false), @@ -210,6 +342,10 @@ public static Iterable compareNeqTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('09:07:00') != DATETIME('1961-04-12 09:07:00')", "t_dt_t", true), + $("DATETIME('" + today + " 09:07:00') != TIME('10:20:30')", "dt_t_t", true), + $("TIME('10:20:30') != DATETIME('" + today + " 10:20:30')", "t_dt_f", false), + $("DATETIME('" + today + " 10:20:30') != TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') != TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') != TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -225,6 +361,22 @@ public static Iterable compareLtTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('2061-04-12 09:07:00')", + "ts_dt_t", + true), + $( + "DATETIME('1961-04-12 09:07:00') < TIMESTAMP('1984-12-15 22:15:07')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('2020-09-16 10:20:30')", + "ts_dt_f", + false), + $( + "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') < DATE('2077-04-12')", "ts_d_t", true), $("DATE('1961-04-12') < TIMESTAMP('1984-12-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') < DATE('1961-04-12')", "ts_d_f", false), @@ -235,6 +387,37 @@ public static Iterable compareLtTimestampWithOtherTypes() { $("TIME('20:50:40') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareLtDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('2077-04-12 09:07:00')", + "dt_ts_t", + true), + $( + "TIMESTAMP('1961-04-12 09:07:00') < DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_f", + false), + $( + "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('1984-12-15 22:15:07')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 10:20:30') < DATE('3077-04-12')", "dt_d_t", true), + $("DATE('1961-04-12') < DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') < DATE('2020-09-16')", "dt_d_f", false), + $("DATE('2020-09-16') < DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), + $("DATETIME('2020-09-16 10:20:30') < TIME('09:07:00')", "dt_t_t", true), + $("TIME('09:07:00') < DATETIME('3077-12-15 22:15:07')", "t_dt_t", true), + $("DATETIME('" + today + " 10:20:30') < TIME('10:20:30')", "dt_t_f", false), + $("TIME('20:40:50') < DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLtDateWithOtherTypes() { return Arrays.asList( @@ -243,6 +426,10 @@ public static Iterable compareLtDateWithOtherTypes() { $("TIMESTAMP('1961-04-12 09:07:00') < DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') < TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('2077-04-12 09:07:00') < DATE('2020-09-16')", "ts_d_f", false), + $("DATE('1961-04-12') < DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('1961-04-12 10:20:30') < DATE('1984-11-15')", "dt_d_t", true), + $("DATE('2020-09-16') < DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), + $("DATETIME('2020-09-16 00:00:00') < DATE('1984-03-22')", "dt_d_f", false), $("DATE('2020-09-16') < TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') < DATE('3077-04-12')", "t_d_t", true), $("DATE('3077-04-12') < TIME('00:00:00')", "d_t_f", false), @@ -254,6 +441,10 @@ public static Iterable compareLtTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('09:07:00') < DATETIME('3077-04-12 09:07:00')", "t_dt_t", true), + $("DATETIME('" + today + " 09:07:00') < TIME('10:20:30')", "dt_t_t", true), + $("TIME('10:20:30') < DATETIME('" + today + " 10:20:30')", "t_dt_f", false), + $("DATETIME('" + today + " 20:40:50') < TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') < TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') < TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -269,6 +460,22 @@ public static Iterable compareGtTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('2020-09-16 10:20:25')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') > TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('2061-04-12 09:07:00')", + "ts_dt_f", + false), + $( + "DATETIME('1961-04-12 09:07:00') > TIMESTAMP('1984-12-15 09:07:00')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') > DATE('1961-04-12')", "ts_d_t", true), $("DATE('2020-09-16') > TIMESTAMP('2020-09-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') > DATE('2077-04-12')", "ts_d_f", false), @@ -279,6 +486,37 @@ public static Iterable compareGtTimestampWithOtherTypes() { $("TIME('09:07:00') > TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareGtDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:31') > TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') > TIMESTAMP('2077-04-12 09:07:00')", + "dt_ts_f", + false), + $( + "TIMESTAMP('1961-04-12 09:07:00') > DATETIME('1961-04-12 09:07:00')", + "ts_dt_f", + false), + $("DATETIME('3077-04-12 10:20:30') > DATE('2020-09-16')", "dt_d_t", true), + $("DATE('2020-09-16') > DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') > DATE('2020-09-16')", "dt_d_f", false), + $("DATE('1961-04-12') > DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('3077-04-12 10:20:30') > TIME('09:07:00')", "dt_t_t", true), + $("TIME('20:40:50') > DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('" + today + " 10:20:30') > TIME('10:20:30')", "dt_t_f", false), + $("TIME('09:07:00') > DATETIME('3077-12-15 22:15:07')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGtDateWithOtherTypes() { return Arrays.asList( @@ -287,6 +525,10 @@ public static Iterable compareGtDateWithOtherTypes() { $("TIMESTAMP('2077-04-12 09:07:00') > DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') > TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('1961-04-12 09:07:00') > DATE('1984-12-15')", "ts_d_f", false), + $("DATE('1984-12-15') > DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') > DATE('1984-03-22')", "dt_d_t", true), + $("DATE('2020-09-16') > DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), + $("DATETIME('1961-04-12 10:20:30') > DATE('1984-11-15')", "dt_d_f", false), $("DATE('3077-04-12') > TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') > DATE('2020-09-16')", "t_d_t", true), $("DATE('2020-09-16') > TIME('09:07:00')", "d_t_f", false), @@ -298,6 +540,10 @@ public static Iterable compareGtTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('09:07:00') > DATETIME('1961-04-12 09:07:00')", "t_dt_t", true), + $("DATETIME('" + today + " 20:40:50') > TIME('10:20:30')", "dt_t_t", true), + $("TIME('10:20:30') > DATETIME('" + today + " 10:20:30')", "t_dt_f", false), + $("DATETIME('" + today + " 09:07:00') > TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') > TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('" + today + " 20:50:42') > TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') > TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -313,6 +559,22 @@ public static Iterable compareLteTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('2020-09-16 10:20:30')", + "ts_dt_t", + true), + $( + "DATETIME('1961-04-12 09:07:00') <= TIMESTAMP('1984-12-15 22:15:07')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('1961-04-12 09:07:00')", + "ts_dt_f", + false), + $( + "DATETIME('2020-09-16 10:20:30') <= TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') <= DATE('2077-04-12')", "ts_d_t", true), $("DATE('2020-09-16') <= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') <= DATE('1961-04-12')", "ts_d_f", false), @@ -323,6 +585,37 @@ public static Iterable compareLteTimestampWithOtherTypes() { $("TIME('20:50:40') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareLteDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') <= TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('1961-04-12 09:07:00') <= DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('3077-09-16 10:20:30') <= TIMESTAMP('2077-04-12 09:07:00')", + "dt_ts_f", + false), + $( + "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('1984-12-15 22:15:07')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 00:00:00') <= DATE('2020-09-16')", "dt_d_t", true), + $("DATE('1961-04-12') <= DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('2020-09-16 10:20:30') <= DATE('1984-04-12')", "dt_d_f", false), + $("DATE('2020-09-16') <= DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), + $("DATETIME('" + today + " 10:20:30') <= TIME('10:20:30')", "dt_t_t", true), + $("TIME('09:07:00') <= DATETIME('3077-12-15 22:15:07')", "t_dt_t", true), + $("DATETIME('3077-09-16 10:20:30') <= TIME('19:07:00')", "dt_t_f", false), + $("TIME('20:40:50') <= DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLteDateWithOtherTypes() { return Arrays.asList( @@ -331,6 +624,10 @@ public static Iterable compareLteDateWithOtherTypes() { $("TIMESTAMP('1961-04-12 09:07:00') <= DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') <= TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('2077-04-12 09:07:00') <= DATE('2020-09-16')", "ts_d_f", false), + $("DATE('2020-09-16') <= DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), + $("DATETIME('1961-04-12 10:20:30') <= DATE('1984-11-15')", "dt_d_t", true), + $("DATE('2077-04-12') <= DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('2020-09-16 00:00:00') <= DATE('1984-03-22')", "dt_d_f", false), $("DATE('2020-09-16') <= TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') <= DATE('3077-04-12')", "t_d_t", true), $("DATE('3077-04-12') <= TIME('00:00:00')", "d_t_f", false), @@ -342,6 +639,10 @@ public static Iterable compareLteTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('10:20:30') <= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('" + today + " 09:07:00') <= TIME('10:20:30')", "dt_t_t", true), + $("TIME('09:07:00') <= DATETIME('1961-04-12 09:07:00')", "t_dt_f", false), + $("DATETIME('" + today + " 20:40:50') <= TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') <= TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') <= TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false), @@ -357,6 +658,22 @@ public static Iterable compareGteTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('2020-09-16 10:20:30')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('2061-04-12 09:07:00')", + "ts_dt_f", + false), + $( + "DATETIME('1961-04-12 09:07:00') >= TIMESTAMP('1984-12-15 09:07:00')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') >= DATE('1961-04-12')", "ts_d_t", true), $("DATE('2020-09-16') >= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') >= DATE('2077-04-12')", "ts_d_f", false), @@ -367,6 +684,37 @@ public static Iterable compareGteTimestampWithOtherTypes() { $("TIME('09:07:00') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareGteDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('2077-04-12 09:07:00')", + "dt_ts_f", + false), + $( + "TIMESTAMP('1961-04-12 00:00:00') >= DATETIME('1961-04-12 09:07:00')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 00:00:00') >= DATE('2020-09-16')", "dt_d_t", true), + $("DATE('2020-09-16') >= DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), + $("DATETIME('1961-04-12 09:07:00') >= DATE('2020-09-16')", "dt_d_f", false), + $("DATE('1961-04-12') >= DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('" + today + " 10:20:30') >= TIME('10:20:30')", "dt_t_t", true), + $("TIME('20:40:50') >= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('1961-04-12 09:07:00') >= TIME('09:07:00')", "dt_t_f", false), + $("TIME('09:07:00') >= DATETIME('3077-12-15 22:15:07')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGteDateWithOtherTypes() { return Arrays.asList( @@ -375,6 +723,10 @@ public static Iterable compareGteDateWithOtherTypes() { $("TIMESTAMP('2077-04-12 09:07:00') >= DATE('2020-09-16')", "ts_d_t", true), $("DATE('1961-04-12') >= TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('1961-04-12 09:07:00') >= DATE('1984-12-15')", "ts_d_f", false), + $("DATE('2020-09-16') >= DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') >= DATE('1984-03-22')", "dt_d_t", true), + $("DATE('1960-12-15') >= DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), + $("DATETIME('1961-04-12 10:20:30') >= DATE('1984-11-15')", "dt_d_f", false), $("DATE('3077-04-12') >= TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') >= DATE('2020-09-16')", "t_d_t", true), $("DATE('2020-09-16') >= TIME('09:07:00')", "d_t_f", false), @@ -386,6 +738,10 @@ public static Iterable compareGteTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('10:20:30') >= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('" + today + " 20:40:50') >= TIME('10:20:30')", "dt_t_t", true), + $("TIME('09:07:00') >= DATETIME('3077-04-12 09:07:00')", "t_dt_f", false), + $("DATETIME('" + today + " 09:07:00') >= TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') >= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('" + today + " 20:50:42') >= TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false), diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java index 3ea6897087..1df87a87b3 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java @@ -67,15 +67,25 @@ public void testAddDateWithDays() throws IOException { + " f = adddate(timestamp('2020-09-16 17:30:00'), 1)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); + result = + executeQuery( + String.format( + "source=%s | eval " + + " f = adddate(DATETIME('2020-09-16 07:40:00'), 1)" + + " | fields f", + TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "datetime")); + verifySome(result.getJSONArray("datarows"), rows("2020-09-17 07:40:00")); + result = executeQuery( String.format( "source=%s | eval " + " f = adddate(TIME('07:40:00'), 0)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(LocalDate.now() + " 07:40:00")); } @@ -88,7 +98,17 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); + verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); + + result = + executeQuery( + String.format( + "source=%s | eval " + + " f = adddate(DATETIME('2020-09-16 17:30:00'), interval 1 day)" + + " | fields f", + TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); result = @@ -98,7 +118,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(date('2020-09-16'), interval 1 day) " + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 00:00:00")); result = @@ -108,7 +128,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(date('2020-09-16'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-16 01:00:00")); result = @@ -118,7 +138,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(TIME('07:40:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -135,7 +155,7 @@ public void testAddDateWithInterval() throws IOException { + " f = adddate(TIME('07:40:00'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -153,7 +173,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2008-05-15 12:00:00','+00:00','+10:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-05-15 22:00:00")); result = @@ -162,7 +182,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 00:00:00','-00:00','+00:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 00:00:00")); result = @@ -171,7 +191,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 00:00:00','+10:00','+11:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 01:00:00")); result = @@ -180,7 +200,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-08:00','+09:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2021-05-13 04:34:50")); result = @@ -189,7 +209,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','+09:00','+09:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 11:34:50")); result = @@ -198,7 +218,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','+12:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2021-05-13 11:34:50")); result = @@ -207,7 +227,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 13:00:00','+09:30','+05:45') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2021-05-12 09:15:00")); result = @@ -216,7 +236,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-30 11:34:50','-17:00','+08:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); result = @@ -225,7 +245,7 @@ public void testConvertTZ() throws IOException { "source=%s | eval f = convert_tz('2021-05-12 11:34:50','-12:00','+15:00') | fields" + " f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -238,7 +258,17 @@ public void testDateAdd() throws IOException { + " f = date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); + verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); + + result = + executeQuery( + String.format( + "source=%s | eval " + + " f = date_add(DATETIME('2020-09-16 17:30:00'), interval 1 day)" + + " | fields f", + TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 17:30:00")); result = @@ -248,7 +278,7 @@ public void testDateAdd() throws IOException { + " f = date_add(date('2020-09-16'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-17 00:00:00")); result = @@ -258,7 +288,7 @@ public void testDateAdd() throws IOException { + " f = date_add(date('2020-09-16'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-16 01:00:00")); result = @@ -268,7 +298,7 @@ public void testDateAdd() throws IOException { + " f = date_add(TIME('07:40:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -285,7 +315,7 @@ public void testDateAdd() throws IOException { + " f = date_add(TIME('07:40:00'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -299,7 +329,7 @@ public void testDateAdd() throws IOException { String.format( "source=%s | eval " + " f = DATE_ADD(birthdate, INTERVAL 1 YEAR)" + " | fields f", TEST_INDEX_BANK)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifyDataRows( result, rows("2018-10-23 00:00:00"), @@ -319,7 +349,7 @@ public void testDateTime() throws IOException { "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-12-24 21:30:00")); result = @@ -327,7 +357,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', '+01:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 06:30:00")); result = @@ -335,7 +365,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00-05:00', '+05:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 15:30:00")); result = @@ -343,7 +373,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2004-02-28 23:00:00-10:00', '+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2004-02-29 19:00:00")); result = @@ -351,7 +381,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2003-02-28 23:00:00-10:00', '+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2003-03-01 19:00:00")); result = @@ -359,7 +389,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', '+14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 19:30:00")); result = @@ -367,7 +397,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00', '-10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2007-12-31 06:00:00")); result = @@ -375,7 +405,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); result = @@ -383,7 +413,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); result = @@ -391,7 +421,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+15:00', '-12:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); result = @@ -399,7 +429,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00', '-14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); result = @@ -407,7 +437,7 @@ public void testDateTime() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00', '-14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -420,7 +450,17 @@ public void testDateSub() throws IOException { + " f = date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); + verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); + + result = + executeQuery( + String.format( + "source=%s | eval " + + " f = date_sub(DATETIME('2020-09-16 17:30:00'), interval 1 day)" + + " | fields f", + TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); result = @@ -430,7 +470,7 @@ public void testDateSub() throws IOException { + " f = date_sub(date('2020-09-16'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 00:00:00")); result = @@ -440,7 +480,7 @@ public void testDateSub() throws IOException { + " f = date_sub(date('2020-09-16'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 23:00:00")); result = @@ -450,7 +490,7 @@ public void testDateSub() throws IOException { + " f = date_sub(TIME('07:40:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -467,7 +507,7 @@ public void testDateSub() throws IOException { + " f = date_sub(TIME('07:40:00'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -1011,7 +1051,7 @@ public void testSubDateDays() throws IOException { + " f = subdate(timestamp('2020-09-16 17:30:00'), 1)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); result = @@ -1027,7 +1067,7 @@ public void testSubDateDays() throws IOException { String.format( "source=%s | eval " + " f = subdate(TIME('07:40:00'), 0)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(LocalDate.now() + " 07:40:00")); } @@ -1040,7 +1080,17 @@ public void testSubDateInterval() throws IOException { + " f = subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); + verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); + + result = + executeQuery( + String.format( + "source=%s | eval " + + " f = subdate(DATETIME('2020-09-16 17:30:00'), interval 1 day)" + + " | fields f", + TEST_INDEX_DATE)); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 17:30:00")); result = @@ -1050,7 +1100,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(date('2020-09-16'), interval 1 day) " + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 00:00:00")); result = @@ -1060,7 +1110,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(date('2020-09-16'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2020-09-15 23:00:00")); result = @@ -1070,7 +1120,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(TIME('07:40:00'), interval 1 day)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -1087,7 +1137,7 @@ public void testSubDateInterval() throws IOException { + " f = subdate(TIME('07:40:00'), interval 1 hour)" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -1266,17 +1316,17 @@ public void testAddTime() throws IOException { + " DATE('2004-01-01')), `'2004-01-01' + '23:59:59'` =" + " ADDTIME(DATE('2004-01-01'), TIME('23:59:59')), `'10:20:30' + '00:05:42'` =" + " ADDTIME(TIME('10:20:30'), TIME('00:05:42')), `'15:42:13' + '09:07:00'` =" - + " ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))" + + " ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00'))" + " | fields `'2008-12-12' + 0`, `'23:59:59' + 0`, `'2004-01-01' + '23:59:59'`," + " `'10:20:30' + '00:05:42'`, `'15:42:13' + '09:07:00'`", TEST_INDEX_DATE)); verifySchema( result, - schema("'2008-12-12' + 0", null, "timestamp"), + schema("'2008-12-12' + 0", null, "datetime"), schema("'23:59:59' + 0", null, "time"), - schema("'2004-01-01' + '23:59:59'", null, "timestamp"), + schema("'2004-01-01' + '23:59:59'", null, "datetime"), schema("'10:20:30' + '00:05:42'", null, "time"), - schema("'15:42:13' + '09:07:00'", null, "timestamp")); + schema("'15:42:13' + '09:07:00'", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -1297,17 +1347,17 @@ public void testSubTime() throws IOException { + " DATE('2004-01-01')), `'2004-01-01' - '23:59:59'` =" + " SUBTIME(DATE('2004-01-01'), TIME('23:59:59')), `'10:20:30' - '00:05:42'` =" + " SUBTIME(TIME('10:20:30'), TIME('00:05:42')), `'15:42:13' - '09:07:00'` =" - + " SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))" + + " SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00'))" + " | fields `'2008-12-12' - 0`, `'23:59:59' - 0`, `'2004-01-01' - '23:59:59'`," + " `'10:20:30' - '00:05:42'`, `'15:42:13' - '09:07:00'`", TEST_INDEX_DATE)); verifySchema( result, - schema("'2008-12-12' - 0", null, "timestamp"), + schema("'2008-12-12' - 0", null, "datetime"), schema("'23:59:59' - 0", null, "time"), - schema("'2004-01-01' - '23:59:59'", null, "timestamp"), + schema("'2004-01-01' - '23:59:59'", null, "datetime"), schema("'10:20:30' - '00:05:42'", null, "time"), - schema("'15:42:13' - '09:07:00'", null, "timestamp")); + schema("'15:42:13' - '09:07:00'", null, "datetime")); verifySome( result.getJSONArray("datarows"), rows( @@ -1328,8 +1378,8 @@ public void testFromUnixTime() throws IOException { TEST_INDEX_DATE)); verifySchema( result, - schema("f1", null, "timestamp"), - schema("f2", null, "timestamp"), + schema("f1", null, "datetime"), + schema("f2", null, "datetime"), schema("f3", null, "string")); verifySome( result.getJSONArray("datarows"), @@ -1377,7 +1427,6 @@ public void testPeriodDiff() throws IOException { verifySome(result.getJSONArray("datarows"), rows(11, -25)); } - @Test public void testDateDiff() throws IOException { var result = executeQuery( @@ -1386,7 +1435,7 @@ public void testDateDiff() throws IOException { + " 00:00:00'), TIMESTAMP('2000-01-01 23:59:59')), `'2001-02-01' -" + " '2004-01-01'` = DATEDIFF(DATE('2001-02-01'), TIMESTAMP('2004-01-01" + " 00:00:00')), `'2004-01-01' - '2002-02-01'` = DATEDIFF(TIMESTAMP('2004-01-01" - + " 00:00:00'), TIMESTAMP('2002-02-01 14:25:30')), `today - today` =" + + " 00:00:00'), DATETIME('2002-02-01 14:25:30')), `today - today` =" + " DATEDIFF(TIME('23:59:59'), TIME('00:00:00')) | fields `'2000-01-02' -" + " '2000-01-01'`, `'2001-02-01' - '2004-01-01'`, `'2004-01-01' -" + " '2002-02-01'`, `today - today`", @@ -1470,7 +1519,7 @@ public void testToSeconds() throws IOException { String.format( "source=%s | eval f1 = to_seconds(date('2008-10-07')) | " + "eval f2 = to_seconds('2020-09-16 07:40:00') | " - + "eval f3 = to_seconds(TIMESTAMP('2020-09-16 07:40:00')) | fields f1, f2, f3", + + "eval f3 = to_seconds(DATETIME('2020-09-16 07:40:00')) | fields f1, f2, f3", TEST_INDEX_DATE)); verifySchema( result, schema("f1", null, "long"), schema("f2", null, "long"), schema("f3", null, "long")); @@ -1484,7 +1533,7 @@ public void testStrToDate() throws IOException { String.format( "source=%s | eval f = str_to_date('01,5,2013', '%s') | fields f", TEST_INDEX_DATE, "%d,%m,%Y")); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2013-05-01 00:00:00")); } @@ -1495,7 +1544,7 @@ public void testTimeStampAdd() throws IOException { String.format( "source=%s | eval f = timestampadd(YEAR, 15, '2001-03-06 00:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2016-03-06 00:00:00")); } @@ -1507,7 +1556,7 @@ public void testTimestampDiff() throws IOException { "source=%s | eval f = timestampdiff(YEAR, '1997-01-01 00:00:00', '2001-03-06" + " 00:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(4)); } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java index f9dc7d8027..fb97da32ab 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeImplementationIT.java @@ -17,11 +17,13 @@ public class DateTimeImplementationIT extends PPLIntegTestCase { + @Override public void init() throws IOException { loadIndex(Index.DATE); } + @Test public void inRangeZeroToStringTZ() throws IOException { JSONObject result = @@ -30,7 +32,7 @@ public void inRangeZeroToStringTZ() throws IOException { "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')" + " | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-12-24 21:30:00")); } @@ -41,7 +43,7 @@ public void inRangeZeroToPositive() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', '+01:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 06:30:00")); } @@ -52,7 +54,7 @@ public void inRangeNegativeToPositive() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00-05:00', '+05:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 15:30:00")); } @@ -63,10 +65,11 @@ public void inRangeTwentyHourOffset() throws IOException { String.format( "source=%s | eval f = DATETIME('2004-02-28 23:00:00-10:00', '+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2004-02-29 19:00:00")); } + @Test public void inRangeYearChange() throws IOException { JSONObject result = @@ -74,7 +77,7 @@ public void inRangeYearChange() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00', '-10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2007-12-31 06:00:00")); } @@ -85,7 +88,7 @@ public void inRangeZeroToMax() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-12-25 05:30:00+00:00', '+14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-12-25 19:30:00")); } @@ -96,7 +99,7 @@ public void inRangeNoToTZ() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); } @@ -107,7 +110,7 @@ public void inRangeNoTZ() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows("2008-01-01 02:00:00")); } @@ -118,7 +121,7 @@ public void nullField3Over() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+15:00', '-12:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -129,7 +132,7 @@ public void nullField2Under() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00+10:00', '-14:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -140,7 +143,7 @@ public void nullTField3Over() throws IOException { String.format( "source=%s | eval f = DATETIME('2008-01-01 02:00:00', '+15:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -151,7 +154,7 @@ public void nullDateTimeInvalidDateValueFebruary() throws IOException { String.format( "source=%s | eval f = DATETIME('2021-02-30 10:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -162,7 +165,7 @@ public void nullDateTimeInvalidDateValueApril() throws IOException { String.format( "source=%s | eval f = DATETIME('2021-04-31 10:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } @@ -173,7 +176,7 @@ public void nullDateTimeInvalidDateValueMonth() throws IOException { String.format( "source=%s | eval f = DATETIME('2021-13-03 10:00:00') | fields f", TEST_INDEX_DATE)); - verifySchema(result, schema("f", null, "timestamp")); + verifySchema(result, schema("f", null, "datetime")); verifySome(result.getJSONArray("datarows"), rows(new Object[] {null})); } } diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/MatchPhrasePrefixIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/MatchPhrasePrefixIT.java index 91ce1bbd10..d6277252a5 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/MatchPhrasePrefixIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/MatchPhrasePrefixIT.java @@ -97,7 +97,8 @@ public void zero_term_query_all() throws IOException { public void slop_is_2() throws IOException { // When slop is 2, the terms are matched exactly in the order specified. // 'open' is used to match prefix of the next term. - String query = "source = %s | where match_phrase_prefix(Tags, 'gas ta', slop=2) | fields Tags"; + String query = + "source = %s | where match_phrase_prefix(Tags, 'gas ta', slop=2) | fields Tags"; JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); verifyDataRows(result, rows("taste gas")); } @@ -105,7 +106,8 @@ public void slop_is_2() throws IOException { @Test public void slop_is_3() throws IOException { // When slop is 3, results will include phrases where the query terms are transposed. - String query = "source = %s | where match_phrase_prefix(Tags, 'gas ta', slop=3) | fields Tags"; + String query = + "source = %s | where match_phrase_prefix(Tags, 'gas ta', slop=3) | fields Tags"; JSONObject result = executeQuery(String.format(query, TEST_INDEX_BEER)); verifyDataRows(result, rows("taste draught gas"), rows("taste gas")); } diff --git a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java index 086f32cba7..19e3debdf0 100644 --- a/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/security/CrossClusterSearchIT.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.sql.security; +package org.opensearch.sql.ppl; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT; import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; @@ -14,30 +14,15 @@ import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import java.io.IOException; -import lombok.SneakyThrows; import org.json.JSONObject; -import org.junit.jupiter.api.BeforeEach; +import org.junit.Rule; import org.junit.jupiter.api.Test; +import org.junit.rules.ExpectedException; import org.opensearch.client.ResponseException; -import org.opensearch.sql.ppl.PPLIntegTestCase; -/** Cross Cluster Search tests to be executed with security plugin. */ public class CrossClusterSearchIT extends PPLIntegTestCase { - static { - // find a remote cluster - String[] clusterNames = System.getProperty("cluster.names").split(","); - var remote = "remoteCluster"; - for (var cluster : clusterNames) { - if (cluster.startsWith("remote")) { - remote = cluster; - break; - } - } - REMOTE_CLUSTER = remote; - } - - public static final String REMOTE_CLUSTER; + @Rule public ExpectedException exceptionRule = ExpectedException.none(); private static final String TEST_INDEX_BANK_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_BANK; private static final String TEST_INDEX_DOG_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_DOG; @@ -45,25 +30,14 @@ public class CrossClusterSearchIT extends PPLIntegTestCase { MATCH_ALL_REMOTE_CLUSTER + ":" + TEST_INDEX_DOG; private static final String TEST_INDEX_ACCOUNT_REMOTE = REMOTE_CLUSTER + ":" + TEST_INDEX_ACCOUNT; - private static boolean initialized = false; - - @SneakyThrows - @BeforeEach - public void initialize() { - if (!initialized) { - setUpIndices(); - initialized = true; - } - } - @Override - protected void init() throws Exception { - configureMultiClusters(REMOTE_CLUSTER); + public void init() throws IOException { + configureMultiClusters(); loadIndex(Index.BANK); loadIndex(Index.BANK, remoteClient()); loadIndex(Index.DOG); loadIndex(Index.DOG, remoteClient()); - loadIndex(Index.ACCOUNT); + loadIndex(Index.ACCOUNT, remoteClient()); } @Test @@ -81,13 +55,11 @@ public void testMatchAllCrossClusterSearchAllFields() throws IOException { @Test public void testCrossClusterSearchWithoutLocalFieldMappingShouldFail() throws IOException { - var exception = - assertThrows( - ResponseException.class, - () -> executeQuery(String.format("search source=%s", TEST_INDEX_ACCOUNT_REMOTE))); - assertTrue( - exception.getMessage().contains("IndexNotFoundException") - && exception.getMessage().contains("400 Bad Request")); + exceptionRule.expect(ResponseException.class); + exceptionRule.expectMessage("400 Bad Request"); + exceptionRule.expectMessage("IndexNotFoundException"); + + executeQuery(String.format("search source=%s", TEST_INDEX_ACCOUNT_REMOTE)); } @Test diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java index 3f71499f97..2f9d19584a 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/AggregationIT.java @@ -37,19 +37,17 @@ protected void init() throws Exception { @Test public void testFilteredAggregatePushDown() throws IOException { - JSONObject response = - executeQuery("SELECT COUNT(*) FILTER(WHERE age > 35) FROM " + TEST_INDEX_BANK); + JSONObject response = executeQuery( + "SELECT COUNT(*) FILTER(WHERE age > 35) FROM " + TEST_INDEX_BANK); verifySchema(response, schema("COUNT(*) FILTER(WHERE age > 35)", null, "integer")); verifyDataRows(response, rows(3)); } @Test public void testFilteredAggregateNotPushDown() throws IOException { - JSONObject response = - executeQuery( - "SELECT COUNT(*) FILTER(WHERE age > 35) FROM (SELECT * FROM " - + TEST_INDEX_BANK - + ") AS a"); + JSONObject response = executeQuery( + "SELECT COUNT(*) FILTER(WHERE age > 35) FROM (SELECT * FROM " + TEST_INDEX_BANK + + ") AS a"); verifySchema(response, schema("COUNT(*) FILTER(WHERE age > 35)", null, "integer")); verifyDataRows(response, rows(3)); } @@ -57,65 +55,45 @@ public void testFilteredAggregateNotPushDown() throws IOException { @Test public void testPushDownAggregationOnNullValues() throws IOException { // OpenSearch aggregation query (MetricAggregation) - var response = - executeQuery( - String.format( - "SELECT min(`int`), max(`int`), avg(`int`), min(`dbl`), max(`dbl`), avg(`dbl`) " - + "FROM %s WHERE `key` = 'null'", - TEST_INDEX_NULL_MISSING)); - verifySchema( - response, - schema("min(`int`)", null, "integer"), - schema("max(`int`)", null, "integer"), - schema("avg(`int`)", null, "double"), - schema("min(`dbl`)", null, "double"), - schema("max(`dbl`)", null, "double"), - schema("avg(`dbl`)", null, "double")); + var response = executeQuery(String.format( + "SELECT min(`int`), max(`int`), avg(`int`), min(`dbl`), max(`dbl`), avg(`dbl`) " + + "FROM %s WHERE `key` = 'null'", TEST_INDEX_NULL_MISSING)); + verifySchema(response, + schema("min(`int`)", null, "integer"), schema("max(`int`)", null, "integer"), + schema("avg(`int`)", null, "double"), schema("min(`dbl`)", null, "double"), + schema("max(`dbl`)", null, "double"), schema("avg(`dbl`)", null, "double")); verifyDataRows(response, rows(null, null, null, null, null, null)); } @Test public void testPushDownAggregationOnMissingValues() throws IOException { // OpenSearch aggregation query (MetricAggregation) - var response = - executeQuery( - String.format( - "SELECT min(`int`), max(`int`), avg(`int`), min(`dbl`), max(`dbl`), avg(`dbl`) " - + "FROM %s WHERE `key` = 'null'", - TEST_INDEX_NULL_MISSING)); - verifySchema( - response, - schema("min(`int`)", null, "integer"), - schema("max(`int`)", null, "integer"), - schema("avg(`int`)", null, "double"), - schema("min(`dbl`)", null, "double"), - schema("max(`dbl`)", null, "double"), - schema("avg(`dbl`)", null, "double")); + var response = executeQuery(String.format( + "SELECT min(`int`), max(`int`), avg(`int`), min(`dbl`), max(`dbl`), avg(`dbl`) " + + "FROM %s WHERE `key` = 'null'", TEST_INDEX_NULL_MISSING)); + verifySchema(response, + schema("min(`int`)", null, "integer"), schema("max(`int`)", null, "integer"), + schema("avg(`int`)", null, "double"), schema("min(`dbl`)", null, "double"), + schema("max(`dbl`)", null, "double"), schema("avg(`dbl`)", null, "double")); verifyDataRows(response, rows(null, null, null, null, null, null)); } @Test public void testInMemoryAggregationOnNullValues() throws IOException { // In-memory aggregation performed by the plugin - var response = - executeQuery( - String.format( - "SELECT" - + " min(`int`) over (PARTITION BY `key`), max(`int`) over (PARTITION BY `key`)," - + " avg(`int`) over (PARTITION BY `key`), min(`dbl`) over (PARTITION BY `key`)," - + " max(`dbl`) over (PARTITION BY `key`), avg(`dbl`) over (PARTITION BY `key`)" - + " FROM %s WHERE `key` = 'null'", - TEST_INDEX_NULL_MISSING)); - verifySchema( - response, + var response = executeQuery(String.format("SELECT" + + " min(`int`) over (PARTITION BY `key`), max(`int`) over (PARTITION BY `key`)," + + " avg(`int`) over (PARTITION BY `key`), min(`dbl`) over (PARTITION BY `key`)," + + " max(`dbl`) over (PARTITION BY `key`), avg(`dbl`) over (PARTITION BY `key`)" + + " FROM %s WHERE `key` = 'null'", TEST_INDEX_NULL_MISSING)); + verifySchema(response, schema("min(`int`) over (PARTITION BY `key`)", null, "integer"), schema("max(`int`) over (PARTITION BY `key`)", null, "integer"), schema("avg(`int`) over (PARTITION BY `key`)", null, "double"), schema("min(`dbl`) over (PARTITION BY `key`)", null, "double"), schema("max(`dbl`) over (PARTITION BY `key`)", null, "double"), schema("avg(`dbl`) over (PARTITION BY `key`)", null, "double")); - verifyDataRows( - response, // 4 rows with null values + verifyDataRows(response, // 4 rows with null values rows(null, null, null, null, null, null), rows(null, null, null, null, null, null), rows(null, null, null, null, null, null), @@ -125,25 +103,19 @@ public void testInMemoryAggregationOnNullValues() throws IOException { @Test public void testInMemoryAggregationOnMissingValues() throws IOException { // In-memory aggregation performed by the plugin - var response = - executeQuery( - String.format( - "SELECT" - + " min(`int`) over (PARTITION BY `key`), max(`int`) over (PARTITION BY `key`)," - + " avg(`int`) over (PARTITION BY `key`), min(`dbl`) over (PARTITION BY `key`)," - + " max(`dbl`) over (PARTITION BY `key`), avg(`dbl`) over (PARTITION BY `key`)" - + " FROM %s WHERE `key` = 'missing'", - TEST_INDEX_NULL_MISSING)); - verifySchema( - response, + var response = executeQuery(String.format("SELECT" + + " min(`int`) over (PARTITION BY `key`), max(`int`) over (PARTITION BY `key`)," + + " avg(`int`) over (PARTITION BY `key`), min(`dbl`) over (PARTITION BY `key`)," + + " max(`dbl`) over (PARTITION BY `key`), avg(`dbl`) over (PARTITION BY `key`)" + + " FROM %s WHERE `key` = 'missing'", TEST_INDEX_NULL_MISSING)); + verifySchema(response, schema("min(`int`) over (PARTITION BY `key`)", null, "integer"), schema("max(`int`) over (PARTITION BY `key`)", null, "integer"), schema("avg(`int`) over (PARTITION BY `key`)", null, "double"), schema("min(`dbl`) over (PARTITION BY `key`)", null, "double"), schema("max(`dbl`) over (PARTITION BY `key`)", null, "double"), schema("avg(`dbl`) over (PARTITION BY `key`)", null, "double")); - verifyDataRows( - response, // 4 rows with null values + verifyDataRows(response, // 4 rows with null values rows(null, null, null, null, null, null), rows(null, null, null, null, null, null), rows(null, null, null, null, null, null), @@ -152,17 +124,12 @@ public void testInMemoryAggregationOnMissingValues() throws IOException { @Test public void testInMemoryAggregationOnNullValuesReturnsNull() throws IOException { - var response = - executeQuery( - String.format( - "SELECT " - + " max(int0) over (PARTITION BY `datetime1`)," - + " min(int0) over (PARTITION BY `datetime1`)," - + " avg(int0) over (PARTITION BY `datetime1`)" - + "from %s where int0 IS NULL;", - TEST_INDEX_CALCS)); - verifySchema( - response, + var response = executeQuery(String.format("SELECT " + + " max(int0) over (PARTITION BY `datetime1`)," + + " min(int0) over (PARTITION BY `datetime1`)," + + " avg(int0) over (PARTITION BY `datetime1`)" + + "from %s where int0 IS NULL;", TEST_INDEX_CALCS)); + verifySchema(response, schema("max(int0) over (PARTITION BY `datetime1`)", null, "integer"), schema("min(int0) over (PARTITION BY `datetime1`)", null, "integer"), schema("avg(int0) over (PARTITION BY `datetime1`)", null, "double")); @@ -171,31 +138,21 @@ public void testInMemoryAggregationOnNullValuesReturnsNull() throws IOException @Test public void testInMemoryAggregationOnAllValuesAndOnNotNullReturnsSameResult() throws IOException { - var responseNotNulls = - executeQuery( - String.format( - "SELECT " - + " max(int0) over (PARTITION BY `datetime1`)," - + " min(int0) over (PARTITION BY `datetime1`)," - + " avg(int0) over (PARTITION BY `datetime1`)" - + "from %s where int0 IS NOT NULL;", - TEST_INDEX_CALCS)); - var responseAllValues = - executeQuery( - String.format( - "SELECT " - + " max(int0) over (PARTITION BY `datetime1`)," - + " min(int0) over (PARTITION BY `datetime1`)," - + " avg(int0) over (PARTITION BY `datetime1`)" - + "from %s;", - TEST_INDEX_CALCS)); - verifySchema( - responseNotNulls, + var responseNotNulls = executeQuery(String.format("SELECT " + + " max(int0) over (PARTITION BY `datetime1`)," + + " min(int0) over (PARTITION BY `datetime1`)," + + " avg(int0) over (PARTITION BY `datetime1`)" + + "from %s where int0 IS NOT NULL;", TEST_INDEX_CALCS)); + var responseAllValues = executeQuery(String.format("SELECT " + + " max(int0) over (PARTITION BY `datetime1`)," + + " min(int0) over (PARTITION BY `datetime1`)," + + " avg(int0) over (PARTITION BY `datetime1`)" + + "from %s;", TEST_INDEX_CALCS)); + verifySchema(responseNotNulls, schema("max(int0) over (PARTITION BY `datetime1`)", null, "integer"), schema("min(int0) over (PARTITION BY `datetime1`)", null, "integer"), schema("avg(int0) over (PARTITION BY `datetime1`)", null, "double")); - verifySchema( - responseAllValues, + verifySchema(responseAllValues, schema("max(int0) over (PARTITION BY `datetime1`)", null, "integer"), schema("min(int0) over (PARTITION BY `datetime1`)", null, "integer"), schema("avg(int0) over (PARTITION BY `datetime1`)", null, "double")); @@ -206,13 +163,9 @@ public void testInMemoryAggregationOnAllValuesAndOnNotNullReturnsSameResult() th @Test public void testPushDownAggregationOnNullNumericValuesReturnsNull() throws IOException { - var response = - executeQuery( - String.format( - "SELECT " + "max(int0), min(int0), avg(int0) from %s where int0 IS NULL;", - TEST_INDEX_CALCS)); - verifySchema( - response, + var response = executeQuery(String.format("SELECT " + + "max(int0), min(int0), avg(int0) from %s where int0 IS NULL;", TEST_INDEX_CALCS)); + verifySchema(response, schema("max(int0)", null, "integer"), schema("min(int0)", null, "integer"), schema("avg(int0)", null, "double")); @@ -221,13 +174,9 @@ public void testPushDownAggregationOnNullNumericValuesReturnsNull() throws IOExc @Test public void testPushDownAggregationOnNullDateTimeValuesFromTableReturnsNull() throws IOException { - var response = - executeQuery( - String.format( - "SELECT " + "max(datetime1), min(datetime1), avg(datetime1) from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, + var response = executeQuery(String.format("SELECT " + + "max(datetime1), min(datetime1), avg(datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, schema("max(datetime1)", null, "timestamp"), schema("min(datetime1)", null, "timestamp"), schema("avg(datetime1)", null, "timestamp")); @@ -236,14 +185,9 @@ public void testPushDownAggregationOnNullDateTimeValuesFromTableReturnsNull() th @Test public void testPushDownAggregationOnNullDateValuesReturnsNull() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(CAST(NULL AS date)), min(CAST(NULL AS date)), avg(CAST(NULL AS date))" - + " from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, + var response = executeQuery(String.format("SELECT " + + "max(CAST(NULL AS date)), min(CAST(NULL AS date)), avg(CAST(NULL AS date)) from %s", TEST_INDEX_CALCS)); + verifySchema(response, schema("max(CAST(NULL AS date))", null, "date"), schema("min(CAST(NULL AS date))", null, "date"), schema("avg(CAST(NULL AS date))", null, "date")); @@ -252,14 +196,9 @@ public void testPushDownAggregationOnNullDateValuesReturnsNull() throws IOExcept @Test public void testPushDownAggregationOnNullTimeValuesReturnsNull() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(CAST(NULL AS time)), min(CAST(NULL AS time)), avg(CAST(NULL AS time))" - + " from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, + var response = executeQuery(String.format("SELECT " + + "max(CAST(NULL AS time)), min(CAST(NULL AS time)), avg(CAST(NULL AS time)) from %s", TEST_INDEX_CALCS)); + verifySchema(response, schema("max(CAST(NULL AS time))", null, "time"), schema("min(CAST(NULL AS time))", null, "time"), schema("avg(CAST(NULL AS time))", null, "time")); @@ -268,14 +207,9 @@ public void testPushDownAggregationOnNullTimeValuesReturnsNull() throws IOExcept @Test public void testPushDownAggregationOnNullTimeStampValuesReturnsNull() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(CAST(NULL AS timestamp)), min(CAST(NULL AS timestamp)), avg(CAST(NULL" - + " AS timestamp)) from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, + var response = executeQuery(String.format("SELECT " + + "max(CAST(NULL AS timestamp)), min(CAST(NULL AS timestamp)), avg(CAST(NULL AS timestamp)) from %s", TEST_INDEX_CALCS)); + verifySchema(response, schema("max(CAST(NULL AS timestamp))", null, "timestamp"), schema("min(CAST(NULL AS timestamp))", null, "timestamp"), schema("avg(CAST(NULL AS timestamp))", null, "timestamp")); @@ -287,35 +221,27 @@ public void testPushDownAggregationOnNullDateTimeValuesReturnsNull() throws IOEx var response = executeQuery( String.format( - "SELECT " - + "max(timestamp(NULL)), min(timestamp(NULL)), avg(timestamp(NULL)) from %s", + "SELECT max(datetime(NULL)), min(datetime(NULL)), avg(datetime(NULL)) from %s", TEST_INDEX_CALCS)); verifySchema( response, - schema("max(timestamp(NULL))", null, "timestamp"), - schema("min(timestamp(NULL))", null, "timestamp"), - schema("avg(timestamp(NULL))", null, "timestamp")); + schema("max(datetime(NULL))", null, "datetime"), + schema("min(datetime(NULL))", null, "datetime"), + schema("avg(datetime(NULL))", null, "datetime")); verifyDataRows(response, rows(null, null, null)); } @Test public void testPushDownAggregationOnAllValuesAndOnNotNullReturnsSameResult() throws IOException { - var responseNotNulls = - executeQuery( - String.format( - "SELECT " + "max(int0), min(int0), avg(int0) from %s where int0 IS NOT NULL;", - TEST_INDEX_CALCS)); - var responseAllValues = - executeQuery( - String.format( - "SELECT " + "max(int0), min(int0), avg(int0) from %s;", TEST_INDEX_CALCS)); - verifySchema( - responseNotNulls, + var responseNotNulls = executeQuery(String.format("SELECT " + + "max(int0), min(int0), avg(int0) from %s where int0 IS NOT NULL;", TEST_INDEX_CALCS)); + var responseAllValues = executeQuery(String.format("SELECT " + + "max(int0), min(int0), avg(int0) from %s;", TEST_INDEX_CALCS)); + verifySchema(responseNotNulls, schema("max(int0)", null, "integer"), schema("min(int0)", null, "integer"), schema("avg(int0)", null, "double")); - verifySchema( - responseAllValues, + verifySchema(responseAllValues, schema("max(int0)", null, "integer"), schema("min(int0)", null, "integer"), schema("avg(int0)", null, "double")); @@ -326,21 +252,18 @@ public void testPushDownAggregationOnAllValuesAndOnNotNullReturnsSameResult() th @Test public void testPushDownAndInMemoryAggregationReturnTheSameResult() throws IOException { - // Playing with 'over (PARTITION BY `datetime1`)' - `datetime1` column has the same value for - // all rows + // Playing with 'over (PARTITION BY `datetime1`)' - `datetime1` column has the same value for all rows // so partitioning by this column has no sense and doesn't (shouldn't) affect the results // Aggregations with `OVER` clause are executed in memory (in SQL plugin memory), // Aggregations without it are performed the OpenSearch node itself (pushed down to opensearch) - // Going to compare results of `min`, `max` and `avg` aggregation on all numeric columns in - // `calcs` + // Going to compare results of `min`, `max` and `avg` aggregation on all numeric columns in `calcs` var columns = List.of("int0", "int1", "int2", "int3", "num0", "num1", "num2", "num3", "num4"); var aggregations = List.of("min", "max", "avg"); var inMemoryAggregQuery = new StringBuilder("SELECT "); var pushDownAggregQuery = new StringBuilder("SELECT "); for (var col : columns) { for (var aggreg : aggregations) { - inMemoryAggregQuery.append( - String.format(" %s(%s) over (PARTITION BY `datetime1`),", aggreg, col)); + inMemoryAggregQuery.append(String.format(" %s(%s) over (PARTITION BY `datetime1`),", aggreg, col)); pushDownAggregQuery.append(String.format(" %s(%s),", aggreg, col)); } } @@ -348,130 +271,132 @@ public void testPushDownAndInMemoryAggregationReturnTheSameResult() throws IOExc inMemoryAggregQuery.deleteCharAt(inMemoryAggregQuery.length() - 1); pushDownAggregQuery.deleteCharAt(pushDownAggregQuery.length() - 1); - var responseInMemory = - executeQuery(inMemoryAggregQuery.append("from " + TEST_INDEX_CALCS).toString()); - var responsePushDown = - executeQuery(pushDownAggregQuery.append("from " + TEST_INDEX_CALCS).toString()); + var responseInMemory = executeQuery( + inMemoryAggregQuery.append("from " + TEST_INDEX_CALCS).toString()); + var responsePushDown = executeQuery( + pushDownAggregQuery.append("from " + TEST_INDEX_CALCS).toString()); for (int i = 0; i < columns.size() * aggregations.size(); i++) { assertEquals( - ((Number) responseInMemory.query("/datarows/0/" + i)).doubleValue(), - ((Number) responsePushDown.query("/datarows/0/" + i)).doubleValue(), + ((Number)responseInMemory.query("/datarows/0/" + i)).doubleValue(), + ((Number)responsePushDown.query("/datarows/0/" + i)).doubleValue(), 0.0000001); // a minor delta is affordable } } public void testMinIntegerPushedDown() throws IOException { - var response = executeQuery(String.format("SELECT min(int2)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT min(int2)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("min(int2)", null, "integer")); verifyDataRows(response, rows(-9)); } @Test public void testMaxIntegerPushedDown() throws IOException { - var response = executeQuery(String.format("SELECT max(int2)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT max(int2)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("max(int2)", null, "integer")); verifyDataRows(response, rows(9)); } @Test public void testAvgIntegerPushedDown() throws IOException { - var response = executeQuery(String.format("SELECT avg(int2)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT avg(int2)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("avg(int2)", null, "double")); verifyDataRows(response, rows(-0.8235294117647058D)); } @Test public void testMinDoublePushedDown() throws IOException { - var response = executeQuery(String.format("SELECT min(num3)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT min(num3)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("min(num3)", null, "double")); verifyDataRows(response, rows(-19.96D)); } @Test public void testMaxDoublePushedDown() throws IOException { - var response = executeQuery(String.format("SELECT max(num3)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT max(num3)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("max(num3)", null, "double")); verifyDataRows(response, rows(12.93D)); } @Test public void testAvgDoublePushedDown() throws IOException { - var response = executeQuery(String.format("SELECT avg(num3)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT avg(num3)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("avg(num3)", null, "double")); verifyDataRows(response, rows(-6.12D)); } @Test public void testMinIntegerInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT min(int2)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("min(int2) OVER(PARTITION BY datetime1)", null, "integer")); + var response = executeQuery(String.format("SELECT min(int2)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("min(int2) OVER(PARTITION BY datetime1)", null, "integer")); verifySome(response.getJSONArray("datarows"), rows(-9)); } @Test public void testMaxIntegerInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(int2)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("max(int2) OVER(PARTITION BY datetime1)", null, "integer")); + var response = executeQuery(String.format("SELECT max(int2)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("max(int2) OVER(PARTITION BY datetime1)", null, "integer")); verifySome(response.getJSONArray("datarows"), rows(9)); } @Test public void testAvgIntegerInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT avg(int2)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("avg(int2) OVER(PARTITION BY datetime1)", null, "double")); + var response = executeQuery(String.format("SELECT avg(int2)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("avg(int2) OVER(PARTITION BY datetime1)", null, "double")); verifySome(response.getJSONArray("datarows"), rows(-0.8235294117647058D)); } @Test public void testMinDoubleInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT min(num3)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("min(num3) OVER(PARTITION BY datetime1)", null, "double")); + var response = executeQuery(String.format("SELECT min(num3)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("min(num3) OVER(PARTITION BY datetime1)", null, "double")); verifySome(response.getJSONArray("datarows"), rows(-19.96D)); } @Test public void testMaxDoubleInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(num3)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("max(num3) OVER(PARTITION BY datetime1)", null, "double")); + var response = executeQuery(String.format("SELECT max(num3)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("max(num3) OVER(PARTITION BY datetime1)", null, "double")); verifySome(response.getJSONArray("datarows"), rows(12.93D)); } @Test public void testAvgDoubleInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT avg(num3)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("avg(num3) OVER(PARTITION BY datetime1)", null, "double")); + var response = executeQuery(String.format("SELECT avg(num3)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("avg(num3) OVER(PARTITION BY datetime1)", null, "double")); verifySome(response.getJSONArray("datarows"), rows(-6.12D)); } @Test public void testMaxDatePushedDown() throws IOException { - var response = executeQuery(String.format("SELECT max(date0)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT max(date0)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("max(date0)", null, "date")); verifyDataRows(response, rows("2004-06-19")); } @Test public void testAvgDatePushedDown() throws IOException { - var response = executeQuery(String.format("SELECT avg(date0)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT avg(date0)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("avg(date0)", null, "date")); verifyDataRows(response, rows("1992-04-23")); } @@ -508,208 +433,157 @@ public void testAvgDateTimePushedDown() throws IOException { @Test public void testMinTimePushedDown() throws IOException { - var response = executeQuery(String.format("SELECT min(time1)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT min(time1)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("min(time1)", null, "time")); verifyDataRows(response, rows("00:05:57")); } @Test public void testMaxTimePushedDown() throws IOException { - var response = executeQuery(String.format("SELECT max(time1)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT max(time1)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("max(time1)", null, "time")); verifyDataRows(response, rows("22:50:16")); } @Test public void testAvgTimePushedDown() throws IOException { - var response = executeQuery(String.format("SELECT avg(time1)" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT avg(time1)" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("avg(time1)", null, "time")); verifyDataRows(response, rows("13:06:36.25")); } @Test public void testMinTimeStampPushedDown() throws IOException { - var response = - executeQuery( - String.format( - "SELECT min(CAST(datetime0 AS timestamp))" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT min(CAST(datetime0 AS timestamp))" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("min(CAST(datetime0 AS timestamp))", null, "timestamp")); verifyDataRows(response, rows("2004-07-04 22:49:28")); } @Test public void testMaxTimeStampPushedDown() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(CAST(datetime0 AS timestamp))" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT max(CAST(datetime0 AS timestamp))" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("max(CAST(datetime0 AS timestamp))", null, "timestamp")); verifyDataRows(response, rows("2004-08-02 07:59:23")); } @Test public void testAvgTimeStampPushedDown() throws IOException { - var response = - executeQuery( - String.format( - "SELECT avg(CAST(datetime0 AS timestamp))" + " from %s", TEST_INDEX_CALCS)); + var response = executeQuery(String.format("SELECT avg(CAST(datetime0 AS timestamp))" + + " from %s", TEST_INDEX_CALCS)); verifySchema(response, schema("avg(CAST(datetime0 AS timestamp))", null, "timestamp")); verifyDataRows(response, rows("2004-07-20 10:38:09.705")); } @Test public void testMinDateInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT min(date0)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("min(date0) OVER(PARTITION BY datetime1)", null, "date")); + var response = executeQuery(String.format("SELECT min(date0)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("min(date0) OVER(PARTITION BY datetime1)", null, "date")); verifySome(response.getJSONArray("datarows"), rows("1972-07-04")); } @Test public void testMaxDateInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(date0)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("max(date0) OVER(PARTITION BY datetime1)", null, "date")); + var response = executeQuery(String.format("SELECT max(date0)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("max(date0) OVER(PARTITION BY datetime1)", null, "date")); verifySome(response.getJSONArray("datarows"), rows("2004-06-19")); } @Test public void testAvgDateInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT avg(date0)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("avg(date0) OVER(PARTITION BY datetime1)", null, "date")); + var response = executeQuery(String.format("SELECT avg(date0)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("avg(date0) OVER(PARTITION BY datetime1)", null, "date")); verifySome(response.getJSONArray("datarows"), rows("1992-04-23")); } @Test public void testMinDateTimeInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT min(timestamp(CAST(time0 AS STRING)))" - + " OVER(PARTITION BY datetime1) from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, - schema( - "min(timestamp(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", - null, - "timestamp")); + var response = executeQuery(String.format("SELECT min(datetime(CAST(time0 AS STRING)))" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("min(datetime(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", null, "datetime")); verifySome(response.getJSONArray("datarows"), rows("1899-12-30 21:07:32")); } @Test public void testMaxDateTimeInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(timestamp(CAST(time0 AS STRING)))" - + " OVER(PARTITION BY datetime1) from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, - schema( - "max(timestamp(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", - null, - "timestamp")); + var response = executeQuery(String.format("SELECT max(datetime(CAST(time0 AS STRING)))" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("max(datetime(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", null, "datetime")); verifySome(response.getJSONArray("datarows"), rows("1900-01-01 20:36:00")); } @Test public void testAvgDateTimeInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT avg(timestamp(CAST(time0 AS STRING)))" - + " OVER(PARTITION BY datetime1) from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, - schema( - "avg(timestamp(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", - null, - "timestamp")); + var response = executeQuery(String.format("SELECT avg(datetime(CAST(time0 AS STRING)))" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("avg(datetime(CAST(time0 AS STRING))) OVER(PARTITION BY datetime1)", null, "datetime")); verifySome(response.getJSONArray("datarows"), rows("1900-01-01 03:35:00.236")); } @Test public void testMinTimeInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT min(time1)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("min(time1) OVER(PARTITION BY datetime1)", null, "time")); + var response = executeQuery(String.format("SELECT min(time1)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("min(time1) OVER(PARTITION BY datetime1)", null, "time")); verifySome(response.getJSONArray("datarows"), rows("00:05:57")); } @Test public void testMaxTimeInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(time1)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("max(time1) OVER(PARTITION BY datetime1)", null, "time")); + var response = executeQuery(String.format("SELECT max(time1)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("max(time1) OVER(PARTITION BY datetime1)", null, "time")); verifySome(response.getJSONArray("datarows"), rows("22:50:16")); } @Test public void testAvgTimeInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT avg(time1)" + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); - verifySchema(response, schema("avg(time1) OVER(PARTITION BY datetime1)", null, "time")); + var response = executeQuery(String.format("SELECT avg(time1)" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("avg(time1) OVER(PARTITION BY datetime1)", null, "time")); verifySome(response.getJSONArray("datarows"), rows("13:06:36.25")); } @Test public void testMinTimeStampInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT min(CAST(datetime0 AS timestamp))" - + " OVER(PARTITION BY datetime1) from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, - schema( - "min(CAST(datetime0 AS timestamp)) OVER(PARTITION BY datetime1)", null, "timestamp")); + var response = executeQuery(String.format("SELECT min(CAST(datetime0 AS timestamp))" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("min(CAST(datetime0 AS timestamp)) OVER(PARTITION BY datetime1)", null, "timestamp")); verifySome(response.getJSONArray("datarows"), rows("2004-07-04 22:49:28")); } @Test public void testMaxTimeStampInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT max(CAST(datetime0 AS timestamp))" - + " OVER(PARTITION BY datetime1) from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, - schema( - "max(CAST(datetime0 AS timestamp)) OVER(PARTITION BY datetime1)", null, "timestamp")); + var response = executeQuery(String.format("SELECT max(CAST(datetime0 AS timestamp))" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("max(CAST(datetime0 AS timestamp)) OVER(PARTITION BY datetime1)", null, "timestamp")); verifySome(response.getJSONArray("datarows"), rows("2004-08-02 07:59:23")); } @Test public void testAvgTimeStampInMemory() throws IOException { - var response = - executeQuery( - String.format( - "SELECT avg(CAST(datetime0 AS timestamp))" - + " OVER(PARTITION BY datetime1) from %s", - TEST_INDEX_CALCS)); - verifySchema( - response, - schema( - "avg(CAST(datetime0 AS timestamp)) OVER(PARTITION BY datetime1)", null, "timestamp")); + var response = executeQuery(String.format("SELECT avg(CAST(datetime0 AS timestamp))" + + " OVER(PARTITION BY datetime1) from %s", TEST_INDEX_CALCS)); + verifySchema(response, + schema("avg(CAST(datetime0 AS timestamp)) OVER(PARTITION BY datetime1)", null, "timestamp")); verifySome(response.getJSONArray("datarows"), rows("2004-07-20 10:38:09.705")); } diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java index af3d81e374..432daef82f 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeComparisonIT.java @@ -105,6 +105,32 @@ public static Iterable compareTwoTimes() { $("TIME('19:16:03') <= TIME('04:12:42')", "lte3", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareTwoDateTimes() { + return Arrays.asList( + $$( + $("DATETIME('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", "eq1", true), + $("DATETIME('2020-09-16 10:20:30') = DATETIME('1961-04-12 09:07:00')", "eq2", false), + $("DATETIME('2020-09-16 10:20:30') != DATETIME('1984-12-15 22:15:07')", "neq1", true), + $("DATETIME('1984-12-15 22:15:08') != DATETIME('1984-12-15 22:15:07')", "neq2", true), + $("DATETIME('1961-04-12 09:07:00') != DATETIME('1961-04-12 09:07:00')", "neq3", false), + $("DATETIME('1984-12-15 22:15:07') > DATETIME('1961-04-12 22:15:07')", "gt1", true), + $("DATETIME('1984-12-15 22:15:07') > DATETIME('1984-12-15 22:15:06')", "gt2", true), + $("DATETIME('1984-12-15 22:15:07') > DATETIME('2020-09-16 10:20:30')", "gt3", false), + $("DATETIME('1961-04-12 09:07:00') < DATETIME('1984-12-15 09:07:00')", "lt1", true), + $("DATETIME('1984-12-15 22:15:07') < DATETIME('1984-12-15 22:15:08')", "lt2", true), + $("DATETIME('1984-12-15 22:15:07') < DATETIME('1961-04-12 09:07:00')", "lt3", false), + $("DATETIME('1984-12-15 22:15:07') >= DATETIME('1961-04-12 09:07:00')", "gte1", true), + $("DATETIME('1984-12-15 22:15:07') >= DATETIME('1984-12-15 22:15:07')", "gte2", true), + $("DATETIME('1984-12-15 22:15:07') >= DATETIME('2020-09-16 10:20:30')", "gte3", false), + $("DATETIME('1961-04-12 09:07:00') <= DATETIME('1984-12-15 22:15:07')", "lte1", true), + $("DATETIME('1961-04-12 09:07:00') <= DATETIME('1961-04-12 09:07:00')", "lte2", true), + $( + "DATETIME('2020-09-16 10:20:30') <= DATETIME('1961-04-12 09:07:00')", + "lte3", + false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareTwoTimestamps() { return Arrays.asList( @@ -142,6 +168,22 @@ public static Iterable compareEqTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('1961-04-12 09:07:00')", + "ts_dt_f", + false), + $( + "DATETIME('1961-04-12 09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 00:00:00') = DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') = TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') = DATE('1961-04-12')", "ts_d_f", false), @@ -152,6 +194,37 @@ public static Iterable compareEqTimestampWithOtherTypes() { $("TIME('09:07:00') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareEqDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') = DATETIME('2020-09-16 10:20:30')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') = TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_f", + false), + $( + "TIMESTAMP('1961-04-12 09:07:00') = DATETIME('1984-12-15 22:15:07')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 00:00:00') = DATE('2020-09-16')", "dt_d_t", true), + $("DATE('2020-09-16') = DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 10:20:30') = DATE('1961-04-12')", "dt_d_f", false), + $("DATE('1961-04-12') = DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('" + today + " 10:20:30') = TIME('10:20:30')", "dt_t_t", true), + $("TIME('10:20:30') = DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('2020-09-16 10:20:30') = TIME('09:07:00')", "dt_t_f", false), + $("TIME('09:07:00') = DATETIME('1984-12-15 22:15:07')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareEqDateWithOtherTypes() { var today = LocalDate.now().toString(); @@ -161,6 +234,10 @@ public static Iterable compareEqDateWithOtherTypes() { $("TIMESTAMP('2020-09-16 00:00:00') = DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') = TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('1984-12-15 09:07:00') = DATE('1984-12-15')", "ts_d_f", false), + $("DATE('2020-09-16') = DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') = DATE('2020-09-16')", "dt_d_t", true), + $("DATE('1961-04-12') = DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('1961-04-12 10:20:30') = DATE('1961-04-12')", "dt_d_f", false), $("DATE('" + today + "') = TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') = DATE('" + today + "')", "t_d_t", true), $("DATE('2020-09-16') = TIME('09:07:00')", "d_t_f", false), @@ -172,6 +249,10 @@ public static Iterable compareEqTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('10:20:30') = DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('" + today + " 10:20:30') = TIME('10:20:30')", "dt_t_t", true), + $("TIME('09:07:00') = DATETIME('1961-04-12 09:07:00')", "t_dt_f", false), + $("DATETIME('" + today + " 09:07:00') = TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') = TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('" + today + " 10:20:30') = TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') = TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false), @@ -187,6 +268,22 @@ public static Iterable compareNeqTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('1961-04-12 09:07:00')", + "ts_dt_t", + true), + $( + "DATETIME('1961-04-12 09:07:00') != TIMESTAMP('1984-12-15 22:15:07')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('2020-09-16 10:20:30')", + "ts_dt_f", + false), + $( + "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') != DATE('1961-04-12')", "ts_d_t", true), $("DATE('1961-04-12') != TIMESTAMP('1984-12-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 00:00:00') != DATE('2020-09-16')", "ts_d_f", false), @@ -197,6 +294,37 @@ public static Iterable compareNeqTimestampWithOtherTypes() { $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareNeqDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_t", + true), + $( + "TIMESTAMP('1961-04-12 09:07:00') != DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') != TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_f", + false), + $( + "TIMESTAMP('2020-09-16 10:20:30') != DATETIME('2020-09-16 10:20:30')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 10:20:30') != DATE('1961-04-12')", "dt_d_t", true), + $("DATE('1961-04-12') != DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') != DATE('2020-09-16')", "dt_d_f", false), + $("DATE('2020-09-16') != DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), + $("DATETIME('2020-09-16 10:20:30') != TIME('09:07:00')", "dt_t_t", true), + $("TIME('09:07:00') != DATETIME('1984-12-15 22:15:07')", "t_dt_t", true), + $("DATETIME('" + today + " 10:20:30') != TIME('10:20:30')", "dt_t_f", false), + $("TIME('10:20:30') != DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareNeqDateWithOtherTypes() { var today = LocalDate.now().toString(); @@ -206,6 +334,10 @@ public static Iterable compareNeqDateWithOtherTypes() { $("TIMESTAMP('1984-12-15 09:07:00') != DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') != TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('2020-09-16 00:00:00') != DATE('2020-09-16')", "ts_d_f", false), + $("DATE('1961-04-12') != DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('1961-04-12 10:20:30') != DATE('1961-04-12')", "dt_d_t", true), + $("DATE('2020-09-16') != DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), + $("DATETIME('2020-09-16 00:00:00') != DATE('2020-09-16')", "dt_d_f", false), $("DATE('2020-09-16') != TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') != DATE('" + today + "')", "t_d_t", true), $("DATE('" + today + "') != TIME('00:00:00')", "d_t_f", false), @@ -217,6 +349,10 @@ public static Iterable compareNeqTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('09:07:00') != DATETIME('1961-04-12 09:07:00')", "t_dt_t", true), + $("DATETIME('" + today + " 09:07:00') != TIME('10:20:30')", "dt_t_t", true), + $("TIME('10:20:30') != DATETIME('" + today + " 10:20:30')", "t_dt_f", false), + $("DATETIME('" + today + " 10:20:30') != TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') != TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') != TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') != TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -232,6 +368,22 @@ public static Iterable compareLtTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('2061-04-12 09:07:00')", + "ts_dt_t", + true), + $( + "DATETIME('1961-04-12 09:07:00') < TIMESTAMP('1984-12-15 22:15:07')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('2020-09-16 10:20:30')", + "ts_dt_f", + false), + $( + "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') < DATE('2077-04-12')", "ts_d_t", true), $("DATE('1961-04-12') < TIMESTAMP('1984-12-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') < DATE('1961-04-12')", "ts_d_f", false), @@ -242,6 +394,37 @@ public static Iterable compareLtTimestampWithOtherTypes() { $("TIME('20:50:40') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareLtDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('2077-04-12 09:07:00')", + "dt_ts_t", + true), + $( + "TIMESTAMP('1961-04-12 09:07:00') < DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') < TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_f", + false), + $( + "TIMESTAMP('2020-09-16 10:20:30') < DATETIME('1984-12-15 22:15:07')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 10:20:30') < DATE('3077-04-12')", "dt_d_t", true), + $("DATE('1961-04-12') < DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') < DATE('2020-09-16')", "dt_d_f", false), + $("DATE('2020-09-16') < DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), + $("DATETIME('2020-09-16 10:20:30') < TIME('09:07:00')", "dt_t_t", true), + $("TIME('09:07:00') < DATETIME('3077-12-15 22:15:07')", "t_dt_t", true), + $("DATETIME('" + today + " 10:20:30') < TIME('10:20:30')", "dt_t_f", false), + $("TIME('20:40:50') < DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLtDateWithOtherTypes() { return Arrays.asList( @@ -250,6 +433,10 @@ public static Iterable compareLtDateWithOtherTypes() { $("TIMESTAMP('1961-04-12 09:07:00') < DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') < TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('2077-04-12 09:07:00') < DATE('2020-09-16')", "ts_d_f", false), + $("DATE('1961-04-12') < DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('1961-04-12 10:20:30') < DATE('1984-11-15')", "dt_d_t", true), + $("DATE('2020-09-16') < DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), + $("DATETIME('2020-09-16 00:00:00') < DATE('1984-03-22')", "dt_d_f", false), $("DATE('2020-09-16') < TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') < DATE('3077-04-12')", "t_d_t", true), $("DATE('3077-04-12') < TIME('00:00:00')", "d_t_f", false), @@ -261,6 +448,10 @@ public static Iterable compareLtTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('09:07:00') < DATETIME('3077-04-12 09:07:00')", "t_dt_t", true), + $("DATETIME('" + today + " 09:07:00') < TIME('10:20:30')", "dt_t_t", true), + $("TIME('10:20:30') < DATETIME('" + today + " 10:20:30')", "t_dt_f", false), + $("DATETIME('" + today + " 20:40:50') < TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') < TIMESTAMP('3077-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') < TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') < TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -276,6 +467,22 @@ public static Iterable compareGtTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('2020-09-16 10:20:25')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') > TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('2061-04-12 09:07:00')", + "ts_dt_f", + false), + $( + "DATETIME('1961-04-12 09:07:00') > TIMESTAMP('1984-12-15 09:07:00')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') > DATE('1961-04-12')", "ts_d_t", true), $("DATE('2020-09-16') > TIMESTAMP('2020-09-15 22:15:07')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') > DATE('2077-04-12')", "ts_d_f", false), @@ -286,6 +493,37 @@ public static Iterable compareGtTimestampWithOtherTypes() { $("TIME('09:07:00') > TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareGtDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:31') > TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') > DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') > TIMESTAMP('2077-04-12 09:07:00')", + "dt_ts_f", + false), + $( + "TIMESTAMP('1961-04-12 09:07:00') > DATETIME('1961-04-12 09:07:00')", + "ts_dt_f", + false), + $("DATETIME('3077-04-12 10:20:30') > DATE('2020-09-16')", "dt_d_t", true), + $("DATE('2020-09-16') > DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') > DATE('2020-09-16')", "dt_d_f", false), + $("DATE('1961-04-12') > DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('3077-04-12 10:20:30') > TIME('09:07:00')", "dt_t_t", true), + $("TIME('20:40:50') > DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('" + today + " 10:20:30') > TIME('10:20:30')", "dt_t_f", false), + $("TIME('09:07:00') > DATETIME('3077-12-15 22:15:07')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGtDateWithOtherTypes() { return Arrays.asList( @@ -294,6 +532,10 @@ public static Iterable compareGtDateWithOtherTypes() { $("TIMESTAMP('2077-04-12 09:07:00') > DATE('2020-09-16')", "ts_d_t", true), $("DATE('2020-09-16') > TIMESTAMP('2020-09-16 00:00:00')", "d_ts_f", false), $("TIMESTAMP('1961-04-12 09:07:00') > DATE('1984-12-15')", "ts_d_f", false), + $("DATE('1984-12-15') > DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') > DATE('1984-03-22')", "dt_d_t", true), + $("DATE('2020-09-16') > DATETIME('2020-09-16 00:00:00')", "d_dt_f", false), + $("DATETIME('1961-04-12 10:20:30') > DATE('1984-11-15')", "dt_d_f", false), $("DATE('3077-04-12') > TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') > DATE('2020-09-16')", "t_d_t", true), $("DATE('2020-09-16') > TIME('09:07:00')", "d_t_f", false), @@ -305,6 +547,10 @@ public static Iterable compareGtTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('09:07:00') > DATETIME('1961-04-12 09:07:00')", "t_dt_t", true), + $("DATETIME('" + today + " 20:40:50') > TIME('10:20:30')", "dt_t_t", true), + $("TIME('10:20:30') > DATETIME('" + today + " 10:20:30')", "t_dt_f", false), + $("DATETIME('" + today + " 09:07:00') > TIME('10:20:30')", "dt_t_f", false), $("TIME('22:15:07') > TIMESTAMP('1984-12-15 22:15:07')", "t_ts_t", true), $("TIMESTAMP('" + today + " 20:50:42') > TIME('10:20:30')", "ts_t_t", true), $("TIME('10:20:30') > TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false), @@ -320,6 +566,22 @@ public static Iterable compareLteTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('2020-09-16 10:20:30')", + "ts_dt_t", + true), + $( + "DATETIME('1961-04-12 09:07:00') <= TIMESTAMP('1984-12-15 22:15:07')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('1961-04-12 09:07:00')", + "ts_dt_f", + false), + $( + "DATETIME('2020-09-16 10:20:30') <= TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') <= DATE('2077-04-12')", "ts_d_t", true), $("DATE('2020-09-16') <= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') <= DATE('1961-04-12')", "ts_d_f", false), @@ -330,6 +592,37 @@ public static Iterable compareLteTimestampWithOtherTypes() { $("TIME('20:50:40') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareLteDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') <= TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('1961-04-12 09:07:00') <= DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('3077-09-16 10:20:30') <= TIMESTAMP('2077-04-12 09:07:00')", + "dt_ts_f", + false), + $( + "TIMESTAMP('2020-09-16 10:20:30') <= DATETIME('1984-12-15 22:15:07')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 00:00:00') <= DATE('2020-09-16')", "dt_d_t", true), + $("DATE('1961-04-12') <= DATETIME('1984-12-15 22:15:07')", "d_dt_t", true), + $("DATETIME('2020-09-16 10:20:30') <= DATE('1984-04-12')", "dt_d_f", false), + $("DATE('2020-09-16') <= DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), + $("DATETIME('" + today + " 10:20:30') <= TIME('10:20:30')", "dt_t_t", true), + $("TIME('09:07:00') <= DATETIME('3077-12-15 22:15:07')", "t_dt_t", true), + $("DATETIME('3077-09-16 10:20:30') <= TIME('19:07:00')", "dt_t_f", false), + $("TIME('20:40:50') <= DATETIME('" + today + " 10:20:30')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareLteDateWithOtherTypes() { return Arrays.asList( @@ -338,6 +631,10 @@ public static Iterable compareLteDateWithOtherTypes() { $("TIMESTAMP('1961-04-12 09:07:00') <= DATE('1984-12-15')", "ts_d_t", true), $("DATE('2020-09-16') <= TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('2077-04-12 09:07:00') <= DATE('2020-09-16')", "ts_d_f", false), + $("DATE('2020-09-16') <= DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), + $("DATETIME('1961-04-12 10:20:30') <= DATE('1984-11-15')", "dt_d_t", true), + $("DATE('2077-04-12') <= DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('2020-09-16 00:00:00') <= DATE('1984-03-22')", "dt_d_f", false), $("DATE('2020-09-16') <= TIME('09:07:00')", "d_t_t", true), $("TIME('09:07:00') <= DATE('3077-04-12')", "t_d_t", true), $("DATE('3077-04-12') <= TIME('00:00:00')", "d_t_f", false), @@ -349,6 +646,10 @@ public static Iterable compareLteTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('10:20:30') <= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('" + today + " 09:07:00') <= TIME('10:20:30')", "dt_t_t", true), + $("TIME('09:07:00') <= DATETIME('1961-04-12 09:07:00')", "t_dt_f", false), + $("DATETIME('" + today + " 20:40:50') <= TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') <= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('1984-12-15 10:20:30') <= TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') <= TIMESTAMP('1984-12-15 22:15:07')", "t_ts_f", false), @@ -364,6 +665,22 @@ public static Iterable compareGteTimestampWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $( + "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('2020-09-16 10:20:30')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('1961-04-12 09:07:00')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('2061-04-12 09:07:00')", + "ts_dt_f", + false), + $( + "DATETIME('1961-04-12 09:07:00') >= TIMESTAMP('1984-12-15 09:07:00')", + "dt_ts_f", + false), $("TIMESTAMP('2020-09-16 10:20:30') >= DATE('1961-04-12')", "ts_d_t", true), $("DATE('2020-09-16') >= TIMESTAMP('2020-09-16 00:00:00')", "d_ts_t", true), $("TIMESTAMP('2020-09-16 10:20:30') >= DATE('2077-04-12')", "ts_d_f", false), @@ -374,6 +691,37 @@ public static Iterable compareGteTimestampWithOtherTypes() { $("TIME('09:07:00') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false))); } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") + public static Iterable compareGteDateTimeWithOtherTypes() { + var today = LocalDate.now().toString(); + return Arrays.asList( + $$( + $( + "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('2020-09-16 10:20:30')", + "dt_ts_t", + true), + $( + "TIMESTAMP('2020-09-16 10:20:30') >= DATETIME('1984-12-15 22:15:07')", + "ts_dt_t", + true), + $( + "DATETIME('2020-09-16 10:20:30') >= TIMESTAMP('2077-04-12 09:07:00')", + "dt_ts_f", + false), + $( + "TIMESTAMP('1961-04-12 00:00:00') >= DATETIME('1961-04-12 09:07:00')", + "ts_dt_f", + false), + $("DATETIME('2020-09-16 00:00:00') >= DATE('2020-09-16')", "dt_d_t", true), + $("DATE('2020-09-16') >= DATETIME('1961-04-12 09:07:00')", "d_dt_t", true), + $("DATETIME('1961-04-12 09:07:00') >= DATE('2020-09-16')", "dt_d_f", false), + $("DATE('1961-04-12') >= DATETIME('1984-12-15 22:15:07')", "d_dt_f", false), + $("DATETIME('" + today + " 10:20:30') >= TIME('10:20:30')", "dt_t_t", true), + $("TIME('20:40:50') >= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('1961-04-12 09:07:00') >= TIME('09:07:00')", "dt_t_f", false), + $("TIME('09:07:00') >= DATETIME('3077-12-15 22:15:07')", "t_dt_f", false))); + } + @ParametersFactory(argumentFormatting = "%1$s => %3$s") public static Iterable compareGteDateWithOtherTypes() { return Arrays.asList( @@ -382,6 +730,10 @@ public static Iterable compareGteDateWithOtherTypes() { $("TIMESTAMP('2077-04-12 09:07:00') >= DATE('2020-09-16')", "ts_d_t", true), $("DATE('1961-04-12') >= TIMESTAMP('1961-04-12 09:07:00')", "d_ts_f", false), $("TIMESTAMP('1961-04-12 09:07:00') >= DATE('1984-12-15')", "ts_d_f", false), + $("DATE('2020-09-16') >= DATETIME('2020-09-16 00:00:00')", "d_dt_t", true), + $("DATETIME('2020-09-16 00:00:00') >= DATE('1984-03-22')", "dt_d_t", true), + $("DATE('1960-12-15') >= DATETIME('1961-04-12 09:07:00')", "d_dt_f", false), + $("DATETIME('1961-04-12 10:20:30') >= DATE('1984-11-15')", "dt_d_f", false), $("DATE('3077-04-12') >= TIME('00:00:00')", "d_t_t", true), $("TIME('00:00:00') >= DATE('2020-09-16')", "t_d_t", true), $("DATE('2020-09-16') >= TIME('09:07:00')", "d_t_f", false), @@ -393,6 +745,10 @@ public static Iterable compareGteTimeWithOtherTypes() { var today = LocalDate.now().toString(); return Arrays.asList( $$( + $("TIME('10:20:30') >= DATETIME('" + today + " 10:20:30')", "t_dt_t", true), + $("DATETIME('" + today + " 20:40:50') >= TIME('10:20:30')", "dt_t_t", true), + $("TIME('09:07:00') >= DATETIME('3077-04-12 09:07:00')", "t_dt_f", false), + $("DATETIME('" + today + " 09:07:00') >= TIME('10:20:30')", "dt_t_f", false), $("TIME('10:20:30') >= TIMESTAMP('" + today + " 10:20:30')", "t_ts_t", true), $("TIMESTAMP('" + today + " 20:50:42') >= TIME('10:20:30')", "ts_t_t", true), $("TIME('22:15:07') >= TIMESTAMP('3077-12-15 22:15:07')", "t_ts_f", false), diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java index 0ec77f9f31..33eb8b693f 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeFunctionIT.java @@ -94,15 +94,15 @@ public void testAddDateWithDays() throws IOException { verifyDataRows(result, rows("2020-09-17")); result = executeQuery("select adddate(timestamp('2020-09-16 17:30:00'), 1)"); - verifySchema(result, schema("adddate(timestamp('2020-09-16 17:30:00'), 1)", null, "timestamp")); + verifySchema(result, schema("adddate(timestamp('2020-09-16 17:30:00'), 1)", null, "datetime")); verifyDataRows(result, rows("2020-09-17 17:30:00")); - result = executeQuery("select adddate(TIMESTAMP('2020-09-16 07:40:00'), 1)"); - verifySchema(result, schema("adddate(TIMESTAMP('2020-09-16 07:40:00'), 1)", null, "timestamp")); + result = executeQuery("select adddate(DATETIME('2020-09-16 07:40:00'), 1)"); + verifySchema(result, schema("adddate(DATETIME('2020-09-16 07:40:00'), 1)", null, "datetime")); verifyDataRows(result, rows("2020-09-17 07:40:00")); result = executeQuery("select adddate(TIME('07:40:00'), 0)"); - verifySchema(result, schema("adddate(TIME('07:40:00'), 0)", null, "timestamp")); + verifySchema(result, schema("adddate(TIME('07:40:00'), 0)", null, "datetime")); verifyDataRows(result, rows(LocalDate.now() + " 07:40:00")); } @@ -112,19 +112,25 @@ public void testAddDateWithInterval() throws IOException { executeQuery("select adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); + schema("adddate(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); + verifyDataRows(result, rows("2020-09-17 17:30:00")); + + result = executeQuery("select adddate(DATETIME('2020-09-16 17:30:00'), interval 1 day)"); + verifySchema( + result, + schema("adddate(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-17 17:30:00")); result = executeQuery("select adddate(date('2020-09-16'), interval 1 day)"); - verifySchema(result, schema("adddate(date('2020-09-16'), interval 1 day)", null, "timestamp")); + verifySchema(result, schema("adddate(date('2020-09-16'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-17 00:00:00")); result = executeQuery("select adddate(date('2020-09-16'), interval 1 hour)"); - verifySchema(result, schema("adddate(date('2020-09-16'), interval 1 hour)", null, "timestamp")); + verifySchema(result, schema("adddate(date('2020-09-16'), interval 1 hour)", null, "datetime")); verifyDataRows(result, rows("2020-09-16 01:00:00")); result = executeQuery("select adddate(TIME('07:40:00'), interval 1 day)"); - verifySchema(result, schema("adddate(TIME('07:40:00'), interval 1 day)", null, "timestamp")); + verifySchema(result, schema("adddate(TIME('07:40:00'), interval 1 day)", null, "datetime")); verifyDataRows( result, rows( @@ -135,7 +141,7 @@ public void testAddDateWithInterval() throws IOException { .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); result = executeQuery("select adddate(TIME('07:40:00'), interval 1 hour)"); - verifySchema(result, schema("adddate(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); + verifySchema(result, schema("adddate(TIME('07:40:00'), interval 1 hour)", null, "datetime")); verifyDataRows( result, rows( @@ -151,26 +157,25 @@ public void testDateAdd() throws IOException { executeQuery("select date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); + schema("date_add(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-17 17:30:00")); - result = executeQuery("select date_add(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)"); + result = executeQuery("select date_add(DATETIME('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("date_add(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); + schema("date_add(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-17 17:30:00")); result = executeQuery("select date_add(date('2020-09-16'), interval 1 day)"); - verifySchema(result, schema("date_add(date('2020-09-16'), interval 1 day)", null, "timestamp")); + verifySchema(result, schema("date_add(date('2020-09-16'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-17 00:00:00")); result = executeQuery("select date_add(date('2020-09-16'), interval 1 hour)"); - verifySchema( - result, schema("date_add(date('2020-09-16'), interval 1 hour)", null, "timestamp")); + verifySchema(result, schema("date_add(date('2020-09-16'), interval 1 hour)", null, "datetime")); verifyDataRows(result, rows("2020-09-16 01:00:00")); result = executeQuery("select date_add(TIME('07:40:00'), interval 1 day)"); - verifySchema(result, schema("date_add(TIME('07:40:00'), interval 1 day)", null, "timestamp")); + verifySchema(result, schema("date_add(TIME('07:40:00'), interval 1 day)", null, "datetime")); verifyDataRows( result, rows( @@ -181,7 +186,7 @@ public void testDateAdd() throws IOException { .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); result = executeQuery("select date_add(TIME('07:40:00'), interval 1 hour)"); - verifySchema(result, schema("date_add(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); + verifySchema(result, schema("date_add(TIME('07:40:00'), interval 1 hour)", null, "datetime")); verifyDataRows( result, rows( @@ -194,7 +199,7 @@ public void testDateAdd() throws IOException { executeQuery( String.format("SELECT DATE_ADD(birthdate, INTERVAL 1 YEAR) FROM %s", TEST_INDEX_BANK)); - verifySchema(result, schema("DATE_ADD(birthdate, INTERVAL 1 YEAR)", null, "timestamp")); + verifySchema(result, schema("DATE_ADD(birthdate, INTERVAL 1 YEAR)", null, "datetime")); verifyDataRows( result, rows("2018-10-23 00:00:00"), @@ -212,26 +217,25 @@ public void testDateSub() throws IOException { executeQuery("select date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); + schema("date_sub(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 17:30:00")); - result = executeQuery("select date_sub(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)"); + result = executeQuery("select date_sub(DATETIME('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("date_sub(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); + schema("date_sub(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 17:30:00")); result = executeQuery("select date_sub(date('2020-09-16'), interval 1 day)"); - verifySchema(result, schema("date_sub(date('2020-09-16'), interval 1 day)", null, "timestamp")); + verifySchema(result, schema("date_sub(date('2020-09-16'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 00:00:00")); result = executeQuery("select date_sub(date('2020-09-16'), interval 1 hour)"); - verifySchema( - result, schema("date_sub(date('2020-09-16'), interval 1 hour)", null, "timestamp")); + verifySchema(result, schema("date_sub(date('2020-09-16'), interval 1 hour)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 23:00:00")); result = executeQuery("select date_sub(TIME('07:40:00'), interval 1 day)"); - verifySchema(result, schema("date_sub(TIME('07:40:00'), interval 1 day)", null, "timestamp")); + verifySchema(result, schema("date_sub(TIME('07:40:00'), interval 1 day)", null, "datetime")); verifyDataRows( result, rows( @@ -242,7 +246,7 @@ public void testDateSub() throws IOException { .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); result = executeQuery("select date_sub(TIME('07:40:00'), interval 1 hour)"); - verifySchema(result, schema("date_sub(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); + verifySchema(result, schema("date_sub(TIME('07:40:00'), interval 1 hour)", null, "datetime")); verifyDataRows( result, rows( @@ -310,11 +314,11 @@ public void testDayOfMonthAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT dayofmonth(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT dayofmonth(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT day_of_month(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT day_of_month(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -367,11 +371,11 @@ public void testDayOfWeekAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT dayofweek(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT dayofweek(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT day_of_week(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT day_of_week(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -405,8 +409,8 @@ public void testDayOfYearWithUnderscores() throws IOException { verifySchema(result, schema("day_of_year(date('2020-09-16'))", null, "integer")); verifyDataRows(result, rows(260)); - result = executeQuery("select day_of_year(timestamp('2020-09-16 00:00:00'))"); - verifySchema(result, schema("day_of_year(timestamp('2020-09-16 00:00:00'))", null, "integer")); + result = executeQuery("select day_of_year(datetime('2020-09-16 00:00:00'))"); + verifySchema(result, schema("day_of_year(datetime('2020-09-16 00:00:00'))", null, "integer")); verifyDataRows(result, rows(260)); result = executeQuery("select day_of_year(timestamp('2020-09-16 00:00:00'))"); @@ -432,11 +436,11 @@ public void testDayOfYearAlternateSyntaxesReturnTheSameResults() throws IOExcept result1 = executeQuery( String.format( - "SELECT dayofyear(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT dayofyear(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT day_of_year(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT day_of_year(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -485,6 +489,10 @@ public void testHourOfDayWithUnderscores() throws IOException { verifySchema(result, schema("hour_of_day(timestamp('2020-09-16 17:30:00'))", null, "integer")); verifyDataRows(result, rows(17)); + result = executeQuery("select hour_of_day(datetime('2020-09-16 17:30:00'))"); + verifySchema(result, schema("hour_of_day(datetime('2020-09-16 17:30:00'))", null, "integer")); + verifyDataRows(result, rows(17)); + result = executeQuery("select hour_of_day(time('17:30:00'))"); verifySchema(result, schema("hour_of_day(time('17:30:00'))", null, "integer")); verifyDataRows(result, rows(17)); @@ -503,7 +511,7 @@ public void testExtractWithDatetime() throws IOException { JSONObject datetimeResult = executeQuery( String.format( - "SELECT extract(DAY_SECOND FROM timestamp(cast(datetime0 AS STRING))) FROM %s LIMIT" + "SELECT extract(DAY_SECOND FROM datetime(cast(datetime0 AS STRING))) FROM %s LIMIT" + " 1", TEST_INDEX_CALCS)); verifyDataRows(datetimeResult, rows(9101735)); @@ -553,11 +561,11 @@ public void testHourFunctionAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT hour(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT hour(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT hour_of_day(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT hour_of_day(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -655,9 +663,8 @@ public void testMinuteOfDay() throws IOException { result, schema("minute_of_day(timestamp('2020-09-16 17:30:00'))", null, "integer")); verifyDataRows(result, rows(1050)); - result = executeQuery("select minute_of_day(timestamp('2020-09-16 17:30:00'))"); - verifySchema( - result, schema("minute_of_day(timestamp('2020-09-16 17:30:00'))", null, "integer")); + result = executeQuery("select minute_of_day(datetime('2020-09-16 17:30:00'))"); + verifySchema(result, schema("minute_of_day(datetime('2020-09-16 17:30:00'))", null, "integer")); verifyDataRows(result, rows(1050)); result = executeQuery("select minute_of_day(time('17:30:00'))"); @@ -703,11 +710,11 @@ public void testMinuteFunctionAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT minute(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT minute(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT minute_of_hour(timestamp(CAST(time0 AS STRING))) FROM %s", + "SELECT minute_of_hour(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); @@ -743,9 +750,8 @@ public void testMonthOfYearTypes() throws IOException { verifySchema(result, schema("month_of_year(date('2020-09-16'))", null, "integer")); verifyDataRows(result, rows(9)); - result = executeQuery("select month_of_year(timestamp('2020-09-16 00:00:00'))"); - verifySchema( - result, schema("month_of_year(timestamp('2020-09-16 00:00:00'))", null, "integer")); + result = executeQuery("select month_of_year(datetime('2020-09-16 00:00:00'))"); + verifySchema(result, schema("month_of_year(datetime('2020-09-16 00:00:00'))", null, "integer")); verifyDataRows(result, rows(9)); result = executeQuery("select month_of_year(timestamp('2020-09-16 00:00:00'))"); @@ -772,12 +778,11 @@ public void testMonthAlternateSyntaxesReturnTheSameResults() throws IOException result1 = executeQuery( String.format( - "SELECT month(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT month(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT month_of_year(timestamp(CAST(time0 AS STRING))) FROM %s", - TEST_INDEX_CALCS)); + "SELECT month_of_year(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); result1 = @@ -871,11 +876,11 @@ public void testSecondFunctionAliasesReturnTheSameResults() throws IOException { result1 = executeQuery( String.format( - "SELECT second(timestamp(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); + "SELECT second(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result2 = executeQuery( String.format( - "SELECT second_of_minute(timestamp(CAST(time0 AS STRING))) FROM %s", + "SELECT second_of_minute(datetime(CAST(time0 AS STRING))) FROM %s", TEST_INDEX_CALCS)); result1.getJSONArray("datarows").similar(result2.getJSONArray("datarows")); @@ -929,15 +934,15 @@ public void testSubDateWithDays() throws IOException { verifyDataRows(result, rows("2020-09-15")); result = executeQuery("select subdate(timestamp('2020-09-16 17:30:00'), 1)"); - verifySchema(result, schema("subdate(timestamp('2020-09-16 17:30:00'), 1)", null, "timestamp")); + verifySchema(result, schema("subdate(timestamp('2020-09-16 17:30:00'), 1)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 17:30:00")); - result = executeQuery("select subdate(TIMESTAMP('2020-09-16 07:40:00'), 1)"); - verifySchema(result, schema("subdate(TIMESTAMP('2020-09-16 07:40:00'), 1)", null, "timestamp")); + result = executeQuery("select subdate(DATETIME('2020-09-16 07:40:00'), 1)"); + verifySchema(result, schema("subdate(DATETIME('2020-09-16 07:40:00'), 1)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 07:40:00")); result = executeQuery("select subdate(TIME('07:40:00'), 0)"); - verifySchema(result, schema("subdate(TIME('07:40:00'), 0)", null, "timestamp")); + verifySchema(result, schema("subdate(TIME('07:40:00'), 0)", null, "datetime")); verifyDataRows(result, rows(LocalDate.now() + " 07:40:00")); } @@ -947,25 +952,25 @@ public void testSubDateWithInterval() throws IOException { executeQuery("select subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); + schema("subdate(timestamp('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 17:30:00")); - result = executeQuery("select subdate(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)"); + result = executeQuery("select subdate(DATETIME('2020-09-16 17:30:00'), interval 1 day)"); verifySchema( result, - schema("subdate(TIMESTAMP('2020-09-16 17:30:00'), interval 1 day)", null, "timestamp")); + schema("subdate(DATETIME('2020-09-16 17:30:00'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 17:30:00")); result = executeQuery("select subdate(date('2020-09-16'), interval 1 day)"); - verifySchema(result, schema("subdate(date('2020-09-16'), interval 1 day)", null, "timestamp")); + verifySchema(result, schema("subdate(date('2020-09-16'), interval 1 day)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 00:00:00")); result = executeQuery("select subdate(date('2020-09-16'), interval 1 hour)"); - verifySchema(result, schema("subdate(date('2020-09-16'), interval 1 hour)", null, "timestamp")); + verifySchema(result, schema("subdate(date('2020-09-16'), interval 1 hour)", null, "datetime")); verifyDataRows(result, rows("2020-09-15 23:00:00")); result = executeQuery("select subdate(TIME('07:40:00'), interval 1 day)"); - verifySchema(result, schema("subdate(TIME('07:40:00'), interval 1 day)", null, "timestamp")); + verifySchema(result, schema("subdate(TIME('07:40:00'), interval 1 day)", null, "datetime")); verifyDataRows( result, rows( @@ -976,7 +981,7 @@ public void testSubDateWithInterval() throws IOException { .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))); result = executeQuery("select subdate(TIME('07:40:00'), interval 1 hour)"); - verifySchema(result, schema("subdate(TIME('07:40:00'), interval 1 hour)", null, "timestamp")); + verifySchema(result, schema("subdate(TIME('07:40:00'), interval 1 hour)", null, "datetime")); verifyDataRows( result, rows( @@ -1040,7 +1045,7 @@ public void testToSeconds() throws IOException { result = executeQuery( String.format( - "SELECT to_seconds(timestamp(cast(datetime0 AS string))) FROM %s LIMIT 2", + "SELECT to_seconds(datetime(cast(datetime0 AS string))) FROM %s LIMIT 2", TEST_INDEX_CALCS)); verifyDataRows(result, rows(63256587455L), rows(63258064234L)); @@ -1137,7 +1142,7 @@ public void testWeekAlternateSyntaxesReturnTheSameResults() throws IOException { result1.getJSONArray("datarows").similar(result3.getJSONArray("datarows")); compareWeekResults("date0", TEST_INDEX_CALCS); - compareWeekResults("timestamp(CAST(time0 AS STRING))", TEST_INDEX_CALCS); + compareWeekResults("datetime(CAST(time0 AS STRING))", TEST_INDEX_CALCS); compareWeekResults("CAST(time0 AS STRING)", TEST_INDEX_CALCS); compareWeekResults("datetime0", TEST_INDEX_CALCS); } @@ -1210,8 +1215,8 @@ public void testFromUnixTime() throws IOException { + "FROM_UNIXTIME(1662601316, '%T') f3"); verifySchema( result, - schema("FROM_UNIXTIME(200300400)", "f1", "timestamp"), - schema("FROM_UNIXTIME(12224.12)", "f2", "timestamp"), + schema("FROM_UNIXTIME(200300400)", "f1", "datetime"), + schema("FROM_UNIXTIME(12224.12)", "f2", "datetime"), schema("FROM_UNIXTIME(1662601316, '%T')", "f3", "keyword")); verifySome( result.getJSONArray("datarows"), @@ -1267,21 +1272,21 @@ public void testAddTime() throws IOException { + " ADDTIME(TIME('23:59:59'), DATE('2004-01-01')) AS `'23:59:59' + 0`," + " ADDTIME(DATE('2004-01-01'), TIME('23:59:59')) AS `'2004-01-01' + '23:59:59'`," + " ADDTIME(TIME('10:20:30'), TIME('00:05:42')) AS `'10:20:30' + '00:05:42'`," - + " ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00')) AS" + + " ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00')) AS" + " `'15:42:13' + '09:07:00'`"); verifySchema( result, - schema("ADDTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' + 0", "timestamp"), + schema("ADDTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' + 0", "datetime"), schema("ADDTIME(TIME('23:59:59'), DATE('2004-01-01'))", "'23:59:59' + 0", "time"), schema( "ADDTIME(DATE('2004-01-01'), TIME('23:59:59'))", "'2004-01-01' + '23:59:59'", - "timestamp"), + "datetime"), schema("ADDTIME(TIME('10:20:30'), TIME('00:05:42'))", "'10:20:30' + '00:05:42'", "time"), schema( - "ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))", + "ADDTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00'))", "'15:42:13' + '09:07:00'", - "timestamp")); + "datetime")); verifyDataRows( result, rows( @@ -1300,21 +1305,21 @@ public void testSubTime() throws IOException { + " SUBTIME(TIME('23:59:59'), DATE('2004-01-01')) AS `'23:59:59' - 0`," + " SUBTIME(DATE('2004-01-01'), TIME('23:59:59')) AS `'2004-01-01' - '23:59:59'`," + " SUBTIME(TIME('10:20:30'), TIME('00:05:42')) AS `'10:20:30' - '00:05:42'`," - + " SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00')) AS" + + " SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00')) AS" + " `'15:42:13' - '09:07:00'`"); verifySchema( result, - schema("SUBTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' - 0", "timestamp"), + schema("SUBTIME(DATE('2008-12-12'), DATE('2008-11-15'))", "'2008-12-12' - 0", "datetime"), schema("SUBTIME(TIME('23:59:59'), DATE('2004-01-01'))", "'23:59:59' - 0", "time"), schema( "SUBTIME(DATE('2004-01-01'), TIME('23:59:59'))", "'2004-01-01' - '23:59:59'", - "timestamp"), + "datetime"), schema("SUBTIME(TIME('10:20:30'), TIME('00:05:42'))", "'10:20:30' - '00:05:42'", "time"), schema( - "SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), TIMESTAMP('1961-04-12 09:07:00'))", + "SUBTIME(TIMESTAMP('1999-12-31 15:42:13'), DATETIME('1961-04-12 09:07:00'))", "'15:42:13' - '09:07:00'", - "timestamp")); + "datetime")); verifyDataRows( result, rows( @@ -1331,7 +1336,7 @@ public void testDateDiff() throws IOException { "SELECT DATEDIFF(TIMESTAMP('2000-01-02 00:00:00'), TIMESTAMP('2000-01-01 23:59:59')) AS" + " `'2000-01-02' - '2000-01-01'`, DATEDIFF(DATE('2001-02-01')," + " TIMESTAMP('2004-01-01 00:00:00')) AS `'2001-02-01' - '2004-01-01'`," - + " DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), TIMESTAMP('2002-02-01 14:25:30')) AS" + + " DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), DATETIME('2002-02-01 14:25:30')) AS" + " `'2004-01-01' - '2002-02-01'`, DATEDIFF(TIME('23:59:59'), TIME('00:00:00')) AS" + " `today - today`"); verifySchema( @@ -1345,7 +1350,7 @@ public void testDateDiff() throws IOException { "'2001-02-01' - '2004-01-01'", "long"), schema( - "DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), TIMESTAMP('2002-02-01 14:25:30'))", + "DATEDIFF(TIMESTAMP('2004-01-01 00:00:00'), DATETIME('2002-02-01 14:25:30'))", "'2004-01-01' - '2002-02-01'", "long"), schema("DATEDIFF(TIME('23:59:59'), TIME('00:00:00'))", "today - today", "long")); @@ -1441,12 +1446,12 @@ public void testDateBracket() throws IOException { verifyDataRows(result, rows("2020-09-16")); } - private void compareBrackets(String query1, String query2, String timestamp) throws IOException { - JSONObject result1 = executeQuery("select " + query1 + " '" + timestamp + "'"); - JSONObject result2 = executeQuery("select {" + query2 + " '" + timestamp + "'}"); + private void compareBrackets(String query1, String query2, String datetime) throws IOException { + JSONObject result1 = executeQuery("select " + query1 + " '" + datetime + "'"); + JSONObject result2 = executeQuery("select {" + query2 + " '" + datetime + "'}"); - verifyDataRows(result1, rows(timestamp)); - verifyDataRows(result2, rows(timestamp)); + verifyDataRows(result1, rows(datetime)); + verifyDataRows(result2, rows(datetime)); } @Test diff --git a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java index 490272d950..750be47de3 100644 --- a/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/sql/DateTimeImplementationIT.java @@ -5,17 +5,18 @@ package org.opensearch.sql.sql; +import org.junit.Test; +import org.opensearch.sql.legacy.SQLIntegTestCase; +import java.io.IOException; + import static org.opensearch.sql.util.MatcherUtils.rows; import static org.opensearch.sql.util.MatcherUtils.schema; import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; import static org.opensearch.sql.util.MatcherUtils.verifySchema; -import java.io.IOException; -import org.junit.Test; -import org.opensearch.sql.legacy.SQLIntegTestCase; - public class DateTimeImplementationIT extends SQLIntegTestCase { + @Override public void init() throws Exception { super.init(); @@ -28,7 +29,7 @@ public void inRangeZeroToStringTZ() throws IOException { executeJdbcRequest("SELECT DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')"); verifySchema( result, - schema("DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')", null, "timestamp")); + schema("DATETIME('2008-12-25 05:30:00+00:00', 'America/Los_Angeles')", null, "datetime")); verifyDataRows(result, rows("2008-12-24 21:30:00")); } @@ -36,7 +37,7 @@ public void inRangeZeroToStringTZ() throws IOException { public void inRangeZeroToPositive() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-12-25 05:30:00+00:00', '+01:00')"); verifySchema( - result, schema("DATETIME('2008-12-25 05:30:00+00:00', '+01:00')", null, "timestamp")); + result, schema("DATETIME('2008-12-25 05:30:00+00:00', '+01:00')", null, "datetime")); verifyDataRows(result, rows("2008-12-25 06:30:00")); } @@ -44,7 +45,7 @@ public void inRangeZeroToPositive() throws IOException { public void inRangeNegativeToPositive() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-12-25 05:30:00-05:00', '+05:00')"); verifySchema( - result, schema("DATETIME('2008-12-25 05:30:00-05:00', '+05:00')", null, "timestamp")); + result, schema("DATETIME('2008-12-25 05:30:00-05:00', '+05:00')", null, "datetime")); verifyDataRows(result, rows("2008-12-25 15:30:00")); } @@ -52,7 +53,7 @@ public void inRangeNegativeToPositive() throws IOException { public void inRangeTwentyHourOffset() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2004-02-28 23:00:00-10:00', '+10:00')"); verifySchema( - result, schema("DATETIME('2004-02-28 23:00:00-10:00', '+10:00')", null, "timestamp")); + result, schema("DATETIME('2004-02-28 23:00:00-10:00', '+10:00')", null, "datetime")); verifyDataRows(result, rows("2004-02-29 19:00:00")); } @@ -60,21 +61,21 @@ public void inRangeTwentyHourOffset() throws IOException { public void inRangeYearChange() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+10:00', '-10:00')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-10:00')", null, "timestamp")); + result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-10:00')", null, "datetime")); verifyDataRows(result, rows("2007-12-31 06:00:00")); } @Test public void inRangeZeroNoToTZ() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+10:00')"); - verifySchema(result, schema("DATETIME('2008-01-01 02:00:00+10:00')", null, "timestamp")); + verifySchema(result, schema("DATETIME('2008-01-01 02:00:00+10:00')", null, "datetime")); verifyDataRows(result, rows("2008-01-01 02:00:00")); } @Test public void inRangeZeroNoTZ() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00')"); - verifySchema(result, schema("DATETIME('2008-01-01 02:00:00')", null, "timestamp")); + verifySchema(result, schema("DATETIME('2008-01-01 02:00:00')", null, "datetime")); verifyDataRows(result, rows("2008-01-01 02:00:00")); } @@ -82,7 +83,7 @@ public void inRangeZeroNoTZ() throws IOException { public void inRangeZeroDayConvert() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+12:00', '-12:00')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+12:00', '-12:00')", null, "timestamp")); + result, schema("DATETIME('2008-01-01 02:00:00+12:00', '-12:00')", null, "datetime")); verifyDataRows(result, rows("2007-12-31 02:00:00")); } @@ -90,7 +91,7 @@ public void inRangeZeroDayConvert() throws IOException { public void inRangeJustInRangeNegative() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+10:00', '-13:59')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-13:59')", null, "timestamp")); + result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-13:59')", null, "datetime")); verifyDataRows(result, rows("2007-12-31 02:01:00")); } @@ -98,7 +99,7 @@ public void inRangeJustInRangeNegative() throws IOException { public void inRangeJustInRangePositive() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+14:00', '-10:00')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+14:00', '-10:00')", null, "timestamp")); + result, schema("DATETIME('2008-01-01 02:00:00+14:00', '-10:00')", null, "datetime")); verifyDataRows(result, rows("2007-12-31 02:00:00")); } @@ -106,7 +107,7 @@ public void inRangeJustInRangePositive() throws IOException { public void nullField3Under() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+10:00', '-14:01')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-14:01')", null, "timestamp")); + result, schema("DATETIME('2008-01-01 02:00:00+10:00', '-14:01')", null, "datetime")); verifyDataRows(result, rows(new Object[] {null})); } @@ -114,28 +115,30 @@ public void nullField3Under() throws IOException { public void nullField1Over() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2008-01-01 02:00:00+14:01', '-10:00')"); verifySchema( - result, schema("DATETIME('2008-01-01 02:00:00+14:01', '-10:00')", null, "timestamp")); + result, schema("DATETIME('2008-01-01 02:00:00+14:01', '-10:00')", null, "datetime")); verifyDataRows(result, rows(new Object[] {null})); } @Test public void nullDateTimeInvalidDateValueFebruary() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2021-02-30 10:00:00')"); - verifySchema(result, schema("DATETIME('2021-02-30 10:00:00')", null, "timestamp")); + verifySchema(result, schema("DATETIME('2021-02-30 10:00:00')", null, "datetime")); verifyDataRows(result, rows(new Object[] {null})); } @Test public void nullDateTimeInvalidDateValueApril() throws IOException { var result = executeJdbcRequest("SELECT DATETIME('2021-04-31 10:00:00')"); - verifySchema(result, schema("DATETIME('2021-04-31 10:00:00')", null, "timestamp")); + verifySchema(result, schema("DATETIME('2021-04-31 10:00:00')", null, "datetime")); verifyDataRows(result, rows(new Object[] {null})); } @Test public void nullDateTimeInvalidDateValueMonth() throws IOException { - var result = executeJdbcRequest("SELECT DATETIME('2021-13-03 10:00:00')"); - verifySchema(result, schema("DATETIME('2021-13-03 10:00:00')", null, "timestamp")); - verifyDataRows(result, rows(new Object[] {null})); + var result = executeJdbcRequest( + "SELECT DATETIME('2021-13-03 10:00:00')"); + verifySchema(result, + schema("DATETIME('2021-13-03 10:00:00')", null, "datetime")); + verifyDataRows(result, rows(new Object[]{null})); } }