Skip to content

introduce ndarr support #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 123 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
87aa240
c client nd array begin.
kafka1991 Apr 1, 2025
6bd3223
Ndarray support for rust client.
kafka1991 Apr 2, 2025
b518a99
optimize doc.
kafka1991 Apr 2, 2025
53a430e
add tests.
kafka1991 Apr 2, 2025
b1ebd1d
fix comments.
kafka1991 Apr 2, 2025
006af98
fix docs.
kafka1991 Apr 3, 2025
a31716a
fix tests and compile error in ffi.
kafka1991 Apr 3, 2025
463a2d3
format code.
kafka1991 Apr 3, 2025
44fae08
ffi supported
kafka1991 Apr 3, 2025
93c6f9d
ndarray c api
kafka1991 Apr 3, 2025
e9da558
format
kafka1991 Apr 3, 2025
0e8a9e5
c++ api support.
kafka1991 Apr 3, 2025
261163c
add include.
kafka1991 Apr 3, 2025
a565109
code format.
kafka1991 Apr 3, 2025
d1edbbc
Merge remote-tracking branch 'origin/main' into array
kafka1991 Apr 6, 2025
e161b1d
conflict resolve
kafka1991 Apr 6, 2025
4a59ec0
code review.
kafka1991 Apr 7, 2025
0c513b1
code format.
kafka1991 Apr 7, 2025
4a58346
c example
kafka1991 Apr 7, 2025
1a6cf6f
make mock.rs recv works.
kafka1991 Apr 7, 2025
9caed7a
easier pre-ci 'proj' script to build lint and test changes
amunra Apr 7, 2025
c2583f1
c api add strides.
kafka1991 Apr 7, 2025
0476faf
add strideArrayView for rust array ingress api
kafka1991 Apr 8, 2025
31e57c5
add strideArrayView for rust array ingress api
kafka1991 Apr 8, 2025
533224a
add benchmark test.
kafka1991 Apr 8, 2025
8d30e57
fix tests
kafka1991 Apr 9, 2025
36203a6
better memory copy.
kafka1991 Apr 9, 2025
feaf5be
code format
kafka1991 Apr 9, 2025
c4bed10
make c api works.
kafka1991 Apr 9, 2025
f3011e1
make c api works.
kafka1991 Apr 9, 2025
70eaa24
code format
kafka1991 Apr 9, 2025
526e8ae
make c++ tests work.
kafka1991 Apr 9, 2025
9c16d74
fix compile error.
kafka1991 Apr 9, 2025
5dae9d0
make c++20 build happy
kafka1991 Apr 9, 2025
ea52293
code format
kafka1991 Apr 9, 2025
193b887
fix cpp problem on windows.
kafka1991 Apr 10, 2025
523a855
lint issues
amunra Apr 10, 2025
3442cbe
introduce line protocol version
kafka1991 Apr 14, 2025
2b927ae
support https
kafka1991 May 5, 2025
edb40fc
code format.
kafka1991 May 5, 2025
c9f1476
implement NDArrayView for common built-in array, vector and slices.
kafka1991 May 6, 2025
a883112
code format
kafka1991 May 6, 2025
f3e8681
add tests for build-in array,vector and slice.
kafka1991 May 6, 2025
1ee3b58
add line protocol version tests for rust client.
kafka1991 May 6, 2025
d34c651
make line protocol version c++ interface more ideamatic
kafka1991 May 6, 2025
9c78839
fix build failure.
kafka1991 May 6, 2025
ced8e05
fix little comment
kafka1991 May 6, 2025
ef8ab61
add system_test.
kafka1991 May 7, 2025
ed3fc06
add more system array tests
kafka1991 May 7, 2025
3839403
code format
kafka1991 May 7, 2025
33767f3
better c/cpp array examples.
kafka1991 May 7, 2025
6e8d77e
fix test.py
kafka1991 May 7, 2025
6168e7f
add array example tests.
kafka1991 May 7, 2025
d758e6d
c error code.
kafka1991 May 8, 2025
bf8ae37
remove unnecessary mut.
kafka1991 May 8, 2025
fa6f04d
make c++20 happy
kafka1991 May 8, 2025
3ce862e
more ideamatic python array interface
kafka1991 May 8, 2025
6678679
code format and cpp compile fix.
kafka1991 May 8, 2025
6f1e7e3
fixed encapsulation issue (we were leaking internal types to the publ…
amunra May 8, 2025
d76b272
Merge branch 'array' of https://github.com/questdb/c-questdb-client i…
amunra May 8, 2025
8d739f1
typo fixed.
kafka1991 May 9, 2025
710a69f
cleanup and added todo comments
amunra May 9, 2025
997937c
Merge branch 'array' of https://github.com/questdb/c-questdb-client i…
amunra May 9, 2025
75d01ae
removed slow build debug artifacts upload which we generally don't need
amunra May 9, 2025
066d0a1
Merge remote-tracking branch 'origin/main' into array
amunra May 9, 2025
b091bf6
fix failed tests.
kafka1991 May 12, 2025
ca4f47c
optimize internal implementation
kafka1991 May 13, 2025
68d89d3
fix benchmark
kafka1991 May 13, 2025
47cdde6
optimize array internal implementation
kafka1991 May 13, 2025
542da03
fix compile error.
kafka1991 May 13, 2025
175d895
test format
kafka1991 May 13, 2025
b89788c
code review.
kafka1991 May 14, 2025
58c6539
fix c api
kafka1991 May 15, 2025
8fb0c4a
code reviews.
kafka1991 May 15, 2025
56e349a
rename c api `new_buffer()` name.
kafka1991 May 15, 2025
ce8a084
Merge remote-tracking branch 'origin/main' into array
amunra May 15, 2025
f163a31
fix system.tests
kafka1991 May 15, 2025
82b0dc3
Merge remote-tracking branch 'origin/array' into array
kafka1991 May 15, 2025
0c5e509
renamed Influx to Ingestion in various places to avoid being misleadi…
amunra May 15, 2025
6e1e68d
fix systemtests
kafka1991 May 15, 2025
a461bfd
reworked the python system tests for cross version testing
amunra May 15, 2025
bf419f1
enrich rust tests.
kafka1991 May 15, 2025
01bfd91
clearing all tables before each test run
amunra May 15, 2025
36cb2e3
Merge branch 'array' of https://github.com/questdb/c-questdb-client i…
amunra May 15, 2025
8c1d9b9
fixed broken C example
amunra May 15, 2025
36f4bd5
minor fixes
amunra May 15, 2025
3392627
fix abnormal tests hang.
kafka1991 May 16, 2025
d4d6bb1
enrich tests
kafka1991 May 16, 2025
e3a6bec
remove buffer size overflow test
kafka1991 May 16, 2025
c05753e
empty array throw exception.
kafka1991 May 16, 2025
b9e023f
enrich tests.
kafka1991 May 16, 2025
3fd415f
test assertion improvements
amunra May 16, 2025
eadbadf
fixed failing test on Windows
amunra May 16, 2025
cba4c33
fix tests
kafka1991 May 16, 2025
a25e66c
tweaks to speed tests up on Windows
amunra May 16, 2025
3b134d2
skipping redundant tests
amunra May 16, 2025
692088e
skipping more redundant tests
amunra May 16, 2025
9521d0f
reduced some timeouts on expected-timeout tests
amunra May 16, 2025
54f6969
skipping even more redundant tests
amunra May 16, 2025
bba4192
ignoring profile result from git-tracked files
amunra May 16, 2025
039ecf6
use `assert_err_contains` in all tests.
kafka1991 May 17, 2025
b3d982f
use `assert_err_contains` in all tests.
kafka1991 May 17, 2025
7c75cdb
fixed buffer/sender version checks
amunra May 19, 2025
d9dd58b
refactoring of the C and C++ public apis and some minor Rust changes
amunra May 20, 2025
ac38b3c
removed convenience constructors, users should prefer conf or env
amunra May 20, 2025
e5fc025
less broken
amunra May 20, 2025
81675ad
gcc fix
amunra May 20, 2025
5889e05
incomplete: moving C strides view to ffi crate
amunra May 20, 2025
0c12e6d
add max_name_len ffi
kafka1991 May 21, 2025
8df0379
You shall pass!
amunra May 21, 2025
48748cb
removed no-panic dependency and cleaned up unused code when building …
amunra May 21, 2025
c51fef2
export max_array_dims
kafka1991 May 21, 2025
09a1172
Merge branch 'array' of github.com:questdb/c-questdb-client into array
kafka1991 May 21, 2025
ea90636
Revert "export max_array_dims"
kafka1991 May 21, 2025
5da905e
remove comment.
kafka1991 May 22, 2025
1ed8d6c
add `line_sender_c_example_array_elem_strides` api
kafka1991 May 23, 2025
27383c8
remove buffer size overflow test
kafka1991 May 23, 2025
f8a1771
remove buffer size overflow test
kafka1991 May 23, 2025
dc8b43b
fix typo.
kafka1991 May 23, 2025
9ecdad9
adapt server json path format.
kafka1991 May 23, 2025
3d9ab0e
code format
kafka1991 May 24, 2025
0c70977
Updated readmes
amunra May 25, 2025
76296ec
add non-contiguous minus strides array.
kafka1991 May 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.0.4
current_version = 5.0.0-rc1
commit = False
tag = False

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ cmake-build-release
.cache
questdb-rs/Cargo.lock
include/questdb/ingress/line_sender.gen.h
cython/questdb/ingress/line_sender.pxd
cython/questdb/ingress/line_sender.pxd
profile.out
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.15.0)
project(c-questdb-client VERSION 4.0.4)
project(c-questdb-client VERSION 5.0.0)
set(PROJECT_PRE_RELEASE "rc1")

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
Expand Down Expand Up @@ -98,6 +99,14 @@ if (QUESTDB_TESTS_AND_EXAMPLES)
line_sender_c_example
examples/concat.c
examples/line_sender_c_example.c)
compile_example(
line_sender_c_example_array_byte_strides
examples/concat.c
examples/line_sender_c_example_array_byte_strides.c)
compile_example(
line_sender_c_example_array_elem_strides
examples/concat.c
examples/line_sender_c_example_array_elem_strides.c)
compile_example(
line_sender_c_example_auth
examples/concat.c
Expand All @@ -123,6 +132,12 @@ if (QUESTDB_TESTS_AND_EXAMPLES)
compile_example(
line_sender_cpp_example
examples/line_sender_cpp_example.cpp)
compile_example(
line_sender_cpp_example_array_byte_strides
examples/line_sender_cpp_example_array_byte_strides.cpp)
compile_example(
line_sender_cpp_example_array_elem_strides
examples/line_sender_cpp_example_array_elem_strides.cpp)
compile_example(
line_sender_cpp_example_auth
examples/line_sender_cpp_example_auth.cpp)
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

This library makes it easy to insert data into [QuestDB](https://questdb.io/).

This client library implements the [InfluxDB Line Protocol](
This client library implements the QuestDB [Ingestion Line Protocol](
https://questdb.io/docs/reference/api/ilp/overview/) (ILP) over HTTP and TCP.

When connecting to QuestDB over HTTP, the library will auto-detect the server's
latest supported version and use it. Version 1 is compatible with
the [InfluxDB Line Protocol](https://docs.influxdata.com/influxdb/v2/reference/syntax/line-protocol/).

* Implementation is in Rust, with no additional
[run-time or link-time dependencies](doc/BUILD.md#pre-requisites-and-dependencies)
on the C++ standard library or other libraries.
Expand Down Expand Up @@ -38,6 +42,21 @@ For an overview and code examples, see the
To understand the protocol in more depth, consult the
[protocol reference docs](https://questdb.io/docs/reference/api/ilp/overview/).

## Protocol Versions

The library supports the following ILP protocol versions.

These protocol versions are supported over both HTTP and TCP.

If you use HTTP, the library will automatically detect the server's
latest supported protocol version and use it. If you use TCP, you can specify the
`protocol_version=N` parameter when constructing the `Sender` object.

| Version | Description | Server Comatibility |
| ------- | ------------------------------------------------------- | --------------------- |
| **1** | Over HTTP it's compatible InfluxDB Line Protocol (ILP) | All QuestDB versions |
| **2** | 64-bit floats sent as binary, adds n-dimentional arrays | 8.4.0+ (2023-10-30) |

## Getting Started

To get started, read the language-specific guides.
Expand Down
4 changes: 4 additions & 0 deletions ci/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ steps:
rustup default $(toolchain)
condition: ne(variables['toolchain'], '')
displayName: "Update and set Rust toolchain"
- script: |
python -m pip install --upgrade pip
pip install numpy
displayName: 'Install Python Dependencies'
- script: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DQUESTDB_TESTS_AND_EXAMPLES=ON
env:
JAVA_HOME: $(JAVA_HOME_11_X64)
Expand Down
6 changes: 4 additions & 2 deletions ci/run_all_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
build_cxx20_dir.glob(f'**/test_line_sender{exe_suffix}')))

system_test_path = pathlib.Path('system_test') / 'test.py'
qdb_v = '8.2.3' # The version of QuestDB we'll test against.
#qdb_v = '8.2.3' # The version of QuestDB we'll test against.

run_cmd('cargo', 'test',
'--', '--nocapture', cwd='questdb-rs')
Expand All @@ -51,9 +51,11 @@ def main():
'--', '--nocapture', cwd='questdb-rs')
run_cmd('cargo', 'test', '--features=almost-all-features',
'--', '--nocapture', cwd='questdb-rs')
run_cmd('cargo', 'test', cwd='questdb-rs-ffi')
run_cmd(str(test_line_sender_path))
run_cmd(str(test_line_sender_path_CXX20))
run_cmd('python3', str(system_test_path), 'run', '--versions', qdb_v, '-v')
#run_cmd('python3', str(system_test_path), 'run', '--versions', qdb_v, '-v')
run_cmd('python3', str(system_test_path), 'run', '--repo', './questdb_nd_arr', '-v')


if __name__ == '__main__':
Expand Down
21 changes: 16 additions & 5 deletions ci/run_tests_pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,25 @@ stages:
cd questdb-rs
cargo build --examples --features almost-all-features
displayName: "Build Rust examples"
############################# temp for test begin #####################
- script: |
git clone -b nd_arr --depth 1 https://github.com/questdb/questdb.git ./questdb_nd_arr
displayName: git clone questdb
- task: Maven@3
displayName: "Compile QuestDB"
inputs:
mavenPOMFile: 'questdb_nd_arr/pom.xml'
jdkVersionOption: '1.11'
options: "-DskipTests -Pbuild-web-console"
############################# temp for test end #####################
- script: python3 ci/run_all_tests.py
env:
JAVA_HOME: $(JAVA_HOME_11_X64)
displayName: "Tests"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: ./build
displayName: "Publish build directory"
# - task: PublishBuildArtifacts@1
# inputs:
# pathToPublish: ./build
# displayName: "Publish build directory"
- job: FormatAndLinting
displayName: "cargo fmt and clippy"
pool:
Expand Down Expand Up @@ -115,7 +126,7 @@ stages:
submodules: false
- template: compile.yaml
- script: |
git clone --depth 1 https://github.com/questdb/questdb.git
git clone -b nd_arr --depth 1 https://github.com/questdb/questdb.git
displayName: git clone questdb
- task: Maven@3
displayName: "Compile QuestDB"
Expand Down
65 changes: 52 additions & 13 deletions cpp_test/mock_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "mock_server.hpp"

#include <string.h>
#include <string>

#if defined(PLATFORM_UNIX)
# include <fcntl.h>
Expand Down Expand Up @@ -190,43 +191,81 @@ bool mock_server::wait_for_data(std::optional<double> wait_timeout_sec)
return !!count;
}

int32_t bytes_to_int32_le(const std::byte* bytes)
{
return static_cast<int32_t>(
(bytes[0] << 0) | (bytes[1] << 8) | (bytes[2] << 16) |
(bytes[3] << 24));
}

size_t mock_server::recv(double wait_timeout_sec)
{
if (!wait_for_data(wait_timeout_sec))
return 0;

char chunk[1024];
std::byte chunk[1024];
size_t chunk_len{sizeof(chunk)};
std::vector<char> accum;
std::vector<std::byte> accum;
for (;;)
{
wait_for_data();
sock_ssize_t count =
::recv(_conn_fd, &chunk[0], static_cast<sock_len_t>(chunk_len), 0);
sock_ssize_t count = ::recv(
_conn_fd,
reinterpret_cast<char*>(&chunk[0]),
static_cast<sock_len_t>(chunk_len),
0);
if (count == -1)
throw std::runtime_error{"Bad `recv()`."};
const size_t u_count = static_cast<size_t>(count);
accum.insert(accum.end(), chunk, chunk + u_count);
if (accum.size() < 2)
continue;
if ((accum[accum.size() - 1] == '\n') &&
(accum[accum.size() - 2] != '\\'))
if ((accum[accum.size() - 1] == std::byte('\n')) &&
(accum[accum.size() - 2] != std::byte('\\')))
break;
}

size_t received_count{0};
const char* head{&accum[0]};
for (size_t index = 1; index < accum.size(); ++index)
const std::byte* head{&accum[0]};
size_t index{1};
while (index < accum.size())
{
const char& last = accum[index];
const char& prev = accum[index - 1];
if ((last == '\n') && (prev != '\\'))
const std::byte& last = accum[index];
const std::byte& prev = accum[index - 1];
if (last == std::byte('=') && prev == std::byte('='))
{
index++;
std::byte& binary_type = accum[index];
if (binary_type == std::byte(16)) // DOUBLE_BINARY_FORMAT_TYPE
index += sizeof(double) + 1;
else if (binary_type == std::byte(14)) // ARRAY_BINARY_FORMAT_TYPE
{
index++;
const std::byte& array_elem_type = accum[index];
if (array_elem_type == std::byte(10))
{
index++;
const size_t dims = size_t(accum[index]);
index++;
size_t data_size{sizeof(double)};
for (size_t i = 0; i < dims; i++)
{
data_size *= bytes_to_int32_le(&accum[index]);
index += sizeof(int32_t);
}
index += data_size;
}
}
continue;
}
else if ((last == std::byte('\n')) && (prev != std::byte('\\')))
{
const char* tail{&last + 1};
_msgs.emplace_back(head, tail - head);
const std::byte* tail{&last + 1};
_msgs.emplace_back(head, tail);
head = tail;
++received_count;
}
index++;
}
return received_count;
}
Expand Down
19 changes: 14 additions & 5 deletions cpp_test/mock_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@

#pragma once

#include <cassert>
#include <vector>
#include <string>
#include <cstdint>
#include <optional>
#include <stdexcept>

#include "build_env.h"
#if __cplusplus < 202002L
# include "questdb/ingress/line_sender.hpp"
#else
# include <span>
#endif

#if defined(PLATFORM_UNIX)
typedef int socketfd_t;
Expand Down Expand Up @@ -60,9 +64,14 @@ class mock_server

size_t recv(double wait_timeout_sec = 0.1);

const std::vector<std::string>& msgs() const
#if __cplusplus >= 202002L
using buffer_view = std::span<const std::byte>;
#endif

buffer_view msgs(size_t index) const
{
return _msgs;
assert(index < _msgs.size());
return {_msgs[index].data(), _msgs[index].size()};
}

void close();
Expand All @@ -75,7 +84,7 @@ class mock_server
socketfd_t _listen_fd;
socketfd_t _conn_fd;
uint16_t _port;
std::vector<std::string> _msgs;
std::vector<std::vector<std::byte>> _msgs;
};

} // namespace questdb::ingress::test
Loading
Loading