diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index 153d3bf..01fc7a9 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -2,5 +2,14 @@ \ No newline at end of file diff --git a/tables.py b/tables.py new file mode 100644 index 0000000..107a873 --- /dev/null +++ b/tables.py @@ -0,0 +1,44 @@ +from typing import Sequence + +# noinspection PyProtectedMember +from azure.kusto.data._response import KustoResponseDataSet +from azure.kusto.data.request import KustoClient + +from query import Query + + +class BaseTable: + client: KustoClient + database: str + + def __init__(self, client: KustoClient, database: str) -> None: + self.client = client + self.database = database + + def execute(self, query: Query) -> KustoResponseDataSet: + raise NotImplementedError() + + +class SingleTable(BaseTable): + table: str + + def __init__(self, client: KustoClient, database: str, table: str) -> None: + super().__init__(client, database) + self.table = table + + def execute(self, query: Query) -> KustoResponseDataSet: + return self.client.execute(self.database, self.table + query.compile_all()) + + +class UnionTable(BaseTable): + tables: Sequence[str] + + def __init__(self, client: KustoClient, database: str, tables: Sequence[str]) -> None: + super().__init__(client, database) + self.tables = tables + + def execute(self, query: Query) -> KustoResponseDataSet: + return self.client.execute(self.database, 'union {}{}'.format( + ', '.join(self.table), + query.compile_all() + ))