Skip to content

Commit 43034d6

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

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/unit_tests/sql_parse_tests.py

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

0 commit comments

Comments
 (0)