Skip to content

Commit cf02771

Browse files
authored
Update test rounding (backport of #70890) (#70921)
When restoring SQL's test for fetching `half_floats` in master we bumped into some type conversion issues. This backports those type changes so 7.x and master line up more closely.
1 parent d571fd9 commit cf02771

File tree

1 file changed

+18
-2
lines changed
  • x-pack/plugin/sql/qa/mixed-node/src/test/java/org/elasticsearch/xpack/sql/qa/mixed_node

1 file changed

+18
-2
lines changed

x-pack/plugin/sql/qa/mixed-node/src/test/java/org/elasticsearch/xpack/sql/qa/mixed_node/SqlSearchIT.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ public void testAllTypesWithRequestToOldNodes() throws Exception {
124124
builder.append("\"geo_point_field\":{\"lat\":\"37.386483\", \"lon\":\"-122.083843\"},");
125125
fieldValues.put("geo_point_field", "POINT (-122.083843 37.386483)");
126126
builder.append("\"float_field\":" + randomFloat + ",");
127+
/*
128+
* Double.valueOf(float.toString) gets a `double` representing
129+
* the `float` that we'd get by going through json which is
130+
* base 10. just casting the `float` to a `double` will get
131+
* a lower number with a lot more trailing digits because
132+
* the cast adds *binary* 0s to the end. And those binary
133+
* 0s don't translate the same as json's decimal 0s.
134+
*/
127135
fieldValues.put("float_field", Double.valueOf(Float.valueOf(randomFloat).toString()));
128136
/*
129137
* In 7.12.x we got full float precision from half floats
@@ -134,7 +142,7 @@ public void testAllTypesWithRequestToOldNodes() throws Exception {
134142
float roundedHalfFloat = HalfFloatPoint.sortableShortToHalfFloat(HalfFloatPoint.halfFloatToSortableShort(randomFloat));
135143
builder.append("\"half_float_field\":\"" + randomFloat + "\"");
136144
if (false == halfFloatMightReturnFullFloatPrecision) {
137-
fieldValues.put("half_float_field", roundedHalfFloat);
145+
fieldValues.put("half_float_field", Double.valueOf(Float.toString(roundedHalfFloat)));
138146
}
139147
}
140148
}
@@ -171,6 +179,14 @@ public void testAllTypesWithRequestToUpgradedNodes() throws Exception {
171179
builder.append("\"geo_point_field\":{\"lat\":\"37.386483\", \"lon\":\"-122.083843\"},");
172180
fieldValues.put("geo_point_field", "POINT (-122.083843 37.386483)");
173181
builder.append("\"float_field\":" + randomFloat + ",");
182+
/*
183+
* Double.valueOf(float.toString) gets a `double` representing
184+
* the `float` that we'd get by going through json which is
185+
* base 10. just casting the `float` to a `double` will get
186+
* a lower number with a lot more trailing digits because
187+
* the cast adds *binary* 0s to the end. And those binary
188+
* 0s don't translate the same as json's decimal 0s.
189+
*/
174190
fieldValues.put("float_field", Double.valueOf(Float.valueOf(randomFloat).toString()));
175191
/*
176192
* In 7.12.x we got full float precision from half floats
@@ -181,7 +197,7 @@ public void testAllTypesWithRequestToUpgradedNodes() throws Exception {
181197
float roundedHalfFloat = HalfFloatPoint.sortableShortToHalfFloat(HalfFloatPoint.halfFloatToSortableShort(randomFloat));
182198
builder.append("\"half_float_field\":\"" + randomFloat + "\"");
183199
if (false == halfFloatMightReturnFullFloatPrecision) {
184-
fieldValues.put("half_float_field", roundedHalfFloat);
200+
fieldValues.put("half_float_field", Double.valueOf(Float.toString(roundedHalfFloat)));
185201
}
186202
}
187203
}

0 commit comments

Comments
 (0)