This commit is contained in:
Shai Keren 2020-01-01 14:41:05 +02:00
Родитель 290b60fd7e
Коммит 844fa3dacc
3 изменённых файлов: 18 добавлений и 3 удалений

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

@ -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)",