|
3 | 3 | import ast
|
4 | 4 | import atexit
|
5 | 5 | import glob
|
6 |
| -import json |
7 | 6 | from contextlib import closing, suppress
|
8 | 7 | from functools import partial
|
9 | 8 | from typing import TYPE_CHECKING, Any, Literal
|
@@ -516,16 +515,16 @@ def get_schema(self, table_name: str, database: str | None = None) -> sch.Schema
|
516 | 515 | return sch.Schema(dict(zip(names, map(ClickhouseType.from_string, types))))
|
517 | 516 |
|
518 | 517 | 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)))) |
529 | 528 |
|
530 | 529 | @classmethod
|
531 | 530 | def has_operation(cls, operation: type[ops.Value]) -> bool:
|
|
0 commit comments