-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathline_sender_cpp_example_array_elem_strides.cpp
More file actions
74 lines (67 loc) · 2.06 KB
/
line_sender_cpp_example_array_elem_strides.cpp
File metadata and controls
74 lines (67 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <questdb/ingress/line_sender.hpp>
#include <iostream>
#include <vector>
using namespace std::literals::string_view_literals;
using namespace questdb::ingress::literals;
/*
* QuestDB server version 9.0.0 or later is required for array support.
*/
static bool array_example(std::string_view host, std::string_view port)
{
try
{
auto sender = questdb::ingress::line_sender::from_conf(
"tcp::addr=" + std::string{host} + ":" + std::string{port} +
";protocol_version=3;");
const auto table_name = "cpp_market_orders_elem_strides"_tn;
const auto symbol_col = "symbol"_cn;
const auto book_col = "order_book"_cn;
size_t rank = 3;
std::vector<uintptr_t> shape{2, 3, 2};
std::vector<intptr_t> strides{6, 2, 1};
std::array<double, 12> arr_data = {
48123.5,
2.4,
48124.0,
1.8,
48124.5,
0.9,
48122.5,
3.1,
48122.0,
2.7,
48121.5,
4.3};
questdb::ingress::array::strided_view<
double,
questdb::ingress::array::strides_mode::elements>
book_data{
3,
shape.data(),
strides.data(),
arr_data.data(),
arr_data.size()};
questdb::ingress::line_sender_buffer buffer = sender.new_buffer();
buffer.table(table_name)
.symbol(symbol_col, "BTC-USD"_utf8)
.column(book_col, book_data)
.at(questdb::ingress::timestamp_nanos::now());
sender.flush(buffer);
return true;
}
catch (const questdb::ingress::line_sender_error& err)
{
std::cerr << "[ERROR] " << err.what() << std::endl;
return false;
}
}
int main(int argc, const char* argv[])
{
auto host = "localhost"sv;
if (argc >= 2)
host = std::string_view{argv[1]};
auto port = "9009"sv;
if (argc >= 3)
port = std::string_view{argv[2]};
return !array_example(host, port);
}