From 93d43e932c58d4f8eccad97602dc97c90b75a53d Mon Sep 17 00:00:00 2001 From: Fang Xing Date: Tue, 22 Jul 2025 09:39:27 -0400 Subject: [PATCH 01/11] replace linear search evaluator with manual evaluators --- .../function/scalar/math/X-RoundTo.java.st | 153 +++++++++++++++++- .../function/scalar/math/RoundToTests.java | 5 +- 2 files changed, 153 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st index 74ace0a5c4c09..f0e0adffe51c4 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st @@ -35,11 +35,16 @@ class RoundTo$Type$ { case 2 -> new RoundTo$Type$2Evaluator.Factory(source, field, f[0], f[1]); case 3 -> new RoundTo$Type$3Evaluator.Factory(source, field, f[0], f[1], f[2]); case 4 -> new RoundTo$Type$4Evaluator.Factory(source, field, f[0], f[1], f[2], f[3]); + case 5 -> new RoundTo$Type$5Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4]); + case 6 -> new RoundTo$Type$6Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5]); + case 7 -> new RoundTo$Type$7Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6]); + case 8 -> new RoundTo$Type$8Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]); + case 9 -> new RoundTo$Type$9Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8]); + case 10 -> new RoundTo$Type$10Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9]); /* * Break point of 10 experimentally derived on Nik's laptop (13th Gen Intel(R) Core(TM) i7-1370P) * on 2025-05-22. */ - case 5, 6, 7, 8, 9, 10 -> new RoundTo$Type$LinearSearchEvaluator.Factory(source, field, f); default -> new RoundTo$Type$BinarySearchEvaluator.Factory(source, field, f); }; }; @@ -102,4 +107,150 @@ class RoundTo$Type$ { } return p3; } + + @Evaluator(extraName = "5") + static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4) { + if (field < p2) { + if (field < p1) { + return p0; + } + return p1; + } + if (field < p3) { + return p2; + } + if (field < p4) { + return p3; + } + return p4; + } + + @Evaluator(extraName = "6") + static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5) { + if (field < p2) { + if (field < p1) { + return p0; + } + return p1; + } + if (field < p4) { + if (field < p3) { + return p2; + } + return p3; + } + if (field < p5) { + return p4; + } + return p5; + } + + @Evaluator(extraName = "7") + static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @Fixed $type$ p6) { + if (field < p3) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + return p2; + } + if (field < p5) { + if (field < p4) { + return p3; + } + return p4; + } + if (field < p6) { + return p5; + } + return p6; + } + + @Evaluator(extraName = "8") + static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @Fixed $type$ p6, @Fixed $type$ p7) { + if (field < p3) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + return p2; + } + if (field < p5) { + if (field < p4) { + return p3; + } + return p4; + } + if (field < p6) { + return p5; + } + if (field < p7) { + return p6; + } + return p7; + } + + @Evaluator(extraName = "9") + static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @Fixed $type$ p6, @Fixed $type$ p7, @Fixed $type$ p8) { + if (field < p4) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + if (field < p3) { + return p2; + } + return p3; + } + if (field < p6) { + if (field < p5) { + return p4; + } + return p5; + } + if (field < p7) { + return p6; + } + if (field < p8) { + return p7; + } + return p8; + } + @Evaluator(extraName = "10") + static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @Fixed $type$ p6, @Fixed $type$ p7, @Fixed $type$ p8, @Fixed $type$ p9) { + if (field < p4) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + if (field < p3) { + return p2; + } + return p3; + } + if (field < p7) { + if (field < p5) { + return p4; + } + if (field < p6) { + return p5; + } + return p6; + } + if (field < p8) { + return p7; + } + if (field < p9) { + return p8; + } + return p9; + } } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToTests.java index 677367885dd8a..a12b1b4d4be8c 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToTests.java @@ -270,11 +270,8 @@ private static

TestCaseSupplier supplier( } private static String specialization(int pointsSize) { - if (pointsSize < 5) { - return Integer.toString(pointsSize); - } if (pointsSize < 11) { - return "LinearSearch"; + return Integer.toString(pointsSize); } return "BinarySearch"; } From 0066fabf7cbc8077faca89eb7c831d33b968f7cb Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Tue, 22 Jul 2025 20:26:13 +0000 Subject: [PATCH 02/11] [CI] Auto commit changes from spotless --- .../function/scalar/math/RoundToDouble.java | 204 +++++++++++++++++- .../function/scalar/math/RoundToInt.java | 187 +++++++++++++++- .../function/scalar/math/RoundToLong.java | 196 ++++++++++++++++- 3 files changed, 584 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java index 623962d293196..a2440b973051b 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java @@ -35,11 +35,16 @@ class RoundToDouble { case 2 -> new RoundToDouble2Evaluator.Factory(source, field, f[0], f[1]); case 3 -> new RoundToDouble3Evaluator.Factory(source, field, f[0], f[1], f[2]); case 4 -> new RoundToDouble4Evaluator.Factory(source, field, f[0], f[1], f[2], f[3]); + case 5 -> new RoundToDouble5Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4]); + case 6 -> new RoundToDouble6Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5]); + case 7 -> new RoundToDouble7Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6]); + case 8 -> new RoundToDouble8Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]); + case 9 -> new RoundToDouble9Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8]); + case 10 -> new RoundToDouble10Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9]); /* * Break point of 10 experimentally derived on Nik's laptop (13th Gen Intel(R) Core(TM) i7-1370P) * on 2025-05-22. */ - case 5, 6, 7, 8, 9, 10 -> new RoundToDoubleLinearSearchEvaluator.Factory(source, field, f); default -> new RoundToDoubleBinarySearchEvaluator.Factory(source, field, f); }; }; @@ -102,4 +107,201 @@ static double process(double field, @Fixed double p0, @Fixed double p1, @Fixed d } return p3; } + + @Evaluator(extraName = "5") + static double process(double field, @Fixed double p0, @Fixed double p1, @Fixed double p2, @Fixed double p3, @Fixed double p4) { + if (field < p2) { + if (field < p1) { + return p0; + } + return p1; + } + if (field < p3) { + return p2; + } + if (field < p4) { + return p3; + } + return p4; + } + + @Evaluator(extraName = "6") + static double process( + double field, + @Fixed double p0, + @Fixed double p1, + @Fixed double p2, + @Fixed double p3, + @Fixed double p4, + @Fixed double p5 + ) { + if (field < p2) { + if (field < p1) { + return p0; + } + return p1; + } + if (field < p4) { + if (field < p3) { + return p2; + } + return p3; + } + if (field < p5) { + return p4; + } + return p5; + } + + @Evaluator(extraName = "7") + static double process( + double field, + @Fixed double p0, + @Fixed double p1, + @Fixed double p2, + @Fixed double p3, + @Fixed double p4, + @Fixed double p5, + @Fixed double p6 + ) { + if (field < p3) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + return p2; + } + if (field < p5) { + if (field < p4) { + return p3; + } + return p4; + } + if (field < p6) { + return p5; + } + return p6; + } + + @Evaluator(extraName = "8") + static double process( + double field, + @Fixed double p0, + @Fixed double p1, + @Fixed double p2, + @Fixed double p3, + @Fixed double p4, + @Fixed double p5, + @Fixed double p6, + @Fixed double p7 + ) { + if (field < p3) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + return p2; + } + if (field < p5) { + if (field < p4) { + return p3; + } + return p4; + } + if (field < p6) { + return p5; + } + if (field < p7) { + return p6; + } + return p7; + } + + @Evaluator(extraName = "9") + static double process( + double field, + @Fixed double p0, + @Fixed double p1, + @Fixed double p2, + @Fixed double p3, + @Fixed double p4, + @Fixed double p5, + @Fixed double p6, + @Fixed double p7, + @Fixed double p8 + ) { + if (field < p4) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + if (field < p3) { + return p2; + } + return p3; + } + if (field < p6) { + if (field < p5) { + return p4; + } + return p5; + } + if (field < p7) { + return p6; + } + if (field < p8) { + return p7; + } + return p8; + } + + @Evaluator(extraName = "10") + static double process( + double field, + @Fixed double p0, + @Fixed double p1, + @Fixed double p2, + @Fixed double p3, + @Fixed double p4, + @Fixed double p5, + @Fixed double p6, + @Fixed double p7, + @Fixed double p8, + @Fixed double p9 + ) { + if (field < p4) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + if (field < p3) { + return p2; + } + return p3; + } + if (field < p7) { + if (field < p5) { + return p4; + } + if (field < p6) { + return p5; + } + return p6; + } + if (field < p8) { + return p7; + } + if (field < p9) { + return p8; + } + return p9; + } } diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java index 1b97e175a6513..4cb32b26c1e51 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java @@ -35,11 +35,16 @@ class RoundToInt { case 2 -> new RoundToInt2Evaluator.Factory(source, field, f[0], f[1]); case 3 -> new RoundToInt3Evaluator.Factory(source, field, f[0], f[1], f[2]); case 4 -> new RoundToInt4Evaluator.Factory(source, field, f[0], f[1], f[2], f[3]); + case 5 -> new RoundToInt5Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4]); + case 6 -> new RoundToInt6Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5]); + case 7 -> new RoundToInt7Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6]); + case 8 -> new RoundToInt8Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]); + case 9 -> new RoundToInt9Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8]); + case 10 -> new RoundToInt10Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9]); /* * Break point of 10 experimentally derived on Nik's laptop (13th Gen Intel(R) Core(TM) i7-1370P) * on 2025-05-22. */ - case 5, 6, 7, 8, 9, 10 -> new RoundToIntLinearSearchEvaluator.Factory(source, field, f); default -> new RoundToIntBinarySearchEvaluator.Factory(source, field, f); }; }; @@ -102,4 +107,184 @@ static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixe } return p3; } + + @Evaluator(extraName = "5") + static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixed int p3, @Fixed int p4) { + if (field < p2) { + if (field < p1) { + return p0; + } + return p1; + } + if (field < p3) { + return p2; + } + if (field < p4) { + return p3; + } + return p4; + } + + @Evaluator(extraName = "6") + static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixed int p3, @Fixed int p4, @Fixed int p5) { + if (field < p2) { + if (field < p1) { + return p0; + } + return p1; + } + if (field < p4) { + if (field < p3) { + return p2; + } + return p3; + } + if (field < p5) { + return p4; + } + return p5; + } + + @Evaluator(extraName = "7") + static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixed int p3, @Fixed int p4, @Fixed int p5, @Fixed int p6) { + if (field < p3) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + return p2; + } + if (field < p5) { + if (field < p4) { + return p3; + } + return p4; + } + if (field < p6) { + return p5; + } + return p6; + } + + @Evaluator(extraName = "8") + static int process( + int field, + @Fixed int p0, + @Fixed int p1, + @Fixed int p2, + @Fixed int p3, + @Fixed int p4, + @Fixed int p5, + @Fixed int p6, + @Fixed int p7 + ) { + if (field < p3) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + return p2; + } + if (field < p5) { + if (field < p4) { + return p3; + } + return p4; + } + if (field < p6) { + return p5; + } + if (field < p7) { + return p6; + } + return p7; + } + + @Evaluator(extraName = "9") + static int process( + int field, + @Fixed int p0, + @Fixed int p1, + @Fixed int p2, + @Fixed int p3, + @Fixed int p4, + @Fixed int p5, + @Fixed int p6, + @Fixed int p7, + @Fixed int p8 + ) { + if (field < p4) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + if (field < p3) { + return p2; + } + return p3; + } + if (field < p6) { + if (field < p5) { + return p4; + } + return p5; + } + if (field < p7) { + return p6; + } + if (field < p8) { + return p7; + } + return p8; + } + + @Evaluator(extraName = "10") + static int process( + int field, + @Fixed int p0, + @Fixed int p1, + @Fixed int p2, + @Fixed int p3, + @Fixed int p4, + @Fixed int p5, + @Fixed int p6, + @Fixed int p7, + @Fixed int p8, + @Fixed int p9 + ) { + if (field < p4) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + if (field < p3) { + return p2; + } + return p3; + } + if (field < p7) { + if (field < p5) { + return p4; + } + if (field < p6) { + return p5; + } + return p6; + } + if (field < p8) { + return p7; + } + if (field < p9) { + return p8; + } + return p9; + } } diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java index 24821b772b35e..1d64c5bd2c812 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java @@ -35,11 +35,16 @@ class RoundToLong { case 2 -> new RoundToLong2Evaluator.Factory(source, field, f[0], f[1]); case 3 -> new RoundToLong3Evaluator.Factory(source, field, f[0], f[1], f[2]); case 4 -> new RoundToLong4Evaluator.Factory(source, field, f[0], f[1], f[2], f[3]); + case 5 -> new RoundToLong5Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4]); + case 6 -> new RoundToLong6Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5]); + case 7 -> new RoundToLong7Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6]); + case 8 -> new RoundToLong8Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7]); + case 9 -> new RoundToLong9Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8]); + case 10 -> new RoundToLong10Evaluator.Factory(source, field, f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9]); /* * Break point of 10 experimentally derived on Nik's laptop (13th Gen Intel(R) Core(TM) i7-1370P) * on 2025-05-22. */ - case 5, 6, 7, 8, 9, 10 -> new RoundToLongLinearSearchEvaluator.Factory(source, field, f); default -> new RoundToLongBinarySearchEvaluator.Factory(source, field, f); }; }; @@ -102,4 +107,193 @@ static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, } return p3; } + + @Evaluator(extraName = "5") + static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, @Fixed long p3, @Fixed long p4) { + if (field < p2) { + if (field < p1) { + return p0; + } + return p1; + } + if (field < p3) { + return p2; + } + if (field < p4) { + return p3; + } + return p4; + } + + @Evaluator(extraName = "6") + static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, @Fixed long p3, @Fixed long p4, @Fixed long p5) { + if (field < p2) { + if (field < p1) { + return p0; + } + return p1; + } + if (field < p4) { + if (field < p3) { + return p2; + } + return p3; + } + if (field < p5) { + return p4; + } + return p5; + } + + @Evaluator(extraName = "7") + static long process( + long field, + @Fixed long p0, + @Fixed long p1, + @Fixed long p2, + @Fixed long p3, + @Fixed long p4, + @Fixed long p5, + @Fixed long p6 + ) { + if (field < p3) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + return p2; + } + if (field < p5) { + if (field < p4) { + return p3; + } + return p4; + } + if (field < p6) { + return p5; + } + return p6; + } + + @Evaluator(extraName = "8") + static long process( + long field, + @Fixed long p0, + @Fixed long p1, + @Fixed long p2, + @Fixed long p3, + @Fixed long p4, + @Fixed long p5, + @Fixed long p6, + @Fixed long p7 + ) { + if (field < p3) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + return p2; + } + if (field < p5) { + if (field < p4) { + return p3; + } + return p4; + } + if (field < p6) { + return p5; + } + if (field < p7) { + return p6; + } + return p7; + } + + @Evaluator(extraName = "9") + static long process( + long field, + @Fixed long p0, + @Fixed long p1, + @Fixed long p2, + @Fixed long p3, + @Fixed long p4, + @Fixed long p5, + @Fixed long p6, + @Fixed long p7, + @Fixed long p8 + ) { + if (field < p4) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + if (field < p3) { + return p2; + } + return p3; + } + if (field < p6) { + if (field < p5) { + return p4; + } + return p5; + } + if (field < p7) { + return p6; + } + if (field < p8) { + return p7; + } + return p8; + } + + @Evaluator(extraName = "10") + static long process( + long field, + @Fixed long p0, + @Fixed long p1, + @Fixed long p2, + @Fixed long p3, + @Fixed long p4, + @Fixed long p5, + @Fixed long p6, + @Fixed long p7, + @Fixed long p8, + @Fixed long p9 + ) { + if (field < p4) { + if (field < p1) { + return p0; + } + if (field < p2) { + return p1; + } + if (field < p3) { + return p2; + } + return p3; + } + if (field < p7) { + if (field < p5) { + return p4; + } + if (field < p6) { + return p5; + } + return p6; + } + if (field < p8) { + return p7; + } + if (field < p9) { + return p8; + } + return p9; + } } From d914ae00e42f0088fa28d34705a62875d2071098 Mon Sep 17 00:00:00 2001 From: Fang Xing Date: Tue, 22 Jul 2025 20:18:09 -0400 Subject: [PATCH 03/11] spotless --- .../function/scalar/math/RoundToDouble.java | 15 --------------- .../function/scalar/math/RoundToInt.java | 15 --------------- .../function/scalar/math/RoundToLong.java | 15 --------------- .../function/scalar/math/X-RoundTo.java.st | 15 --------------- 4 files changed, 60 deletions(-) diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java index a2440b973051b..d46a1b21f36ab 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java @@ -49,21 +49,6 @@ class RoundToDouble { }; }; - /** - * Search the points array for the match linearly. This is faster for smaller arrays even - * when finding a position late in the array. Presumably because this is super-SIMD-able. - */ - @Evaluator(extraName = "LinearSearch") - static double processLinear(double field, @Fixed(includeInToString = false) double[] points) { - // points is always longer than 3 or we use one of the specialized methods below - for (int i = 1; i < points.length; i++) { - if (field < points[i]) { - return points[i - 1]; - } - } - return points[points.length - 1]; - } - @Evaluator(extraName = "BinarySearch") static double process(double field, @Fixed(includeInToString = false) double[] points) { int idx = Arrays.binarySearch(points, field); diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java index 4cb32b26c1e51..fdcda60a8a3cd 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java @@ -49,21 +49,6 @@ class RoundToInt { }; }; - /** - * Search the points array for the match linearly. This is faster for smaller arrays even - * when finding a position late in the array. Presumably because this is super-SIMD-able. - */ - @Evaluator(extraName = "LinearSearch") - static int processLinear(int field, @Fixed(includeInToString = false) int[] points) { - // points is always longer than 3 or we use one of the specialized methods below - for (int i = 1; i < points.length; i++) { - if (field < points[i]) { - return points[i - 1]; - } - } - return points[points.length - 1]; - } - @Evaluator(extraName = "BinarySearch") static int process(int field, @Fixed(includeInToString = false) int[] points) { int idx = Arrays.binarySearch(points, field); diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java index 1d64c5bd2c812..208facbbd0e4b 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java @@ -49,21 +49,6 @@ class RoundToLong { }; }; - /** - * Search the points array for the match linearly. This is faster for smaller arrays even - * when finding a position late in the array. Presumably because this is super-SIMD-able. - */ - @Evaluator(extraName = "LinearSearch") - static long processLinear(long field, @Fixed(includeInToString = false) long[] points) { - // points is always longer than 3 or we use one of the specialized methods below - for (int i = 1; i < points.length; i++) { - if (field < points[i]) { - return points[i - 1]; - } - } - return points[points.length - 1]; - } - @Evaluator(extraName = "BinarySearch") static long process(long field, @Fixed(includeInToString = false) long[] points) { int idx = Arrays.binarySearch(points, field); diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st index f0e0adffe51c4..9f31ac21d7579 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st @@ -49,21 +49,6 @@ class RoundTo$Type$ { }; }; - /** - * Search the points array for the match linearly. This is faster for smaller arrays even - * when finding a position late in the array. Presumably because this is super-SIMD-able. - */ - @Evaluator(extraName = "LinearSearch") - static $type$ processLinear($type$ field, @Fixed(includeInToString = false) $type$[] points) { - // points is always longer than 3 or we use one of the specialized methods below - for (int i = 1; i < points.length; i++) { - if (field < points[i]) { - return points[i - 1]; - } - } - return points[points.length - 1]; - } - @Evaluator(extraName = "BinarySearch") static $type$ process($type$ field, @Fixed(includeInToString = false) $type$[] points) { int idx = Arrays.binarySearch(points, field); From e6b4e5fb1a7d7636fa58f24fe8e4eecfd2465e04 Mon Sep 17 00:00:00 2001 From: Fang Xing Date: Wed, 23 Jul 2025 14:12:32 -0400 Subject: [PATCH 04/11] try to fix spotless --- .../scalar/math/RoundToDouble10Evaluator.java | 185 ++++++++++++++++++ ...ator.java => RoundToDouble5Evaluator.java} | 53 +++-- .../scalar/math/RoundToDouble6Evaluator.java | 159 +++++++++++++++ .../scalar/math/RoundToDouble7Evaluator.java | 166 ++++++++++++++++ .../scalar/math/RoundToDouble8Evaluator.java | 172 ++++++++++++++++ .../scalar/math/RoundToDouble9Evaluator.java | 178 +++++++++++++++++ .../scalar/math/RoundToInt10Evaluator.java | 184 +++++++++++++++++ ...aluator.java => RoundToInt5Evaluator.java} | 53 +++-- .../scalar/math/RoundToInt6Evaluator.java | 159 +++++++++++++++ .../scalar/math/RoundToInt7Evaluator.java | 165 ++++++++++++++++ .../scalar/math/RoundToInt8Evaluator.java | 171 ++++++++++++++++ .../scalar/math/RoundToInt9Evaluator.java | 177 +++++++++++++++++ .../scalar/math/RoundToLong10Evaluator.java | 184 +++++++++++++++++ ...luator.java => RoundToLong5Evaluator.java} | 53 +++-- .../scalar/math/RoundToLong6Evaluator.java | 159 +++++++++++++++ .../scalar/math/RoundToLong7Evaluator.java | 165 ++++++++++++++++ .../scalar/math/RoundToLong8Evaluator.java | 171 ++++++++++++++++ .../scalar/math/RoundToLong9Evaluator.java | 178 +++++++++++++++++ 18 files changed, 2690 insertions(+), 42 deletions(-) create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble10Evaluator.java rename x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/{RoundToDoubleLinearSearchEvaluator.java => RoundToDouble5Evaluator.java} (69%) create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble6Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble7Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble8Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble9Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt10Evaluator.java rename x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/{RoundToIntLinearSearchEvaluator.java => RoundToInt5Evaluator.java} (70%) create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt6Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt7Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt8Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt9Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong10Evaluator.java rename x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/{RoundToLongLinearSearchEvaluator.java => RoundToLong5Evaluator.java} (69%) create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong6Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong7Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong8Evaluator.java create mode 100644 x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong9Evaluator.java diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble10Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble10Evaluator.java new file mode 100644 index 0000000000000..120ee64338bc2 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble10Evaluator.java @@ -0,0 +1,185 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToDouble}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToDouble10Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final double p6; + + private final double p7; + + private final double p8; + + private final double p9; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToDouble10Evaluator(Source source, EvalOperator.ExpressionEvaluator field, double p0, + double p1, double p2, double p3, double p4, double p5, double p6, double p7, double p8, + double p9, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.p9 = p9; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (DoubleBlock fieldBlock = (DoubleBlock) field.eval(page)) { + DoubleVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public DoubleBlock eval(int positionCount, DoubleBlock fieldBlock) { + try(DoubleBlock.Builder result = driverContext.blockFactory().newDoubleBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendDouble(RoundToDouble.process(fieldBlock.getDouble(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8, this.p9)); + } + return result.build(); + } + } + + public DoubleVector eval(int positionCount, DoubleVector fieldVector) { + try(DoubleVector.FixedBuilder result = driverContext.blockFactory().newDoubleVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendDouble(p, RoundToDouble.process(fieldVector.getDouble(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8, this.p9)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToDouble10Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + ", p9=" + p9 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final double p6; + + private final double p7; + + private final double p8; + + private final double p9; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, double p0, + double p1, double p2, double p3, double p4, double p5, double p6, double p7, double p8, + double p9) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.p9 = p9; + } + + @Override + public RoundToDouble10Evaluator get(DriverContext context) { + return new RoundToDouble10Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, context); + } + + @Override + public String toString() { + return "RoundToDouble10Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + ", p9=" + p9 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDoubleLinearSearchEvaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble5Evaluator.java similarity index 69% rename from x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDoubleLinearSearchEvaluator.java rename to x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble5Evaluator.java index 8485e6576f82c..de3c6c5358fdc 100644 --- a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDoubleLinearSearchEvaluator.java +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble5Evaluator.java @@ -21,22 +21,34 @@ * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToDouble}. * This class is generated. Edit {@code EvaluatorImplementer} instead. */ -public final class RoundToDoubleLinearSearchEvaluator implements EvalOperator.ExpressionEvaluator { +public final class RoundToDouble5Evaluator implements EvalOperator.ExpressionEvaluator { private final Source source; private final EvalOperator.ExpressionEvaluator field; - private final double[] points; + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; private final DriverContext driverContext; private Warnings warnings; - public RoundToDoubleLinearSearchEvaluator(Source source, EvalOperator.ExpressionEvaluator field, - double[] points, DriverContext driverContext) { + public RoundToDouble5Evaluator(Source source, EvalOperator.ExpressionEvaluator field, double p0, + double p1, double p2, double p3, double p4, DriverContext driverContext) { this.source = source; this.field = field; - this.points = points; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; this.driverContext = driverContext; } @@ -65,7 +77,7 @@ public DoubleBlock eval(int positionCount, DoubleBlock fieldBlock) { result.appendNull(); continue position; } - result.appendDouble(RoundToDouble.processLinear(fieldBlock.getDouble(fieldBlock.getFirstValueIndex(p)), this.points)); + result.appendDouble(RoundToDouble.process(fieldBlock.getDouble(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4)); } return result.build(); } @@ -74,7 +86,7 @@ public DoubleBlock eval(int positionCount, DoubleBlock fieldBlock) { public DoubleVector eval(int positionCount, DoubleVector fieldVector) { try(DoubleVector.FixedBuilder result = driverContext.blockFactory().newDoubleVectorFixedBuilder(positionCount)) { position: for (int p = 0; p < positionCount; p++) { - result.appendDouble(p, RoundToDouble.processLinear(fieldVector.getDouble(p), this.points)); + result.appendDouble(p, RoundToDouble.process(fieldVector.getDouble(p), this.p0, this.p1, this.p2, this.p3, this.p4)); } return result.build(); } @@ -82,7 +94,7 @@ public DoubleVector eval(int positionCount, DoubleVector fieldVector) { @Override public String toString() { - return "RoundToDoubleLinearSearchEvaluator[" + "field=" + field + "]"; + return "RoundToDouble5Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + "]"; } @Override @@ -107,22 +119,35 @@ static class Factory implements EvalOperator.ExpressionEvaluator.Factory { private final EvalOperator.ExpressionEvaluator.Factory field; - private final double[] points; + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; - public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, double[] points) { + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, double p0, + double p1, double p2, double p3, double p4) { this.source = source; this.field = field; - this.points = points; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; } @Override - public RoundToDoubleLinearSearchEvaluator get(DriverContext context) { - return new RoundToDoubleLinearSearchEvaluator(source, field.get(context), points, context); + public RoundToDouble5Evaluator get(DriverContext context) { + return new RoundToDouble5Evaluator(source, field.get(context), p0, p1, p2, p3, p4, context); } @Override public String toString() { - return "RoundToDoubleLinearSearchEvaluator[" + "field=" + field + "]"; + return "RoundToDouble5Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + "]"; } } } diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble6Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble6Evaluator.java new file mode 100644 index 0000000000000..dd479ed54b26b --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble6Evaluator.java @@ -0,0 +1,159 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToDouble}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToDouble6Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToDouble6Evaluator(Source source, EvalOperator.ExpressionEvaluator field, double p0, + double p1, double p2, double p3, double p4, double p5, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (DoubleBlock fieldBlock = (DoubleBlock) field.eval(page)) { + DoubleVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public DoubleBlock eval(int positionCount, DoubleBlock fieldBlock) { + try(DoubleBlock.Builder result = driverContext.blockFactory().newDoubleBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendDouble(RoundToDouble.process(fieldBlock.getDouble(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5)); + } + return result.build(); + } + } + + public DoubleVector eval(int positionCount, DoubleVector fieldVector) { + try(DoubleVector.FixedBuilder result = driverContext.blockFactory().newDoubleVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendDouble(p, RoundToDouble.process(fieldVector.getDouble(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToDouble6Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, double p0, + double p1, double p2, double p3, double p4, double p5) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + } + + @Override + public RoundToDouble6Evaluator get(DriverContext context) { + return new RoundToDouble6Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, context); + } + + @Override + public String toString() { + return "RoundToDouble6Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble7Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble7Evaluator.java new file mode 100644 index 0000000000000..ff5f0d3885861 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble7Evaluator.java @@ -0,0 +1,166 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToDouble}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToDouble7Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final double p6; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToDouble7Evaluator(Source source, EvalOperator.ExpressionEvaluator field, double p0, + double p1, double p2, double p3, double p4, double p5, double p6, + DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (DoubleBlock fieldBlock = (DoubleBlock) field.eval(page)) { + DoubleVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public DoubleBlock eval(int positionCount, DoubleBlock fieldBlock) { + try(DoubleBlock.Builder result = driverContext.blockFactory().newDoubleBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendDouble(RoundToDouble.process(fieldBlock.getDouble(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6)); + } + return result.build(); + } + } + + public DoubleVector eval(int positionCount, DoubleVector fieldVector) { + try(DoubleVector.FixedBuilder result = driverContext.blockFactory().newDoubleVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendDouble(p, RoundToDouble.process(fieldVector.getDouble(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToDouble7Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final double p6; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, double p0, + double p1, double p2, double p3, double p4, double p5, double p6) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + } + + @Override + public RoundToDouble7Evaluator get(DriverContext context) { + return new RoundToDouble7Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, context); + } + + @Override + public String toString() { + return "RoundToDouble7Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble8Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble8Evaluator.java new file mode 100644 index 0000000000000..142cb8da3fece --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble8Evaluator.java @@ -0,0 +1,172 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToDouble}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToDouble8Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final double p6; + + private final double p7; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToDouble8Evaluator(Source source, EvalOperator.ExpressionEvaluator field, double p0, + double p1, double p2, double p3, double p4, double p5, double p6, double p7, + DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (DoubleBlock fieldBlock = (DoubleBlock) field.eval(page)) { + DoubleVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public DoubleBlock eval(int positionCount, DoubleBlock fieldBlock) { + try(DoubleBlock.Builder result = driverContext.blockFactory().newDoubleBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendDouble(RoundToDouble.process(fieldBlock.getDouble(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7)); + } + return result.build(); + } + } + + public DoubleVector eval(int positionCount, DoubleVector fieldVector) { + try(DoubleVector.FixedBuilder result = driverContext.blockFactory().newDoubleVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendDouble(p, RoundToDouble.process(fieldVector.getDouble(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToDouble8Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final double p6; + + private final double p7; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, double p0, + double p1, double p2, double p3, double p4, double p5, double p6, double p7) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + } + + @Override + public RoundToDouble8Evaluator get(DriverContext context) { + return new RoundToDouble8Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, context); + } + + @Override + public String toString() { + return "RoundToDouble8Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble9Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble9Evaluator.java new file mode 100644 index 0000000000000..b1cc994eeb4b8 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble9Evaluator.java @@ -0,0 +1,178 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.DoubleBlock; +import org.elasticsearch.compute.data.DoubleVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToDouble}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToDouble9Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final double p6; + + private final double p7; + + private final double p8; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToDouble9Evaluator(Source source, EvalOperator.ExpressionEvaluator field, double p0, + double p1, double p2, double p3, double p4, double p5, double p6, double p7, double p8, + DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (DoubleBlock fieldBlock = (DoubleBlock) field.eval(page)) { + DoubleVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public DoubleBlock eval(int positionCount, DoubleBlock fieldBlock) { + try(DoubleBlock.Builder result = driverContext.blockFactory().newDoubleBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendDouble(RoundToDouble.process(fieldBlock.getDouble(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8)); + } + return result.build(); + } + } + + public DoubleVector eval(int positionCount, DoubleVector fieldVector) { + try(DoubleVector.FixedBuilder result = driverContext.blockFactory().newDoubleVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendDouble(p, RoundToDouble.process(fieldVector.getDouble(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToDouble9Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final double p0; + + private final double p1; + + private final double p2; + + private final double p3; + + private final double p4; + + private final double p5; + + private final double p6; + + private final double p7; + + private final double p8; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, double p0, + double p1, double p2, double p3, double p4, double p5, double p6, double p7, double p8) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + } + + @Override + public RoundToDouble9Evaluator get(DriverContext context) { + return new RoundToDouble9Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, p8, context); + } + + @Override + public String toString() { + return "RoundToDouble9Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt10Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt10Evaluator.java new file mode 100644 index 0000000000000..61bd5cc74049d --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt10Evaluator.java @@ -0,0 +1,184 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToInt}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToInt10Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final int p6; + + private final int p7; + + private final int p8; + + private final int p9; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToInt10Evaluator(Source source, EvalOperator.ExpressionEvaluator field, int p0, + int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, + DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.p9 = p9; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (IntBlock fieldBlock = (IntBlock) field.eval(page)) { + IntVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public IntBlock eval(int positionCount, IntBlock fieldBlock) { + try(IntBlock.Builder result = driverContext.blockFactory().newIntBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendInt(RoundToInt.process(fieldBlock.getInt(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8, this.p9)); + } + return result.build(); + } + } + + public IntVector eval(int positionCount, IntVector fieldVector) { + try(IntVector.FixedBuilder result = driverContext.blockFactory().newIntVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendInt(p, RoundToInt.process(fieldVector.getInt(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8, this.p9)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToInt10Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + ", p9=" + p9 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final int p6; + + private final int p7; + + private final int p8; + + private final int p9; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, int p0, int p1, + int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.p9 = p9; + } + + @Override + public RoundToInt10Evaluator get(DriverContext context) { + return new RoundToInt10Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, context); + } + + @Override + public String toString() { + return "RoundToInt10Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + ", p9=" + p9 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToIntLinearSearchEvaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt5Evaluator.java similarity index 70% rename from x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToIntLinearSearchEvaluator.java rename to x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt5Evaluator.java index ed703c3c994f1..9ebd71cfc34c0 100644 --- a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToIntLinearSearchEvaluator.java +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt5Evaluator.java @@ -21,22 +21,34 @@ * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToInt}. * This class is generated. Edit {@code EvaluatorImplementer} instead. */ -public final class RoundToIntLinearSearchEvaluator implements EvalOperator.ExpressionEvaluator { +public final class RoundToInt5Evaluator implements EvalOperator.ExpressionEvaluator { private final Source source; private final EvalOperator.ExpressionEvaluator field; - private final int[] points; + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; private final DriverContext driverContext; private Warnings warnings; - public RoundToIntLinearSearchEvaluator(Source source, EvalOperator.ExpressionEvaluator field, - int[] points, DriverContext driverContext) { + public RoundToInt5Evaluator(Source source, EvalOperator.ExpressionEvaluator field, int p0, int p1, + int p2, int p3, int p4, DriverContext driverContext) { this.source = source; this.field = field; - this.points = points; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; this.driverContext = driverContext; } @@ -65,7 +77,7 @@ public IntBlock eval(int positionCount, IntBlock fieldBlock) { result.appendNull(); continue position; } - result.appendInt(RoundToInt.processLinear(fieldBlock.getInt(fieldBlock.getFirstValueIndex(p)), this.points)); + result.appendInt(RoundToInt.process(fieldBlock.getInt(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4)); } return result.build(); } @@ -74,7 +86,7 @@ public IntBlock eval(int positionCount, IntBlock fieldBlock) { public IntVector eval(int positionCount, IntVector fieldVector) { try(IntVector.FixedBuilder result = driverContext.blockFactory().newIntVectorFixedBuilder(positionCount)) { position: for (int p = 0; p < positionCount; p++) { - result.appendInt(p, RoundToInt.processLinear(fieldVector.getInt(p), this.points)); + result.appendInt(p, RoundToInt.process(fieldVector.getInt(p), this.p0, this.p1, this.p2, this.p3, this.p4)); } return result.build(); } @@ -82,7 +94,7 @@ public IntVector eval(int positionCount, IntVector fieldVector) { @Override public String toString() { - return "RoundToIntLinearSearchEvaluator[" + "field=" + field + "]"; + return "RoundToInt5Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + "]"; } @Override @@ -107,22 +119,35 @@ static class Factory implements EvalOperator.ExpressionEvaluator.Factory { private final EvalOperator.ExpressionEvaluator.Factory field; - private final int[] points; + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; - public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, int[] points) { + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, int p0, int p1, + int p2, int p3, int p4) { this.source = source; this.field = field; - this.points = points; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; } @Override - public RoundToIntLinearSearchEvaluator get(DriverContext context) { - return new RoundToIntLinearSearchEvaluator(source, field.get(context), points, context); + public RoundToInt5Evaluator get(DriverContext context) { + return new RoundToInt5Evaluator(source, field.get(context), p0, p1, p2, p3, p4, context); } @Override public String toString() { - return "RoundToIntLinearSearchEvaluator[" + "field=" + field + "]"; + return "RoundToInt5Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + "]"; } } } diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt6Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt6Evaluator.java new file mode 100644 index 0000000000000..7040f3c7157d4 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt6Evaluator.java @@ -0,0 +1,159 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToInt}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToInt6Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToInt6Evaluator(Source source, EvalOperator.ExpressionEvaluator field, int p0, int p1, + int p2, int p3, int p4, int p5, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (IntBlock fieldBlock = (IntBlock) field.eval(page)) { + IntVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public IntBlock eval(int positionCount, IntBlock fieldBlock) { + try(IntBlock.Builder result = driverContext.blockFactory().newIntBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendInt(RoundToInt.process(fieldBlock.getInt(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5)); + } + return result.build(); + } + } + + public IntVector eval(int positionCount, IntVector fieldVector) { + try(IntVector.FixedBuilder result = driverContext.blockFactory().newIntVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendInt(p, RoundToInt.process(fieldVector.getInt(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToInt6Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, int p0, int p1, + int p2, int p3, int p4, int p5) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + } + + @Override + public RoundToInt6Evaluator get(DriverContext context) { + return new RoundToInt6Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, context); + } + + @Override + public String toString() { + return "RoundToInt6Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt7Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt7Evaluator.java new file mode 100644 index 0000000000000..96bd4734f77f2 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt7Evaluator.java @@ -0,0 +1,165 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToInt}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToInt7Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final int p6; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToInt7Evaluator(Source source, EvalOperator.ExpressionEvaluator field, int p0, int p1, + int p2, int p3, int p4, int p5, int p6, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (IntBlock fieldBlock = (IntBlock) field.eval(page)) { + IntVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public IntBlock eval(int positionCount, IntBlock fieldBlock) { + try(IntBlock.Builder result = driverContext.blockFactory().newIntBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendInt(RoundToInt.process(fieldBlock.getInt(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6)); + } + return result.build(); + } + } + + public IntVector eval(int positionCount, IntVector fieldVector) { + try(IntVector.FixedBuilder result = driverContext.blockFactory().newIntVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendInt(p, RoundToInt.process(fieldVector.getInt(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToInt7Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final int p6; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, int p0, int p1, + int p2, int p3, int p4, int p5, int p6) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + } + + @Override + public RoundToInt7Evaluator get(DriverContext context) { + return new RoundToInt7Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, context); + } + + @Override + public String toString() { + return "RoundToInt7Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt8Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt8Evaluator.java new file mode 100644 index 0000000000000..aa19d41014f78 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt8Evaluator.java @@ -0,0 +1,171 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToInt}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToInt8Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final int p6; + + private final int p7; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToInt8Evaluator(Source source, EvalOperator.ExpressionEvaluator field, int p0, int p1, + int p2, int p3, int p4, int p5, int p6, int p7, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (IntBlock fieldBlock = (IntBlock) field.eval(page)) { + IntVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public IntBlock eval(int positionCount, IntBlock fieldBlock) { + try(IntBlock.Builder result = driverContext.blockFactory().newIntBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendInt(RoundToInt.process(fieldBlock.getInt(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7)); + } + return result.build(); + } + } + + public IntVector eval(int positionCount, IntVector fieldVector) { + try(IntVector.FixedBuilder result = driverContext.blockFactory().newIntVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendInt(p, RoundToInt.process(fieldVector.getInt(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToInt8Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final int p6; + + private final int p7; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, int p0, int p1, + int p2, int p3, int p4, int p5, int p6, int p7) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + } + + @Override + public RoundToInt8Evaluator get(DriverContext context) { + return new RoundToInt8Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, context); + } + + @Override + public String toString() { + return "RoundToInt8Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt9Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt9Evaluator.java new file mode 100644 index 0000000000000..577fba57fe806 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt9Evaluator.java @@ -0,0 +1,177 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.IntBlock; +import org.elasticsearch.compute.data.IntVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToInt}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToInt9Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final int p6; + + private final int p7; + + private final int p8; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToInt9Evaluator(Source source, EvalOperator.ExpressionEvaluator field, int p0, int p1, + int p2, int p3, int p4, int p5, int p6, int p7, int p8, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (IntBlock fieldBlock = (IntBlock) field.eval(page)) { + IntVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public IntBlock eval(int positionCount, IntBlock fieldBlock) { + try(IntBlock.Builder result = driverContext.blockFactory().newIntBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendInt(RoundToInt.process(fieldBlock.getInt(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8)); + } + return result.build(); + } + } + + public IntVector eval(int positionCount, IntVector fieldVector) { + try(IntVector.FixedBuilder result = driverContext.blockFactory().newIntVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendInt(p, RoundToInt.process(fieldVector.getInt(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToInt9Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final int p0; + + private final int p1; + + private final int p2; + + private final int p3; + + private final int p4; + + private final int p5; + + private final int p6; + + private final int p7; + + private final int p8; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, int p0, int p1, + int p2, int p3, int p4, int p5, int p6, int p7, int p8) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + } + + @Override + public RoundToInt9Evaluator get(DriverContext context) { + return new RoundToInt9Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, p8, context); + } + + @Override + public String toString() { + return "RoundToInt9Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong10Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong10Evaluator.java new file mode 100644 index 0000000000000..1c5026582b48c --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong10Evaluator.java @@ -0,0 +1,184 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToLong}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToLong10Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final long p6; + + private final long p7; + + private final long p8; + + private final long p9; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToLong10Evaluator(Source source, EvalOperator.ExpressionEvaluator field, long p0, + long p1, long p2, long p3, long p4, long p5, long p6, long p7, long p8, long p9, + DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.p9 = p9; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (LongBlock fieldBlock = (LongBlock) field.eval(page)) { + LongVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public LongBlock eval(int positionCount, LongBlock fieldBlock) { + try(LongBlock.Builder result = driverContext.blockFactory().newLongBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendLong(RoundToLong.process(fieldBlock.getLong(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8, this.p9)); + } + return result.build(); + } + } + + public LongVector eval(int positionCount, LongVector fieldVector) { + try(LongVector.FixedBuilder result = driverContext.blockFactory().newLongVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendLong(p, RoundToLong.process(fieldVector.getLong(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8, this.p9)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToLong10Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + ", p9=" + p9 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final long p6; + + private final long p7; + + private final long p8; + + private final long p9; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, long p0, long p1, + long p2, long p3, long p4, long p5, long p6, long p7, long p8, long p9) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.p9 = p9; + } + + @Override + public RoundToLong10Evaluator get(DriverContext context) { + return new RoundToLong10Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, context); + } + + @Override + public String toString() { + return "RoundToLong10Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + ", p9=" + p9 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLongLinearSearchEvaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong5Evaluator.java similarity index 69% rename from x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLongLinearSearchEvaluator.java rename to x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong5Evaluator.java index 62a6c81d148e3..07e4452b7a21c 100644 --- a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLongLinearSearchEvaluator.java +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong5Evaluator.java @@ -21,22 +21,34 @@ * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToLong}. * This class is generated. Edit {@code EvaluatorImplementer} instead. */ -public final class RoundToLongLinearSearchEvaluator implements EvalOperator.ExpressionEvaluator { +public final class RoundToLong5Evaluator implements EvalOperator.ExpressionEvaluator { private final Source source; private final EvalOperator.ExpressionEvaluator field; - private final long[] points; + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; private final DriverContext driverContext; private Warnings warnings; - public RoundToLongLinearSearchEvaluator(Source source, EvalOperator.ExpressionEvaluator field, - long[] points, DriverContext driverContext) { + public RoundToLong5Evaluator(Source source, EvalOperator.ExpressionEvaluator field, long p0, + long p1, long p2, long p3, long p4, DriverContext driverContext) { this.source = source; this.field = field; - this.points = points; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; this.driverContext = driverContext; } @@ -65,7 +77,7 @@ public LongBlock eval(int positionCount, LongBlock fieldBlock) { result.appendNull(); continue position; } - result.appendLong(RoundToLong.processLinear(fieldBlock.getLong(fieldBlock.getFirstValueIndex(p)), this.points)); + result.appendLong(RoundToLong.process(fieldBlock.getLong(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4)); } return result.build(); } @@ -74,7 +86,7 @@ public LongBlock eval(int positionCount, LongBlock fieldBlock) { public LongVector eval(int positionCount, LongVector fieldVector) { try(LongVector.FixedBuilder result = driverContext.blockFactory().newLongVectorFixedBuilder(positionCount)) { position: for (int p = 0; p < positionCount; p++) { - result.appendLong(p, RoundToLong.processLinear(fieldVector.getLong(p), this.points)); + result.appendLong(p, RoundToLong.process(fieldVector.getLong(p), this.p0, this.p1, this.p2, this.p3, this.p4)); } return result.build(); } @@ -82,7 +94,7 @@ public LongVector eval(int positionCount, LongVector fieldVector) { @Override public String toString() { - return "RoundToLongLinearSearchEvaluator[" + "field=" + field + "]"; + return "RoundToLong5Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + "]"; } @Override @@ -107,22 +119,35 @@ static class Factory implements EvalOperator.ExpressionEvaluator.Factory { private final EvalOperator.ExpressionEvaluator.Factory field; - private final long[] points; + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; - public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, long[] points) { + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, long p0, long p1, + long p2, long p3, long p4) { this.source = source; this.field = field; - this.points = points; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; } @Override - public RoundToLongLinearSearchEvaluator get(DriverContext context) { - return new RoundToLongLinearSearchEvaluator(source, field.get(context), points, context); + public RoundToLong5Evaluator get(DriverContext context) { + return new RoundToLong5Evaluator(source, field.get(context), p0, p1, p2, p3, p4, context); } @Override public String toString() { - return "RoundToLongLinearSearchEvaluator[" + "field=" + field + "]"; + return "RoundToLong5Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + "]"; } } } diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong6Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong6Evaluator.java new file mode 100644 index 0000000000000..a1582395cbfe5 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong6Evaluator.java @@ -0,0 +1,159 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToLong}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToLong6Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToLong6Evaluator(Source source, EvalOperator.ExpressionEvaluator field, long p0, + long p1, long p2, long p3, long p4, long p5, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (LongBlock fieldBlock = (LongBlock) field.eval(page)) { + LongVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public LongBlock eval(int positionCount, LongBlock fieldBlock) { + try(LongBlock.Builder result = driverContext.blockFactory().newLongBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendLong(RoundToLong.process(fieldBlock.getLong(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5)); + } + return result.build(); + } + } + + public LongVector eval(int positionCount, LongVector fieldVector) { + try(LongVector.FixedBuilder result = driverContext.blockFactory().newLongVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendLong(p, RoundToLong.process(fieldVector.getLong(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToLong6Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, long p0, long p1, + long p2, long p3, long p4, long p5) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + } + + @Override + public RoundToLong6Evaluator get(DriverContext context) { + return new RoundToLong6Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, context); + } + + @Override + public String toString() { + return "RoundToLong6Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong7Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong7Evaluator.java new file mode 100644 index 0000000000000..567194b05c5d0 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong7Evaluator.java @@ -0,0 +1,165 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToLong}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToLong7Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final long p6; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToLong7Evaluator(Source source, EvalOperator.ExpressionEvaluator field, long p0, + long p1, long p2, long p3, long p4, long p5, long p6, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (LongBlock fieldBlock = (LongBlock) field.eval(page)) { + LongVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public LongBlock eval(int positionCount, LongBlock fieldBlock) { + try(LongBlock.Builder result = driverContext.blockFactory().newLongBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendLong(RoundToLong.process(fieldBlock.getLong(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6)); + } + return result.build(); + } + } + + public LongVector eval(int positionCount, LongVector fieldVector) { + try(LongVector.FixedBuilder result = driverContext.blockFactory().newLongVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendLong(p, RoundToLong.process(fieldVector.getLong(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToLong7Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final long p6; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, long p0, long p1, + long p2, long p3, long p4, long p5, long p6) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + } + + @Override + public RoundToLong7Evaluator get(DriverContext context) { + return new RoundToLong7Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, context); + } + + @Override + public String toString() { + return "RoundToLong7Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong8Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong8Evaluator.java new file mode 100644 index 0000000000000..b40744f429b79 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong8Evaluator.java @@ -0,0 +1,171 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToLong}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToLong8Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final long p6; + + private final long p7; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToLong8Evaluator(Source source, EvalOperator.ExpressionEvaluator field, long p0, + long p1, long p2, long p3, long p4, long p5, long p6, long p7, DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (LongBlock fieldBlock = (LongBlock) field.eval(page)) { + LongVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public LongBlock eval(int positionCount, LongBlock fieldBlock) { + try(LongBlock.Builder result = driverContext.blockFactory().newLongBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendLong(RoundToLong.process(fieldBlock.getLong(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7)); + } + return result.build(); + } + } + + public LongVector eval(int positionCount, LongVector fieldVector) { + try(LongVector.FixedBuilder result = driverContext.blockFactory().newLongVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendLong(p, RoundToLong.process(fieldVector.getLong(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToLong8Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final long p6; + + private final long p7; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, long p0, long p1, + long p2, long p3, long p4, long p5, long p6, long p7) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + } + + @Override + public RoundToLong8Evaluator get(DriverContext context) { + return new RoundToLong8Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, context); + } + + @Override + public String toString() { + return "RoundToLong8Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + "]"; + } + } +} diff --git a/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong9Evaluator.java b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong9Evaluator.java new file mode 100644 index 0000000000000..99b9ed1d23375 --- /dev/null +++ b/x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong9Evaluator.java @@ -0,0 +1,178 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License +// 2.0; you may not use this file except in compliance with the Elastic License +// 2.0. +package org.elasticsearch.xpack.esql.expression.function.scalar.math; + +import java.lang.IllegalArgumentException; +import java.lang.Override; +import java.lang.String; +import org.elasticsearch.compute.data.Block; +import org.elasticsearch.compute.data.LongBlock; +import org.elasticsearch.compute.data.LongVector; +import org.elasticsearch.compute.data.Page; +import org.elasticsearch.compute.operator.DriverContext; +import org.elasticsearch.compute.operator.EvalOperator; +import org.elasticsearch.compute.operator.Warnings; +import org.elasticsearch.core.Releasables; +import org.elasticsearch.xpack.esql.core.tree.Source; + +/** + * {@link EvalOperator.ExpressionEvaluator} implementation for {@link RoundToLong}. + * This class is generated. Edit {@code EvaluatorImplementer} instead. + */ +public final class RoundToLong9Evaluator implements EvalOperator.ExpressionEvaluator { + private final Source source; + + private final EvalOperator.ExpressionEvaluator field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final long p6; + + private final long p7; + + private final long p8; + + private final DriverContext driverContext; + + private Warnings warnings; + + public RoundToLong9Evaluator(Source source, EvalOperator.ExpressionEvaluator field, long p0, + long p1, long p2, long p3, long p4, long p5, long p6, long p7, long p8, + DriverContext driverContext) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + this.driverContext = driverContext; + } + + @Override + public Block eval(Page page) { + try (LongBlock fieldBlock = (LongBlock) field.eval(page)) { + LongVector fieldVector = fieldBlock.asVector(); + if (fieldVector == null) { + return eval(page.getPositionCount(), fieldBlock); + } + return eval(page.getPositionCount(), fieldVector).asBlock(); + } + } + + public LongBlock eval(int positionCount, LongBlock fieldBlock) { + try(LongBlock.Builder result = driverContext.blockFactory().newLongBlockBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + if (fieldBlock.isNull(p)) { + result.appendNull(); + continue position; + } + if (fieldBlock.getValueCount(p) != 1) { + if (fieldBlock.getValueCount(p) > 1) { + warnings().registerException(new IllegalArgumentException("single-value function encountered multi-value")); + } + result.appendNull(); + continue position; + } + result.appendLong(RoundToLong.process(fieldBlock.getLong(fieldBlock.getFirstValueIndex(p)), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8)); + } + return result.build(); + } + } + + public LongVector eval(int positionCount, LongVector fieldVector) { + try(LongVector.FixedBuilder result = driverContext.blockFactory().newLongVectorFixedBuilder(positionCount)) { + position: for (int p = 0; p < positionCount; p++) { + result.appendLong(p, RoundToLong.process(fieldVector.getLong(p), this.p0, this.p1, this.p2, this.p3, this.p4, this.p5, this.p6, this.p7, this.p8)); + } + return result.build(); + } + } + + @Override + public String toString() { + return "RoundToLong9Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + "]"; + } + + @Override + public void close() { + Releasables.closeExpectNoException(field); + } + + private Warnings warnings() { + if (warnings == null) { + this.warnings = Warnings.createWarnings( + driverContext.warningsMode(), + source.source().getLineNumber(), + source.source().getColumnNumber(), + source.text() + ); + } + return warnings; + } + + static class Factory implements EvalOperator.ExpressionEvaluator.Factory { + private final Source source; + + private final EvalOperator.ExpressionEvaluator.Factory field; + + private final long p0; + + private final long p1; + + private final long p2; + + private final long p3; + + private final long p4; + + private final long p5; + + private final long p6; + + private final long p7; + + private final long p8; + + public Factory(Source source, EvalOperator.ExpressionEvaluator.Factory field, long p0, long p1, + long p2, long p3, long p4, long p5, long p6, long p7, long p8) { + this.source = source; + this.field = field; + this.p0 = p0; + this.p1 = p1; + this.p2 = p2; + this.p3 = p3; + this.p4 = p4; + this.p5 = p5; + this.p6 = p6; + this.p7 = p7; + this.p8 = p8; + } + + @Override + public RoundToLong9Evaluator get(DriverContext context) { + return new RoundToLong9Evaluator(source, field.get(context), p0, p1, p2, p3, p4, p5, p6, p7, p8, context); + } + + @Override + public String toString() { + return "RoundToLong9Evaluator[" + "field=" + field + ", p0=" + p0 + ", p1=" + p1 + ", p2=" + p2 + ", p3=" + p3 + ", p4=" + p4 + ", p5=" + p5 + ", p6=" + p6 + ", p7=" + p7 + ", p8=" + p8 + "]"; + } + } +} From 4af67be046ea3d2d87f59f4ef18b8e694372ba9a Mon Sep 17 00:00:00 2001 From: Fang Xing Date: Wed, 23 Jul 2025 14:36:46 -0400 Subject: [PATCH 05/11] try to fix spotless --- .../function/scalar/math/X-RoundTo.java.st | 69 +++++++++++++++++-- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st index 9f31ac21d7579..d478961eccb22 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st @@ -94,7 +94,14 @@ class RoundTo$Type$ { } @Evaluator(extraName = "5") - static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4) { + static $type$ process( + $type$ field, + @Fixed $type$ p0, + @Fixed $type$ p1, + @Fixed $type$ p2, + @Fixed $type$ p3, + @Fixed $type$ p4 + ) { if (field < p2) { if (field < p1) { return p0; @@ -111,7 +118,15 @@ class RoundTo$Type$ { } @Evaluator(extraName = "6") - static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5) { + static $type$ process( + $type$ field, + @Fixed $type$ p0, + @Fixed $type$ p1, + @Fixed $type$ p2, + @Fixed $type$ p3, + @Fixed $type$ p4, + @Fixed $type$ p5 + ) { if (field < p2) { if (field < p1) { return p0; @@ -131,7 +146,16 @@ class RoundTo$Type$ { } @Evaluator(extraName = "7") - static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @Fixed $type$ p6) { + static $type$ process( + $type$ field, + @Fixed $type$ p0, + @Fixed $type$ p1, + @Fixed $type$ p2, + @Fixed $type$ p3, + @Fixed $type$ p4, + @Fixed $type$ p5, + @Fixed $type$ p6 + ) { if (field < p3) { if (field < p1) { return p0; @@ -154,7 +178,17 @@ class RoundTo$Type$ { } @Evaluator(extraName = "8") - static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @Fixed $type$ p6, @Fixed $type$ p7) { + static $type$ process( + $type$ field, + @Fixed $type$ p0, + @Fixed $type$ p1, + @Fixed $type$ p2, + @Fixed $type$ p3, + @Fixed $type$ p4, + @Fixed $type$ p5, + @Fixed $type$ p6, + @Fixed $type$ p7 + ) { if (field < p3) { if (field < p1) { return p0; @@ -180,7 +214,18 @@ class RoundTo$Type$ { } @Evaluator(extraName = "9") - static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @Fixed $type$ p6, @Fixed $type$ p7, @Fixed $type$ p8) { + static $type$ process( + $type$ field, + @Fixed $type$ p0, + @Fixed $type$ p1, + @Fixed $type$ p2, + @Fixed $type$ p3, + @Fixed $type$ p4, + @Fixed $type$ p5, + @Fixed $type$ p6, + @Fixed $type$ p7, + @Fixed $type$ p8 + ) { if (field < p4) { if (field < p1) { return p0; @@ -208,7 +253,19 @@ class RoundTo$Type$ { return p8; } @Evaluator(extraName = "10") - static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @Fixed $type$ p6, @Fixed $type$ p7, @Fixed $type$ p8, @Fixed $type$ p9) { + static $type$ process( + $type$ field, + @Fixed $type$ p0, + @Fixed $type$ p1, + @Fixed $type$ p2, + @Fixed $type$ p3, + @Fixed $type$ p4, + @Fixed $type$ p5, + @Fixed $type$ p6, + @Fixed $type$ p7, + @Fixed $type$ p8, + @Fixed $type$ p9 + ) { if (field < p4) { if (field < p1) { return p0; From 5eb0a290bb0beddcd67a7a1072407d1431886abf Mon Sep 17 00:00:00 2001 From: Fang Xing Date: Wed, 23 Jul 2025 19:23:54 -0400 Subject: [PATCH 06/11] Try to fix spotless --- .../expression/function/scalar/math/X-RoundTo.java.st | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st index d478961eccb22..337e1bcc46a44 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st @@ -94,14 +94,7 @@ class RoundTo$Type$ { } @Evaluator(extraName = "5") - static $type$ process( - $type$ field, - @Fixed $type$ p0, - @Fixed $type$ p1, - @Fixed $type$ p2, - @Fixed $type$ p3, - @Fixed $type$ p4 - ) { + static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4) { if (field < p2) { if (field < p1) { return p0; From c1013b43145d1299371cf70b0c120b66f5ca5553 Mon Sep 17 00:00:00 2001 From: Fang Xing Date: Wed, 23 Jul 2025 21:12:34 -0400 Subject: [PATCH 07/11] exclude all files under generated-src from spotless --- x-pack/plugin/esql/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/esql/build.gradle b/x-pack/plugin/esql/build.gradle index 447ceb53489f2..a836619fa3cb1 100644 --- a/x-pack/plugin/esql/build.gradle +++ b/x-pack/plugin/esql/build.gradle @@ -297,7 +297,7 @@ pluginManager.withPlugin('com.diffplug.spotless') { targetExclude "src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseLexer*.java", "src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser*.java", "src/main/generated/**/*.java", - "src/main/generated-src/generated/**/*.java" + "src/main/generated-src/**/*.java" toggleOffOn('begin generated imports', 'end generated imports') } } From 378660cf6964b4f7f2f3772173960328f3636d34 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Thu, 24 Jul 2025 01:23:07 +0000 Subject: [PATCH 08/11] [CI] Auto commit changes from spotless --- .../function/scalar/math/RoundToDouble.java | 1 - .../function/scalar/math/RoundToInt.java | 22 ++++++++++++++++--- .../function/scalar/math/RoundToLong.java | 11 ++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java index d46a1b21f36ab..7b684820e64ca 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java @@ -245,7 +245,6 @@ static double process( } return p8; } - @Evaluator(extraName = "10") static double process( double field, diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java index fdcda60a8a3cd..f1e39f23caac8 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java @@ -111,7 +111,15 @@ static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixe } @Evaluator(extraName = "6") - static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixed int p3, @Fixed int p4, @Fixed int p5) { + static int process( + int field, + @Fixed int p0, + @Fixed int p1, + @Fixed int p2, + @Fixed int p3, + @Fixed int p4, + @Fixed int p5 + ) { if (field < p2) { if (field < p1) { return p0; @@ -131,7 +139,16 @@ static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixe } @Evaluator(extraName = "7") - static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixed int p3, @Fixed int p4, @Fixed int p5, @Fixed int p6) { + static int process( + int field, + @Fixed int p0, + @Fixed int p1, + @Fixed int p2, + @Fixed int p3, + @Fixed int p4, + @Fixed int p5, + @Fixed int p6 + ) { if (field < p3) { if (field < p1) { return p0; @@ -228,7 +245,6 @@ static int process( } return p8; } - @Evaluator(extraName = "10") static int process( int field, diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java index 208facbbd0e4b..0382a29bf504b 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java @@ -111,7 +111,15 @@ static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, } @Evaluator(extraName = "6") - static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, @Fixed long p3, @Fixed long p4, @Fixed long p5) { + static long process( + long field, + @Fixed long p0, + @Fixed long p1, + @Fixed long p2, + @Fixed long p3, + @Fixed long p4, + @Fixed long p5 + ) { if (field < p2) { if (field < p1) { return p0; @@ -237,7 +245,6 @@ static long process( } return p8; } - @Evaluator(extraName = "10") static long process( long field, From c7b5d8d1eba003d3686d9ed0164fa3142326fa5a Mon Sep 17 00:00:00 2001 From: Fang Xing <155562079+fang-xing-esql@users.noreply.github.com> Date: Thu, 24 Jul 2025 11:58:21 -0400 Subject: [PATCH 09/11] Update docs/changelog/131733.yaml --- docs/changelog/131733.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/131733.yaml diff --git a/docs/changelog/131733.yaml b/docs/changelog/131733.yaml new file mode 100644 index 0000000000000..b29e706fad609 --- /dev/null +++ b/docs/changelog/131733.yaml @@ -0,0 +1,5 @@ +pr: 131733 +summary: Replace `RoundTo` linear search evaluator with manual evaluators +area: ES|QL +type: enhancement +issues: [] From 086dd8f8e380fc47974d016d269c3f58f6968bf7 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 24 Jul 2025 14:47:23 -0400 Subject: [PATCH 10/11] fix formatter --- x-pack/plugin/esql/build.gradle | 2 +- .../function/scalar/math/RoundToDouble.java | 17 +++++++++-------- .../function/scalar/math/RoundToInt.java | 17 +++++++++-------- .../function/scalar/math/RoundToLong.java | 17 +++++++++-------- .../function/scalar/math/X-RoundTo.java.st | 17 +++++++++-------- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/x-pack/plugin/esql/build.gradle b/x-pack/plugin/esql/build.gradle index acbd1c71ba4bd..cf49e644e4313 100644 --- a/x-pack/plugin/esql/build.gradle +++ b/x-pack/plugin/esql/build.gradle @@ -323,7 +323,7 @@ pluginManager.withPlugin('com.diffplug.spotless') { targetExclude "src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseLexer*.java", "src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser*.java", "src/main/generated/**/*.java", - "src/main/generated-src/**/*.java" + "src/main/generated-src/generated/**/*.java" toggleOffOn('begin generated imports', 'end generated imports') } } diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java index 7b684820e64ca..099af021e8acb 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java @@ -112,10 +112,10 @@ static double process(double field, @Fixed double p0, @Fixed double p1, @Fixed d @Evaluator(extraName = "6") static double process( - double field, - @Fixed double p0, - @Fixed double p1, - @Fixed double p2, + double field, // hack to keep the formatter happy. + @Fixed double p0, // int is so short this should be on one line but double is not. + @Fixed double p1, // That's not compatible with the templates. + @Fixed double p2, // So we comment to make the formatter not try to change the line. @Fixed double p3, @Fixed double p4, @Fixed double p5 @@ -140,10 +140,10 @@ static double process( @Evaluator(extraName = "7") static double process( - double field, - @Fixed double p0, - @Fixed double p1, - @Fixed double p2, + double field, // hack to keep the formatter happy. + @Fixed double p0, // int is so short this should be on one line but double is not. + @Fixed double p1, // That's not compatible with the templates. + @Fixed double p2, // So we comment to make the formatter not try to change the line. @Fixed double p3, @Fixed double p4, @Fixed double p5, @@ -245,6 +245,7 @@ static double process( } return p8; } + @Evaluator(extraName = "10") static double process( double field, diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java index f1e39f23caac8..8aec02311cfb6 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java @@ -112,10 +112,10 @@ static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixe @Evaluator(extraName = "6") static int process( - int field, - @Fixed int p0, - @Fixed int p1, - @Fixed int p2, + int field, // hack to keep the formatter happy. + @Fixed int p0, // int is so short this should be on one line but double is not. + @Fixed int p1, // That's not compatible with the templates. + @Fixed int p2, // So we comment to make the formatter not try to change the line. @Fixed int p3, @Fixed int p4, @Fixed int p5 @@ -140,10 +140,10 @@ static int process( @Evaluator(extraName = "7") static int process( - int field, - @Fixed int p0, - @Fixed int p1, - @Fixed int p2, + int field, // hack to keep the formatter happy. + @Fixed int p0, // int is so short this should be on one line but double is not. + @Fixed int p1, // That's not compatible with the templates. + @Fixed int p2, // So we comment to make the formatter not try to change the line. @Fixed int p3, @Fixed int p4, @Fixed int p5, @@ -245,6 +245,7 @@ static int process( } return p8; } + @Evaluator(extraName = "10") static int process( int field, diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java index 0382a29bf504b..8ee9cb60c4c65 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java @@ -112,10 +112,10 @@ static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, @Evaluator(extraName = "6") static long process( - long field, - @Fixed long p0, - @Fixed long p1, - @Fixed long p2, + long field, // hack to keep the formatter happy. + @Fixed long p0, // int is so short this should be on one line but double is not. + @Fixed long p1, // That's not compatible with the templates. + @Fixed long p2, // So we comment to make the formatter not try to change the line. @Fixed long p3, @Fixed long p4, @Fixed long p5 @@ -140,10 +140,10 @@ static long process( @Evaluator(extraName = "7") static long process( - long field, - @Fixed long p0, - @Fixed long p1, - @Fixed long p2, + long field, // hack to keep the formatter happy. + @Fixed long p0, // int is so short this should be on one line but double is not. + @Fixed long p1, // That's not compatible with the templates. + @Fixed long p2, // So we comment to make the formatter not try to change the line. @Fixed long p3, @Fixed long p4, @Fixed long p5, @@ -245,6 +245,7 @@ static long process( } return p8; } + @Evaluator(extraName = "10") static long process( long field, diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st index 337e1bcc46a44..95b1796a4e8fb 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st @@ -112,10 +112,10 @@ class RoundTo$Type$ { @Evaluator(extraName = "6") static $type$ process( - $type$ field, - @Fixed $type$ p0, - @Fixed $type$ p1, - @Fixed $type$ p2, + $type$ field, // hack to keep the formatter happy. + @Fixed $type$ p0, // int is so short this should be on one line but double is not. + @Fixed $type$ p1, // That's not compatible with the templates. + @Fixed $type$ p2, // So we comment to make the formatter not try to change the line. @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5 @@ -140,10 +140,10 @@ class RoundTo$Type$ { @Evaluator(extraName = "7") static $type$ process( - $type$ field, - @Fixed $type$ p0, - @Fixed $type$ p1, - @Fixed $type$ p2, + $type$ field, // hack to keep the formatter happy. + @Fixed $type$ p0, // int is so short this should be on one line but double is not. + @Fixed $type$ p1, // That's not compatible with the templates. + @Fixed $type$ p2, // So we comment to make the formatter not try to change the line. @Fixed $type$ p3, @Fixed $type$ p4, @Fixed $type$ p5, @@ -245,6 +245,7 @@ class RoundTo$Type$ { } return p8; } + @Evaluator(extraName = "10") static $type$ process( $type$ field, From 728d247c33c38061babfbe95adcb135c57d6e6d1 Mon Sep 17 00:00:00 2001 From: Fang Xing Date: Thu, 24 Jul 2025 16:00:19 -0400 Subject: [PATCH 11/11] add comments to the manual binary search methods --- .../function/scalar/math/RoundToDouble.java | 18 ++++++++++++++++++ .../function/scalar/math/RoundToInt.java | 18 ++++++++++++++++++ .../function/scalar/math/RoundToLong.java | 18 ++++++++++++++++++ .../function/scalar/math/X-RoundTo.java.st | 18 ++++++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java index 099af021e8acb..9196f9abe7de1 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToDouble.java @@ -93,6 +93,9 @@ static double process(double field, @Fixed double p0, @Fixed double p1, @Fixed d return p3; } + /* + * Manual binary search for 5 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "5") static double process(double field, @Fixed double p0, @Fixed double p1, @Fixed double p2, @Fixed double p3, @Fixed double p4) { if (field < p2) { @@ -110,6 +113,9 @@ static double process(double field, @Fixed double p0, @Fixed double p1, @Fixed d return p4; } + /* + * Manual binary search for 6 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "6") static double process( double field, // hack to keep the formatter happy. @@ -138,6 +144,9 @@ static double process( return p5; } + /* + * Manual binary search for 7 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "7") static double process( double field, // hack to keep the formatter happy. @@ -170,6 +179,9 @@ static double process( return p6; } + /* + * Manual binary search for 8 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "8") static double process( double field, @@ -206,6 +218,9 @@ static double process( return p7; } + /* + * Manual binary search for 9 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "9") static double process( double field, @@ -246,6 +261,9 @@ static double process( return p8; } + /* + * Manual binary search for 10 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "10") static double process( double field, diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java index 8aec02311cfb6..0dfd93ecd2d18 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToInt.java @@ -93,6 +93,9 @@ static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixe return p3; } + /* + * Manual binary search for 5 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "5") static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixed int p3, @Fixed int p4) { if (field < p2) { @@ -110,6 +113,9 @@ static int process(int field, @Fixed int p0, @Fixed int p1, @Fixed int p2, @Fixe return p4; } + /* + * Manual binary search for 6 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "6") static int process( int field, // hack to keep the formatter happy. @@ -138,6 +144,9 @@ static int process( return p5; } + /* + * Manual binary search for 7 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "7") static int process( int field, // hack to keep the formatter happy. @@ -170,6 +179,9 @@ static int process( return p6; } + /* + * Manual binary search for 8 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "8") static int process( int field, @@ -206,6 +218,9 @@ static int process( return p7; } + /* + * Manual binary search for 9 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "9") static int process( int field, @@ -246,6 +261,9 @@ static int process( return p8; } + /* + * Manual binary search for 10 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "10") static int process( int field, diff --git a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java index 8ee9cb60c4c65..6fbd5dbd2caca 100644 --- a/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java +++ b/x-pack/plugin/esql/src/main/generated-src/org/elasticsearch/xpack/esql/expression/function/scalar/math/RoundToLong.java @@ -93,6 +93,9 @@ static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, return p3; } + /* + * Manual binary search for 5 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "5") static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, @Fixed long p3, @Fixed long p4) { if (field < p2) { @@ -110,6 +113,9 @@ static long process(long field, @Fixed long p0, @Fixed long p1, @Fixed long p2, return p4; } + /* + * Manual binary search for 6 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "6") static long process( long field, // hack to keep the formatter happy. @@ -138,6 +144,9 @@ static long process( return p5; } + /* + * Manual binary search for 7 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "7") static long process( long field, // hack to keep the formatter happy. @@ -170,6 +179,9 @@ static long process( return p6; } + /* + * Manual binary search for 8 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "8") static long process( long field, @@ -206,6 +218,9 @@ static long process( return p7; } + /* + * Manual binary search for 9 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "9") static long process( long field, @@ -246,6 +261,9 @@ static long process( return p8; } + /* + * Manual binary search for 10 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "10") static long process( long field, diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st index 95b1796a4e8fb..849d4d338a386 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math/X-RoundTo.java.st @@ -93,6 +93,9 @@ class RoundTo$Type$ { return p3; } + /* + * Manual binary search for 5 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "5") static $type$ process($type$ field, @Fixed $type$ p0, @Fixed $type$ p1, @Fixed $type$ p2, @Fixed $type$ p3, @Fixed $type$ p4) { if (field < p2) { @@ -110,6 +113,9 @@ class RoundTo$Type$ { return p4; } + /* + * Manual binary search for 6 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "6") static $type$ process( $type$ field, // hack to keep the formatter happy. @@ -138,6 +144,9 @@ class RoundTo$Type$ { return p5; } + /* + * Manual binary search for 7 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "7") static $type$ process( $type$ field, // hack to keep the formatter happy. @@ -170,6 +179,9 @@ class RoundTo$Type$ { return p6; } + /* + * Manual binary search for 8 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "8") static $type$ process( $type$ field, @@ -206,6 +218,9 @@ class RoundTo$Type$ { return p7; } + /* + * Manual binary search for 9 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "9") static $type$ process( $type$ field, @@ -246,6 +261,9 @@ class RoundTo$Type$ { return p8; } + /* + * Manual binary search for 10 rounding points, it is faster than linear search or array style binary search. + */ @Evaluator(extraName = "10") static $type$ process( $type$ field,