kou commented on code in PR #39081:
URL: https://github.com/apache/arrow/pull/39081#discussion_r1421773362
##########
http/examples/get/client.cpp:
##########
Review Comment:
We can just count the number of received record batches:
```cpp
#include <curl/curl.h>
#include <arrow/api.h>
#include <arrow/io/api.h>
#include <arrow/ipc/api.h>
#include <chrono>
#include <iostream>
#include <fstream>
class CountListener : public arrow::ipc::Listener {
public:
CountListener() : num_record_batches_(0) {
}
int64_t num_record_batches() const {
return num_record_batches_;
}
arrow::Status OnRecordBatchWithMetadataDecoded(
arrow::RecordBatchWithMetadata record_batch_with_metadata) override {
++num_record_batches_;
return arrow::Status::OK();
}
private:
int64_t num_record_batches_;
};
static size_t
WriteFunction(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t real_size = size * nmemb;
auto decoder = static_cast<arrow::ipc::StreamDecoder *>(userp);
auto status = decoder->Consume(static_cast<const uint8_t*>(contents),
real_size);
if (status.ok()) {
return real_size;
} else {
std::cerr << status.ToString() << std::endl;
return 0;
}
}
int main(void)
{
std::string url = "http://localhost:8000";
CURL *curl_handle;
CURLcode res;
auto count_listener = std::make_shared<CountListener>();
arrow::ipc::StreamDecoder decoder(count_listener);
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteFunction);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &decoder);
auto start_time = std::chrono::steady_clock::now();
res = curl_easy_perform(curl_handle);
printf("%ld record batches received\n",
count_listener->num_record_batches());
auto end_time = std::chrono::steady_clock::now();
auto time_duration =
std::chrono::duration_cast<std::chrono::duration<double>>(end_time -
start_time);
printf("%.2f seconds elapsed\n", time_duration.count());
curl_easy_cleanup(curl_handle);
curl_global_cleanup();
return 0;
}
// to compile (for example):
//clang++ client.cpp -std=c++17 $(pkg-config --cflags --libs arrow libcurl)
-o client
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]