villebro commented on a change in pull request #16139:
URL: https://github.com/apache/superset/pull/16139#discussion_r685287056



##########
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:
       The way `form_data` is evolving right now, it's actually pretty close to 
`Dict[str, Any]` as we need to make it possible to have any key-value pairs in 
there, with very few reserved keywords (`QueryContext` and `QueryObject` are 
another thing, but those are already currently well formalized by Marshmallow 
schemas). If/when we create the v2 chart data endpoint I believe we'll have 
better separation between reserved keywords (`adhoc_filter`, `columns`, 
`metrics` etc) and a separate property for storing custom controls, like 
(`series`, `rows` etc).




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

Reply via email to