From 5f881026df531005a9e3d8384f34aa38fc7de0fa Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sun, 13 Aug 2023 10:17:22 -0400 Subject: [PATCH] fix(clickhouse): do not always prefix the table name with database, because temp tables cannot be assigned a database --- ibis/backends/clickhouse/__init__.py | 4 +--- .../test_complex_array_expr_projection/out.sql | 2 +- .../test_isin_notin_in_select/out1.sql | 2 +- .../test_isin_notin_in_select/out2.sql | 2 +- .../out.sql | 2 +- .../test_join_self_reference/out.sql | 4 ++-- .../out.sql | 2 +- .../test_self_reference_simple/out.sql | 2 +- .../playerID-awardID-any_inner_join/out.sql | 4 ++-- .../playerID-awardID-any_left_join/out.sql | 4 ++-- .../playerID-awardID-inner_join/out.sql | 4 ++-- .../playerID-awardID-left_join/out.sql | 4 ++-- .../playerID-playerID-any_inner_join/out.sql | 4 ++-- .../playerID-playerID-any_left_join/out.sql | 4 ++-- .../playerID-playerID-inner_join/out.sql | 4 ++-- .../playerID-playerID-left_join/out.sql | 4 ++-- .../test_simple_scalar_aggregates/out.sql | 2 +- .../test_table_column_unbox/out.sql | 2 +- .../test_timestamp_extract_field/out.sql | 2 +- .../test_where_simple_comparisons/out.sql | 2 +- .../test_where_with_between/out.sql | 2 +- ibis/backends/clickhouse/tests/test_client.py | 18 ++---------------- 22 files changed, 32 insertions(+), 48 deletions(-) diff --git a/ibis/backends/clickhouse/__init__.py b/ibis/backends/clickhouse/__init__.py index c8634df603be..48776e36b2bc 100644 --- a/ibis/backends/clickhouse/__init__.py +++ b/ibis/backends/clickhouse/__init__.py @@ -468,9 +468,7 @@ def close(self) -> None: self.con.close() def _fully_qualified_name(self, name: str, database: str | None) -> str: - return sg.table(name, db=database or self.current_database or None).sql( - dialect="clickhouse" - ) + return sg.table(name, db=database).sql(dialect="clickhouse") def get_schema(self, table_name: str, database: str | None = None) -> sch.Schema: """Return a Schema object for the indicated table and database. diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_array_expr_projection/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_array_expr_projection/out.sql index a9a0af297357..99cfcc6685c4 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_array_expr_projection/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_complex_array_expr_projection/out.sql @@ -4,7 +4,7 @@ FROM ( SELECT t0.string_col, count(*) AS count - FROM ibis_testing.functional_alltypes AS t0 + FROM functional_alltypes AS t0 GROUP BY t0.string_col ) AS t1 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out1.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out1.sql index 68f805955300..6320f23aa1a2 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out1.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out1.sql @@ -1,5 +1,5 @@ SELECT * -FROM ibis_testing.functional_alltypes AS t0 +FROM functional_alltypes AS t0 WHERE t0.string_col IN ('foo', 'bar') \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out2.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out2.sql index 6b54ac33071c..d89b906f9ea1 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out2.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isin_notin_in_select/out2.sql @@ -1,5 +1,5 @@ SELECT * -FROM ibis_testing.functional_alltypes AS t0 +FROM functional_alltypes AS t0 WHERE NOT t0.string_col IN ('foo', 'bar') \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isnull_case_expr_rewrite_failure/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isnull_case_expr_rewrite_failure/out.sql index 64ab0d8308a1..b391d150d2dd 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_isnull_case_expr_rewrite_failure/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_isnull_case_expr_rewrite_failure/out.sql @@ -1,3 +1,3 @@ SELECT sum(CASE WHEN isNull(t0.string_col) THEN 1 ELSE 0 END) AS "Sum(Where(IsNull(string_col), 1, 0))" -FROM ibis_testing.functional_alltypes AS t0 \ No newline at end of file +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_join_self_reference/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_join_self_reference/out.sql index f369044c93e4..4a756ab86ec9 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_join_self_reference/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_join_self_reference/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.functional_alltypes AS t0 -INNER JOIN ibis_testing.functional_alltypes AS t1 +FROM functional_alltypes AS t0 +INNER JOIN functional_alltypes AS t1 ON t0.id = t1.id \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_physical_table_reference_translate/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_physical_table_reference_translate/out.sql index 1db32cc34a27..cdcc673f9d1c 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_physical_table_reference_translate/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_physical_table_reference_translate/out.sql @@ -1,3 +1,3 @@ SELECT * -FROM ibis_testing.functional_alltypes \ No newline at end of file +FROM functional_alltypes \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_self_reference_simple/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_self_reference_simple/out.sql index 834569d7bcda..99d5c76e03f3 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_self_reference_simple/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_self_reference_simple/out.sql @@ -1,3 +1,3 @@ SELECT * -FROM ibis_testing.functional_alltypes AS t0 \ No newline at end of file +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_inner_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_inner_join/out.sql index 0d241ee9d400..f879a888124a 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_inner_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_inner_join/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.batting AS t0 -ANY JOIN ibis_testing.awards_players AS t1 +FROM batting AS t0 +ANY JOIN awards_players AS t1 ON t0.playerID = t1.awardID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_left_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_left_join/out.sql index a12ee0ef961d..88c96b29443c 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_left_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-any_left_join/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.batting AS t0 -LEFT ANY JOIN ibis_testing.awards_players AS t1 +FROM batting AS t0 +LEFT ANY JOIN awards_players AS t1 ON t0.playerID = t1.awardID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-inner_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-inner_join/out.sql index 8dc68ced27bf..700f214f0382 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-inner_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-inner_join/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.batting AS t0 -INNER JOIN ibis_testing.awards_players AS t1 +FROM batting AS t0 +INNER JOIN awards_players AS t1 ON t0.playerID = t1.awardID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-left_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-left_join/out.sql index 35d611b2f340..9e158d9dd8a1 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-left_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-awardID-left_join/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.batting AS t0 -LEFT OUTER JOIN ibis_testing.awards_players AS t1 +FROM batting AS t0 +LEFT OUTER JOIN awards_players AS t1 ON t0.playerID = t1.awardID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_inner_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_inner_join/out.sql index 41b1278f5f1d..363aaebf890c 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_inner_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_inner_join/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.batting AS t0 -ANY JOIN ibis_testing.awards_players AS t1 +FROM batting AS t0 +ANY JOIN awards_players AS t1 ON t0.playerID = t1.playerID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_left_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_left_join/out.sql index 701a461d51e1..3ba9f0d4e06f 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_left_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-any_left_join/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.batting AS t0 -LEFT ANY JOIN ibis_testing.awards_players AS t1 +FROM batting AS t0 +LEFT ANY JOIN awards_players AS t1 ON t0.playerID = t1.playerID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-inner_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-inner_join/out.sql index 8c9eed45dfd9..5d0d8dc31e6e 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-inner_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-inner_join/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.batting AS t0 -INNER JOIN ibis_testing.awards_players AS t1 +FROM batting AS t0 +INNER JOIN awards_players AS t1 ON t0.playerID = t1.playerID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-left_join/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-left_join/out.sql index f70a784199a9..cc098eca7bfb 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-left_join/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_joins/playerID-playerID-left_join/out.sql @@ -1,5 +1,5 @@ SELECT t0.* -FROM ibis_testing.batting AS t0 -LEFT OUTER JOIN ibis_testing.awards_players AS t1 +FROM batting AS t0 +LEFT OUTER JOIN awards_players AS t1 ON t0.playerID = t1.playerID \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_scalar_aggregates/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_scalar_aggregates/out.sql index 7faf72ff9a02..b811ff3d4c8d 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_scalar_aggregates/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_simple_scalar_aggregates/out.sql @@ -1,5 +1,5 @@ SELECT sum(t0.float_col) AS "Sum(float_col)" -FROM ibis_testing.functional_alltypes AS t0 +FROM functional_alltypes AS t0 WHERE t0.int_col > 0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_table_column_unbox/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_table_column_unbox/out.sql index 2941bd01a40b..63da10f48421 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_table_column_unbox/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_table_column_unbox/out.sql @@ -4,7 +4,7 @@ FROM ( SELECT t0.string_col, sum(t0.float_col) AS total - FROM ibis_testing.functional_alltypes AS t0 + FROM functional_alltypes AS t0 WHERE t0.int_col > 0 GROUP BY diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_timestamp_extract_field/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_timestamp_extract_field/out.sql index 201e06f72f71..9336d08bda8d 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_timestamp_extract_field/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_timestamp_extract_field/out.sql @@ -5,4 +5,4 @@ SELECT toHour(t0.timestamp_col) AS hour, toMinute(t0.timestamp_col) AS minute, toSecond(t0.timestamp_col) AS second -FROM ibis_testing.functional_alltypes AS t0 \ No newline at end of file +FROM functional_alltypes AS t0 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_simple_comparisons/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_simple_comparisons/out.sql index 86486220be26..6806def413a1 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_simple_comparisons/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_simple_comparisons/out.sql @@ -1,6 +1,6 @@ SELECT * -FROM ibis_testing.functional_alltypes AS t0 +FROM functional_alltypes AS t0 WHERE t0.float_col > 0 AND t0.int_col < ( t0.float_col * 2 diff --git a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_between/out.sql b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_between/out.sql index 27630e4efaa5..7982cdf7c584 100644 --- a/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_between/out.sql +++ b/ibis/backends/clickhouse/tests/snapshots/test_select/test_where_with_between/out.sql @@ -1,5 +1,5 @@ SELECT * -FROM ibis_testing.functional_alltypes AS t0 +FROM functional_alltypes AS t0 WHERE t0.int_col > 0 AND t0.float_col BETWEEN 0 AND 1 \ No newline at end of file diff --git a/ibis/backends/clickhouse/tests/test_client.py b/ibis/backends/clickhouse/tests/test_client.py index 86a8ac00a729..e9fd3ac4e011 100644 --- a/ibis/backends/clickhouse/tests/test_client.py +++ b/ibis/backends/clickhouse/tests/test_client.py @@ -10,7 +10,6 @@ import ibis.expr.datatypes as dt import ibis.expr.types as ir from ibis import config -from ibis.common.exceptions import IbisError from ibis.util import gen_name cc = pytest.importorskip("clickhouse_connect") @@ -72,7 +71,7 @@ def logger(x): with config.option_context("verbose_log", logger): con.table("functional_alltypes") - expected = "DESCRIBE ibis_testing.functional_alltypes" + expected = "DESCRIBE functional_alltypes" # might be other queries in there, we only check that a describe table # query was logged @@ -198,20 +197,7 @@ def test_list_tables_empty_database(con, temp_db): assert not con.list_tables(database=temp_db) -@pytest.mark.parametrize( - "temp", - [ - param( - True, - marks=pytest.mark.xfail( - reason="Ibis is likely making incorrect assumptions about object lifetime and cursors", - raises=IbisError, - ), - ), - False, - ], - ids=["temp", "no_temp"], -) +@pytest.mark.parametrize("temp", [True, False], ids=["temp", "no_temp"]) def test_create_table_no_data(con, temp, temp_table): schema = ibis.schema(dict(a="!int", b="string")) t = con.create_table(temp_table, schema=schema, temp=temp, engine="Memory")