Skip to content

Commit 7c63288

Browse files
committed
Implementing copy_sign function for ESQL
1 parent f0d7ec4 commit 7c63288

File tree

8 files changed

+487
-2
lines changed

8 files changed

+487
-2
lines changed

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/Methods.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
import static org.elasticsearch.compute.gen.Types.DOUBLE_VECTOR;
3939
import static org.elasticsearch.compute.gen.Types.DOUBLE_VECTOR_BUILDER;
4040
import static org.elasticsearch.compute.gen.Types.DOUBLE_VECTOR_FIXED_BUILDER;
41+
import static org.elasticsearch.compute.gen.Types.FLOAT_BLOCK_BUILDER;
42+
import static org.elasticsearch.compute.gen.Types.FLOAT_VECTOR_BUILDER;
43+
import static org.elasticsearch.compute.gen.Types.FLOAT_VECTOR_FIXED_BUILDER;
4144
import static org.elasticsearch.compute.gen.Types.INT_BLOCK;
4245
import static org.elasticsearch.compute.gen.Types.INT_BLOCK_BUILDER;
4346
import static org.elasticsearch.compute.gen.Types.INT_VECTOR;
@@ -216,6 +219,9 @@ static String appendMethod(TypeName t) {
216219
if (t.equals(TypeName.DOUBLE) || t.equals(DOUBLE_BLOCK) || t.equals(DOUBLE_VECTOR)) {
217220
return "appendDouble";
218221
}
222+
if (t.equals(TypeName.FLOAT) || t.equals(FLOAT_BLOCK_BUILDER)) {
223+
return "appendFloat";
224+
}
219225
throw new IllegalArgumentException("unknown append method for [" + t + "]");
220226
}
221227

@@ -266,6 +272,15 @@ static String buildFromFactory(TypeName t) {
266272
if (t.equals(DOUBLE_VECTOR_FIXED_BUILDER)) {
267273
return "newDoubleVectorFixedBuilder";
268274
}
275+
if (t.equals(FLOAT_BLOCK_BUILDER)) {
276+
return "newFloatBlockBuilder";
277+
}
278+
if (t.equals(FLOAT_VECTOR_BUILDER)) {
279+
return "newFloatVectorBuilder";
280+
}
281+
if (t.equals(FLOAT_VECTOR_FIXED_BUILDER)) {
282+
return "newFloatVectorFixedBuilder";
283+
}
269284
throw new IllegalArgumentException("unknown build method for [" + t + "]");
270285
}
271286

@@ -289,6 +304,9 @@ static String getMethod(TypeName elementType) {
289304
if (elementType.equals(TypeName.DOUBLE)) {
290305
return "getDouble";
291306
}
307+
if (elementType.equals(TypeName.FLOAT)) {
308+
return "getFloat";
309+
}
292310
throw new IllegalArgumentException("unknown get method for [" + elementType + "]");
293311
}
294312

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/Types.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ static TypeName elementType(TypeName t) {
252252
if (t.equals(DOUBLE_BLOCK) || t.equals(DOUBLE_VECTOR) || t.equals(DOUBLE_BLOCK_BUILDER)) {
253253
return TypeName.DOUBLE;
254254
}
255+
if (t.equals(FLOAT_BLOCK) || t.equals(FLOAT_VECTOR) || t.equals(FLOAT_BLOCK_BUILDER)) {
256+
return TypeName.FLOAT;
257+
}
255258
throw new IllegalArgumentException("unknown element type for [" + t + "]");
256259
}
257260

x-pack/plugin/esql/qa/testFixtures/src/main/resources/math.csv-spec

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,3 +1702,13 @@ emp_no:integer | l1:double | l2:double
17021702
10002 | -7.23 | null
17031703
10003 | 4.0 | null
17041704
;
1705+
1706+
copySignWithMixedNumericValues
1707+
ROW a = 1.0, b = -2.0
1708+
| EVAL c = COPY_SIGN(a, b)
1709+
| EVAL d = COPY_SIGN(b, a)
1710+
;
1711+
1712+
a:double | b:double | c:double | d:double
1713+
1.0 | -2.0 | -1.0 | 2.0
1714+
;

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/CopySignDoubleEvaluator.java

Lines changed: 147 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/math/CopySignFloatEvaluator.java

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import org.elasticsearch.xpack.esql.expression.function.scalar.math.Atan2;
9090
import org.elasticsearch.xpack.esql.expression.function.scalar.math.Cbrt;
9191
import org.elasticsearch.xpack.esql.expression.function.scalar.math.Ceil;
92+
import org.elasticsearch.xpack.esql.expression.function.scalar.math.CopySign;
9293
import org.elasticsearch.xpack.esql.expression.function.scalar.math.Cos;
9394
import org.elasticsearch.xpack.esql.expression.function.scalar.math.Cosh;
9495
import org.elasticsearch.xpack.esql.expression.function.scalar.math.E;
@@ -318,6 +319,7 @@ private static FunctionDefinition[][] functions() {
318319
def(Exp.class, Exp::new, "exp"),
319320
def(Floor.class, Floor::new, "floor"),
320321
def(Greatest.class, Greatest::new, "greatest"),
322+
def(CopySign.class, CopySign::new, "copy_sign"),
321323
def(Hypot.class, Hypot::new, "hypot"),
322324
def(Log.class, Log::new, "log"),
323325
def(Log10.class, Log10::new, "log10"),

0 commit comments

Comments
 (0)