Skip to content

Commit e3a5a98

Browse files
committed
test checks
1 parent 095210c commit e3a5a98

File tree

2 files changed

+60
-23
lines changed
  • x-pack/plugin/esql
    • qa/testFixtures/src/main/resources
    • src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/math

2 files changed

+60
-23
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,13 +1844,26 @@ emp_no:integer | l1:double | l2:double
18441844
;
18451845

18461846
copySignWithMixedNumericValues
1847+
required_capability: mixed_numeric_types_in_case_copy_sign
1848+
1849+
ROW cs1=COPY_SIGN(10.0, -5.0), cs2=COPY_SIGN(10.0, null);
1850+
1851+
cs1:double | cs2:double
1852+
-5.0 | null
1853+
;
1854+
1855+
copySignWithMixedNumericValuesWithMV
18471856
required_capability: mixed_numeric_types_in_case_greatest_least
18481857

1849-
ROW a = 1.0, b = -2.0
1850-
| EVAL c = copy_sign(a, b)
1851-
| EVAL d = copy_sign(b, a)
1858+
FROM employees
1859+
| EVAL cs1 = COPY_SIGN(salary, salary_change)
1860+
| KEEP emp_no, salary, salary_change, cs1
1861+
| SORT emp_no
1862+
| LIMIT 3
18521863
;
18531864

1854-
a:double | b:double | c:double | d:double
1855-
1.0 | -2.0 | -1.0 | 2.0
1865+
emp_no:integer | salary:long | salary_change:double | cs1:double
1866+
10001 | 57305 | 1.19 | 57305
1867+
10002 | 56371 | -7.23 | -56371
1868+
10003 | 61805 | 4.0 | 61805
18561869
;

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

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public CopySign(
6565
Source source,
6666
@Param(
6767
name = "magnitude",
68-
type = { "double", "float" },
68+
type = { "double", "float", "integer", "long" },
6969
description = "The expression providing the magnitude of the result. Must be a numeric type."
7070
) Expression magnitude,
7171
@Param(
7272
name = "sign",
73-
type = { "double", "float" },
73+
type = { "double", "float", "integer", "long" },
7474
description = "The expression providing the sign of the result. Must be a numeric type."
7575
) Expression sign
7676
) {
@@ -122,24 +122,31 @@ public TypeResolution resolveType() {
122122
}
123123
var magnitude = children().get(0);
124124
var sign = children().get(1);
125-
if (magnitude.dataType().isNumeric() == false || magnitude.dataType().isRationalNumber() == false) {
126-
return new TypeResolution("Magnitude must be a float or double type");
125+
if (magnitude.dataType().isNumeric() == false) {
126+
return new TypeResolution("Magnitude must be a numeric type");
127127
}
128-
if (sign.dataType().isNumeric() == false || sign.dataType().isRationalNumber() == false) {
129-
return new TypeResolution("Sign must be a float or double type");
128+
if (sign.dataType().isNumeric() == false) {
129+
return new TypeResolution("Sign must be a numeric type");
130130
}
131-
var commonType = EsqlDataTypeConverter.commonType(magnitude.dataType(), sign.dataType());
132-
TypeResolution resolution = TypeResolutions.isType(
133-
magnitude,
134-
t -> t == commonType,
135-
sourceText(),
136-
TypeResolutions.ParamOrdinal.fromIndex(1),
137-
magnitude.dataType().typeName()
138-
);
139-
if (resolution.unresolved()) {
140-
return resolution;
141-
}
142-
dataType = commonType;
131+
dataType = EsqlDataTypeConverter.commonType(magnitude.dataType(), sign.dataType());
132+
// TypeResolution resolution = TypeResolutions.isType(
133+
// magnitude,
134+
// t -> t == commonType,
135+
// sourceText(),
136+
// TypeResolutions.ParamOrdinal.fromIndex(1),
137+
// magnitude.dataType().typeName()
138+
// );
139+
// if (resolution.unresolved()) {
140+
// throw new EsqlIllegalArgumentException(
141+
// "Magnitude [{}] is not compatible with sign [{}] for function [{}] - common type is [{}]",
142+
// magnitude.dataType(),
143+
// sign.dataType(),
144+
// NAME
145+
// ,commonType
146+
// );
147+
//// return resolution;
148+
// }
149+
// dataType = commonType;
143150
return TypeResolution.TYPE_RESOLVED;
144151
}
145152

@@ -168,4 +175,21 @@ static float processFloat(float magnitude, float sign) {
168175
static double processDouble(double magnitude, double sign) {
169176
return Math.copySign(magnitude, sign);
170177
}
178+
179+
@Evaluator(extraName = "Long")
180+
static long processLong(long magnitude, long sign) {
181+
if (sign < 0) {
182+
return -Math.abs(magnitude);
183+
} else {
184+
return Math.abs(magnitude);
185+
}
186+
}
187+
@Evaluator(extraName = "Integer")
188+
static int processInteger(int magnitude, int sign) {
189+
if (sign < 0) {
190+
return -Math.abs(magnitude);
191+
} else {
192+
return Math.abs(magnitude);
193+
}
194+
}
171195
}

0 commit comments

Comments
 (0)