dpgaspar commented on a change in pull request #16139:
URL: https://github.com/apache/superset/pull/16139#discussion_r685255866
##########
File path: superset/utils/core.py
##########
@@ -988,28 +1007,32 @@ def zlib_decompress(blob: bytes, decode: Optional[bool]
= True) -> Union[bytes,
return decompressed.decode("utf-8") if decode else decompressed
-def to_adhoc(
- filt: Dict[str, Any], expression_type: str = "SIMPLE", clause: str =
"where"
-) -> Dict[str, Any]:
- result = {
+def simple_filter_to_adhoc(
+ filt: QueryObjectFilterClause, clause: str = "where",
Review comment:
nit: `filter_clause` instead of `filt`
##########
File path: superset/connectors/sqla/models.py
##########
@@ -303,13 +307,15 @@ def get_timestamp_expression(
pdf = self.python_date_format
is_epoch = pdf in ("epoch_s", "epoch_ms")
+ column_spec = self.db_engine_spec.get_column_spec(self.type)
+ type_ = column_spec.sqla_type if column_spec else DateTime
if not self.expression and not time_grain and not is_epoch:
- sqla_col = column(self.column_name, type_=DateTime)
+ sqla_col = column(self.column_name, type_=type_)
Review comment:
is there a test for this change?
##########
File path: superset/utils/core.py
##########
@@ -988,28 +1007,32 @@ def zlib_decompress(blob: bytes, decode: Optional[bool]
= True) -> Union[bytes,
return decompressed.decode("utf-8") if decode else decompressed
-def to_adhoc(
- filt: Dict[str, Any], expression_type: str = "SIMPLE", clause: str =
"where"
-) -> Dict[str, Any]:
- result = {
+def simple_filter_to_adhoc(
+ filt: QueryObjectFilterClause, clause: str = "where",
+) -> AdhocFilterClause:
+ result: AdhocFilterClause = {
"clause": clause.upper(),
- "expressionType": expression_type,
- "isExtra": bool(filt.get("isExtra")),
+ "expressionType": "SIMPLE",
+ "comparator": filt.get("val"),
+ "operator": filt["op"],
+ "subject": filt["col"],
}
+ if filt.get("isExtra"):
+ result["isExtra"] = True
+ result["filterOptionName"] = md5_sha_from_dict(cast(Dict[Any, Any],
result))
- if expression_type == "SIMPLE":
- result.update(
- {
- "comparator": filt.get("val"),
- "operator": filt.get("op"),
- "subject": filt.get("col"),
- }
- )
- elif expression_type == "SQL":
- result.update({"sqlExpression": filt.get(clause)})
+ return result
- deterministic_name = md5_sha_from_dict(result)
- result["filterOptionName"] = deterministic_name
+
+def form_data_to_adhoc(form_data: Dict[str, Any], clause: str) ->
AdhocFilterClause:
Review comment:
Probably for a another PR, but can `form_data` be a `TypedDict` also?
##########
File path: superset/utils/core.py
##########
@@ -189,6 +189,25 @@ class DatasourceDict(TypedDict):
id: int
+class AdhocFilterClause(TypedDict, total=False):
Review comment:
Hope someday this can be supported...
##########
File path: superset/typing.py
##########
@@ -42,7 +42,7 @@ class AdhocMetric(TypedDict):
]
DbapiDescription = Union[List[DbapiDescriptionRow], Tuple[DbapiDescriptionRow,
...]]
DbapiResult = Sequence[Union[List[Any], Tuple[Any, ...]]]
-FilterValue = Union[datetime, float, int, str]
+FilterValue = Union[bool, datetime, float, int, str]
Review comment:
is there a test for this filter value?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]