зеркало из https://github.com/Azure/pykusto.git
Fix argument types in hash function
This commit is contained in:
Родитель
0f6ff9a350
Коммит
4a4a8db08f
|
@ -53,13 +53,11 @@ class BaseExpression:
|
|||
def get_type(self) -> '_StringExpression':
|
||||
return _StringExpression(KQL(f'gettype({self.kql})'))
|
||||
|
||||
def __hash__(self, mod: _NumberType = None) -> '_StringExpression':
|
||||
def __hash__(self, mod: Union['_NumberExpression', int] = None) -> '_StringExpression':
|
||||
"""
|
||||
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/hashfunction
|
||||
"""
|
||||
if mod is not None:
|
||||
if not isinstance(mod, (_NumberExpression, int)):
|
||||
raise ValueError("'mod' argument must be an integer")
|
||||
return _StringExpression(KQL(f'hash({self.kql}, {_to_kql(mod)})'))
|
||||
return _StringExpression(KQL(f'hash({self.kql})'))
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ class Functions:
|
|||
return expr.get_year()
|
||||
|
||||
@staticmethod
|
||||
def hash(expr: _ExpressionType, mod: _NumberType = None) -> _StringExpression:
|
||||
def hash(expr: BaseExpression, mod: Union['_NumberExpression', int] = None) -> _StringExpression:
|
||||
"""
|
||||
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/hashfunction
|
||||
"""
|
||||
|
|
|
@ -173,10 +173,6 @@ class TestFunction(TestBase):
|
|||
" | where (hash(stringField, 100)) == 3",
|
||||
Query().where(f.hash(t.stringField, 100) == 3).render()
|
||||
)
|
||||
self.assertRaises(
|
||||
ValueError("'mod' argument must be an integer"),
|
||||
lambda: Query().where(f.hash(t.stringField, 1.5) == 3).render()
|
||||
)
|
||||
self.assertEqual(
|
||||
" | where (hash(stringField, numField)) == 3",
|
||||
Query().where(f.hash(t.stringField, t.numField) == 3).render()
|
||||
|
|
Загрузка…
Ссылка в новой задаче