Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 51c54b3

Browse files
authored
fix: add get_column function for Query obj (apache#21691)
1 parent 7b66e0b commit 51c54b3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

superset/common/query_context_processor.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ def _get_timestamp_format(
266266
# Query datasource didn't support `get_column`
267267
and hasattr(datasource, "get_column")
268268
and (col := datasource.get_column(label))
269-
and col.is_dttm
269+
# todo(hugh) standardize column object in Query datasource
270+
and (col.get("is_dttm") if isinstance(col, dict) else col.is_dttm)
270271
)
271272
dttm_cols = [
272273
DateColumn(

superset/models/sql_lab.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
)
5252
from superset.sql_parse import CtasMethod, ParsedQuery, Table
5353
from superset.sqllab.limiting_factor import LimitingFactor
54-
from superset.superset_typing import ResultSetColumnType
5554
from superset.utils.core import GenericDataType, QueryStatus, user_label
5655

5756
if TYPE_CHECKING:
@@ -183,7 +182,7 @@ def sql_tables(self) -> List[Table]:
183182
return list(ParsedQuery(self.sql).tables)
184183

185184
@property
186-
def columns(self) -> List[ResultSetColumnType]:
185+
def columns(self) -> List[Dict[str, Any]]:
187186
bool_types = ("BOOL",)
188187
num_types = (
189188
"DOUBLE",
@@ -217,7 +216,7 @@ def columns(self) -> List[ResultSetColumnType]:
217216
computed_column["column_name"] = col.get("name")
218217
computed_column["groupby"] = True
219218
columns.append(computed_column)
220-
return columns # type: ignore
219+
return columns
221220

222221
@property
223222
def data(self) -> Dict[str, Any]:
@@ -288,7 +287,7 @@ def offset(self) -> int:
288287
def main_dttm_col(self) -> Optional[str]:
289288
for col in self.columns:
290289
if col.get("is_dttm"):
291-
return col.get("column_name") # type: ignore
290+
return col.get("column_name")
292291
return None
293292

294293
@property
@@ -332,6 +331,14 @@ def tracking_url(self) -> Optional[str]:
332331
def tracking_url(self, value: str) -> None:
333332
self.tracking_url_raw = value
334333

334+
def get_column(self, column_name: Optional[str]) -> Optional[Dict[str, Any]]:
335+
if not column_name:
336+
return None
337+
for col in self.columns:
338+
if col.get("column_name") == column_name:
339+
return col
340+
return None
341+
335342

336343
class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin):
337344
"""ORM model for SQL query"""

0 commit comments

Comments
 (0)