Skip to content

Conversation

@theory
Copy link
Contributor

@theory theory commented Dec 3, 2025

To allow the user to configure other bits of the query, like settings.

To allow the user to configure other bits of the query, like settings.
theory added a commit to ClickHouse/pg_clickhouse that referenced this pull request Dec 4, 2025
Add a new struct, `ch_query`, and replace all instances of passing a
`char *` with passing `ch_query`. This allows it to included additional
fields relevant to the query, starting here with `sql` and `settings`,
the latter currently being a PostgreSQL `List` of the settings parsed
from `pg_clickhouse.session_settings`. Provide `new_query()` to keep its
construction in one place; in the future it might take parameters to
merge additional settings fetched from a server or user mapping to merge
into the GUC's settings.

Update `ch_binary_simple_query()` to iterate over the list of settings
in the `ch_query` and apply them to the query as a `QuerySettings` map.
Add a comment to do the same for inserts, held until
[clickhouse-cpp#453] is merged and released.

Update `ch_http_simple_query()` to use `curl_url_set()` to build each
request URL, starting with the base URL and query ID, then adding
another query parameter for each item in `ch_query.settings`. This also
eliminates the need for `ch_http_connection_t.base_url_len`.

Add tests to ensure consistent application of a variety of settings via
both the binary and http engines.

While at it, fix a bug where http query results treated an empty string
as `NULL` and add a test for it. Also replace a buffer allocation with
simple use of `psprintf()`, which is automatically cleaned up in the
current PostgreSQL memory context.

Other bits:

*   Document `pg_clickhouse.session_settings`
*   Rename `connect.h` to `engine.h`, which better describes its purpose
    providing objects and functions used by both the http and binary
    engines.

  [clickhouse-cpp#453]: ClickHouse/clickhouse-cpp#453
theory added a commit to ClickHouse/pg_clickhouse that referenced this pull request Dec 4, 2025
Add a new struct, `ch_query`, and replace all instances of passing a
`char *` with passing `ch_query`. This allows it to included additional
fields relevant to the query, starting here with `sql` and `settings`,
the latter currently being a PostgreSQL `List` of the settings parsed
from `pg_clickhouse.session_settings`. Provide `new_query()` to keep its
construction in one place; in the future it might take parameters to
merge additional settings fetched from a server or user mapping to merge
into the GUC's settings.

Update `ch_binary_simple_query()` to iterate over the list of settings
in the `ch_query` and apply them to the query as a `QuerySettings` map.
Add a comment to do the same for inserts, held until
[clickhouse-cpp#453] is merged and released.

Update `ch_http_simple_query()` to use `curl_url_set()` to build each
request URL, starting with the base URL and query ID, then adding
another query parameter for each item in `ch_query.settings`. This also
eliminates the need for `ch_http_connection_t.base_url_len`.

Add tests to ensure consistent application of a variety of settings via
both the binary and http engines.

While at it, fix a bug where http query results treated an empty string
as `NULL` and add a test for it. Also replace a buffer allocation with
simple use of `psprintf()`, which is automatically cleaned up in the
current PostgreSQL memory context.

Other bits:

*   Document `pg_clickhouse.session_settings`
*   Rename `connect.h` to `engine.h`, which better describes its purpose
    providing objects and functions used by both the http and binary
    engines
*   Remove the unused `cursor_free_method` field from the
    `libclickhouse_methods` struct

  [clickhouse-cpp#453]: ClickHouse/clickhouse-cpp#453
theory added a commit to ClickHouse/pg_clickhouse that referenced this pull request Dec 5, 2025
Add a new struct, `ch_query`, and replace all instances of passing a
`char *` with passing `ch_query`. This allows it to included additional
fields relevant to the query, starting here with `sql` and `settings`,
the latter currently being a PostgreSQL `List` of the settings parsed
from `pg_clickhouse.session_settings`. Provide `new_query()` to keep its
construction in one place; in the future it might take parameters to
merge additional settings fetched from a server or user mapping to merge
into the GUC's settings.

Update `ch_binary_simple_query()` to iterate over the list of settings
in the `ch_query` and apply them to the query as a `QuerySettings` map.
Add a comment to do the same for inserts, held until
[clickhouse-cpp#453] is merged and released.

Update `ch_http_simple_query()` to use `curl_url_set()` to build each
request URL, starting with the base URL and query ID, then adding
another query parameter for each item in `ch_query.settings`. This also
eliminates the need for `ch_http_connection_t.base_url_len`.

Add tests to ensure consistent application of a variety of settings via
both the binary and http engines.

While at it, fix a bug where http query results treated an empty string
as `NULL` and add a test for it. Also replace a buffer allocation with
simple use of `psprintf()`, which is automatically cleaned up in the
current PostgreSQL memory context.

Other bits:

*   Document `pg_clickhouse.session_settings`
*   Rename `connect.h` to `engine.h`, which better describes its purpose
    providing objects and functions used by both the http and binary
    engines
*   Remove the unused `cursor_free_method` field from the
    `libclickhouse_methods` struct

  [clickhouse-cpp#453]: ClickHouse/clickhouse-cpp#453
theory added a commit to ClickHouse/pg_clickhouse that referenced this pull request Dec 5, 2025
Add a new struct, `ch_query`, and replace all instances of passing a
`char *` with passing `ch_query`. This allows it to included additional
fields relevant to the query, starting here with `sql` and `settings`,
the latter currently being a PostgreSQL `List` of the settings parsed
from `pg_clickhouse.session_settings`. Provide `new_query()` to keep its
construction in one place; in the future it might take parameters to
merge additional settings fetched from a server or user mapping to merge
into the GUC's settings.

Update `ch_binary_simple_query()` to iterate over the list of settings
in the `ch_query` and apply them to the query as a `QuerySettings` map.
Add a comment to do the same for inserts, held until
[clickhouse-cpp#453] is merged and released.

Update `ch_http_simple_query()` to use `curl_url_set()` to build each
request URL, starting with the base URL and query ID, then adding
another query parameter for each item in `ch_query.settings`. This also
eliminates the need for `ch_http_connection_t.base_url_len`.

Add tests to ensure consistent application of a variety of settings via
both the binary and http engines.

While at it, fix a bug where http query results treated an empty string
as `NULL` and add a test for it. Also replace a buffer allocation with
simple use of `psprintf()`, which is automatically cleaned up in the
current PostgreSQL memory context.

Other bits:

*   Document `pg_clickhouse.session_settings`
*   Rename `connect.h` to `engine.h`, which better describes its purpose
    providing objects and functions used by both the http and binary
    engines
*   Remove the unused `cursor_free_method` field from the
    `libclickhouse_methods` struct

  [clickhouse-cpp#453]: ClickHouse/clickhouse-cpp#453
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.

2 participants