You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/01/10 10:40:33 UTC

[GitHub] [superset] xneg commented on a change in pull request #17898: feat: Add support for Azure Data Explorer (Kusto) db engine spec

xneg commented on a change in pull request #17898:
URL: https://github.com/apache/superset/pull/17898#discussion_r781068057



##########
File path: tests/unit_tests/db_engine_specs/test_kusto.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=unused-argument, import-outside-toplevel, protected-access
+import pytest
+from flask.ctx import AppContext
+
+
+@pytest.mark.parametrize(
+    "sql,expected",
+    [
+        ("SELECT foo FROM tbl", True),
+        ("SHOW TABLES", False),
+        ("EXPLAIN SELECT foo FROM tbl", False),
+        ("INSERT INTO tbl (foo) VALUES (1)", False),
+    ],
+)
+def test_sql_is_readonly_query(
+    app_context: AppContext, sql: str, expected: bool
+) -> None:
+    """
+    Make sure that SQL dialect consider only SELECT statements as read-only
+    """
+
+    from superset.db_engine_specs.kusto import KustoSqlEngineSpec
+    from superset.sql_parse import ParsedQuery
+
+    parsed_query = ParsedQuery(sql)
+    is_readonly = KustoSqlEngineSpec.is_readonly_query(parsed_query)
+
+    assert expected == is_readonly
+
+
+@pytest.mark.parametrize(
+    "kql,expected",
+    [
+        ("tbl | limit 100", True),
+        ("let foo = 1; tbl | where bar == foo", True),
+        (".show tables", False),
+    ],
+)
+def test_kql_is_select_query(app_context: AppContext, kql: str, expected: bool) -> None:
+    """
+    Make sure that KQL dialect consider only statements that do not start with "." (dot)
+    as a SELECT statements
+    """
+
+    from superset.db_engine_specs.kusto import KustoKqlEngineSpec
+    from superset.sql_parse import ParsedQuery
+
+    parsed_query = ParsedQuery(kql)
+    is_select = KustoKqlEngineSpec.is_readonly_query(parsed_query)
+
+    assert expected == is_select
+
+
+@pytest.mark.parametrize(
+    "kql,expected",
+    [
+        ("tbl | limit 100", True),
+        ("let foo = 1; tbl | where bar == foo", True),
+        (".show tables", False),

Review comment:
       Your remark is valuable. Thank you. We will add more specific code.




-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org