def test_ago(self): self.assertEqual( " | where dateField > (ago(time(4.0:0:0.0)))", Query().where(t.dateField > f.ago(timedelta(4))).render()) self.assertEqual( " | where dateField > (ago(timespanField))", Query().where(t.dateField > f.ago(t.timespanField)).render())
def test_iff_different_types(self): with self.assertLogs(_logger, logging.WARN) as cm: self.assertEqual( ' | project foo = iff(dateField > (ago(time(2.0:0:0.0))), time(3.0:0:0.0), "hello")', Query().project(foo=f.iff(t.dateField > f.ago(timedelta(2)), timedelta(3), "hello")).render()) self.assertEqual([ 'WARNING:pykusto:The second and third arguments must be of the same type, but they are: timespan and string. ' 'If this is a mistake, please report it at https://github.com/Azure/pykusto/issues' ], cm.output)
def test_iif(self): # iif is just an alias to iff self.assertEqual( " | project foo = iff(dateField > (ago(time(2.0:0:0.0))), time(3.0:0:0.0), time(4.0:0:0.0))", Query().project(foo=f.iif(t.dateField > f.ago(timedelta(2)), timedelta(3), timedelta(4))).render() )
def test_iff_related_types(self): self.assertEqual( " | project foo = iff(dateField > (ago(time(2.0:0:0.0))), 2, array_length(arrayField))", Query().project(foo=f.iff(t.dateField > f.ago(timedelta(2)), 2, f.array_length(t.arrayField))).render() )
def test_iff_expression_return_type(self): self.assertEqual( " | project foo = iff(dateField > (ago(time(2.0:0:0.0))), array_length(arrayField), array_length(arrayField2))", Query().project(foo=f.iff(t.dateField > f.ago(timedelta(2)), f.array_length(t.arrayField), f.array_length(t.arrayField2))).render() )