rusackas commented on code in PR #43167:
URL: https://github.com/apache/superset/pull/43167#discussion_r3964530621


##########
tests/unit_tests/db_engine_specs/test_postgres.py:
##########
@@ -418,6 +418,44 @@ def test_get_timestamp_expr_datetime_column_not_cast() -> 
None:
     assert _compile(expr) == "DATE_TRUNC('day', event_ts)"
 
 
+def test_get_timestamp_expr_string_column_casts_to_timestamp() -> None:
+    """DB Eng Specs (postgres): temporal string columns are cast before 
truncation."""
+    col = column("event_timestamp", type_=types.String())
+    expr = spec.get_timestamp_expr(col, None, "P1D")
+    assert (
+        _compile(expr)
+        == "DATE_TRUNC('day', CAST(event_timestamp AS TIMESTAMP))"
+    )
+
+
+def test_get_timestamp_expr_string_column_without_grain_not_cast() -> None:
+    """DB Eng Specs (postgres): strings without a time grain remain 
unchanged."""
+    col = column("event_timestamp", type_=types.String())
+    expr = spec.get_timestamp_expr(col, None, None)
+    assert _compile(expr) == "event_timestamp"
+
+
+def test_get_timestamp_expr_epoch_string_column_not_cast() -> None:
+    """DB Eng Specs (postgres): epoch conversion handles strings before 
truncation."""
+    col = column("event_timestamp", type_=types.String())
+    expr = spec.get_timestamp_expr(col, "epoch_s", "P1D")
+    assert _compile(expr) == (
+        "DATE_TRUNC('day', "
+        "(timestamp 'epoch' + event_timestamp * interval '1 second'))"
+    )

Review Comment:
   Same as my note on the other thread, this locks in the existing 
`epoch_s`/`epoch_ms` behavior from the base spec, not something this PR 
changes. Not expanding scope here to fix the string-epoch arithmetic.



-- 
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]

Reply via email to