Skip to content

Commit

Permalink
Merge pull request #138 from Azure/master
Browse files Browse the repository at this point in the history
#91- add wildcard to functions (#137)
  • Loading branch information
ymost committed Apr 4, 2021
2 parents f0a8111 + 7d2f1fc commit 2375772
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pykusto/_src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,10 @@ def zip() -> _DynamicExpression:
def any(*args: ExpressionType) -> _AnyAggregationExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/any-aggfunction
:param args: The expressions to return for the chosen record. An empty list will cause all columns to be returned.
"""
if len(args) == 0:
return _AnyAggregationExpression(KQL("any(*)"))
return _AnyAggregationExpression(KQL(f"any({', '.join(arg.kql for arg in args)})"))

@staticmethod
Expand All @@ -1127,18 +1130,26 @@ def any_if(expr: ExpressionType, predicate: BooleanType) -> _AnyAggregationExpre
return _AnyAggregationExpression(KQL(f"anyif({_to_kql(expr)}, {_to_kql(predicate)})"))

@staticmethod
def arg_max(*args: ExpressionType) -> _AnyAggregationExpression:
def arg_max(expr_to_maximize: ExpressionType, *args: ExpressionType) -> _AnyAggregationExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/arg-max-aggfunction
:param expr_to_maximize: The expression to maximize.
:param args: The expressions to return for the chosen record. An empty list will cause all columns to be returned.
"""
return _AnyAggregationExpression(KQL(f"arg_max({', '.join(arg.kql for arg in args)})"))
if len(args) == 0:
return _AnyAggregationExpression(KQL(f"arg_max({expr_to_maximize}, *)"))
return _AnyAggregationExpression(KQL(f"arg_max({expr_to_maximize}, {', '.join(arg.kql for arg in args)})"))

@staticmethod
def arg_min(*args: ExpressionType) -> _AnyAggregationExpression:
def arg_min(expr_to_minimize: ExpressionType, *args: ExpressionType) -> _AnyAggregationExpression:
"""
https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/arg-min-aggfunction
:param expr_to_minimize: The expression to minimize.
:param args: The expressions to return for the chosen record. An empty list will cause all columns to be returned.
"""
return _AnyAggregationExpression(KQL(f"arg_min({', '.join(arg.kql for arg in args)})"))
if len(args) == 0:
return _AnyAggregationExpression(KQL(f"arg_min({expr_to_minimize}, *)"))
return _AnyAggregationExpression(KQL(f"arg_min({expr_to_minimize}, {', '.join(arg.kql for arg in args)})"))

@staticmethod
def avg(expr: ExpressionType) -> _NumberAggregationExpression:
Expand Down
18 changes: 18 additions & 0 deletions test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ def test_any(self):
Query().summarize(f.any(t.stringField, t.numField, t.boolField)).render()
)

def test_any_wildcard(self):
self.assertEqual(
" | summarize any(*)",
Query().summarize(f.any()).render()
)

def test_any_if(self):
self.assertEqual(
" | summarize anyif(stringField, boolField)",
Expand Down Expand Up @@ -616,12 +622,24 @@ def test_arg_max(self):
Query().summarize(f.arg_max(t.stringField, t.numField, t.boolField)).render()
)

def test_arg_max_wildcard(self):
self.assertEqual(
" | summarize arg_max(stringField, *)",
Query().summarize(f.arg_max(t.stringField)).render()
)

def test_arg_min(self):
self.assertEqual(
" | summarize arg_min(stringField, numField, boolField)",
Query().summarize(f.arg_min(t.stringField, t.numField, t.boolField)).render()
)

def test_arg_min_wildcard(self):
self.assertEqual(
" | summarize arg_min(stringField, *)",
Query().summarize(f.arg_min(t.stringField)).render()
)

def test_avg(self):
self.assertEqual(
" | summarize avg(numField)",
Expand Down

0 comments on commit 2375772

Please sign in to comment.