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

add parameterized syntax, just syntax-sugar #260

Closed
wants to merge 2 commits into from
Closed

add parameterized syntax, just syntax-sugar #260

wants to merge 2 commits into from

Conversation

1261385937
Copy link
Contributor

Now clickhouse-cpp supports parameterized syntax, and the placeholder should be ? .
It is just syntax-sugar, all replacing happens on the client side

Any document about clickhouse-server prepare statement?
@Enmk

@1261385937
Copy link
Contributor Author

#153

@1261385937 1261385937 closed this Dec 6, 2022
@1261385937 1261385937 reopened this Dec 6, 2022
@Enmk
Copy link
Collaborator

Enmk commented Dec 10, 2022

Closing to re-open and re-trigger CI/CD

@Enmk Enmk closed this Dec 10, 2022
@Enmk Enmk reopened this Dec 10, 2022
Copy link
Collaborator

@Enmk Enmk left a comment

Choose a reason for hiding this comment

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

Requires more test cases, e.g. when there is an '?' already present in query string, like this:
SELECT 'hello!?'

@Enmk
Copy link
Collaborator

Enmk commented Apr 21, 2023

I suggest utilizing existing CH features for that:
https://clickhouse.com/docs/en/sql-reference/syntax#defining-and-using-query-parameters
For users that means they'd have to use {pid:UInt16} syntax.

For developers, that means we'd have to either

  • prepend query with multiple SET queries, which I dislike.
  • or update TCPHandler to take parameters from settings and apply that to query context (pretty much the same way it is done in HTTP handler)

Notes to myself on how to implement later on CH side:
src/Parsers/ASTSetQuery.h:10 constexpr char QUERY_PARAMETER_NAME_PREFIX[] = "param_";
Context::setQueryParameter() with those in TCPHandler.cpp
src/Interpreters/executeQuery.cpp executeQuery seems to be handling query parameters just fine.

@Enmk
Copy link
Collaborator

Enmk commented Apr 21, 2023

I suggest utilizing existing CH features for that: https://clickhouse.com/docs/en/sql-reference/syntax#defining-and-using-query-parameters For users that means they'd have to use {pid:UInt16} syntax.

For developers, that means we'd have to either

* prepend query with multiple `SET` queries, which I dislike.

* or update `TCPHandler` to take parameters from settings and apply that to query context (pretty much the same way it is done in HTTP handler)

Notes to myself on how to implement later on CH side: src/Parsers/ASTSetQuery.h:10 constexpr char QUERY_PARAMETER_NAME_PREFIX[] = "param_"; Context::setQueryParameter() with those in TCPHandler.cpp src/Interpreters/executeQuery.cpp executeQuery seems to be handling query parameters just fine.

Update: it looks like CH already supports setting parameters via native TCP protocol, we just need to update protocol version up to DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS (which is 54459) we currently support DBMS_MIN_REVISION_WITH_INCREMENTAL_PROFILE_EVENTS (which is 54451).

So we need to add following features one by one:

  • DBMS_MIN_REVISION_WITH_AGGREGATE_FUNCTIONS_VERSIONING - medium (or simple if we don't add support of new aggregate function serialization formats)
  • DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS - easy, just read (or ignore) more field into ClientInfo
  • DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION - hard, but 95% ready in Support sparse serialization #245
  • DBMS_MIN_PROTOCOL_VERSION_WITH_PROFILE_EVENTS_IN_INSERT - simple
  • DBMS_MIN_PROTOCOL_VERSION_WITH_VIEW_IF_PERMITTED - simple if we just don't load warnings from server, medium if we do
  • DBMS_MIN_PROTOCOL_VERSION_WITH_ADDENDUM - simple
  • DBMS_MIN_PROTOCOL_VERSION_WITH_QUOTA_KEY - simple - just add String quota_key to ClientInfo and send/receive it to/from the server.

So yeah,

@Enmk Enmk mentioned this pull request Apr 21, 2023
@1261385937
Copy link
Contributor Author

ok

@1261385937 1261385937 closed this by deleting the head repository Nov 15, 2023
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