Skip to content

clickhouse client move support#441

Merged
slabko merged 6 commits into
ClickHouse:masterfrom
ilandry:clickhouse_client_move
Jul 9, 2026
Merged

clickhouse client move support#441
slabko merged 6 commits into
ClickHouse:masterfrom
ilandry:clickhouse_client_move

Conversation

@ilandry

@ilandry ilandry commented Sep 21, 2025

Copy link
Copy Markdown
Contributor

As user of the library, the absence of support for move restricts design choices as it forces to use (smart or raw) ptr on Client or to make user classes non-movable too to accommodate.
While this is not dramatic, it is not ideal either. Looking at Client implementation, it has two members:

  • a unique_ptr to Impl which by definition should have correct and well defined move
  • a const ClientInfo object, as far as I saw all members are movable with non surprising side effect (std::string, std::vector, raw ptr and native integer types), by removing the const qualifier we make sure it is moved rather than copied (which could have unintended consequence for the raw ptr especially).

Hence I do not see large obstacle to make Client movable but happy to have second opinions from regular contributors. This is to kick start some discussions on the topic, I can test the change further on some applications if there is no opposition to the idea.

@CLAassistant

CLAassistant commented Sep 21, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Enmk Enmk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add proper unit-tests (https://github.com/ClickHouse/clickhouse-cpp/blob/master/ut/client_ut.cpp), since tests/simple/main.cpp is not built/executed on CI/CD.

Something like:

TEST(Client, MoveConstructor) {
...
}


TEST(Client, MoveAssignment) {
...
}

@ilandry

ilandry commented Sep 27, 2025

Copy link
Copy Markdown
Contributor Author

Nice, I missed that folder and looked in test only.
Added unit tests and removed the simple test change.

I used clang-format google style, let me know if you would like me to use a different code format (edit: used the project clang-format except for tied functions, I think it was more readable with one member per line but lmk).

@slabko slabko force-pushed the clickhouse_client_move branch from 2579b9c to 0753103 Compare July 8, 2026 15:18
@slabko slabko requested review from mzitnik and slabko as code owners July 8, 2026 15:18
They are not used anywhere, and go straight to clickhouse::Client::Impl
during initialization

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR enables move support for clickhouse::Client (previously non-movable due to rule-of-five + stored options), and adds unit tests to validate move behavior for both Client and ClientOptions.

Changes:

  • Make Client explicitly move-only (adds move ctor/assignment; deletes copy operations).
  • Remove the Client::options_ data member and rely on Impl’s internal options storage.
  • Add unit tests covering Client move construction/assignment and ClientOptions move behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
ut/client_ut.cpp Adds move-related unit tests for Client and ClientOptions (including an ABI-size “tripwire” under specific toolchain macros).
clickhouse/client.h Declares Client move operations and deletes copy operations; removes stored options_ member.
clickhouse/client.cpp Updates constructors to no longer initialize options_; defines defaulted move ctor/assignment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread clickhouse/client.h
Comment on lines +249 to +253
// movable only
Client(Client&&);
Client& operator=(Client&&);
Client(const Client&) = delete;
Client& operator=(const Client&) = delete;
Comment thread clickhouse/client.cpp Outdated
Comment on lines +1293 to +1294
Client::Client(Client&&) = default;
Client& Client::operator=(Client&&) = default;
Comment thread ut/client_ut.cpp Outdated
// below (both the initialization and the field-by-field comparison) and update
// the expected size here. Guarded to a single reference toolchain so it doesn't
// break builds on other platforms/STL implementations where the size differs.
#if defined(__linux__) && defined(__x86_64__) && defined(WITH_OPENSSL) && defined(__GLIBCXX__)
@slabko slabko force-pushed the clickhouse_client_move branch 2 times, most recently from 06f13bc to ed7bc17 Compare July 9, 2026 10:49
@slabko slabko requested a review from Copilot July 9, 2026 12:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread ut/client_ut.cpp Outdated
Comment on lines +2034 to +2035
TEST_P(ClientCase, ClientMoveAssign) {
Client client = std::move(*client_.get());
Comment thread clickhouse/client.h
Comment on lines +249 to +253
// movable only
Client(Client&&) noexcept;
Client& operator=(Client&&) noexcept;
Client(const Client&) = delete;
Client& operator=(const Client&) = delete;
Comment thread ut/client_ut.cpp
}

TEST_P(ClientCase, ClientMoveConstructor) {
Client client{std::move(*client_.get())};
Comment thread ut/client_ut.cpp Outdated
}

TEST_P(ClientCase, ClientMoveAssign) {
Client client = std::move(*client_.get());
@slabko slabko force-pushed the clickhouse_client_move branch from aea7a69 to 93fa35c Compare July 9, 2026 14:25
@slabko slabko requested a review from Copilot July 9, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@slabko slabko merged commit faf632e into ClickHouse:master Jul 9, 2026
39 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.

5 participants