Skip to content

Postgres wire protocol: add copy command#74344

Merged
scanhex12 merged 51 commits intoClickHouse:masterfrom
scanhex12:copy_command
Aug 12, 2025
Merged

Postgres wire protocol: add copy command#74344
scanhex12 merged 51 commits intoClickHouse:masterfrom
scanhex12:copy_command

Conversation

@scanhex12
Copy link
Copy Markdown
Member

@scanhex12 scanhex12 commented Jan 8, 2025

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

PostgreSQL protocol COPY command support

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

CI Settings (Only check the boxes if you know what you are doing)

All builds in Builds_1 and Builds_2 stages are always mandatory
and will run independently of the checks below:

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64
  • Exclude: All with release
  • Exclude: All with debug

  • Run only fuzzers related jobs (libFuzzer fuzzers, AST fuzzers, BuzzHouse, etc.)
  • Exclude: AST fuzzers

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@scanhex12 scanhex12 marked this pull request as draft January 8, 2025 23:45
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jan 9, 2025
@kssenii kssenii self-assigned this Jan 9, 2025
@scanhex12 scanhex12 marked this pull request as ready for review January 9, 2025 19:20
@scanhex12 scanhex12 changed the title Draft: Postgres wire protocol : add copy command Postgres wire protocol : add copy command Jan 9, 2025
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-feature Pull request with new product feature label Jan 9, 2025
@robot-ch-test-poll robot-ch-test-poll added pr-improvement Pull request with some product improvements and removed pr-feature Pull request with new product feature labels Jan 9, 2025
@robot-ch-test-poll1
Copy link
Copy Markdown
Contributor

robot-ch-test-poll1 commented Jan 9, 2025

This is an automated comment for commit f701035 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS⏳ pending
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc❌ failure
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Successful checks
Check nameDescriptionStatus
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success

@scanhex12
Copy link
Copy Markdown
Member Author

@kssenii can you please review this MR? failed tests are not relevant to my changes

@kssenii kssenii removed their assignment Feb 4, 2025
@scanhex12 scanhex12 requested a review from rschu1ze February 8, 2025 20:47
@rschu1ze
Copy link
Copy Markdown
Member

rschu1ze commented Feb 9, 2025

@scanhex12 Thanks for the PR. Please help the reviewers a bit: What does this PR implement, how does it implement it (in particular is it modeled after some spec document or information), what are implications (e.g. in terms of backward compatibility, documentation, required tests, etc.)? Please be as verbose as possible. Sorry for asking, there are zero comments in the code, no information in the PR message and the Git commit history is list of "fix" commits.

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Feb 9, 2025

Workflow [PR], commit [4b42c7d]

@pamarcos
Copy link
Copy Markdown
Member

pamarcos commented Feb 17, 2025

@scanhex12 thanks for your contribution. After all the effort with the source code, please don't forget to address what Robert asked at #74344 (comment) to help us conduct the review.

Seems there are a couple of conflicts you'll need to resolve as well.

@clickhouse-ci clickhouse-ci bot added the manual approve Manual approve required to run CI label Mar 2, 2025
@scanhex12
Copy link
Copy Markdown
Member Author

@pamarcos Sorry for the delay in the review, I rebased the branch and wrote a couple of comments in the code, I hope it’s clearer. If not, let me know, I'll try to describe it in more detail.

@pamarcos
Copy link
Copy Markdown
Member

pamarcos commented Mar 3, 2025

@pamarcos Sorry for the delay in the review, I rebased the branch and wrote a couple of comments in the code, I hope it’s clearer. If not, let me know, I'll try to describe it in more detail.

No worries. I think Robert's ask and my own was that we're missing a proper description on the PR itself, not comments on the code. Please check out Robert's comment 🙏

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Apr 8, 2025

Dear @pamarcos, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

@alexey-milovidov alexey-milovidov changed the title Postgres wire protocol : add copy command Postgres wire protocol: add copy command Jun 1, 2025
@GrigoryPervakov GrigoryPervakov self-assigned this Jun 2, 2025
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Jun 16, 2025

Workflow [PR], commit [9cf66c5]

Summary:

job_name test_name status info comment
Stateless tests (amd_binary, old analyzer, s3 storage, DatabaseReplicated, parallel) failure
02435_rollback_cancelled_queries FAIL

@pamarcos pamarcos removed their request for review June 17, 2025 14:44
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 28, 2025
Copy link
Copy Markdown
Member

@GrigoryPervakov GrigoryPervakov left a comment

Choose a reason for hiding this comment

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

Overall LGTM
I've also noticed in the documentation that during the COPY FROM query, a client is allowed to send a batch in the middle of the row. It can break in such a case.
But for now, we can just leave a notice about that and fix it later if needed

String columns_to_insert;
if (!copy_query->column_names.empty())
{
for (const auto & column_name : copy_query->column_names)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: could use boost::algorithm::join(copy_query->column_names, ", ");

@scanhex12 scanhex12 enabled auto-merge August 12, 2025 12:08
format_ptr->flush();
output_buffer.finalize();
message_transport->send(PostgreSQLProtocol::Messaging::CopyOutData(std::move(result_buf)));
message_transport->send(PostgreSQLProtocol::Messaging::CopyOutData(result_buf));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it's better to move it and then explicitly initialize it after.
Extra empty vector allocation looks better than a full buffer copy before send

@scanhex12 scanhex12 added this pull request to the merge queue Aug 12, 2025
Merged via the queue into ClickHouse:master with commit 04304c3 Aug 12, 2025
113 of 122 checks passed
@scanhex12 scanhex12 deleted the copy_command branch August 12, 2025 16:00
@rschu1ze
Copy link
Copy Markdown
Member

rschu1ze commented Aug 12, 2025

@scanhex12 Kindly add a proper changelog message to the PR, thanks.

@scanhex12 scanhex12 added pr-feature Pull request with new product feature and removed pr-improvement Pull request with some product improvements labels Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants