From a632e4a67018b8258c09a876a38646990b91c419 Mon Sep 17 00:00:00 2001 From: Mark Tozzi Date: Wed, 14 Aug 2024 12:20:48 -0400 Subject: [PATCH 1/6] equals --- .../predicate/operator/comparison/Equals.java | 1 + .../operator/comparison/EqualsTests.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/Equals.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/Equals.java index 32e15deb07b4e..614d9aa3ec920 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/Equals.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/Equals.java @@ -35,6 +35,7 @@ public class Equals extends EsqlBinaryComparison implements Negatable parameters() { ) ); // Datetime - // TODO: I'm surprised this passes. Shouldn't there be a cast from DateTime to Long? suppliers.addAll( TestCaseSupplier.forBinaryNotCasting( "EqualsLongsEvaluator", @@ -131,6 +130,20 @@ public static Iterable parameters() { ) ); + suppliers.addAll( + TestCaseSupplier.forBinaryNotCasting( + "EqualsLongsEvaluator", + "lhs", + "rhs", + Object::equals, + DataType.BOOLEAN, + TestCaseSupplier.dateNanosCases(), + TestCaseSupplier.dateNanosCases(), + List.of(), + false + ) + ); + suppliers.addAll( TestCaseSupplier.stringCases( Object::equals, @@ -204,7 +217,7 @@ public static Iterable parameters() { } private static String typeErrorString = - "boolean, cartesian_point, cartesian_shape, datetime, double, geo_point, geo_shape, integer, ip, keyword, long, text, " + "boolean, cartesian_point, cartesian_shape, datetime, date_nanos, double, geo_point, geo_shape, integer, ip, keyword, long, text, " + "unsigned_long or version"; @Override From 44fc544e44e3ffafb75ed0bd0f9fb46f016b1859 Mon Sep 17 00:00:00 2001 From: Mark Tozzi Date: Wed, 14 Aug 2024 12:55:53 -0400 Subject: [PATCH 2/6] not equals --- .../operator/comparison/NotEquals.java | 1 + .../operator/comparison/NotEqualsTests.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/NotEquals.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/NotEquals.java index d61953587f79b..abca00212b848 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/NotEquals.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/NotEquals.java @@ -35,6 +35,7 @@ public class NotEquals extends EsqlBinaryComparison implements Negatable parameters() { ) ); // Datetime - // TODO: I'm surprised this passes. Shouldn't there be a cast from DateTime to Long? suppliers.addAll( TestCaseSupplier.forBinaryNotCasting( "NotEqualsLongsEvaluator", @@ -129,6 +128,20 @@ public static Iterable parameters() { false ) ); + // Datetime + suppliers.addAll( + TestCaseSupplier.forBinaryNotCasting( + "NotEqualsLongsEvaluator", + "lhs", + "rhs", + (l, r) -> false == l.equals(r), + DataType.BOOLEAN, + TestCaseSupplier.dateNanosCases(), + TestCaseSupplier.dateNanosCases(), + List.of(), + false + ) + ); suppliers.addAll( TestCaseSupplier.stringCases( (l, r) -> false == l.equals(r), @@ -198,7 +211,7 @@ public static Iterable parameters() { } private static String typeErrorString = - "boolean, cartesian_point, cartesian_shape, datetime, double, geo_point, geo_shape, integer, ip, keyword, long, text, " + "boolean, cartesian_point, cartesian_shape, datetime, date_nanos, double, geo_point, geo_shape, integer, ip, keyword, long, text, " + "unsigned_long or version"; @Override From 3ae2f5a4f49e2bbea911d5907bbcf8499f319014 Mon Sep 17 00:00:00 2001 From: Mark Tozzi Date: Wed, 14 Aug 2024 13:31:32 -0400 Subject: [PATCH 3/6] greater than --- .../operator/comparison/GreaterThan.java | 1 + .../operator/comparison/GreaterThanTests.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThan.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThan.java index 33981a3337737..6aef5c76f7385 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThan.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThan.java @@ -34,6 +34,7 @@ public class GreaterThan extends EsqlBinaryComparison implements Negatable parameters() { ) ); // Datetime - // TODO: I'm surprised this passes. Shouldn't there be a cast from DateTime to Long? suppliers.addAll( TestCaseSupplier.forBinaryNotCasting( "GreaterThanLongsEvaluator", @@ -121,6 +120,20 @@ public static Iterable parameters() { ) ); + suppliers.addAll( + TestCaseSupplier.forBinaryNotCasting( + "GreaterThanLongsEvaluator", + "lhs", + "rhs", + (l, r) -> ((Number) l).longValue() > ((Number) r).longValue(), + DataType.BOOLEAN, + TestCaseSupplier.dateNanosCases(), + TestCaseSupplier.dateNanosCases(), + List.of(), + false + ) + ); + suppliers.addAll( TestCaseSupplier.stringCases( (l, r) -> ((BytesRef) l).compareTo((BytesRef) r) > 0, @@ -137,7 +150,7 @@ public static Iterable parameters() { o, v, t, - (l, p) -> "datetime, double, integer, ip, keyword, long, text, unsigned_long or version" + (l, p) -> "date_nanos, datetime, double, integer, ip, keyword, long, text, unsigned_long or version" ) ) ); From e302a8f4f87094eb66df5e0aa858f16deb92a807 Mon Sep 17 00:00:00 2001 From: Mark Tozzi Date: Wed, 14 Aug 2024 14:08:23 -0400 Subject: [PATCH 4/6] gte --- .../operator/comparison/GreaterThanOrEqual.java | 1 + .../comparison/GreaterThanOrEqualTests.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThanOrEqual.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThanOrEqual.java index ffcd99558c6ad..1b1d301428d73 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThanOrEqual.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThanOrEqual.java @@ -34,6 +34,7 @@ public class GreaterThanOrEqual extends EsqlBinaryComparison implements Negatabl Map.entry(DataType.LONG, GreaterThanOrEqualLongsEvaluator.Factory::new), Map.entry(DataType.UNSIGNED_LONG, GreaterThanOrEqualLongsEvaluator.Factory::new), Map.entry(DataType.DATETIME, GreaterThanOrEqualLongsEvaluator.Factory::new), + Map.entry(DataType.DATE_NANOS, GreaterThanOrEqualLongsEvaluator.Factory::new), Map.entry(DataType.KEYWORD, GreaterThanOrEqualKeywordsEvaluator.Factory::new), Map.entry(DataType.TEXT, GreaterThanOrEqualKeywordsEvaluator.Factory::new), Map.entry(DataType.VERSION, GreaterThanOrEqualKeywordsEvaluator.Factory::new), diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThanOrEqualTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThanOrEqualTests.java index 5435a7f629d43..a4d1bf69796e0 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThanOrEqualTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/GreaterThanOrEqualTests.java @@ -106,7 +106,6 @@ public static Iterable parameters() { ) ); // Datetime - // TODO: I'm surprised this passes. Shouldn't there be a cast from DateTime to Long? suppliers.addAll( TestCaseSupplier.forBinaryNotCasting( "GreaterThanOrEqualLongsEvaluator", @@ -121,6 +120,20 @@ public static Iterable parameters() { ) ); + suppliers.addAll( + TestCaseSupplier.forBinaryNotCasting( + "GreaterThanOrEqualLongsEvaluator", + "lhs", + "rhs", + (l, r) -> ((Number) l).longValue() >= ((Number) r).longValue(), + DataType.BOOLEAN, + TestCaseSupplier.dateNanosCases(), + TestCaseSupplier.dateNanosCases(), + List.of(), + false + ) + ); + suppliers.addAll( TestCaseSupplier.stringCases( (l, r) -> ((BytesRef) l).compareTo((BytesRef) r) >= 0, @@ -137,7 +150,7 @@ public static Iterable parameters() { o, v, t, - (l, p) -> "datetime, double, integer, ip, keyword, long, text, unsigned_long or version" + (l, p) -> "date_nanos, datetime, double, integer, ip, keyword, long, text, unsigned_long or version" ) ) ); From 2cfd3aa9756a84114cc573f37ce35111152bbf9b Mon Sep 17 00:00:00 2001 From: Mark Tozzi Date: Wed, 14 Aug 2024 14:12:06 -0400 Subject: [PATCH 5/6] less than --- .../predicate/operator/comparison/LessThan.java | 1 + .../operator/comparison/LessThanTests.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/LessThan.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/LessThan.java index a9a1f774f4ebb..333b18e21ab1b 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/LessThan.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/LessThan.java @@ -34,6 +34,7 @@ public class LessThan extends EsqlBinaryComparison implements Negatable parameters() { ) ); // Datetime - // TODO: I'm surprised this passes. Shouldn't there be a cast from DateTime to Long? + suppliers.addAll( + TestCaseSupplier.forBinaryNotCasting( + "LessThanLongsEvaluator", + "lhs", + "rhs", + (l, r) -> ((Number) l).longValue() < ((Number) r).longValue(), + DataType.BOOLEAN, + TestCaseSupplier.dateCases(), + TestCaseSupplier.dateCases(), + List.of(), + false + ) + ); + suppliers.addAll( TestCaseSupplier.forBinaryNotCasting( "LessThanLongsEvaluator", @@ -137,7 +150,7 @@ public static Iterable parameters() { o, v, t, - (l, p) -> "datetime, double, integer, ip, keyword, long, text, unsigned_long or version" + (l, p) -> "date_nanos, datetime, double, integer, ip, keyword, long, text, unsigned_long or version" ) ) ); From 5ba193513a61a7edcd89f87fdaa850ddc0e144cc Mon Sep 17 00:00:00 2001 From: Mark Tozzi Date: Wed, 14 Aug 2024 14:27:35 -0400 Subject: [PATCH 6/6] lte --- .../operator/comparison/LessThanOrEqual.java | 1 + .../comparison/LessThanOrEqualTests.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/LessThanOrEqual.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/LessThanOrEqual.java index 5623750ea0f91..94c3911a02f64 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/LessThanOrEqual.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/comparison/LessThanOrEqual.java @@ -34,6 +34,7 @@ public class LessThanOrEqual extends EsqlBinaryComparison implements Negatable parameters() { ) ); // Datetime - // TODO: I'm surprised this passes. Shouldn't there be a cast from DateTime to Long? suppliers.addAll( TestCaseSupplier.forBinaryNotCasting( "LessThanOrEqualLongsEvaluator", @@ -121,6 +120,20 @@ public static Iterable parameters() { ) ); + suppliers.addAll( + TestCaseSupplier.forBinaryNotCasting( + "LessThanOrEqualLongsEvaluator", + "lhs", + "rhs", + (l, r) -> ((Number) l).longValue() <= ((Number) r).longValue(), + DataType.BOOLEAN, + TestCaseSupplier.dateNanosCases(), + TestCaseSupplier.dateNanosCases(), + List.of(), + false + ) + ); + suppliers.addAll( TestCaseSupplier.stringCases( (l, r) -> ((BytesRef) l).compareTo((BytesRef) r) <= 0, @@ -137,7 +150,7 @@ public static Iterable parameters() { o, v, t, - (l, p) -> "datetime, double, integer, ip, keyword, long, text, unsigned_long or version" + (l, p) -> "date_nanos, datetime, double, integer, ip, keyword, long, text, unsigned_long or version" ) ) );