Skip to content

Commit

Permalink
fix!: convert dt with isoformat sep space for better compat, trino do…
Browse files Browse the repository at this point in the history
…esnt accept T
  • Loading branch information
tobymao committed Mar 27, 2024
1 parent 0919be5 commit 163c85c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion sqlglot/expressions.py
Expand Up @@ -6980,7 +6980,9 @@ def convert(value: t.Any, copy: bool = False) -> Expression:
return HexString(this=value.hex())
if isinstance(value, datetime.datetime):
datetime_literal = Literal.string(
(value if value.tzinfo else value.replace(tzinfo=datetime.timezone.utc)).isoformat()
(value if value.tzinfo else value.replace(tzinfo=datetime.timezone.utc)).isoformat(
sep=" "
)
)
return TimeStrToTime(this=datetime_literal)
if isinstance(value, datetime.date):
Expand Down
4 changes: 2 additions & 2 deletions tests/dataframe/unit/test_column.py
Expand Up @@ -150,8 +150,8 @@ def test_between(self):
F.col("cola").between(datetime.date(2022, 1, 1), datetime.date(2022, 3, 1)).sql(),
)
self.assertEqual(
"cola BETWEEN CAST('2022-01-01T01:01:01+00:00' AS TIMESTAMP) "
"AND CAST('2022-03-01T01:01:01+00:00' AS TIMESTAMP)",
"cola BETWEEN CAST('2022-01-01 01:01:01+00:00' AS TIMESTAMP) "
"AND CAST('2022-03-01 01:01:01+00:00' AS TIMESTAMP)",
F.col("cola")
.between(datetime.datetime(2022, 1, 1, 1, 1, 1), datetime.datetime(2022, 3, 1, 1, 1, 1))
.sql(),
Expand Down
4 changes: 2 additions & 2 deletions tests/dataframe/unit/test_functions.py
Expand Up @@ -29,7 +29,7 @@ def test_lit(self):
test_date = SF.lit(datetime.date(2022, 1, 1))
self.assertEqual("CAST('2022-01-01' AS DATE)", test_date.sql())
test_datetime = SF.lit(datetime.datetime(2022, 1, 1, 1, 1, 1))
self.assertEqual("CAST('2022-01-01T01:01:01+00:00' AS TIMESTAMP)", test_datetime.sql())
self.assertEqual("CAST('2022-01-01 01:01:01+00:00' AS TIMESTAMP)", test_datetime.sql())
test_dict = SF.lit({"cola": 1, "colb": "test"})
self.assertEqual("STRUCT(1 AS cola, 'test' AS colb)", test_dict.sql())

Expand All @@ -51,7 +51,7 @@ def test_col(self):
test_date = SF.col(datetime.date(2022, 1, 1))
self.assertEqual("CAST('2022-01-01' AS DATE)", test_date.sql())
test_datetime = SF.col(datetime.datetime(2022, 1, 1, 1, 1, 1))
self.assertEqual("CAST('2022-01-01T01:01:01+00:00' AS TIMESTAMP)", test_datetime.sql())
self.assertEqual("CAST('2022-01-01 01:01:01+00:00' AS TIMESTAMP)", test_datetime.sql())
test_dict = SF.col({"cola": 1, "colb": "test"})
self.assertEqual("STRUCT(1 AS cola, 'test' AS colb)", test_dict.sql())

Expand Down
4 changes: 2 additions & 2 deletions tests/test_expressions.py
Expand Up @@ -794,11 +794,11 @@ def test_convert(self):
({"x": None}, "MAP(ARRAY('x'), ARRAY(NULL))"),
(
datetime.datetime(2022, 10, 1, 1, 1, 1, 1),
"TIME_STR_TO_TIME('2022-10-01T01:01:01.000001+00:00')",
"TIME_STR_TO_TIME('2022-10-01 01:01:01.000001+00:00')",
),
(
datetime.datetime(2022, 10, 1, 1, 1, 1, tzinfo=datetime.timezone.utc),
"TIME_STR_TO_TIME('2022-10-01T01:01:01+00:00')",
"TIME_STR_TO_TIME('2022-10-01 01:01:01+00:00')",
),
(datetime.date(2022, 10, 1), "DATE_STR_TO_DATE('2022-10-01')"),
(math.nan, "NULL"),
Expand Down

0 comments on commit 163c85c

Please sign in to comment.