kekwan opened a new issue #13009:
URL: https://github.com/apache/superset/issues/13009


   When previewing a table in SQL Lab, a SELECT * statement is generated based 
on table data and table metadata if it contains partitions. When generating the 
SELECT * statement on a table with partitions, the table data, 'TIMESTAMP' in 
my case is not casted in the WHERE block. 
   
   ### Expected results
   
   Previewing tables with data partitions should work. The WHERE block of the 
generated SELECT * statement should talk into account casting of data types, 
particularly TIMESTAMP.
   
   ### Actual results
   
   `select_star` method calls `where_latest_partition` to generate WHERE block 
when partition exists. `where_latest_partition` is failing to CAST data types 
needed for WHERE block causing syntax error when it runs the select * statement.
   
   SQL Statement generated by `get_table_metadata` calling `select_star`. 
Columns `datetimepartition` and `etl_ts` should be casted to TIMESTAMP, not 
VARCHAR.
   
   ```
   SELECT "event_type" AS "event_type",
          "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-08 16:00:00.000'
     AND "etl_ts" = '2021-02-08 16:30:00.000'
     AND "insert_try_number" = 1
   LIMIT 100
   ```
   Syntax error from Presto due to the incorrect SQL statement
   `Presto error: Cannot apply operator: timestamp(3) = varchar(23)`
   
   #### Screenshots
   
![image](https://user-images.githubusercontent.com/19199254/107262094-fc413280-69f4-11eb-8816-af2de056338e.png)
   
   
   #### How to reproduce the bug
   
   1. Go to SQL Lab
   2. Preview Trino/Presto table with partitions and TIMESTAMP as a partition 
column.
   
   ### Environment
   
   
   - superset version: `0.37.2`
   - python version: `python 3.6`
   
   ### Checklist
   
   Make sure to follow these steps before submitting your issue - thank you!
   
   - [x] I have checked the superset logs for python stacktraces and included 
it here as text if there are any.
   - [x] I have reproduced the issue with at least the latest released version 
of superset.
   - [x] I have checked the issue tracker for the same issue and I haven't 
found one similar.
   
   


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

Reply via email to