Skip to content

Commit 7c22694

Browse files
pabloemelasticsearchmachine
andauthored
Implementing copy_sign function for ESQL (#128281)
* Implementing copy_sign function for ESQL * enforcing floating point only for CopySign operation * fixup * fix count test * fixup * test checks * [CI] Auto commit changes from spotless * casting * fix checkstyle * figured types out and set it up * pass some classes * try again * address comments * comments * fixup * fix docs --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 637c7e7 commit 7c22694

File tree

13 files changed

+841
-4
lines changed

13 files changed

+841
-4
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,3 +1842,28 @@ emp_no:integer | l1:double | l2:double
18421842
10002 | -7.23 | null
18431843
10003 | 4.0 | null
18441844
;
1845+
1846+
copySignWithMixedNumericValues
1847+
required_capability: copy_sign
1848+
1849+
ROW cs1=COPY_SIGN(10.0, -5.0), cs2=COPY_SIGN(10, 1), cs3=COPY_SIGN(1, -5.0);
1850+
1851+
cs1:double | cs2:integer | cs3:integer
1852+
-10.0 | 10 | -1
1853+
;
1854+
1855+
copySignWithMixedNumericValuesWithMV
1856+
required_capability: copy_sign
1857+
1858+
FROM employees
1859+
| EVAL cs1 = COPY_SIGN(salary, LEAST(salary_change))
1860+
| KEEP emp_no, salary, salary_change, cs1
1861+
| SORT emp_no
1862+
| LIMIT 3
1863+
;
1864+
1865+
emp_no:integer | salary:integer | salary_change:double | cs1:integer
1866+
10001 | 57305 | 1.19 | 57305
1867+
10002 | 56371 | [-7.23, 11.17] | -56371
1868+
10003 | 61805 | [12.82, 14.68] | 61805
1869+
;

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: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)