#30- adding support for constant column extend

This commit is contained in:
Amos Rimon 2019-12-04 17:54:13 +02:00
Родитель a6f85c8015
Коммит bf635e84b6
2 изменённых файлов: 15 добавлений и 2 удалений

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

@ -12,7 +12,7 @@ from pykusto.expressions import BooleanType, ExpressionType, AggregationExpressi
StringType, AssignmentBase, AssignmentFromAggregationToColumn, AssignmentToSingleColumn, Column, BaseExpression, \ StringType, AssignmentBase, AssignmentFromAggregationToColumn, AssignmentToSingleColumn, Column, BaseExpression, \
AssignmentFromColumnToColumn AssignmentFromColumnToColumn
from pykusto.udf import stringify_python_func from pykusto.udf import stringify_python_func
from pykusto.utils import KQL, logger from pykusto.utils import KQL, logger, to_kql
class Order(Enum): class Order(Enum):
@ -137,7 +137,10 @@ class Query:
else: else:
assignments.append(arg) assignments.append(arg)
for column_name, expression in kwargs.items(): for column_name, expression in kwargs.items():
assignments.append(expression.assign_to(Column(column_name))) if isinstance(expression, BaseExpression):
assignments.append(expression.assign_to(Column(column_name)))
else:
assignments.append(BaseExpression(to_kql(expression)).assign_to(Column(column_name)))
return ExtendQuery(self, *assignments) return ExtendQuery(self, *assignments)
def summarize(self, *args: Union[AggregationExpression, AssignmentFromAggregationToColumn], def summarize(self, *args: Union[AggregationExpression, AssignmentFromAggregationToColumn],

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

@ -55,6 +55,16 @@ class TestExpressions(TestBase):
" | extend ['foo.bar'] = (shoo * 2)", " | extend ['foo.bar'] = (shoo * 2)",
Query().extend((col.shoo * 2).assign_to(col.foo.bar)).render(), Query().extend((col.shoo * 2).assign_to(col.foo.bar)).render(),
) )
self.assertEqual(
" | extend foo = (shoo * 2)",
Query().extend(foo=(col.shoo * 2)).render(),
)
def test_extend_const(self):
self.assertEqual(
" | extend foo = (5), bar = (\"bar\"), other_col = other",
Query().extend(foo=5, bar="bar", other_col=col.other).render(),
)
def test_between_timespan(self): def test_between_timespan(self):
self.assertEqual( self.assertEqual(