Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clickhouse] Use chrono::NaiveDateTime for distributed_ddl_queue endpoint #7001

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

karencfv
Copy link
Contributor

@karencfv karencfv commented Nov 6, 2024

Adds a couple of fields (formatted_query_create_time and formatted_query_finish_time) to the response from the clickhouse-admin endpoint to retrieve information from system.distributed_ddl_queue.

@bnaecker suggested in #6986 (comment) that we use SET date_time_output_format = 'iso'; which works great to set the output format within a clickhouse client session, but sadly when using the -q flag with the clickhouse CLI it doesn't really work as multi-statements are not allowed:

$ clickhouse client --port 22001 -q "SET date_time_output_format = 'iso'; SELECT * FROM system.distributed_ddl_queue WHERE cluster = 'oximeter_cluster'"
Code: 62. DB::Exception: Syntax error (Multi-statements are not allowed): failed at position 36 (end of query): ; SELECT * FROM system.distributed_ddl_queue WHERE cluster = 'oximeter_cluster'. . (SYNTAX_ERROR)

I found a workaround though. By using the formatDateTime() function we can add the necessary formatted fields to the response.

$ clickhouse client --port 22001 -q "SELECT *, formatDateTime(query_finish_time, '%Y-%m-%dT%H:%i:%s') AS formatted_query_finish_time FROM system.distributed_ddl_queue WHERE cluster = 'oximeter_cluster' FORMAT JSONEachRow"
{"entry":"query-0000000001","entry_version":5,"initiator_host":"ixchel","initiator_port":22001,"cluster":"oximeter_cluster","query":"CREATE DATABASE IF NOT EXISTS db1 UUID '701a3dd3-10f0-4f5d-b5b2-0ad11bcf2b17' ON CLUSTER oximeter_cluster","settings":{"load_balancing":"random"},"query_create_time":"2024-11-01 16:17:08","host":"::1","port":22001,"status":"Finished","exception_code":0,"exception_text":"","query_finish_time":"2024-11-01 16:17:08","query_duration_ms":"3","formatted_query_finish_time":"2024-11-01T16:17:08"}
{"entry":"query-0000000001","entry_version":5,"initiator_host":"ixchel","initiator_port":22001,"cluster":"oximeter_cluster","query":"CREATE DATABASE IF NOT EXISTS db1 UUID '701a3dd3-10f0-4f5d-b5b2-0ad11bcf2b17' ON CLUSTER oximeter_cluster","settings":{"load_balancing":"random"},"query_create_time":"2024-11-01 16:17:08","host":"::1","port":22002,"status":"Finished","exception_code":0,"exception_text":"","query_finish_time":"2024-11-01 16:17:08","query_duration_ms":"4","formatted_query_finish_time":"2024-11-01T16:17:08"}
{"entry":"query-0000000000","entry_version":5,"initiator_host":"ixchel","initiator_port":22001,"cluster":"oximeter_cluster","query":"CREATE DATABASE IF NOT EXISTS db1 UUID 'a49757e4-179e-42bd-866f-93ac43136e2d' ON CLUSTER oximeter_cluster","settings":{"load_balancing":"random","output_format_json_quote_64bit_integers":"0"},"query_create_time":"2024-11-01 16:16:45","host":"::1","port":22002,"status":"Finished","exception_code":0,"exception_text":"","query_finish_time":"2024-11-01 16:16:45","query_duration_ms":"4","formatted_query_finish_time":"2024-11-01T16:16:45"}
{"entry":"query-0000000000","entry_version":5,"initiator_host":"ixchel","initiator_port":22001,"cluster":"oximeter_cluster","query":"CREATE DATABASE IF NOT EXISTS db1 UUID 'a49757e4-179e-42bd-866f-93ac43136e2d' ON CLUSTER oximeter_cluster","settings":{"load_balancing":"random","output_format_json_quote_64bit_integers":"0"},"query_create_time":"2024-11-01 16:16:45","host":"::1","port":22001,"status":"Finished","exception_code":0,"exception_text":"","query_finish_time":"2024-11-01 16:16:45","query_duration_ms":"4","formatted_query_finish_time":"2024-11-01T16:16:45"}

Perhaps there is a better way to do this? Open to suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant