diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py index d8109e1a301..baea622d92e 100644 --- a/superset/db_engine_specs/presto.py +++ b/superset/db_engine_specs/presto.py @@ -920,6 +920,19 @@ class PrestoEngineSpec(PrestoBaseEngineSpec): ], } + @classmethod + def convert_dttm( + cls, target_type: str, dttm: datetime, db_extra: dict[str, Any] | None = None + ) -> str | None: + sqla_type = cls.get_sqla_column_type(target_type) + + if isinstance(sqla_type, types.Date): + return f"DATE '{dttm.date().isoformat()}'" + if isinstance(sqla_type, types.TIMESTAMP): + return f"""TIMESTAMP '{dttm.isoformat(timespec="milliseconds", sep=" ")}'""" + + return None + custom_errors: dict[Pattern[str], tuple[str, SupersetErrorType, dict[str, Any]]] = { COLUMN_DOES_NOT_EXIST_REGEX: ( __( diff --git a/tests/unit_tests/db_engine_specs/test_presto.py b/tests/unit_tests/db_engine_specs/test_presto.py index d73b46f861d..8dd31a4f9c9 100644 --- a/tests/unit_tests/db_engine_specs/test_presto.py +++ b/tests/unit_tests/db_engine_specs/test_presto.py @@ -42,17 +42,17 @@ from tests.unit_tests.db_engine_specs.utils import ( ( "TIMESTAMP", datetime(2022, 1, 1, 1, 23, 45, 600000), - "TIMESTAMP '2022-01-01 01:23:45.600000'", + "TIMESTAMP '2022-01-01 01:23:45.600'", ), ( "TIMESTAMP WITH TIME ZONE", datetime(2022, 1, 1, 1, 23, 45, 600000), - "TIMESTAMP '2022-01-01 01:23:45.600000'", + "TIMESTAMP '2022-01-01 01:23:45.600'", ), ( "TIMESTAMP WITH TIME ZONE", datetime(2022, 1, 1, 1, 23, 45, 600000, tzinfo=pytz.UTC), - "TIMESTAMP '2022-01-01 01:23:45.600000+00:00'", + "TIMESTAMP '2022-01-01 01:23:45.600+00:00'", ), ], )