This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 317532752c feat(KustoKQL): Update KQL alchemy version and update
timegrain expressions (#32509)
317532752c is described below
commit 317532752cd34048b7d6310e32bf6b9ebf44802f
Author: Ramachandran A G <[email protected]>
AuthorDate: Wed Mar 5 17:53:47 2025 -0800
feat(KustoKQL): Update KQL alchemy version and update timegrain expressions
(#32509)
---
pyproject.toml | 2 +-
superset/db_engine_specs/kusto.py | 18 ++++++++++--------
tests/unit_tests/db_engine_specs/test_kusto.py | 24 ++++++++++++++++++++++++
3 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/pyproject.toml b/pyproject.toml
index 5074a20353..97c8252a41 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -144,7 +144,7 @@ hive = [
"thrift_sasl>=0.4.3, < 1.0.0",
]
impala = ["impyla>0.16.2, <0.17"]
-kusto = ["sqlalchemy-kusto>=2.0.0, <3"]
+kusto = ["sqlalchemy-kusto>=3.0.0, <4"]
kylin = ["kylinpy>=2.8.1, <2.9"]
mssql = ["pymssql>=2.2.8, <3"]
mysql = ["mysqlclient>=2.1.0, <3"]
diff --git a/superset/db_engine_specs/kusto.py
b/superset/db_engine_specs/kusto.py
index 56b93b2ec4..59c3b1f231 100644
--- a/superset/db_engine_specs/kusto.py
+++ b/superset/db_engine_specs/kusto.py
@@ -117,14 +117,16 @@ class KustoKqlEngineSpec(BaseEngineSpec): # pylint:
disable=abstract-method
_time_grain_expressions = {
None: "{col}",
- TimeGrain.SECOND: "{col}/ time(1s)",
- TimeGrain.MINUTE: "{col}/ time(1min)",
- TimeGrain.HOUR: "{col}/ time(1h)",
- TimeGrain.DAY: "{col}/ time(1d)",
- TimeGrain.MONTH: "datetime_diff('month', CreateDate, \
- datetime(0001-01-01 00:00:00))+1",
- TimeGrain.YEAR: "datetime_diff('year', CreateDate, \
- datetime(0001-01-01 00:00:00))+1",
+ TimeGrain.SECOND: "bin({col},1s)",
+ TimeGrain.THIRTY_SECONDS: "bin({col},30s)",
+ TimeGrain.MINUTE: "bin({col},1m)",
+ TimeGrain.FIVE_MINUTES: "bin({col},5m)",
+ TimeGrain.THIRTY_MINUTES: "bin({col},30m)",
+ TimeGrain.HOUR: "bin({col},1h)",
+ TimeGrain.DAY: "startofday({col})",
+ TimeGrain.WEEK: "startofweek({col})",
+ TimeGrain.MONTH: "startofmonth({col})",
+ TimeGrain.YEAR: "startofyear({col})",
}
type_code_map: dict[int, str] = {} # loaded from get_datatype only if
needed
diff --git a/tests/unit_tests/db_engine_specs/test_kusto.py
b/tests/unit_tests/db_engine_specs/test_kusto.py
index a0593f7e3f..e8759f38cf 100644
--- a/tests/unit_tests/db_engine_specs/test_kusto.py
+++ b/tests/unit_tests/db_engine_specs/test_kusto.py
@@ -19,7 +19,9 @@ from datetime import datetime
from typing import Optional
import pytest
+from sqlalchemy import column
+from superset.db_engine_specs.kusto import KustoKqlEngineSpec
from superset.sql.parse import SQLScript
from superset.sql_parse import ParsedQuery
from tests.unit_tests.db_engine_specs.utils import assert_convert_dttm
@@ -149,3 +151,25 @@ def test_sql_convert_dttm(
from superset.db_engine_specs.kusto import KustoSqlEngineSpec as spec #
noqa: N813
assert_convert_dttm(spec, target_type, expected_result, dttm)
+
+
[email protected](
+ "in_duration,expected_result",
+ [
+ ("PT1S", "bin(temporal,1s)"),
+ ("PT1M", "bin(temporal,1m)"),
+ ("PT5M", "bin(temporal,5m)"),
+ ("PT1H", "bin(temporal,1h)"),
+ ("P1D", "startofday(temporal)"),
+ ("P1W", "startofweek(temporal)"),
+ ("P1M", "startofmonth(temporal)"),
+ ("P1Y", "startofyear(temporal)"),
+ ],
+)
+def test_timegrain_expressions(in_duration: str, expected_result: str) -> None:
+ col = column("temporal")
+
+ actual_result = KustoKqlEngineSpec.get_timestamp_expr(
+ col=col, pdf=None, time_grain=in_duration
+ )
+ assert str(actual_result) == expected_result