kekwan opened a new pull request #13082: URL: https://github.com/apache/superset/pull/13082
### SUMMARY <!--- Describe the change below, including rationale and design decisions --> Described in detail in: https://github.com/apache/superset/issues/13009 but described here again just for clarity. When previewing a table in SQL Lab, a `SELECT *` statement is generated based on table data and metadata. This particular bug occur whens previewing tables with `TIMESTAMP` partition for Presto/Trino data sources. Unlike some other databases, Presto doesn't automatically convert between varchars and other types. In particular, `TIMESTAMP` needs to be explicitly casted. The simplest way is to use the type constructor `TIMESTAMP` before the value. Therefore, `where_latest_partition` in `presto.py` needs to cast the `TIMESTAMP` when it generates the `WHERE` block in the preview table statement. Accomplish this by creating new SQLAlchemy Type which subclasses [TypeDecorator](https://docs.sqlalchemy.org/en/13/core/custom_types.html#sqlalchemy.types.TypeDecorator) adding additional functionality to existing [TIMESTAMP](https://docs.sqlalchemy.org/en/13/core/type_basics.html#sqlalchemy.types.TIMESTAMP) type. Invalid selectStar syntax (generated by `/<int:pk>/table/<table_name>/<schema_name>/` -> `get_table_metadata` -> `select_star` -> `where_latest_partition`) ``` presto:events> SELECT "event_type" AS "event_type", -> "functional_domain" AS "functional_domain", -> "falcon_instance" AS "falcon_instance", -> "trace_id" AS "trace_id", -> "tenant" AS "tenant", -> "core_tenant" AS "core_tenant", -> "event_timestamp" AS "event_timestamp", -> "table_id" AS "table_id", -> "dtr_workspace_id" AS "dtr_workspace_id", -> "connectors" AS "connectors", -> "table_type" AS "table_type", -> "row_count" AS "row_count", -> "field_count" AS "field_count", -> "partition_count" AS "partition_count", -> "data_size_bytes" AS "data_size_bytes", -> "datetimepartition" AS "datetimepartition", -> "etl_ts" AS "etl_ts", -> "insert_try_number" AS "insert_try_number" -> FROM "events"."data_tables" -> WHERE "datetimepartition" = '2021-02-11 18:00:00.000' -> AND "etl_ts" = '2021-02-11 18:50:00.000' -> AND "insert_try_number" = 1 -> LIMIT 100; Query 20210211_191554_05354_4nnfj failed: line 20:27: Cannot apply operator: timestamp(3) = varchar(23) ``` Proper syntax ``` presto:events> SELECT "event_type" AS "event_type", -> "functional_domain" AS "functional_domain", -> "falcon_instance" AS "falcon_instance", -> "trace_id" AS "trace_id", -> "tenant" AS "tenant", -> "core_tenant" AS "core_tenant", -> "event_timestamp" AS "event_timestamp", -> "table_id" AS "table_id", -> "dtr_workspace_id" AS "dtr_workspace_id", -> "connectors" AS "connectors", -> "table_type" AS "table_type", -> "row_count" AS "row_count", -> "field_count" AS "field_count", -> "partition_count" AS "partition_count", -> "data_size_bytes" AS "data_size_bytes", -> "datetimepartition" AS "datetimepartition", -> "etl_ts" AS "etl_ts", -> "insert_try_number" AS "insert_try_number" -> FROM "events"."data_tables" -> WHERE "datetimepartition" = TIMESTAMP '2021-02-11 18:00:00.000' -> AND "etl_ts" = TIMESTAMP '2021-02-11 18:50:00.000' -> AND "insert_try_number" = 1 -> LIMIT 100 ``` ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF <!--- Skip this if not applicable --> Before  After  ### TEST PLAN <!--- What steps should be taken to verify the changes --> ### ADDITIONAL INFORMATION <!--- Check any relevant boxes with "x" --> <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> - [X] Has associated issue: https://github.com/apache/superset/issues/13009 - [ ] Changes UI - [ ] Requires DB Migration. - [ ] Confirm DB Migration upgrade and downgrade tested. - [ ] Introduces new feature or API - [ ] Removes existing feature or API ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
