-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sql_lab): Add custom timestamp type for literal casting for presto timestamps #13082
Changes from 6 commits
d0d9424
30dc769
72237b3
8b41dba
593b821
91fc846
626a723
a7f0940
c206354
2feb219
862478e
7d1e104
6c69f95
1a0614f
5dee4c7
a06038b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -48,6 +48,8 @@ | |||||
Map, | ||||||
Row, | ||||||
TinyInteger, | ||||||
TimeStamp, | ||||||
Date | ||||||
) | ||||||
from superset.result_set import destringify | ||||||
from superset.sql_parse import ParsedQuery | ||||||
|
@@ -911,10 +913,19 @@ def where_latest_partition( # pylint: disable=too-many-arguments | |||||
if values is None: | ||||||
return None | ||||||
|
||||||
column_names = {column.get("name") for column in columns or []} | ||||||
column_type_by_name = { | ||||||
column.get("name") : column.get('type') for column in columns or [] | ||||||
} | ||||||
|
||||||
for col_name, value in zip(col_names, values): | ||||||
if col_name in column_names: | ||||||
query = query.where(Column(col_name) == value) | ||||||
if col_name in column_type_by_name: | ||||||
col_type = column_type_by_name.get(col_name) | ||||||
if col_type == 'TIMESTAMP': | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree the existing logic is wrong but I wonder if SQLAlchemy has a mechanism for auto-casting between the type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that would be ideal solution or getting Presto/Trino to support auto-casting. I've looked into it a bit and tried a few things but couldn't get any auto-casting. I've tried to pass in the default SQLAlchemy data types e.g. I have only done this casting for 2 Trino data types There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
query = query.where(Column(col_name, TimeStamp()) == value) | ||||||
elif col_type == 'DATE': | ||||||
query = query.where(Column(col_name, Date()) == value) | ||||||
else: | ||||||
query = query.where(Column(col_name) == value) | ||||||
return query | ||||||
|
||||||
@classmethod | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.