|
40 | 40 | KustoKQLStatement, |
41 | 41 | ParsedQuery, |
42 | 42 | sanitize_clause, |
| 43 | + split_kql, |
43 | 44 | SQLScript, |
44 | 45 | SQLStatement, |
45 | 46 | strip_comments_from_sql, |
@@ -2039,3 +2040,58 @@ def test_kustokqlstatement_with_set() -> None: |
2039 | 2040 | ) |
2040 | 2041 | def test_kustokql_statement_split_special(kql: str, statements: int) -> None: |
2041 | 2042 | 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