Skip to content

Conversation

joe-clickhouse
Copy link
Contributor

Summary

Adds a client option called rename_response_column that will automatically rename columns according to one of the chosen renaming schemes. Options are:

Option Original Column Name New Column Name
None a.b.c d_e a.b.c d_e
remove_prefix a.b.c d_e c d_e
to_camelcase a.b.c d_e a.b.cDE
to_camelcase_without_prefix a.b.c d_e cDE
to_underscore a.b.c d_e a.b.c_d_e
to_underscore_without_prefix a.b.c d_e c_d_e

Follows closely the Java implementation from ClickHouse/clickhouse-java#923.

Closes #228

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

@joe-clickhouse joe-clickhouse linked an issue Sep 5, 2025 that may be closed by this pull request
byte_source = RespBuffCls(ResponseSource(response)) # pylint: disable=not-callable
context.set_response_tz(self._check_tz_change(response.headers.get('X-ClickHouse-Timezone')))
query_result = self._transform.parse_response(byte_source, context)
if self._column_renamer:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to move this functionality into the _transform.parse_response method or the query_result object. The client doesn't need to know how to modify query_result data, and the _column_renamer seems like it belongs more to the context. The only annoyance is that the "LIMIT 0" hack is currently in the client because ClickHouse Native won't return column names :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood! Makes sense. I'll move it.

@joe-clickhouse joe-clickhouse merged commit 4d40b1f into main Sep 11, 2025
78 checks passed
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.

Support new setting rename_response_column
2 participants