nastra commented on code in PR #19279:
URL: https://github.com/apache/iceberg/pull/19279#discussion_r4797430031
##########
core/src/test/java/org/apache/iceberg/TestSingleValueParser.java:
##########
@@ -113,6 +113,60 @@ public void testValidDefaults() throws IOException {
}
}
+ @Test
+ public void testFloatAndDoubleValues() {
+ Type floatType = Types.FloatType.get();
+ assertThat(SingleValueParser.fromJson(floatType, "0")).isEqualTo(0.0f);
+ assertThat(SingleValueParser.fromJson(floatType, "-1")).isEqualTo(-1.0f);
+ assertThat(SingleValueParser.fromJson(floatType,
"2147483648")).isEqualTo(2147483648.0f);
+ assertThat(SingleValueParser.fromJson(floatType, "9223372036854775808"))
+ .isEqualTo(9223372036854775808.0f);
+ assertThat(SingleValueParser.fromJson(floatType,
"16777217")).isEqualTo(16777216.0f);
+ assertThat(SingleValueParser.fromJson(floatType,
"3.4028235e38")).isEqualTo(Float.MAX_VALUE);
+
+ Type doubleType = Types.DoubleType.get();
+ assertThat(SingleValueParser.fromJson(doubleType, "0")).isEqualTo(0.0d);
+ assertThat(SingleValueParser.fromJson(doubleType, "-1")).isEqualTo(-1.0d);
+ assertThat(SingleValueParser.fromJson(doubleType,
"2147483648")).isEqualTo(2147483648.0d);
+ assertThat(SingleValueParser.fromJson(doubleType, "9223372036854775808"))
+ .isEqualTo(9223372036854775808.0d);
+ assertThat(SingleValueParser.fromJson(doubleType, "9007199254740993"))
+ .isEqualTo(9007199254740992.0d);
+ assertThat(SingleValueParser.fromJson(doubleType, "1" +
"0".repeat(39))).isEqualTo(1.0e39d);
+
+ assertThat(SingleValueParser.toJson(floatType,
SingleValueParser.fromJson(floatType, "1")))
+ .isEqualTo("1.0");
+ assertThat(SingleValueParser.toJson(doubleType,
SingleValueParser.fromJson(doubleType, "1")))
+ .isEqualTo("1.0");
+ }
+
+ @Test
+ public void testInvalidFloatAndDouble() {
+ String[][] outOfRange = {
+ {"float", "1" + "0".repeat(39)},
+ {"float", "-1" + "0".repeat(39)},
+ {"float", "1e39"},
+ {"double", "1" + "0".repeat(400)},
+ {"double", "-1e400"},
+ {"double", "1e400"},
+ };
+ for (String[] typeAndValue : outOfRange) {
+ Type type = typeAndValue[0].equals("float") ? Types.FloatType.get() :
Types.DoubleType.get();
+ assertThatThrownBy(() -> SingleValueParser.fromJson(type,
typeAndValue[1]))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageStartingWith("Cannot parse default as a " + type + "
value")
Review Comment:
please use hasMessage here: `hasMessage("Cannot parse default as a %s value:
%s is out of range", type, typeAndValue[1])`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]