Skip to content

Commit 975556f

Browse files
cpcloudgforsyth
authored andcommitted
fix(clickhouse): use backwards compatible methods of getting query metadata
1 parent a7fd32b commit 975556f

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

ibis/backends/clickhouse/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import ast
44
import atexit
55
import glob
6-
import json
76
from contextlib import closing, suppress
87
from functools import partial
98
from typing import TYPE_CHECKING, Any, Literal
@@ -516,16 +515,16 @@ def get_schema(self, table_name: str, database: str | None = None) -> sch.Schema
516515
return sch.Schema(dict(zip(names, map(ClickhouseType.from_string, types))))
517516

518517
def _get_schema_using_query(self, query: str) -> sch.Schema:
519-
query = f"EXPLAIN json = 1, description = 0, header = 1 {query}"
520-
with closing(self.raw_sql(query)) as results:
521-
[[raw_plans]] = results.result_columns
522-
[plan] = json.loads(raw_plans)
523-
return sch.Schema(
524-
{
525-
field["Name"]: ClickhouseType.from_string(field["Type"])
526-
for field in plan["Plan"]["Header"]
527-
}
528-
)
518+
name = util.gen_name("get_schema_using_query")
519+
with closing(self.raw_sql(f"CREATE VIEW {name} AS {query}")):
520+
pass
521+
try:
522+
with closing(self.raw_sql(f"DESCRIBE {name}")) as results:
523+
names, types, *_ = results.result_columns
524+
finally:
525+
with closing(self.raw_sql(f"DROP VIEW {name}")):
526+
pass
527+
return sch.Schema(dict(zip(names, map(ClickhouseType.from_string, types))))
529528

530529
@classmethod
531530
def has_operation(cls, operation: type[ops.Value]) -> bool:

0 commit comments

Comments
 (0)