betodealmeida commented on code in PR #37890:
URL: https://github.com/apache/superset/pull/37890#discussion_r2982043507
##########
superset/db_engine_specs/kusto.py:
##########
@@ -213,3 +266,33 @@ def convert_dttm(
return f"""datetime({dttm.isoformat(timespec="microseconds")})"""
return None
+
+ @classmethod
+ def execute(
+ cls,
+ cursor: Any,
+ query: str,
+ database: "Database",
+ **kwargs: Any,
+ ) -> None:
+ """
+ Execute a KQL query, fixing ARRAY() wrappers around
+ bracket-quoted identifiers.
+
+ Example:
+ ARRAY(["age"]) -> ["age"]
+ ARRAY(["user_name"]) -> ["user_name"]
+ """
+ # Replace ARRAY(["identifier"]) with ["identifier"]
+ processed_query, num_replacements = re.subn(
Review Comment:
We already have a [tokenizer for
KQL](https://github.com/apache/superset/blob/89d1b80ce7d22c9c0a90fbc4db0455c16e896f72/superset/sql/parse.py#L977),
let's use it here instead of relying on regular expressions. Something like
this should work:
```python
from superset.sql.parse import KQLTokenType, tokenize_kql
def strip_array_brackets(kql: str) -> str:
tokens = tokenize_kql(kql)
OPENING_BRACKET = [
(KQLTokenType.WORD, "ARRAY"),
(KQLTokenType.OTHER, "("),
(KQLTokenType.OTHER, "["),
]
CLOSING_BRACKET = [(KQLTokenType.OTHER, "]"), (KQLTokenType.OTHER, ")")]
to_remove = set()
for i in range(len(tokens)):
if tokens[i : i + 3] == OPENING_BRACKET:
to_remove.add(i)
to_remove.add(i + 1)
elif tokens[i : i + 2] == CLOSING_BRACKET:
to_remove.add(i + 1)
tokens = [token for i, token in enumerate(tokens) if i not in to_remove]
return "".join(val for _, val in tokens)
```
This could be improved to ensure the number of opening brackets match the
number of closing brackets, or that we only strip them when the tokens between
them are of a certain type.
--
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]