diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 09:58:56 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 10:20:20 +0300 |
commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/python/clickhouse-connect/clickhouse_connect/driver/ddl.py | |
parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
download | ydb-c2b2dfd9827a400a8495e172a56343462e3ceb82.tar.gz |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/python/clickhouse-connect/clickhouse_connect/driver/ddl.py')
-rw-r--r-- | contrib/python/clickhouse-connect/clickhouse_connect/driver/ddl.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/driver/ddl.py b/contrib/python/clickhouse-connect/clickhouse_connect/driver/ddl.py new file mode 100644 index 0000000000..a9a1a4b0aa --- /dev/null +++ b/contrib/python/clickhouse-connect/clickhouse_connect/driver/ddl.py @@ -0,0 +1,28 @@ +from typing import NamedTuple, Sequence + +from clickhouse_connect.datatypes.base import ClickHouseType + + +class TableColumnDef(NamedTuple): + """ + Simplified ClickHouse Table Column definition for DDL + """ + name: str + ch_type: ClickHouseType + expr_type: str = None + expr: str = None + + @property + def col_expr(self): + expr = f'{self.name} {self.ch_type.name}' + if self.expr_type: + expr += f' {self.expr_type} {self.expr}' + return expr + + +def create_table(table_name: str, columns: Sequence[TableColumnDef], engine: str, engine_params: dict): + stmt = f"CREATE TABLE {table_name} ({', '.join(col.col_expr for col in columns)}) ENGINE {engine} " + if engine_params: + for key, value in engine_params.items(): + stmt += f' {key} {value}' + return stmt |