|
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, |
@@ -1962,6 +1963,7 @@ def test_extract_tables_from_jinja_sql( |
1962 | 1963 | == expected |
1963 | 1964 | ) |
1964 | 1965 |
|
| 1966 | + |
1965 | 1967 | def test_kustokqlstatement_split_query() -> None: |
1966 | 1968 | """ |
1967 | 1969 | Test the `KustoKQLStatement` split method. |
@@ -2039,3 +2041,58 @@ def test_kustokqlstatement_with_set() -> None: |
2039 | 2041 | ) |
2040 | 2042 | def test_kustokql_statement_split_special(kql: str, statements: int) -> None: |
2041 | 2043 | 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