Skip to content

Commit f22648e

Browse files
committed
Add explicit test for split_kql
1 parent 0d61992 commit f22648e

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/unit_tests/sql_parse_tests.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
KustoKQLStatement,
4141
ParsedQuery,
4242
sanitize_clause,
43+
split_kql,
4344
SQLScript,
4445
SQLStatement,
4546
strip_comments_from_sql,
@@ -1962,6 +1963,7 @@ def test_extract_tables_from_jinja_sql(
19621963
== expected
19631964
)
19641965

1966+
19651967
def test_kustokqlstatement_split_query() -> None:
19661968
"""
19671969
Test the `KustoKQLStatement` split method.
@@ -2039,3 +2041,58 @@ def test_kustokqlstatement_with_set() -> None:
20392041
)
20402042
def test_kustokql_statement_split_special(kql: str, statements: int) -> None:
20412043
assert len(KustoKQLStatement.split_query(kql, "kustokql")) == statements
2044+
2045+
2046+
def test_split_kql() -> None:
2047+
"""
2048+
Test the `split_kql` function.
2049+
"""
2050+
kql = """
2051+
let totalPagesPerDay = PageViews
2052+
| summarize by Page, Day = startofday(Timestamp)
2053+
| summarize count() by Day;
2054+
let materializedScope = PageViews
2055+
| summarize by Page, Day = startofday(Timestamp);
2056+
let cachedResult = materialize(materializedScope);
2057+
cachedResult
2058+
| project Page, Day1 = Day
2059+
| join kind = inner
2060+
(
2061+
cachedResult
2062+
| project Page, Day2 = Day
2063+
)
2064+
on Page
2065+
| where Day2 > Day1
2066+
| summarize count() by Day1, Day2
2067+
| join kind = inner
2068+
totalPagesPerDay
2069+
on $left.Day1 == $right.Day
2070+
| project Day1, Day2, Percentage = count_*100.0/count_1
2071+
"""
2072+
assert split_kql(kql) == [
2073+
"""
2074+
let totalPagesPerDay = PageViews
2075+
| summarize by Page, Day = startofday(Timestamp)
2076+
| summarize count() by Day""",
2077+
"""
2078+
let materializedScope = PageViews
2079+
| summarize by Page, Day = startofday(Timestamp)""",
2080+
"""
2081+
let cachedResult = materialize(materializedScope)""",
2082+
"""
2083+
cachedResult
2084+
| project Page, Day1 = Day
2085+
| join kind = inner
2086+
(
2087+
cachedResult
2088+
| project Page, Day2 = Day
2089+
)
2090+
on Page
2091+
| where Day2 > Day1
2092+
| summarize count() by Day1, Day2
2093+
| join kind = inner
2094+
totalPagesPerDay
2095+
on $left.Day1 == $right.Day
2096+
| project Day1, Day2, Percentage = count_*100.0/count_1
2097+
""",
2098+
]

0 commit comments

Comments
 (0)