query_log.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from ob_jobs.common import ChOptions
  2. def query_log_source_table(ch_opts: ChOptions):
  3. tmp_table_name = 't_query_log'
  4. sql = f"""
  5. create table {tmp_table_name} (
  6. `hostname` STRING,
  7. `type` STRING,
  8. `event_date` DATE,
  9. `event_time` TIMESTAMP,
  10. `query_start_time` TIMESTAMP,
  11. `query_duration_ms` DECIMAL,
  12. `read_rows` DECIMAL,
  13. `read_bytes` DECIMAL,
  14. `written_rows` DECIMAL,
  15. `written_bytes` DECIMAL,
  16. `result_rows` DECIMAL,
  17. `result_bytes` DECIMAL,
  18. `memory_usage` DECIMAL,
  19. `current_database` STRING,
  20. `query` STRING,
  21. `formatted_query` STRING,
  22. `normalized_query_hash` DECIMAL(20, 0),
  23. `query_kind` STRING,
  24. `databases` ARRAY<STRING>,
  25. `tables` ARRAY<STRING>,
  26. `columns` ARRAY<STRING>,
  27. `partitions` ARRAY<STRING>,
  28. `exception_code` INTEGER,
  29. `exception` STRING,
  30. `stack_trace` STRING,
  31. `is_initial_query` SMALLINT,
  32. `user` STRING,
  33. `query_id` STRING,
  34. `port` INTEGER,
  35. `client_name` STRING,
  36. `http_user_agent` STRING
  37. ) with (
  38. 'connector' = 'clickhouse',
  39. 'url' = 'clickhouse://{ch_opts.ch_host}:{ch_opts.ch_port}',
  40. 'database-name' = '{ch_opts.ch_dbname}',
  41. 'table-name' = 'query_log',
  42. 'username' = '{ch_opts.ch_user}',
  43. 'password' = '{ch_opts.ch_password}'
  44. )
  45. """
  46. return sql, tmp_table_name