Skip to content

Commit 69325bd

Browse files
authored
Merge pull request #221 from den818/CLIENT_WRITE_INFO
Support client write info & progress written_rows/written_bytes
2 parents 0ef73e2 + 85f8c35 commit 69325bd

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

clickhouse/block.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ const BlockInfo& Block::Info() const {
7171
return info_;
7272
}
7373

74+
/// Set block info
75+
void Block::SetInfo(BlockInfo info) {
76+
info_ = std::move(info);
77+
}
78+
7479
/// Count of rows in the block.
7580
size_t Block::GetRowCount() const {
7681
return rows_;

clickhouse/block.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class Block {
7373

7474
const BlockInfo& Info() const;
7575

76+
/// Set block info
77+
void SetInfo(BlockInfo info);
78+
7679
/// Count of rows in the block.
7780
size_t GetRowCount() const;
7881

clickhouse/client.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
#define DBMS_MIN_REVISION_WITH_VERSION_PATCH 54401
3636
#define DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE 54405
3737
#define DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA 54410
38+
#define DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO 54420
3839

39-
#define REVISION DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA
40+
#define REVISION DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO
4041

4142
namespace clickhouse {
4243

@@ -408,6 +409,15 @@ bool Client::Impl::ReceivePacket(uint64_t* server_packet) {
408409
return false;
409410
}
410411
}
412+
if (REVISION >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO)
413+
{
414+
if (!WireFormat::ReadUInt64(*input_, &info.written_rows)) {
415+
return false;
416+
}
417+
if (!WireFormat::ReadUInt64(*input_, &info.written_bytes)) {
418+
return false;
419+
}
420+
}
411421

412422
if (events_) {
413423
events_->OnProgress(info);
@@ -475,7 +485,7 @@ bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
475485
return false;
476486
}
477487

478-
// TODO use data
488+
block->SetInfo(std::move(info));
479489
}
480490

481491
uint64_t num_columns = 0;

clickhouse/query.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct Progress {
4848
uint64_t rows = 0;
4949
uint64_t bytes = 0;
5050
uint64_t total_rows = 0;
51+
uint64_t written_rows = 0;
52+
uint64_t written_bytes = 0;
5153
};
5254

5355

ut/client_ut.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,35 @@ TEST_P(ClientCase, RoundtripArrayTString) {
10101010
EXPECT_TRUE(CompareRecursive(*array, *result_typed));
10111011
}
10121012

1013+
TEST_P(ClientCase, OnProgress) {
1014+
Block block;
1015+
createTableWithOneColumn<ColumnString>(block);
1016+
1017+
std::optional<Progress> received_progress;
1018+
Query query("INSERT INTO " + table_name + " (*) VALUES (\'Foo\'), (\'Bar\')" );
1019+
query.OnProgress([&](const Progress& progress) {
1020+
received_progress = progress;
1021+
});
1022+
client_->Execute(query);
1023+
1024+
ASSERT_TRUE(received_progress.has_value());
1025+
1026+
EXPECT_GE(received_progress->rows, 0u);
1027+
EXPECT_LE(received_progress->rows, 2u);
1028+
1029+
EXPECT_GE(received_progress->bytes, 0u);
1030+
EXPECT_LE(received_progress->bytes, 10000u);
1031+
1032+
EXPECT_GE(received_progress->total_rows, 0u);
1033+
EXPECT_LE(received_progress->total_rows, 2u);
1034+
1035+
EXPECT_GE(received_progress->written_rows, 0u);
1036+
EXPECT_LE(received_progress->written_rows, 2u);
1037+
1038+
EXPECT_GE(received_progress->written_bytes, 0u);
1039+
EXPECT_LE(received_progress->written_bytes, 10000u);
1040+
}
1041+
10131042
const auto LocalHostEndpoint = ClientOptions()
10141043
.SetHost( getEnvOrDefault("CLICKHOUSE_HOST", "localhost"))
10151044
.SetPort( getEnvOrDefault<size_t>("CLICKHOUSE_PORT", "9000"))

0 commit comments

Comments
 (0)