CR comments - refactor summarize query compilation to KQL

This commit is contained in:
Ofri Kleinfeld 2022-04-11 15:45:28 +03:00
Родитель be8d1a798e
Коммит a704cd9426
1 изменённых файлов: 7 добавлений и 6 удалений

Просмотреть файл

@ -633,18 +633,19 @@ class _SummarizeQuery(Query):
return self
def _compile(self) -> KQL:
result = f"{self._compile_summarize_with_shuffle_hint()} {', '.join(a.to_kql() for a in self._assignments)}"
result = "summarize"
if self._shuffle_by_keys:
result += self._compile_shuffle_hint()
result += f' {", ".join(a.to_kql() for a in self._assignments)}'
if len(self._by_assignments) != 0 or len(self._by_columns) != 0:
result += f' by {", ".join(chain((c.kql for c in self._by_columns), (a.to_kql() for a in self._by_assignments)))}'
return KQL(result)
def _compile_summarize_with_shuffle_hint(self) -> str:
if not self._shuffle_by_keys:
return "summarize"
def _compile_shuffle_hint(self) -> str:
if len(self._shuffle_keys) == 0:
return "summarize hint.strategy = shuffle"
return " hint.strategy = shuffle"
else:
return "summarize " + " ".join([f"hint.shufflekey = {k.kql}" for k in self._shuffle_keys])
return f' {" ".join([f"hint.shufflekey = {k.kql}" for k in self._shuffle_keys])}'
class _MvExpandQuery(Query):