diff --git a/CHANGELOG.md b/CHANGELOG.md index 479841b..4b35a2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +* Remove unnecessary `print` statement leading to test failures + ## [0.6.1] **Full Changelog**: diff --git a/src/sql_mock/helpers.py b/src/sql_mock/helpers.py index 36bd88e..ec4aed3 100644 --- a/src/sql_mock/helpers.py +++ b/src/sql_mock/helpers.py @@ -78,7 +78,6 @@ def replace_original_table_references( query_ast = _replace_table_ref_in_columns( query_ast=query_ast, table_ref=table_ref, new_ref=sql_mock_cte_name, dialect=dialect ) - print(query_ast.sql(pretty=True)) return replace_tables(expression=query_ast, mapping={table_ref: sql_mock_cte_name}, dialect=dialect) diff --git a/tests/sql_mock/clickhouse/test_query_execution.py b/tests/sql_mock/clickhouse/test_query_execution.py index 2a8efbe..12c5784 100644 --- a/tests/sql_mock/clickhouse/test_query_execution.py +++ b/tests/sql_mock/clickhouse/test_query_execution.py @@ -1,4 +1,5 @@ import os +from datetime import datetime import pytest @@ -55,3 +56,76 @@ class ResultMock(ClickHouseTableMock): ] result.assert_equal(expected) + + +def test_argmaxif(): + query = """SELECT + user_id, + count() AS num_sessions, + countIf(valid = 1) AS num_valid_sessions, + argMaxIf(in_trial, dt, isNotNull(in_trial)) AS in_trial + FROM sessions + GROUP BY user_id + """ + + @table_meta(table_ref="sessions") + class SessionsMock(ClickHouseTableMock): + dt = col.Datetime(default=datetime(2024, 1, 1, 10, 30)) + valid = col.Boolean(default=True) + user_id = col.String(default="foo") + in_trial = col.Int(default=0, nullable=True) + + @table_meta(query=query) + class ResultMock(ClickHouseTableMock): + user_id = col.String(default="foo") + num_sessions = col.Int(default=0) + num_valid_sessions = col.Int(default=0) + in_trial = col.Int(default=0) + + sessions_mock = SessionsMock.from_dicts( + [ + dict( + dt=datetime(2024, 1, 1, 10), + valid=1, + user_id="foo", + in_trial=1, + ), + dict( + dt=datetime(2024, 1, 2, 10), + valid=0, + user_id="foo", + in_trial=1, + ), + dict( + dt=datetime(2024, 1, 3, 10), + valid=1, + user_id="foo", + in_trial=1, + ), + dict( + dt=datetime(2024, 1, 4, 10), + valid=1, + user_id="foo", + in_trial=None, + ), + dict( + dt=datetime(2024, 1, 5, 10), + valid=1, + user_id="foo", + in_trial=0, + ), + ] + ) + + result = ResultMock.from_mocks(input_data=[sessions_mock]) + + expected = [ + dict( + user_id="foo", + num_sessions=5, + num_valid_sessions=4, + in_trial=0, + ) + ] + + result.assert_equal(expected)