mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat(KustoKQL): Update KQL alchemy version and update timegrain expressions (#32509)
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"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
|
||||
|
||||
Reference in New Issue
Block a user