rusackas commented on code in PR #34513:
URL: https://github.com/apache/superset/pull/34513#discussion_r2801765458
##########
tests/unit_tests/db_engine_specs/test_postgres.py:
##########
@@ -280,3 +280,34 @@ 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
+
+ INTERVAL values are converted to milliseconds so users can apply
+ the built-in "DURATION" number format for human-readable display.
+ """
+ mutator = spec.column_type_mutators[INTERVAL]
+
+ # Test timedelta conversion (most common case from psycopg2)
+ # Result is in milliseconds for compatibility with DURATION formatter
+ td = timedelta(days=1, hours=2, minutes=30, seconds=45)
+ assert mutator(td) == 95445000.0 # Total ms: (1*86400 + 2*3600 + 30*60 +
45) * 1000
+
+ # Test numeric values (assumed to be seconds) are converted to milliseconds
+ assert mutator(12345) == 12345000.0
+ assert mutator(123.45) == 123450.0
+
+ # Test None returns 0 (for aggregations)
+ assert mutator(None) == 0
+
+ # Test string values pass through unchanged
+ # (PostgreSQL may return string representations in some cases)
+ assert mutator("1 day 02:30:45") == "1 day 02:30:45"
+ assert mutator("P1DT2H30M45S") == "P1DT2H30M45S" # ISO 8601 duration
+
+ # Test other types pass through unchanged
+ assert mutator([1, 2, 3]) == [1, 2, 3]
+ assert mutator({"days": 1}) == {"days": 1}
Review Comment:
Applied in fab40b6b69. Added the suggested test improvements:
**Column spec test** - Added INTERVAL to the parametrized
`test_get_column_spec` list:
```python
("INTERVAL", INTERVAL, None, GenericDataType.NUMERIC, False),
```
**Edge cases** - Added tests for:
- Zero duration: `timedelta(0)` → `0.0`
- Negative interval: `timedelta(days=-1)` → `-86400000.0`
- Bool handling: `True`/`False` → `None` (not treated as numeric)
**Integration test** - Skipped this one because PostgreSQL's `get_datatype`
method uses psycopg2 type codes (integers from `binary_types`/`string_types`)
rather than string type names like MySQL. This makes the cursor description
format difficult to mock without the actual psycopg2 type system. The unit
tests provide comprehensive coverage of the mutator behavior.
--
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]