Skip to content

Commit

Permalink
receiving server logs
Browse files Browse the repository at this point in the history
  • Loading branch information
den818 committed Oct 9, 2022
1 parent 9782b5c commit ed2384c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions clickhouse/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,25 @@ bool Client::Impl::ReceivePacket(uint64_t* server_packet) {
return false;
}

case ServerCodes::Log: {
// log tag
if (!WireFormat::SkipString(*input_)) {
return false;
}
Block block;

// Use uncompressed stream since log blocks usually contain only one row
if (!ReadBlock(*input_, &block)) {
return false;
}

if (events_) {
events_->OnServerLog(block);
}

return true;
}

default:
throw UnimplementedError("unimplemented " + std::to_string((int)packet_type));
break;
Expand Down
16 changes: 16 additions & 0 deletions clickhouse/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class QueryEvents {

virtual void OnProgress(const Progress& progress) = 0;

virtual void OnServerLog(const Block& block) = 0;

virtual void OnFinish() = 0;
};

Expand All @@ -74,6 +76,7 @@ using ExceptionCallback = std::function<void(const Exception& e)>;
using ProgressCallback = std::function<void(const Progress& progress)>;
using SelectCallback = std::function<void(const Block& block)>;
using SelectCancelableCallback = std::function<bool(const Block& block)>;
using SelectServerLogCallback = std::function<bool(const Block& block)>;


class Query : public QueryEvents {
Expand Down Expand Up @@ -116,6 +119,12 @@ class Query : public QueryEvents {
return *this;
}

/// Set handler for receiving a server log of query exceution.
inline Query& OnServerLog(SelectServerLogCallback cb) {
select_server_log_cb_ = std::move(cb);
return *this;
}

static const std::string default_query_id;

private:
Expand Down Expand Up @@ -149,6 +158,12 @@ class Query : public QueryEvents {
}
}

void OnServerLog(const Block& block) override {
if (select_server_log_cb_) {
select_server_log_cb_(block);
}
}

void OnFinish() override {
}

Expand All @@ -159,6 +174,7 @@ class Query : public QueryEvents {
ProgressCallback progress_cb_;
SelectCallback select_cb_;
SelectCancelableCallback select_cancelable_cb_;
SelectServerLogCallback select_server_log_cb_;
};

}

0 comments on commit ed2384c

Please sign in to comment.