8
8
package org .elasticsearch .xpack .sql .qa .mixed_node ;
9
9
10
10
import org .apache .http .HttpHost ;
11
+ import org .apache .lucene .document .HalfFloatPoint ;
11
12
import org .elasticsearch .Version ;
12
13
import org .elasticsearch .client .Request ;
13
14
import org .elasticsearch .client .Response ;
@@ -94,7 +95,7 @@ public void testAllTypesWithRequestToOldNodes() throws Exception {
94
95
columns -> {
95
96
columns .add (columnInfo ("geo_point_field" , "geo_point" ));
96
97
columns .add (columnInfo ("float_field" , "float" ));
97
- // Until #70653 is backported we won't assert that the half_float is returned with any kind of precision
98
+ columns . add ( columnInfo ( "half_float_field" , " half_float" ));
98
99
},
99
100
(builder , fieldValues ) -> {
100
101
Float randomFloat = randomFloat ();
@@ -113,9 +114,18 @@ public void testAllTypesWithRequestToOldNodes() throws Exception {
113
114
builder .append ("\" geo_point_field\" :{\" lat\" :\" 37.386483\" , \" lon\" :\" -122.083843\" }," );
114
115
fieldValues .put ("geo_point_field" , "POINT (-122.083843 37.386483)" );
115
116
builder .append ("\" float_field\" :" + randomFloat + "," );
117
+ /*
118
+ * Double.valueOf(float.toString) gets a `double` representing
119
+ * the `float` that we'd get by going through json which is
120
+ * base 10. just casting the `float` to a `double` will get
121
+ * a lower number with a lot more trailing digits because
122
+ * the cast adds *binary* 0s to the end. And those binary
123
+ * 0s don't translate the same as json's decimal 0s.
124
+ */
116
125
fieldValues .put ("float_field" , Double .valueOf (Float .valueOf (randomFloat ).toString ()));
117
- builder .append ("\" half_float_field\" :\" 123.456\" " );
118
- // Until #70653 is backported we won't assert that the half_float is returned with any kind of precision
126
+ float roundedHalfFloat = HalfFloatPoint .sortableShortToHalfFloat (HalfFloatPoint .halfFloatToSortableShort (randomFloat ));
127
+ builder .append ("\" half_float_field\" :\" " + randomFloat + "\" " );
128
+ fieldValues .put ("half_float_field" , Double .valueOf (Float .toString (roundedHalfFloat )));
119
129
}
120
130
}
121
131
);
@@ -127,7 +137,7 @@ public void testAllTypesWithRequestToUpgradedNodes() throws Exception {
127
137
columns -> {
128
138
columns .add (columnInfo ("geo_point_field" , "geo_point" ));
129
139
columns .add (columnInfo ("float_field" , "float" ));
130
- // Until #70653 is backported we won't assert that the half_float is returned with any kind of precision
140
+ columns . add ( columnInfo ( "half_float_field" , " half_float" ));
131
141
},
132
142
(builder , fieldValues ) -> {
133
143
Float randomFloat = randomFloat ();
@@ -143,9 +153,18 @@ public void testAllTypesWithRequestToUpgradedNodes() throws Exception {
143
153
builder .append ("\" geo_point_field\" :{\" lat\" :\" 37.386483\" , \" lon\" :\" -122.083843\" }," );
144
154
fieldValues .put ("geo_point_field" , "POINT (-122.083843 37.386483)" );
145
155
builder .append ("\" float_field\" :" + randomFloat + "," );
156
+ /*
157
+ * Double.valueOf(float.toString) gets a `double` representing
158
+ * the `float` that we'd get by going through json which is
159
+ * base 10. just casting the `float` to a `double` will get
160
+ * a lower number with a lot more trailing digits because
161
+ * the cast adds *binary* 0s to the end. And those binary
162
+ * 0s don't translate the same as json's decimal 0s.
163
+ */
146
164
fieldValues .put ("float_field" , Double .valueOf (Float .valueOf (randomFloat ).toString ()));
147
- builder .append ("\" half_float_field\" :\" 123.456\" " );
148
- // Until #70653 is backported we won't assert that the half_float is returned with any kind of precision
165
+ float roundedHalfFloat = HalfFloatPoint .sortableShortToHalfFloat (HalfFloatPoint .halfFloatToSortableShort (randomFloat ));
166
+ builder .append ("\" half_float_field\" :\" " + randomFloat + "\" " );
167
+ fieldValues .put ("half_float_field" , Double .valueOf (Float .toString (roundedHalfFloat )));
149
168
}
150
169
}
151
170
);
0 commit comments