giftig commented on code in PR #34513:
URL: https://github.com/apache/superset/pull/34513#discussion_r2249167326


##########
tests/unit_tests/db_engine_specs/test_postgres.py:
##########
@@ -280,3 +280,18 @@ def quote_table(table: Table, dialect: Dialect) -> str:
  LIMIT :param_1
     """.strip()
     )
+
+
+def test_interval_type_mutator() -> None:
+    """
+    DB Eng Specs (postgres): Test INTERVAL type mutator
+    """
+    # Test timedelta conversion
+    td = timedelta(days=1, hours=2, minutes=30, seconds=45)
+    mutator = spec.column_type_mutators[INTERVAL]
+    assert mutator(td) == 95445.0  # Total seconds: 1*86400 + 2*3600 + 30*60 + 
45
+
+    # Test that non-timedelta values pass through unchanged
+    assert mutator("not a timedelta") == "not a timedelta"
+    assert mutator(12345) == 12345
+    assert mutator(None) is None

Review Comment:
   This technically tests the code that was added but it's not really clear why 
the mutator is needed, or if it is at all. This seems to be a rarely-used 
feature; I only see it used to create `Decimal` values in mysql.
   
   It also just converts it to a number of seconds, but that's not going to 
display in a very friendly way on the frontend; I think we'll probably want to 
preserve the `timedelta` and pass it to the frontend in a way it can understand 
that is an `INTERVAL`, so that it can be displayed as an interval but also be 
correctly used in aggregations etc.
   
   I'm not sure if there's a concept of an `INTERVAL` for other engines or not. 
It can probably be reused if there is one, but if not it may need some frontend 
work as well.



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to