зеркало из https://github.com/Azure/pykusto.git
fix #37 - split
This commit is contained in:
Родитель
290b60fd7e
Коммит
844fa3dacc
|
@ -238,8 +238,8 @@ class StringExpression(BaseExpression):
|
|||
|
||||
def split(self, delimiter: StringType, requested_index: NumberType = None) -> 'ArrayExpression':
|
||||
if requested_index is None:
|
||||
return ArrayExpression(KQL('split({}, {}'.format(self.kql, delimiter)))
|
||||
return ArrayExpression(KQL('split({}, {}, {}'.format(self.kql, delimiter, requested_index)))
|
||||
return ArrayExpression(KQL('split({}, "{}")'.format(_subexpr_to_kql(self.kql), delimiter)))
|
||||
return ArrayExpression(KQL('split({}, "{}", {})'.format(_subexpr_to_kql(self.kql), delimiter, requested_index)))
|
||||
|
||||
def equals(self, other: StringType, case_sensitive: bool = False) -> BooleanExpression:
|
||||
return BooleanExpression.binary_op(self, ' == ' if case_sensitive else ' =~ ', other)
|
||||
|
|
|
@ -548,7 +548,8 @@ def sign(expr: NumberType) -> NumberExpression:
|
|||
# def sin(self): return
|
||||
#
|
||||
#
|
||||
# def split(self): return
|
||||
def split(string: StringType, delimiter: StringType, requested_index: NumberType = None) -> 'ArrayExpression':
|
||||
return StringExpression(KQL(string)).split(delimiter, requested_index)
|
||||
|
||||
|
||||
def sqrt(expr: NumberType) -> NumberExpression:
|
||||
|
|
|
@ -389,6 +389,20 @@ class TestFunction(TestBase):
|
|||
Query().where(f.substring(col.foo, col.bar, 4) == 'ABC,ABC').render()
|
||||
)
|
||||
|
||||
def test_split(self):
|
||||
self.assertEqual(
|
||||
' | extend foo = (split(bar, "_", 3))',
|
||||
Query().extend(foo=f.split(col.bar, "_", 3)).render()
|
||||
)
|
||||
self.assertEqual(
|
||||
' | extend foo = (split(bar, "_")[3])',
|
||||
Query().extend(foo=f.split(col.bar, "_")[3]).render()
|
||||
)
|
||||
self.assertEqual(
|
||||
' | extend foo = (split("1_2", "_")[3])',
|
||||
Query().extend(foo=f.split("1_2", "_")[3]).render()
|
||||
)
|
||||
|
||||
def test_tobool(self):
|
||||
self.assertEqual(
|
||||
" | where tobool(foo)",
|
||||
|
|
Загрузка…
Ссылка в новой задаче