* Make Table and Database classes public

* Make all expression types public

Co-authored-by: Yonatan Most <>
This commit is contained in:
Yonatan Most 2021-03-24 20:56:25 +02:00 коммит произвёл GitHub
Родитель c9fbfd2c3b
Коммит a887518ef4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 291 добавлений и 291 удалений

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

@ -128,12 +128,12 @@ class PyKustoClient(_ItemFetcher):
def to_query_format(self) -> KQL:
return KQL(f'cluster("{self.__cluster_name}")')
def _new_item(self, name: str) -> '_Database':
def _new_item(self, name: str) -> 'Database':
# "fetch_by_default" set to false because often a database generated this way is not represented by an actual
# Kusto database
return _Database(self, name, fetch_by_default=False)
return Database(self, name, fetch_by_default=False)
def get_database(self, name: str) -> '_Database':
def get_database(self, name: str) -> 'Database':
return self[name]
def execute(self, database: str, query: KQL, properties: ClientRequestProperties = None, retry_config: RetryConfig = None) -> KustoResponse:
@ -152,7 +152,7 @@ class PyKustoClient(_ItemFetcher):
def get_databases_names(self) -> Generator[str, None, None]:
yield from self._get_item_names()
def get_databases(self) -> Generator['_Database', None, None]:
def get_databases(self) -> Generator['Database', None, None]:
yield from self._get_items()
def get_cluster_name(self) -> str:
@ -179,7 +179,7 @@ class PyKustoClient(_ItemFetcher):
"""
return PyKustoClient._get_client_for_cluster(cluster)
def _internal_get_items(self) -> Dict[str, '_Database']:
def _internal_get_items(self) -> Dict[str, 'Database']:
# Retrieves database names, table names, column names and types for all databases. A database name is required
# by the "execute" method, but is ignored for this query
res: KustoResponse = self.execute(
@ -193,7 +193,7 @@ class PyKustoClient(_ItemFetcher):
return {
# Database instances are provided with all table and column data, preventing them from generating more
# queries. However the "fetch_by_default" behavior is passed on to them for future actions.
database_name: _Database(
database_name: Database(
self, database_name,
{table_name: tuple(columns) for table_name, columns in table_to_columns.items()},
fetch_by_default=self._fetch_by_default
@ -202,7 +202,7 @@ class PyKustoClient(_ItemFetcher):
}
class _Database(_ItemFetcher):
class Database(_ItemFetcher):
"""
Handle to a Kusto database.
Uses :class:`ItemFetcher` to fetch and cache the full database schema, including all tables, columns and their
@ -228,7 +228,7 @@ class _Database(_ItemFetcher):
# Providing the items to ItemFetcher prevents further queries until the "refresh" method is explicitly
# called
None if tables is None else {
table_name: _Table(self, table_name, columns, fetch_by_default=fetch_by_default)
table_name: Table(self, table_name, columns, fetch_by_default=fetch_by_default)
for table_name, columns in tables.items()
},
fetch_by_default
@ -246,10 +246,10 @@ class _Database(_ItemFetcher):
def get_name(self) -> str:
return self.__name
def _new_item(self, name: str) -> '_Table':
def _new_item(self, name: str) -> 'Table':
# "fetch_by_default" set to false because often a table generated this way is not represented by an actual
# Kusto table
return _Table(self, name, fetch_by_default=False)
return Table(self, name, fetch_by_default=False)
def execute(self, query: KQL, properties: ClientRequestProperties = None, retry_config: RetryConfig = None) -> KustoResponse:
return self.__client.execute(self.__name, query, properties, retry_config)
@ -257,13 +257,13 @@ class _Database(_ItemFetcher):
def get_table_names(self) -> Generator[str, None, None]:
yield from self._get_item_names()
def get_table(self, *tables: str) -> '_Table':
def get_table(self, *tables: str) -> 'Table':
assert len(tables) > 0
if not _Table.static_is_union(*tables):
if not Table.static_is_union(*tables):
return self[tables[0]]
columns: Optional[Tuple[BaseColumn, ...]] = None
if self._items_fetched():
resolved_tables: Set[_Table] = set()
resolved_tables: Set[Table] = set()
for table_pattern in tables:
if '*' in table_pattern:
resolved_tables.update(table for table in self._get_items() if fnmatch(table.get_name(), table_pattern))
@ -272,10 +272,10 @@ class _Database(_ItemFetcher):
if len(resolved_tables) == 1:
return next(iter(resolved_tables))
columns = self.__try_to_resolve_union_columns(*resolved_tables)
return _Table(self, tables, columns, fetch_by_default=self._fetch_by_default)
return Table(self, tables, columns, fetch_by_default=self._fetch_by_default)
@staticmethod
def __try_to_resolve_union_columns(*resolved_tables: '_Table') -> Optional[Tuple[BaseColumn, ...]]:
def __try_to_resolve_union_columns(*resolved_tables: 'Table') -> Optional[Tuple[BaseColumn, ...]]:
column_by_name: Dict[str, BaseColumn] = {}
for table in resolved_tables:
for column in table.get_columns():
@ -284,7 +284,7 @@ class _Database(_ItemFetcher):
return None # Fallback to Kusto query for column name conflict resolution
return tuple(column_by_name.values())
def _internal_get_items(self) -> Dict[str, '_Table']:
def _internal_get_items(self) -> Dict[str, 'Table']:
# Retrieves table names, column names and types for this database only (the database name is added in the
# "execute" method)
res: KustoResponse = self.execute(
@ -297,21 +297,21 @@ class _Database(_ItemFetcher):
# "fetch_by_default" behavior is
# passed on to them for future actions.
return {
table_name: _Table(self, table_name, tuple(columns), fetch_by_default=self._fetch_by_default)
table_name: Table(self, table_name, tuple(columns), fetch_by_default=self._fetch_by_default)
for table_name, columns in table_to_columns.items()
}
class _Table(_ItemFetcher):
class Table(_ItemFetcher):
"""
Handle to a Kusto table.
Uses :class:`ItemFetcher` to fetch and cache the table schema of columns and their types.
"""
__database: _Database
__database: Database
__tables: Tuple[str, ...]
def __init__(
self, database: _Database, tables: Union[str, List[str], Tuple[str, ...]],
self, database: Database, tables: Union[str, List[str], Tuple[str, ...]],
columns: Tuple[BaseColumn, ...] = None, fetch_by_default: bool = True
) -> None:
"""

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

@ -7,16 +7,16 @@ from .kql_converters import KQL
from .type_utils import _plain_expression, _aggregation_expression, PythonTypes, _kql_converter, _KustoType, \
_typed_column, _TypeRegistrar, _get_base_types, _NUMBER_TYPES
_ExpressionType = Union[PythonTypes, 'BaseExpression']
_StringType = Union[str, '_StringExpression']
_BooleanType = Union[bool, '_BooleanExpression']
_NumberType = Union[int, float, '_NumberExpression']
_ArrayType = Union[List, Tuple, '_ArrayExpression']
_MappingType = Union[Mapping, '_MappingExpression']
_DatetimeType = Union[datetime, '_DatetimeExpression']
_TimespanType = Union[timedelta, '_TimespanExpression']
_DynamicType = Union[_ArrayType, _MappingType]
_OrderedType = Union[_DatetimeType, _TimespanType, _NumberType, _StringType]
ExpressionType = Union[PythonTypes, 'BaseExpression']
StringType = Union[str, '_StringExpression']
BooleanType = Union[bool, '_BooleanExpression']
NumberType = Union[int, float, '_NumberExpression']
ArrayType = Union[List, Tuple, '_ArrayExpression']
MappingType = Union[Mapping, '_MappingExpression']
DatetimeType = Union[datetime, '_DatetimeExpression']
TimespanType = Union[timedelta, '_TimespanExpression']
DynamicType = Union[ArrayType, MappingType]
OrderedType = Union[DatetimeType, TimespanType, NumberType, StringType]
# All classes in the same file to prevent circular dependencies
@ -81,7 +81,7 @@ class BaseExpression:
@staticmethod
def base_binary_op(
left: _ExpressionType, operator: str, right: _ExpressionType, result_type: Optional[_KustoType]
left: ExpressionType, operator: str, right: ExpressionType, result_type: Optional[_KustoType]
) -> 'BaseExpression':
registrar = _plain_expression
fallback = AnyExpression
@ -91,13 +91,13 @@ class BaseExpression:
return_type = fallback if result_type is None else registrar.registry[result_type]
return return_type(KQL(f'{_to_kql(left, True)}{operator}{_to_kql(right, True)}'))
def __eq__(self, other: _ExpressionType) -> '_BooleanExpression':
def __eq__(self, other: ExpressionType) -> '_BooleanExpression':
return _BooleanExpression.binary_op(self, ' == ', other)
def __ne__(self, other: _ExpressionType) -> '_BooleanExpression':
def __ne__(self, other: ExpressionType) -> '_BooleanExpression':
return _BooleanExpression.binary_op(self, ' != ', other)
def is_in(self, other: _DynamicType, case_sensitive: bool = False) -> '_BooleanExpression':
def is_in(self, other: DynamicType, case_sensitive: bool = False) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/dynamic#operators-and-functions-over-dynamic-types
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/inoperator
@ -116,7 +116,7 @@ class BaseExpression:
assert case_sensitive, "Member test for non-literal array cannot be case insensitive"
return _BooleanExpression(KQL(f'set_has_element({_to_kql(other)}, {self.kql})'))
def not_in(self, other: _DynamicType, case_sensitive: bool = False) -> '_BooleanExpression':
def not_in(self, other: DynamicType, case_sensitive: bool = False) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/dynamic#operators-and-functions-over-dynamic-types
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/inoperator
@ -197,29 +197,29 @@ class BaseExpression:
@_plain_expression(_KustoType.BOOL)
class _BooleanExpression(BaseExpression):
@staticmethod
def binary_op(left: _ExpressionType, operator: str, right: _ExpressionType) -> '_BooleanExpression':
def binary_op(left: ExpressionType, operator: str, right: ExpressionType) -> '_BooleanExpression':
# noinspection PyTypeChecker
return BaseExpression.base_binary_op(left, operator, right, _KustoType.BOOL)
def __and__(self, other: _BooleanType) -> '_BooleanExpression':
def __and__(self, other: BooleanType) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/logicaloperators
"""
return _BooleanExpression.binary_op(self, ' and ', other)
def __rand__(self, other: _BooleanType) -> '_BooleanExpression':
def __rand__(self, other: BooleanType) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/logicaloperators
"""
return _BooleanExpression.binary_op(other, ' and ', self)
def __or__(self, other: _BooleanType) -> '_BooleanExpression':
def __or__(self, other: BooleanType) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/logicaloperators
"""
return _BooleanExpression.binary_op(self, ' or ', other)
def __ror__(self, other: _BooleanType) -> '_BooleanExpression':
def __ror__(self, other: BooleanType) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/logicaloperators
"""
@ -236,50 +236,50 @@ class _BooleanExpression(BaseExpression):
@_plain_expression(*_NUMBER_TYPES)
class _NumberExpression(BaseExpression):
@staticmethod
def binary_op(left: _NumberType, operator: str, right: _NumberType) -> '_NumberExpression':
def binary_op(left: NumberType, operator: str, right: NumberType) -> '_NumberExpression':
# noinspection PyTypeChecker
return BaseExpression.base_binary_op(left, operator, right, _KustoType.INT)
def __lt__(self, other: _NumberType) -> _BooleanExpression:
def __lt__(self, other: NumberType) -> _BooleanExpression:
return _BooleanExpression.binary_op(self, ' < ', other)
def __le__(self, other: _NumberType) -> _BooleanExpression:
def __le__(self, other: NumberType) -> _BooleanExpression:
return _BooleanExpression.binary_op(self, ' <= ', other)
def __gt__(self, other: _NumberType) -> _BooleanExpression:
def __gt__(self, other: NumberType) -> _BooleanExpression:
return _BooleanExpression.binary_op(self, ' > ', other)
def __ge__(self, other: _NumberType) -> _BooleanExpression:
def __ge__(self, other: NumberType) -> _BooleanExpression:
return _BooleanExpression.binary_op(self, ' >= ', other)
def __add__(self, other: _NumberType) -> '_NumberExpression':
def __add__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(self, ' + ', other)
def __radd__(self, other: _NumberType) -> '_NumberExpression':
def __radd__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(other, ' + ', self)
def __sub__(self, other: _NumberType) -> '_NumberExpression':
def __sub__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(self, ' - ', other)
def __rsub__(self, other: _NumberType) -> '_NumberExpression':
def __rsub__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(other, ' - ', self)
def __mul__(self, other: _NumberType) -> '_NumberExpression':
def __mul__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(self, ' * ', other)
def __rmul__(self, other: _NumberType) -> '_NumberExpression':
def __rmul__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(other, ' * ', self)
def __truediv__(self, other: _NumberType) -> '_NumberExpression':
def __truediv__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(self, ' / ', other)
def __rtruediv__(self, other: _NumberType) -> '_NumberExpression':
def __rtruediv__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(other, ' / ', self)
def __mod__(self, other: _NumberType) -> '_NumberExpression':
def __mod__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(self, ' % ', other)
def __rmod__(self, other: _NumberType) -> '_NumberExpression':
def __rmod__(self, other: NumberType) -> '_NumberExpression':
return _NumberExpression.binary_op(other, ' % ', self)
def __neg__(self) -> '_NumberExpression':
@ -291,7 +291,7 @@ class _NumberExpression(BaseExpression):
"""
return _NumberExpression(KQL(f'abs({self.kql})'))
def between(self, lower: _NumberType, upper: _NumberType) -> _BooleanExpression:
def between(self, lower: NumberType, upper: NumberType) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/betweenoperator
"""
@ -309,19 +309,19 @@ class _NumberExpression(BaseExpression):
"""
return _NumberExpression(KQL(f'cos({self.kql})'))
def floor(self, round_to: _NumberType) -> '_NumberExpression':
def floor(self, round_to: NumberType) -> '_NumberExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/floorfunction
"""
return _NumberExpression(KQL(f'floor({self.kql}, {_to_kql(round_to)})'))
def bin(self, round_to: _NumberType) -> 'BaseExpression':
def bin(self, round_to: NumberType) -> 'BaseExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/binfunction
"""
return _NumberExpression(KQL(f'bin({self.kql}, {_to_kql(round_to)})'))
def bin_at(self, round_to: _NumberType, fixed_point: _NumberType) -> 'BaseExpression':
def bin_at(self, round_to: NumberType, fixed_point: NumberType) -> 'BaseExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/binatfunction
"""
@ -399,7 +399,7 @@ class _NumberExpression(BaseExpression):
"""
return _NumberExpression(KQL(f'loggamma({self.kql})'))
def round(self, precision: _NumberType = None) -> '_NumberExpression':
def round(self, precision: NumberType = None) -> '_NumberExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/roundfunction
"""
@ -415,7 +415,7 @@ class _StringExpression(BaseExpression):
"""
return _NumberExpression(KQL(f'string_size({self.kql})'))
def split(self, delimiter: _StringType, requested_index: _NumberType = None) -> '_ArrayExpression':
def split(self, delimiter: StringType, requested_index: NumberType = None) -> '_ArrayExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/splitfunction
"""
@ -423,7 +423,7 @@ class _StringExpression(BaseExpression):
return _ArrayExpression(KQL(f'split({self.kql}, {_to_kql(delimiter)})'))
return _ArrayExpression(KQL(f'split({self.kql}, {_to_kql(delimiter)}, {_to_kql(requested_index)})'))
def equals(self, other: _StringType, case_sensitive: bool = False) -> _BooleanExpression:
def equals(self, other: StringType, case_sensitive: bool = False) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
@ -433,7 +433,7 @@ class _StringExpression(BaseExpression):
"""
return _BooleanExpression.binary_op(self, ' == ' if case_sensitive else ' =~ ', other)
def not_equals(self, other: _StringType, case_sensitive: bool = False) -> _BooleanExpression:
def not_equals(self, other: StringType, case_sensitive: bool = False) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
@ -443,13 +443,13 @@ class _StringExpression(BaseExpression):
"""
return _BooleanExpression.binary_op(self, ' != ' if case_sensitive else ' !~ ', other)
def matches(self, regex: _StringType) -> '_BooleanExpression':
def matches(self, regex: StringType) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
"""
return _BooleanExpression.binary_op(self, ' matches regex ', regex)
def contains(self, other: _StringType, case_sensitive: bool = False) -> _BooleanExpression:
def contains(self, other: StringType, case_sensitive: bool = False) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
@ -460,7 +460,7 @@ class _StringExpression(BaseExpression):
"""
return _BooleanExpression.binary_op(self, ' contains_cs ' if case_sensitive else ' contains ', other)
def not_contains(self, other: _StringType, case_sensitive: bool = False) -> _BooleanExpression:
def not_contains(self, other: StringType, case_sensitive: bool = False) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
@ -471,13 +471,13 @@ class _StringExpression(BaseExpression):
"""
return _BooleanExpression.binary_op(self, ' !contains_cs ' if case_sensitive else ' !contains ', other)
def startswith(self, other: _StringType, case_sensitive: bool = False) -> _BooleanExpression:
def startswith(self, other: StringType, case_sensitive: bool = False) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
"""
return _BooleanExpression.binary_op(self, ' startswith_cs ' if case_sensitive else ' startswith ', other)
def endswith(self, other: _StringType, case_sensitive: bool = False) -> _BooleanExpression:
def endswith(self, other: StringType, case_sensitive: bool = False) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
"""
@ -507,7 +507,7 @@ class _StringExpression(BaseExpression):
"""
return _BooleanExpression(KQL(f'isutf8({self.kql})'))
def has(self, exp: _StringType, case_sensitive: bool = False) -> '_BooleanExpression':
def has(self, exp: StringType, case_sensitive: bool = False) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
"""
@ -515,7 +515,7 @@ class _StringExpression(BaseExpression):
f'{self.as_subexpression()} {"has_cs" if case_sensitive else "has"} {_to_kql(exp, True)}'
))
def has_not(self, exp: _StringType, case_sensitive: bool = False) -> '_BooleanExpression':
def has_not(self, exp: StringType, case_sensitive: bool = False) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datatypes-string-operators
"""
@ -527,27 +527,27 @@ class _StringExpression(BaseExpression):
@_plain_expression(_KustoType.DATETIME)
class _DatetimeExpression(BaseExpression):
@staticmethod
def binary_op(left: _ExpressionType, operator: str, right: _ExpressionType) -> '_DatetimeExpression':
def binary_op(left: ExpressionType, operator: str, right: ExpressionType) -> '_DatetimeExpression':
# noinspection PyTypeChecker
return BaseExpression.base_binary_op(left, operator, right, _KustoType.DATETIME)
def __lt__(self, other: _DatetimeType) -> _BooleanExpression:
def __lt__(self, other: DatetimeType) -> _BooleanExpression:
return _BooleanExpression.binary_op(self, ' < ', other)
def __le__(self, other: _DatetimeType) -> _BooleanExpression:
def __le__(self, other: DatetimeType) -> _BooleanExpression:
return _BooleanExpression.binary_op(self, ' <= ', other)
def __gt__(self, other: _DatetimeType) -> _BooleanExpression:
def __gt__(self, other: DatetimeType) -> _BooleanExpression:
return _BooleanExpression.binary_op(self, ' > ', other)
def __ge__(self, other: _DatetimeType) -> _BooleanExpression:
def __ge__(self, other: DatetimeType) -> _BooleanExpression:
return _BooleanExpression.binary_op(self, ' >= ', other)
def __add__(self, other: _TimespanType) -> '_DatetimeExpression':
def __add__(self, other: TimespanType) -> '_DatetimeExpression':
# https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic
return _DatetimeExpression.binary_op(self, ' + ', other)
def __sub__(self, other: Union[_DatetimeType, _TimespanType]) -> Union['_DatetimeExpression', '_TimespanExpression']:
def __sub__(self, other: Union[DatetimeType, TimespanType]) -> Union['_DatetimeExpression', '_TimespanExpression']:
# https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic
# noinspection PyTypeChecker
@ -560,29 +560,29 @@ class _DatetimeExpression(BaseExpression):
return_type = _TimespanExpression if next(iter(possible_types)) == _KustoType.DATETIME else _DatetimeExpression
return return_type(_DatetimeExpression.binary_op(self, ' - ', other))
def __rsub__(self, other: _DatetimeType) -> '_TimespanExpression':
def __rsub__(self, other: DatetimeType) -> '_TimespanExpression':
# https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic
return _TimespanExpression.binary_op(other, ' - ', self)
def between(self, lower: _DatetimeType, upper: _DatetimeType) -> _BooleanExpression:
def between(self, lower: DatetimeType, upper: DatetimeType) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/betweenoperator
"""
return _BooleanExpression(KQL(f'{self.kql} between ({_to_kql(lower, True)} .. {_to_kql(upper, True)})'))
def floor(self, round_to: _TimespanType) -> '_DatetimeExpression':
def floor(self, round_to: TimespanType) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/floorfunction
"""
return _DatetimeExpression(KQL(f'floor({self.kql}, {_to_kql(round_to)})'))
def bin(self, round_to: _TimespanType) -> 'BaseExpression':
def bin(self, round_to: TimespanType) -> 'BaseExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/binfunction
"""
return _DatetimeExpression(KQL(f'bin({self.kql}, {_to_kql(round_to)})'))
def bin_at(self, round_to: _TimespanType, fixed_point: _DatetimeType) -> 'BaseExpression':
def bin_at(self, round_to: TimespanType, fixed_point: DatetimeType) -> 'BaseExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/binatfunction
"""
@ -594,7 +594,7 @@ class _DatetimeExpression(BaseExpression):
"""
return _DatetimeExpression(KQL(f'bin_auto({self.kql})'))
def end_of_day(self, offset: _NumberType = None) -> '_DatetimeExpression':
def end_of_day(self, offset: NumberType = None) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/endofdayfunction
"""
@ -604,7 +604,7 @@ class _DatetimeExpression(BaseExpression):
res = f'endofday({self.kql}, {_to_kql(offset)})'
return _DatetimeExpression(KQL(res))
def end_of_month(self, offset: _NumberType = None) -> '_DatetimeExpression':
def end_of_month(self, offset: NumberType = None) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/endofmonthfunction
"""
@ -614,7 +614,7 @@ class _DatetimeExpression(BaseExpression):
res = f'endofmonth({self.kql}, {_to_kql(offset)})'
return _DatetimeExpression(KQL(res))
def end_of_week(self, offset: _NumberType = None) -> '_DatetimeExpression':
def end_of_week(self, offset: NumberType = None) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/endofweekfunction
"""
@ -624,7 +624,7 @@ class _DatetimeExpression(BaseExpression):
res = f'endofweek({self.kql}, {_to_kql(offset)})'
return _DatetimeExpression(KQL(res))
def end_of_year(self, offset: _NumberType = None) -> '_DatetimeExpression':
def end_of_year(self, offset: NumberType = None) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/endofyearfunction
"""
@ -634,7 +634,7 @@ class _DatetimeExpression(BaseExpression):
res = f'endofyear({self.kql}, {_to_kql(offset)})'
return _DatetimeExpression(KQL(res))
def format_datetime(self, format_string: _StringType) -> _StringExpression:
def format_datetime(self, format_string: StringType) -> _StringExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/format-datetimefunction
"""
@ -658,25 +658,25 @@ class _DatetimeExpression(BaseExpression):
"""
return _NumberExpression(KQL(f'hourofday({self.kql})'))
def start_of_day(self, offset: _NumberType = None) -> '_DatetimeExpression':
def start_of_day(self, offset: NumberType = None) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/startofdayfunction
"""
return _DatetimeExpression(KQL(f'startofday({self.kql})' if offset is None else f'startofday({self.kql}, {_to_kql(offset)})'))
def start_of_month(self, offset: _NumberType = None) -> '_DatetimeExpression':
def start_of_month(self, offset: NumberType = None) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/startofmonthfunction
"""
return _DatetimeExpression(KQL(f'startofmonth({self.kql})' if offset is None else f'startofmonth({self.kql}, {_to_kql(offset)})'))
def start_of_week(self, offset: _NumberType = None) -> '_DatetimeExpression':
def start_of_week(self, offset: NumberType = None) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/startofweekfunction
"""
return _DatetimeExpression(KQL(f'startofweek({self.kql})' if offset is None else f'startofweek({self.kql}, {_to_kql(offset)})'))
def start_of_year(self, offset: _NumberType = None) -> '_DatetimeExpression':
def start_of_year(self, offset: NumberType = None) -> '_DatetimeExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/startofyearfunction
"""
@ -686,23 +686,23 @@ class _DatetimeExpression(BaseExpression):
@_plain_expression(_KustoType.TIMESPAN)
class _TimespanExpression(BaseExpression):
@staticmethod
def binary_op(left: _ExpressionType, operator: str, right: _ExpressionType) -> '_TimespanExpression':
def binary_op(left: ExpressionType, operator: str, right: ExpressionType) -> '_TimespanExpression':
# noinspection PyTypeChecker
return BaseExpression.base_binary_op(left, operator, right, _KustoType.TIMESPAN)
def __add__(self, other: _TimespanType) -> '_TimespanExpression':
def __add__(self, other: TimespanType) -> '_TimespanExpression':
# https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic
return _TimespanExpression.binary_op(self, ' + ', other)
def __radd__(self, other: _TimespanType) -> '_TimespanExpression':
def __radd__(self, other: TimespanType) -> '_TimespanExpression':
# https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic
return _TimespanExpression.binary_op(other, ' + ', self)
def __sub__(self, other: _TimespanType) -> '_TimespanExpression':
def __sub__(self, other: TimespanType) -> '_TimespanExpression':
# https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic
return _TimespanExpression.binary_op(self, ' - ', other)
def __rsub__(self, other: _TimespanType) -> '_TimespanExpression':
def __rsub__(self, other: TimespanType) -> '_TimespanExpression':
# https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic
return _TimespanExpression.binary_op(other, ' - ', self)
@ -712,13 +712,13 @@ class _TimespanExpression(BaseExpression):
"""
return _DatetimeExpression(KQL(f'ago({_to_kql(self)})'))
def bin(self, round_to: _TimespanType) -> 'BaseExpression':
def bin(self, round_to: TimespanType) -> 'BaseExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/binfunction
"""
return _TimespanExpression(KQL(f'bin({self.kql}, {_to_kql(round_to)})'))
def bin_at(self, round_to: _TimespanType, fixed_point: _TimespanType) -> 'BaseExpression':
def bin_at(self, round_to: TimespanType, fixed_point: TimespanType) -> 'BaseExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/binatfunction
"""
@ -730,13 +730,13 @@ class _TimespanExpression(BaseExpression):
"""
return _TimespanExpression(KQL(f'bin_auto({self.kql})'))
def format_timespan(self, format_string: _StringType) -> _StringExpression:
def format_timespan(self, format_string: StringType) -> _StringExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/format-timespanfunction
"""
return _StringExpression(KQL(f'format_timespan({self.kql}, {_to_kql(format_string)})'))
def between(self, lower: _TimespanType, upper: _TimespanType) -> _BooleanExpression:
def between(self, lower: TimespanType, upper: TimespanType) -> _BooleanExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/betweenoperator
"""
@ -750,10 +750,10 @@ class _BaseDynamicExpression(BaseExpression):
assert cls is not _BaseDynamicExpression, "BaseDynamicExpression is abstract"
return object.__new__(cls)
def __getitem__(self, index: Union[_StringType, _NumberType]) -> 'AnyExpression':
def __getitem__(self, index: Union[StringType, NumberType]) -> 'AnyExpression':
return AnyExpression(KQL(f'{self.kql}[{_to_kql(index)}]'))
def contains(self, other: _ExpressionType) -> '_BooleanExpression':
def contains(self, other: ExpressionType) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/dynamic#operators-and-functions-over-dynamic-types
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/inoperator
@ -768,7 +768,7 @@ class _BaseDynamicExpression(BaseExpression):
@_plain_expression(_KustoType.ARRAY)
class _ArrayExpression(_BaseDynamicExpression):
def __getitem__(self, index: _NumberType) -> 'AnyExpression':
def __getitem__(self, index: NumberType) -> 'AnyExpression':
return super().__getitem__(index)
# We would like to allow using len(), but Python requires it to return an int, so we can't
@ -778,7 +778,7 @@ class _ArrayExpression(_BaseDynamicExpression):
"""
return _NumberExpression(KQL(f'array_length({self.kql})'))
def array_contains(self, other: _ExpressionType) -> '_BooleanExpression':
def array_contains(self, other: ExpressionType) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/dynamic#operators-and-functions-over-dynamic-types
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/inoperator
@ -792,7 +792,7 @@ class _ArrayExpression(_BaseDynamicExpression):
@_plain_expression(_KustoType.MAPPING)
class _MappingExpression(_BaseDynamicExpression):
def __getitem__(self, index: _StringType) -> 'AnyExpression':
def __getitem__(self, index: StringType) -> 'AnyExpression':
return super().__getitem__(index)
def __getattr__(self, name: str) -> 'AnyExpression':
@ -804,7 +804,7 @@ class _MappingExpression(_BaseDynamicExpression):
"""
return _ArrayExpression(KQL(f'bag_keys({self.kql})'))
def bag_contains(self, other: _ExpressionType) -> '_BooleanExpression':
def bag_contains(self, other: ExpressionType) -> '_BooleanExpression':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/dynamic#operators-and-functions-over-dynamic-types
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/inoperator
@ -814,7 +814,7 @@ class _MappingExpression(_BaseDynamicExpression):
class _DynamicExpression(_ArrayExpression, _MappingExpression):
def __getitem__(self, index: Union[_StringType, _NumberType]) -> 'AnyExpression':
def __getitem__(self, index: Union[StringType, NumberType]) -> 'AnyExpression':
return super().__getitem__(index)
@ -889,7 +889,7 @@ class _AssignmentBase:
_lvalue: Optional[KQL]
_rvalue: KQL
def __init__(self, lvalue: Optional[KQL], rvalue: _ExpressionType) -> None:
def __init__(self, lvalue: Optional[KQL], rvalue: ExpressionType) -> None:
self._lvalue = lvalue
self._rvalue = _to_kql(rvalue)
@ -901,7 +901,7 @@ class _AssignmentBase:
class _AssignmentToSingleColumn(_AssignmentBase):
def __init__(self, column: '_AnyTypeColumn', expression: _ExpressionType) -> None:
def __init__(self, column: '_AnyTypeColumn', expression: ExpressionType) -> None:
super().__init__(column.kql, expression)
@ -911,7 +911,7 @@ class _AssignmentFromColumnToColumn(_AssignmentToSingleColumn):
class _AssignmentToMultipleColumns(_AssignmentBase):
def __init__(self, columns: Union[List['_AnyTypeColumn'], Tuple['_AnyTypeColumn']], expression: _ArrayType) -> None:
def __init__(self, columns: Union[List['_AnyTypeColumn'], Tuple['_AnyTypeColumn']], expression: ArrayType) -> None:
super().__init__(KQL(f'({", ".join(c.kql for c in columns)})'), expression)
@ -992,7 +992,7 @@ class _TimespanColumn(BaseColumn, _TimespanExpression):
class _SubtractableColumn(_NumberColumn, _DatetimeColumn, _TimespanColumn):
@staticmethod
def __resolve_type(type_to_resolve: Union['_NumberType', '_DatetimeType', '_TimespanType']) -> Optional[_KustoType]:
def __resolve_type(type_to_resolve: Union['NumberType', 'DatetimeType', 'TimespanType']) -> Optional[_KustoType]:
# noinspection PyTypeChecker
base_types = _get_base_types(type_to_resolve)
possible_types = base_types & ({_KustoType.DATETIME, _KustoType.TIMESPAN} | _NUMBER_TYPES)
@ -1003,7 +1003,7 @@ class _SubtractableColumn(_NumberColumn, _DatetimeColumn, _TimespanColumn):
return None
return next(iter(possible_types))
def __sub__(self, other: Union['_NumberType', '_DatetimeType', '_TimespanType']) -> Union['_NumberExpression', '_TimespanExpression', 'AnyExpression']:
def __sub__(self, other: Union['NumberType', 'DatetimeType', 'TimespanType']) -> Union['_NumberExpression', '_TimespanExpression', 'AnyExpression']:
resolved_type = self.__resolve_type(other)
if resolved_type == _KustoType.DATETIME:
# Subtracting a datetime can only result in a timespan
@ -1016,7 +1016,7 @@ class _SubtractableColumn(_NumberColumn, _DatetimeColumn, _TimespanColumn):
# noinspection PyTypeChecker
return BaseExpression.base_binary_op(self, ' - ', other, resolved_type)
def __rsub__(self, other: Union['_NumberType', '_DatetimeType', '_TimespanType']) -> Union['_NumberExpression', '_TimespanExpression', 'AnyExpression']:
def __rsub__(self, other: Union['NumberType', 'DatetimeType', 'TimespanType']) -> Union['_NumberExpression', '_TimespanExpression', 'AnyExpression']:
resolved_type = self.__resolve_type(other)
if resolved_type == _KustoType.DATETIME:
# Subtracting from a datetime can result in either a datetime or a timespan
@ -1056,7 +1056,7 @@ class _ColumnToType(BaseExpression):
super().__init__(KQL(f"{col.kql} to typeof({kusto_type.primary_name})"))
def _to_kql(obj: _ExpressionType, parentheses: bool = False) -> KQL:
def _to_kql(obj: ExpressionType, parentheses: bool = False) -> KQL:
"""
Convert the given expression to KQL. If this is a subexpression of a greater expression, neighboring operators might
take precedence over operators included in this expression, causing an incorrect evaluation order. This might not be a concern, if
@ -1072,7 +1072,7 @@ def _to_kql(obj: _ExpressionType, parentheses: bool = False) -> KQL:
return _kql_converter.for_obj(obj)
def _expression_to_type(expression: _ExpressionType, type_registrar: _TypeRegistrar, fallback_type: Any) -> Any:
def _expression_to_type(expression: ExpressionType, type_registrar: _TypeRegistrar, fallback_type: Any) -> Any:
types = set(type_registrar.registry[base_type] for base_type in _plain_expression.get_base_types(expression))
return next(iter(types)) if len(types) == 1 else fallback_type

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -5,12 +5,12 @@ from os import linesep
from types import FunctionType
from typing import Tuple, List, Union, Optional
from .client import _Table, KustoResponse, RetryConfig
from .client import Table, KustoResponse, RetryConfig
from .enums import Order, Nulls, JoinKind, Distribution, BagExpansion
from .expressions import _BooleanType, _ExpressionType, AggregationExpression, _OrderedType, \
_StringType, _AssignmentBase, _AssignmentFromAggregationToColumn, _AssignmentToSingleColumn, _AnyTypeColumn, \
from .expressions import BooleanType, ExpressionType, AggregationExpression, OrderedType, \
StringType, _AssignmentBase, _AssignmentFromAggregationToColumn, _AssignmentToSingleColumn, _AnyTypeColumn, \
BaseExpression, \
_AssignmentFromColumnToColumn, AnyExpression, _to_kql, _expression_to_type, BaseColumn, _NumberType
_AssignmentFromColumnToColumn, AnyExpression, _to_kql, _expression_to_type, BaseColumn, NumberType
from .functions import Functions as f
from .kql_converters import KQL
from .logger import _logger
@ -20,7 +20,7 @@ from .udf import _stringify_python_func
class Query:
_head: Optional['Query']
_table: Optional[_Table]
_table: Optional[Table]
_table_name: Optional[str]
def __init__(self, head=None) -> None:
@ -29,7 +29,7 @@ class Query:
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/best-practices
"""
self._head = head if isinstance(head, Query) else None
self._table = head if isinstance(head, _Table) else None
self._table = head if isinstance(head, Table) else None
self._table_name = head if isinstance(head, str) else None
def __add__(self, other: 'Query') -> 'Query':
@ -50,7 +50,7 @@ class Query:
new_object._head = self._head.__deepcopy__(memo)
return new_object
def where(self, *predicates: _BooleanType) -> 'Query':
def where(self, *predicates: BooleanType) -> 'Query':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/whereoperator
@ -105,13 +105,13 @@ class Query:
"""
return _CountQuery(self)
def sort_by(self, col: _OrderedType, order: Order = None, nulls: Nulls = None) -> '_SortQuery':
def sort_by(self, col: OrderedType, order: Order = None, nulls: Nulls = None) -> '_SortQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/sortoperator
"""
return _SortQuery(self, col, order, nulls)
def order_by(self, col: _OrderedType, order: Order = None, nulls: Nulls = None) -> '_SortQuery':
def order_by(self, col: OrderedType, order: Order = None, nulls: Nulls = None) -> '_SortQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/orderoperator
"""
@ -139,7 +139,7 @@ class Query:
"""
return _JoinQuery(self, query, kind)
def project(self, *args: Union[_AssignmentBase, BaseExpression], **kwargs: _ExpressionType) -> '_ProjectQuery':
def project(self, *args: Union[_AssignmentBase, BaseExpression], **kwargs: ExpressionType) -> '_ProjectQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/projectoperator
"""
@ -154,7 +154,7 @@ class Query:
assignments.append(_AssignmentFromColumnToColumn(_AnyTypeColumn(column_name), column))
return _ProjectRenameQuery(self, assignments)
def project_away(self, *columns: _StringType) -> '_ProjectAwayQuery':
def project_away(self, *columns: StringType) -> '_ProjectAwayQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/projectawayoperator
"""
@ -172,7 +172,7 @@ class Query:
"""
return _DistinctQuery(self, (_AnyTypeColumn(KQL("*")),))
def extend(self, *args: Union[BaseExpression, _AssignmentBase], **kwargs: _ExpressionType) -> '_ExtendQuery':
def extend(self, *args: Union[BaseExpression, _AssignmentBase], **kwargs: ExpressionType) -> '_ExtendQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/extendoperator
"""
@ -196,7 +196,7 @@ class Query:
def mv_expand(
self, *args: Union[BaseExpression, _AssignmentBase], bag_expansion: BagExpansion = None,
with_item_index: BaseColumn = None, limit: int = None, **kwargs: _ExpressionType
with_item_index: BaseColumn = None, limit: int = None, **kwargs: ExpressionType
) -> '_MvExpandQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/mvexpandoperator
@ -209,7 +209,7 @@ class Query:
def custom(self, custom_query: str) -> '_CustomQuery':
return _CustomQuery(self, custom_query)
def evaluate(self, plugin_name, *args: _ExpressionType, distribution: Distribution = None) -> '_EvaluateQuery':
def evaluate(self, plugin_name, *args: ExpressionType, distribution: Distribution = None) -> '_EvaluateQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/evaluateoperator
"""
@ -256,7 +256,7 @@ class Query:
else:
return KQL(f"{self._head._compile_all(use_full_table_name)} | {self._compile()}")
def get_table(self) -> _Table:
def get_table(self) -> Table:
if self._head is None:
return self._table
else:
@ -279,7 +279,7 @@ class Query:
kql = KQL(kql.replace(" |", linesep + "|"))
return kql
def execute(self, table: _Table = None, retry_config: RetryConfig = None) -> KustoResponse:
def execute(self, table: Table = None, retry_config: RetryConfig = None) -> KustoResponse:
if self.get_table() is None:
if table is None:
raise RuntimeError("No table supplied")
@ -293,11 +293,11 @@ class Query:
_logger.debug("Running query: " + rendered_query)
return table.execute(rendered_query, retry_config)
def to_dataframe(self, table: _Table = None, retry_config: RetryConfig = None):
def to_dataframe(self, table: Table = None, retry_config: RetryConfig = None):
return self.execute(table, retry_config).to_dataframe()
@staticmethod
def _extract_assignments(*args: Union[_AssignmentBase, BaseExpression], **kwargs: _ExpressionType) -> List[_AssignmentBase]:
def _extract_assignments(*args: Union[_AssignmentBase, BaseExpression], **kwargs: ExpressionType) -> List[_AssignmentBase]:
assignments: List[_AssignmentBase] = []
for arg in args:
if isinstance(arg, BaseExpression):
@ -338,9 +338,9 @@ class _ProjectRenameQuery(Query):
class _ProjectAwayQuery(Query):
_columns: Tuple[_StringType, ...]
_columns: Tuple[StringType, ...]
def __init__(self, head: 'Query', columns: Tuple[_StringType]) -> None:
def __init__(self, head: 'Query', columns: Tuple[StringType]) -> None:
super().__init__(head)
self._columns = columns
@ -355,14 +355,14 @@ class _DistinctQuery(Query):
super().__init__(head)
self._columns = columns
def sample(self, number_of_values: _NumberType) -> '_SampleDistinctQuery':
def sample(self, number_of_values: NumberType) -> '_SampleDistinctQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/sampledistinctoperator
"""
assert len(self._columns) == 1, "sample-distinct supports only one column"
return _SampleDistinctQuery(self._head, self._columns[0], number_of_values)
def top_hitters(self, number_of_values: _NumberType) -> '_TopHittersQuery':
def top_hitters(self, number_of_values: NumberType) -> '_TopHittersQuery':
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/tophittersoperator
"""
@ -374,10 +374,10 @@ class _DistinctQuery(Query):
class _SampleDistinctQuery(Query):
_number_of_values: _NumberType
_number_of_values: NumberType
_column: BaseColumn
def __init__(self, head: 'Query', column: BaseColumn, number_of_values: _NumberType) -> None:
def __init__(self, head: 'Query', column: BaseColumn, number_of_values: NumberType) -> None:
super().__init__(head)
self._column = column
self._number_of_values = number_of_values
@ -387,17 +387,17 @@ class _SampleDistinctQuery(Query):
class _TopHittersQuery(Query):
_number_of_values: _NumberType
_number_of_values: NumberType
_column: BaseColumn
_by_expression: Optional[_NumberType]
_by_expression: Optional[NumberType]
def __init__(self, head: 'Query', column: BaseColumn, number_of_values: _NumberType, by_expression: Optional[_NumberType] = None) -> None:
def __init__(self, head: 'Query', column: BaseColumn, number_of_values: NumberType, by_expression: Optional[NumberType] = None) -> None:
super().__init__(head)
self._column = column
self._number_of_values = number_of_values
self._by_expression = by_expression
def by(self, by_expression: _NumberType) -> '_TopHittersQuery':
def by(self, by_expression: NumberType) -> '_TopHittersQuery':
assert self._by_expression is None, "duplicate 'by' clause"
return _TopHittersQuery(self._head, self._column, self._number_of_values, by_expression)
@ -417,9 +417,9 @@ class _ExtendQuery(Query):
class _WhereQuery(Query):
_predicates: Tuple[_BooleanType, ...]
_predicates: Tuple[BooleanType, ...]
def __init__(self, head: Query, *predicates: _BooleanType):
def __init__(self, head: Query, *predicates: BooleanType):
super(_WhereQuery, self).__init__(head)
self._predicates = predicates
@ -475,11 +475,11 @@ class _CountQuery(Query):
class _OrderQueryBase(Query):
class OrderSpec:
col: _OrderedType
col: OrderedType
order: Order
nulls: Nulls
def __init__(self, col: _OrderedType, order: Order, nulls: Nulls):
def __init__(self, col: OrderedType, order: Order, nulls: Nulls):
self.col = col
self.order = order
self.nulls = nulls
@ -487,13 +487,13 @@ class _OrderQueryBase(Query):
_query_name: str
_order_specs: List[OrderSpec]
def __init__(self, head: Query, query_name: str, col: _OrderedType, order: Order, nulls: Nulls):
def __init__(self, head: Query, query_name: str, col: OrderedType, order: Order, nulls: Nulls):
super(_OrderQueryBase, self).__init__(head)
self._query_name = query_name
self._order_specs = []
self.then_by(col, order, nulls)
def then_by(self, col: _OrderedType, order: Order = None, nulls: Nulls = None):
def then_by(self, col: OrderedType, order: Order = None, nulls: Nulls = None):
self._order_specs.append(_OrderQueryBase.OrderSpec(col, order, nulls))
return self
@ -511,7 +511,7 @@ class _OrderQueryBase(Query):
class _SortQuery(_OrderQueryBase):
def __init__(self, head: Query, col: _OrderedType, order: Order, nulls: Nulls):
def __init__(self, head: Query, col: OrderedType, order: Order, nulls: Nulls):
super(_SortQuery, self).__init__(head, "sort", col, order, nulls)
@ -637,10 +637,10 @@ class _CustomQuery(Query):
class _EvaluateQuery(Query):
_plugin_name: str
_args: Tuple[_ExpressionType]
_args: Tuple[ExpressionType]
_distribution: Distribution
def __init__(self, head: Query, plugin_name: str, *args: _ExpressionType, distribution: Distribution = None):
def __init__(self, head: Query, plugin_name: str, *args: ExpressionType, distribution: Distribution = None):
super().__init__(head)
self._plugin_name = plugin_name
self._args = args

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

@ -15,7 +15,7 @@ from azure.kusto.data._models import KustoResultTable, KustoResultRow
from azure.kusto.data.response import KustoResponseDataSet
# noinspection PyProtectedMember
from pykusto._src.client import _Table
from pykusto._src.client import Table
# noinspection PyProtectedMember
from pykusto._src.expressions import _NumberColumn, _BooleanColumn, _ArrayColumn, _MappingColumn, _StringColumn, _DatetimeColumn, _TimespanColumn, _DynamicColumn
# noinspection PyProtectedMember
@ -23,7 +23,7 @@ from pykusto._src.type_utils import _KustoType
# Naming this variable "test_table" triggers the following bug: https://github.com/pytest-dev/pytest/issues/7378
# noinspection PyTypeChecker
mock_table = _Table(
mock_table = Table(
None, "mock_table",
(
_NumberColumn('numField'), _NumberColumn('numField2'), _NumberColumn('numField3'), _NumberColumn('numField4'), _NumberColumn('numField5'), _NumberColumn('numField6'),

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

@ -4,7 +4,7 @@ from unittest.mock import patch
from pykusto import PyKustoClient, Query
# noinspection PyProtectedMember
from pykusto._src.client import _Database
from pykusto._src.client import Database
# noinspection PyProtectedMember
from pykusto._src.expressions import _StringColumn, _NumberColumn, _AnyTypeColumn, _BooleanColumn
# noinspection PyProtectedMember
@ -222,7 +222,7 @@ class TestClientFetch(TestBase):
self.assertType(client.test_db['other_table']['foo'], _AnyTypeColumn)
# Various utility methods
db = client.get_database('test_db')
self.assertType(db, _Database)
self.assertType(db, Database)
self.assertEqual('test_db', db.get_name())
self.assertEqual(('test_db',), tuple(client.get_databases_names()))
self.assertEqual(('mock_table', 'other_table'), tuple(client.test_db.get_table_names()))