Skip to content

Commit

Permalink
Add comments showing deviation from the standard
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiafi committed Jan 20, 2022
1 parent 3701f92 commit e3de11f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ private DateTimeUtils() {}

public static int parseDate(String value)
{
// in order to follow the standard, we should validate the value:
// - the required format is 'YYYY-MM-DD'
// - all components should be unsigned numbers
// https://github.com/trinodb/trino/issues/10677
return toIntExact(TimeUnit.MILLISECONDS.toDays(DATE_FORMATTER.parseMillis(value)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ public void testCastRealToBoundedVarchar()
public void testCastDateToBoundedVarchar()
{
assertEvaluatedEquals("CAST(DATE '2013-02-02' AS varchar(10))", "'2013-02-02'");
// according to the SQL standard, this literal is incorrect. Year should be unsigned. https://github.com/trinodb/trino/issues/10677
assertEvaluatedEquals("CAST(DATE '-2013-02-02' AS varchar(50))", "'-2013-02-02'");

// the result value does not fit in the type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public void testDateCastFromVarchar()
public void testDateCastToVarchar()
{
assertFunction("cast(DATE '2013-02-02' AS varchar)", VARCHAR, "2013-02-02");
// according to the SQL standard, this literal is incorrect. The required format is 'YYYY-MM-DD'. https://github.com/trinodb/trino/issues/10677
assertFunction("cast(DATE '13-2-2' AS varchar)", VARCHAR, "0013-02-02");
assertFunction("cast(DATE '2013-02-02' AS varchar(50))", createVarcharType(50), "2013-02-02");
assertFunction("cast(DATE '2013-02-02' AS varchar(10))", createVarcharType(10), "2013-02-02");
Expand Down

0 comments on commit e3de11f

Please sign in to comment.