From 0afc492248e9f7427696c1a7ab794fa4798b8efe Mon Sep 17 00:00:00 2001 From: Ofri Kleinfeld Date: Tue, 20 Jul 2021 15:00:47 +0300 Subject: [PATCH] CR fixes - fixed bug with not raising an exception and adding test coverage for wrong arguments type --- pykusto/_src/query.py | 6 +++--- test/test_query.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pykusto/_src/query.py b/pykusto/_src/query.py index b768dd3..0755a5d 100644 --- a/pykusto/_src/query.py +++ b/pykusto/_src/query.py @@ -553,11 +553,11 @@ class _JoinQuery(Query): def _inner_on_with_or_without_table(self, col: Union[BaseColumn, Tuple[BaseColumn, BaseColumn]]) -> '_JoinQuery': if isinstance(col, BaseColumn): return self._inner_on(col) - elif isinstance(col, tuple) and isinstance(col[0], BaseColumn) and isinstance(col[1], BaseColumn): + elif isinstance(col, tuple) and len(col) == 2 and isinstance(col[0], BaseColumn) and isinstance(col[1], BaseColumn): return self._inner_on_with_table(*col) else: - JoinException( - "A join argument could be a column, or a tuple of columns corresponding to the input and join " + raise JoinException( + "A join argument could be a column, or a tuple of two columns corresponding to the input and join " f"tables column names. However, the join argument provided is {col} of type {type(col)}" ) diff --git a/test/test_query.py b/test/test_query.py index 948b680..39f0796 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -265,6 +265,24 @@ class TestQuery(TestBase): Query(t).take(2), kind=JoinKind.INNER).render ) + def test_join_wrong_arguments_type(self): + col_name_str = "numField" + # noinspection PyTypeChecker + self.assertRaises( + JoinException( + "A join argument could be a column, or a tuple of two columns corresponding to the input and join " + f"tables column names. However, the join argument provided is {col_name_str} of type {type(col_name_str)}" + ), + lambda: ( + Query(t) + .where(t.numField > 4) + .take(5) + .join(Query(t).take(2), kind=JoinKind.INNER) + .on(col_name_str) + .render() + ) + ) + def test_extend(self): self.assertEqual( "mock_table | extend sumField = numField + numField2, foo = numField3 * 4 | take 5",