Merge pull request #42 from Azure/#40-literal-dynamic

fix #40 literal dynamic
This commit is contained in:
shaike87 2020-01-14 11:14:44 +02:00 коммит произвёл GitHub
Родитель 8783b166ce ed956aa337
Коммит 1a096bf3a4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 13 добавлений и 10 удалений

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

@ -1,3 +1,4 @@
import json
from typing import Union
from pykusto.expressions import Column, NumberType, NumberExpression, TimespanType, \
@ -583,16 +584,20 @@ def startofyear(expr: DatetimeType, offset: NumberType = None) -> DatetimeExpres
return expr.startofyear(offset)
def strcat(expr1: StringType, expr2: StringType, *exprs: StringType) -> StringExpression:
res = 'strcat({}, {}'.format(to_kql(expr1),
to_kql(expr2))
if len(exprs) > 0:
res = res + ', ' + ', '.join([to_kql(expr) for expr in exprs])
return StringExpression(KQL(res + ')'))
def strcat(*strings: StringType) -> StringExpression:
if len(strings) < 2:
raise ValueError("strcat requires at least two arguments")
return StringExpression(KQL('strcat({})'.format(', '.join(to_kql(s) for s in strings))))
def to_literal_dynamic(d: DynamicType) -> KQL:
if isinstance(d, BaseExpression):
return d.kql
return KQL('dynamic({})'.format(json.dumps(d)))
def strcat_array(expr: ArrayType, delimiter: StringType) -> StringExpression:
return StringExpression(KQL('strcat_array({}, {})'.format(to_kql(expr), to_kql(delimiter))))
return StringExpression(KQL('strcat_array({}, {})'.format(to_literal_dynamic(expr), to_kql(delimiter))))
def strcat_delim(delimiter: StringType, expr1: StringType, expr2: StringType, *exprs: StringType) -> StringExpression:

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

@ -29,7 +29,7 @@ def timedelta_to_kql(td: timedelta) -> KQL:
@kql_converter(Mapping, List, Tuple)
def dynamic_to_kql(d: Union[Mapping, List, Tuple]) -> KQL:
query = list(json.dumps(d))
# Issue #11
# Convert square brackets to round brackets (Issue #11)
counter = 0
prev = ""
for i, c in enumerate(query):

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

@ -1,5 +1,4 @@
import datetime
import unittest
from pykusto import functions as f
from pykusto.expressions import column_generator as col
@ -372,7 +371,6 @@ class TestFunction(TestBase):
Query().extend(f.strcat_delim('-', ',', col.foo)).render()
)
@unittest.skip("Enabled after #40 is fixed")
def test_strcat_array(self):
self.assertEqual(
" | where (strcat_array(foo, \",\")) == \"A,B,C\"",