Skip to content

Commit

Permalink
Do not use historic dates in SQL Server tests
Browse files Browse the repository at this point in the history
Presto JDBC (used throught Tempto) constructs `java.sql.Date` object
from millis calculated with Joda Time. For historic dates, time zone
offset information is very likely to be differing between JDK and Joda.
As a result, for a date like 0001-01-02, Presto JDBC returns
`java.sql.Date` object which (according to JDK zone information) is not
pointing at midnight of the desired date. Instead, it's some uneven
number of minuts and seconds off. Since the `java.sql.Date#equals`
compares timestamp values (not the date value the object is supposed to
represent), the test would fail.

To avoid problems like that one would use JDK in Presto JDBC
exclusively. However, even then mixing old-school classes like
`java.sql.Date` and java.time classes is likely not to solve all
problems.  This is because, even though JDK classes have single time
zone database information, they process it differently.
  • Loading branch information
findepi committed Feb 28, 2019
1 parent da5051c commit 42c3375
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private SqlServerDataTypesTableDefinition() {}
return ImmutableList.<List<Object>>of(
ImmutableList.of(Long.MIN_VALUE, Short.MIN_VALUE, Integer.MIN_VALUE, Byte.MIN_VALUE,
Double.MIN_VALUE, Float.valueOf("-3.40E+38"), "\0", "\0", "\0", "\0", "\0", "\0",
Date.valueOf("0001-01-02"), Timestamp.valueOf("1753-01-01 00:00:00.000"),
Date.valueOf("1953-01-02"), Timestamp.valueOf("1753-01-01 00:00:00.000"),
Timestamp.valueOf("0001-01-01 00:00:00.000"), Timestamp.valueOf("1900-01-01 00:00:00"),
Double.MIN_VALUE, Float.valueOf("-3.40E+38")),
ImmutableList.of(Long.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE, Byte.MAX_VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void testAllDatatypes()
.containsOnly(
row(Long.MIN_VALUE, Short.MIN_VALUE, Integer.MIN_VALUE, Byte.MIN_VALUE, Double.MIN_VALUE,
Float.valueOf("-3.40E+38"), "\0 ", "\0", "\0", "\0 ", "\0", "\0",
Date.valueOf("0001-01-02"), Timestamp.valueOf("1753-01-01 00:00:00.000"),
Date.valueOf("1953-01-02"), Timestamp.valueOf("1753-01-01 00:00:00.000"),
Timestamp.valueOf("0001-01-01 00:00:00.000"), Timestamp.valueOf("1900-01-01 00:00:00"),
Double.MIN_VALUE, Float.valueOf("-3.40E+38")),
row(Long.MAX_VALUE, Short.MAX_VALUE, Integer.MAX_VALUE, Byte.MAX_VALUE, Double.MAX_VALUE,
Expand Down

0 comments on commit 42c3375

Please sign in to comment.