-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run selected tests with Java 19 #15709
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,7 +318,9 @@ public void testArrayToJson() | |
assertThat(assertions.expression("CAST(a AS JSON)") | ||
.binding("a", "ARRAY[3.14E0, 1e-323, 1e308, nan(), infinity(), -infinity(), null]")) | ||
.hasType(JSON) | ||
.isEqualTo("[3.14,1.0E-323,1.0E308,\"NaN\",\"Infinity\",\"-Infinity\",null]"); | ||
.isEqualTo(Runtime.version().feature() >= 19 | ||
? "[3.14,9.9E-324,1.0E308,\"NaN\",\"Infinity\",\"-Infinity\",null]" | ||
: "[3.14,1.0E-323,1.0E308,\"NaN\",\"Infinity\",\"-Infinity\",null]"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double a = 1.0E-323;
double b = 9.9E-324;
System.out.println(a == b); // true in both Java 17 and 19. I.e. same value, different representation. |
||
|
||
assertThat(assertions.expression("CAST(a AS JSON)") | ||
.binding("a", "ARRAY[DECIMAL '3.14', null]")) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,7 +267,9 @@ public void testDoubleToShortDecimalCasts() | |
assertDecimalFunction("CAST(DOUBLE '-1234567890.0' AS DECIMAL(20,10))", decimal("-1234567890.0000000000", createDecimalType(20, 10))); | ||
assertDecimalFunction("CAST(DOUBLE '1234567890.0' AS DECIMAL(30,20))", decimal("1234567890.00000000000000000000", createDecimalType(30, 20))); | ||
assertDecimalFunction("CAST(DOUBLE '-1234567890.0' AS DECIMAL(30,20))", decimal("-1234567890.00000000000000000000", createDecimalType(30, 20))); | ||
assertDecimalFunction("CAST(DOUBLE '123456789123456784' AS DECIMAL(18,0))", decimal("123456789123456784", createDecimalType(18))); | ||
assertDecimalFunction("CAST(DOUBLE '123456789123456784' AS DECIMAL(18,0))", Runtime.version().feature() >= 19 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a bug somewhere since the resulting numbers are different. If the problem is that the input value doesn't have a precise representation, then we should change the test to have one that does. Ideally, we shouldn't be gating all tests based on the version of the runtime. It makes it harder to reason about correctness. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In any case, it's a behavior change. For same input, same expression Trino on Java 19 produces different results. I am grateful to the test author for writing this test, otherwise I wouldn't know the behavior changed.
If the results depend on runtime version, then it's a necessity.
Agreed! OTOH it's temporary. Once we move to 19+ as required runtime, we will remove the conditionality here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If we call it a bug, it would be a correctness bug, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW here are some details double input = 123456789123456784d;
// 17: "17"
// 18: "18"
// 19: "19"
System.out.println(Runtime.version().feature());
// This is equivalent to part of io.trino.spi.type.DecimalConversions#internalDoubleToLongDecimal
// 17: "123456789123456784000000000000000000"
// 18: "123456789123456784000000000000000000"
// 19: "123456789123456780000000000000000000"
System.out.println(BigDecimal.valueOf(input).setScale(18, HALF_UP).unscaledValue());
// Some more details on the above expression:
// 17: "123456789123456784"
// 18: "123456789123456784"
// 19: "1.2345678912345678E+17"
System.out.println(BigDecimal.valueOf(input));
// java.math.BigDecimal.valueOf(double) uses Double.toString (in Java 17, 18 and 19)
// 17: "1.23456789123456784E17"
// 18: "1.23456789123456784E17"
// 19: "1.2345678912345678E17"
System.out.println(Double.toString(input)); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this https://bugs.openjdk.org/browse/JDK-4511638 ? This is considered a bug in JDK, fixed in 19 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is expected for Double/Float.toString to have a different ("more" correct) representation in the 19 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @wendigo for the pointer! |
||
? decimal("123456789123456780", createDecimalType(18)) | ||
: decimal("123456789123456784", createDecimalType(18))); | ||
assertDecimalFunction("CAST(DOUBLE '123456789.123456790' AS DECIMAL(18,9))", decimal("123456789.123456790", createDecimalType(18, 9))); | ||
|
||
// test rounding | ||
|
@@ -367,18 +369,42 @@ public void testFloatToDecimalCasts() | |
assertDecimalFunction("CAST(REAL '1000' AS DECIMAL(4,0))", decimal("1000", createDecimalType(4))); | ||
assertDecimalFunction("CAST(REAL '1000.01' AS DECIMAL(7,2))", decimal("01000.01", createDecimalType(7, 2))); | ||
assertDecimalFunction("CAST(REAL '-234.0' AS DECIMAL(3,0))", decimal("-234", createDecimalType(3))); | ||
assertDecimalFunction("CAST(REAL '12345678400000000' AS DECIMAL(17,0))", decimal("12345678400000000", createDecimalType(17))); | ||
assertDecimalFunction("CAST(REAL '-12345678400000000' AS DECIMAL(17,0))", decimal("-12345678400000000", createDecimalType(17))); | ||
assertDecimalFunction("CAST(REAL '1234567940' AS DECIMAL(20,10))", decimal("1234567940.0000000000", createDecimalType(20, 10))); | ||
assertDecimalFunction("CAST(REAL '-1234567940' AS DECIMAL(20,10))", decimal("-1234567940.0000000000", createDecimalType(20, 10))); | ||
assertDecimalFunction("CAST(REAL '1234567940' AS DECIMAL(30,20))", decimal("1234567940.00000000000000000000", createDecimalType(30, 20))); | ||
assertDecimalFunction("CAST(REAL '-1234567940' AS DECIMAL(30,20))", decimal("-1234567940.00000000000000000000", createDecimalType(30, 20))); | ||
assertDecimalFunction("CAST(REAL '123456790519087104' AS DECIMAL(18,0))", decimal("123456791000000000", createDecimalType(18))); | ||
assertDecimalFunction("CAST(REAL '-123456790519087104' AS DECIMAL(18,0))", decimal("-123456791000000000", createDecimalType(18))); | ||
assertDecimalFunction("CAST(REAL '123456790519087104' AS DECIMAL(20,2))", decimal("123456791000000000.00", createDecimalType(20, 2))); | ||
assertDecimalFunction("CAST(REAL '-123456790519087104' AS DECIMAL(20,2))", decimal("-123456791000000000.00", createDecimalType(20, 2))); | ||
assertDecimalFunction("CAST(REAL '1234567905190871' AS DECIMAL(18,2))", decimal("1234567950000000.00", createDecimalType(18, 2))); | ||
assertDecimalFunction("CAST(REAL '-1234567905190871' AS DECIMAL(18,2))", decimal("-1234567950000000.00", createDecimalType(18, 2))); | ||
assertDecimalFunction("CAST(REAL '12345678400000000' AS DECIMAL(17,0))", Runtime.version().feature() >= 19 | ||
? decimal("12345678000000000", createDecimalType(17)) | ||
: decimal("12345678400000000", createDecimalType(17))); | ||
assertDecimalFunction("CAST(REAL '-12345678400000000' AS DECIMAL(17,0))", Runtime.version().feature() >= 19 | ||
? decimal("-12345678000000000", createDecimalType(17)) | ||
: decimal("-12345678400000000", createDecimalType(17))); | ||
assertDecimalFunction("CAST(REAL '1234567940' AS DECIMAL(20,10))", Runtime.version().feature() >= 19 | ||
? decimal("1234568000.0000000000", createDecimalType(20, 10)) | ||
: decimal("1234567940.0000000000", createDecimalType(20, 10))); | ||
assertDecimalFunction("CAST(REAL '-1234567940' AS DECIMAL(20,10))", Runtime.version().feature() >= 19 | ||
? decimal("-1234568000.0000000000", createDecimalType(20, 10)) | ||
: decimal("-1234567940.0000000000", createDecimalType(20, 10))); | ||
assertDecimalFunction("CAST(REAL '1234567940' AS DECIMAL(30,20))", Runtime.version().feature() >= 19 | ||
? decimal("1234568000.00000000000000000000", createDecimalType(30, 20)) | ||
: decimal("1234567940.00000000000000000000", createDecimalType(30, 20))); | ||
assertDecimalFunction("CAST(REAL '-1234567940' AS DECIMAL(30,20))", Runtime.version().feature() >= 19 | ||
? decimal("-1234568000.00000000000000000000", createDecimalType(30, 20)) | ||
: decimal("-1234567940.00000000000000000000", createDecimalType(30, 20))); | ||
assertDecimalFunction("CAST(REAL '123456790519087104' AS DECIMAL(18,0))", Runtime.version().feature() >= 19 | ||
? decimal("123456790000000000", createDecimalType(18)) | ||
: decimal("123456791000000000", createDecimalType(18))); | ||
assertDecimalFunction("CAST(REAL '-123456790519087104' AS DECIMAL(18,0))", Runtime.version().feature() >= 19 | ||
? decimal("-123456790000000000", createDecimalType(18)) | ||
: decimal("-123456791000000000", createDecimalType(18))); | ||
assertDecimalFunction("CAST(REAL '123456790519087104' AS DECIMAL(20,2))", Runtime.version().feature() >= 19 | ||
? decimal("123456790000000000.00", createDecimalType(20, 2)) | ||
: decimal("123456791000000000.00", createDecimalType(20, 2))); | ||
assertDecimalFunction("CAST(REAL '-123456790519087104' AS DECIMAL(20,2))", Runtime.version().feature() >= 19 | ||
? decimal("-123456790000000000.00", createDecimalType(20, 2)) | ||
: decimal("-123456791000000000.00", createDecimalType(20, 2))); | ||
assertDecimalFunction("CAST(REAL '1234567905190871' AS DECIMAL(18,2))", Runtime.version().feature() >= 19 | ||
? decimal("1234568000000000.00", createDecimalType(18, 2)) | ||
: decimal("1234567950000000.00", createDecimalType(18, 2))); | ||
assertDecimalFunction("CAST(REAL '-1234567905190871' AS DECIMAL(18,2))", Runtime.version().feature() >= 19 | ||
? decimal("-1234568000000000.00", createDecimalType(18, 2)) | ||
: decimal("-1234567950000000.00", createDecimalType(18, 2))); | ||
assertDecimalFunction("CAST(REAL '1456213.432632456' AS DECIMAL(18,9))", decimal("001456213.400000000", createDecimalType(18, 9))); | ||
|
||
// test roundtrip | ||
|
@@ -390,7 +416,9 @@ public void testFloatToDecimalCasts() | |
assertInvalidCast("CAST(REAL '234.0' AS DECIMAL(2,0))", "Cannot cast REAL '234.0' to DECIMAL(2, 0)"); | ||
assertInvalidCast("CAST(REAL '1000.01' AS DECIMAL(5,2))", "Cannot cast REAL '1000.01' to DECIMAL(5, 2)"); | ||
assertInvalidCast("CAST(REAL '-234.0' AS DECIMAL(2,0))", "Cannot cast REAL '-234.0' to DECIMAL(2, 0)"); | ||
assertInvalidCast("CAST(REAL '98765430784.0' AS DECIMAL(20, 10))", "Cannot cast REAL '9.8765431E10' to DECIMAL(20, 10)"); | ||
assertInvalidCast("CAST(REAL '98765430784.0' AS DECIMAL(20, 10))", Runtime.version().feature() >= 19 | ||
? "Cannot cast REAL '9.876543E10' to DECIMAL(20, 10)" | ||
: "Cannot cast REAL '9.8765431E10' to DECIMAL(20, 10)"); | ||
|
||
assertInvalidCast("CAST(CAST(nan() as REAL) AS DECIMAL(10,5))", "Cannot cast REAL 'NaN' to DECIMAL(10, 5)"); | ||
assertInvalidCast("CAST(CAST(infinity() as REAL) AS DECIMAL(10,1))", "Cannot cast REAL 'Infinity' to DECIMAL(10, 1)"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @nineinchnick