From bf635e84b600bbd8a54b7f20f3ab5cd755f1d415 Mon Sep 17 00:00:00 2001 From: Amos Rimon Date: Wed, 4 Dec 2019 17:54:13 +0200 Subject: [PATCH] #30- adding support for constant column extend --- pykusto/query.py | 7 +++++-- test/test_expressions.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pykusto/query.py b/pykusto/query.py index 5025977..b7157fb 100644 --- a/pykusto/query.py +++ b/pykusto/query.py @@ -12,7 +12,7 @@ from pykusto.expressions import BooleanType, ExpressionType, AggregationExpressi StringType, AssignmentBase, AssignmentFromAggregationToColumn, AssignmentToSingleColumn, Column, BaseExpression, \ AssignmentFromColumnToColumn from pykusto.udf import stringify_python_func -from pykusto.utils import KQL, logger +from pykusto.utils import KQL, logger, to_kql class Order(Enum): @@ -137,7 +137,10 @@ class Query: else: assignments.append(arg) 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) def summarize(self, *args: Union[AggregationExpression, AssignmentFromAggregationToColumn], diff --git a/test/test_expressions.py b/test/test_expressions.py index 3074ef4..7c42e8a 100644 --- a/test/test_expressions.py +++ b/test/test_expressions.py @@ -55,6 +55,16 @@ class TestExpressions(TestBase): " | extend ['foo.bar'] = (shoo * 2)", 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): self.assertEqual(