from ob_jobs.common import ChOptions def query_log_source_table(ch_opts: ChOptions): tmp_table_name = 't_query_log' sql = f""" create table {tmp_table_name} ( `hostname` STRING, `type` STRING, `event_date` DATE, `event_time` TIMESTAMP, `query_start_time` TIMESTAMP, `query_duration_ms` DECIMAL, `read_rows` DECIMAL, `read_bytes` DECIMAL, `written_rows` DECIMAL, `written_bytes` DECIMAL, `result_rows` DECIMAL, `result_bytes` DECIMAL, `memory_usage` DECIMAL, `current_database` STRING, `query` STRING, `formatted_query` STRING, `normalized_query_hash` DECIMAL(20, 0), `query_kind` STRING, `databases` ARRAY, `tables` ARRAY, `columns` ARRAY, `partitions` ARRAY, `exception_code` INTEGER, `exception` STRING, `stack_trace` STRING, `is_initial_query` SMALLINT, `user` STRING, `query_id` STRING, `port` INTEGER, `client_name` STRING, `http_user_agent` STRING ) with ( 'connector' = 'clickhouse', 'url' = 'clickhouse://{ch_opts.ch_host}:{ch_opts.ch_port}', 'database-name' = '{ch_opts.ch_dbname}', 'table-name' = 'query_log', 'username' = '{ch_opts.ch_user}', 'password' = '{ch_opts.ch_password}' ) """ return sql, tmp_table_name