Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 .github/workflows/timeplus_cpp_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
- name: Test - Start timeplusd server in background
run: |
docker pull timeplus/timeplusd:${{matrix.timeplusd}}
docker run -d --name timeplusd -p 8463:8463 timeplus/timeplusd:${{matrix.timeplusd}}
docker run -d --name timeplusd -p 8463:8463 -v /mnt/timeplusd:/var/lib/timeplusd timeplus/timeplusd:${{matrix.timeplusd}}
docker ps -a
docker stats -a --no-stream
## Check and wait until timeplusd is ready to accept connections
Expand Down
35 changes: 35 additions & 0 deletions tests/simple/TestFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,38 @@ void testNestedType(Client& client){

client.Execute("DROP STREAM IF EXISTS nested_example");
}

void testJsonType(Client& client) {
client.Execute("DROP STREAM IF EXISTS json_example");
client.Execute("CREATE STREAM IF NOT EXISTS json_example (j json)");

{
Block block;

auto json_col = std::make_shared<ColumnJson>();

auto f1 = std::make_shared<ColumnFloat64>(std::vector<double>{3.1415, 9898.5679});
auto f2 = std::make_shared<ColumnFloat64>(std::vector<double>{23.123, 0.999754});

auto json1 = std::unordered_map<std::string, ColumnRef>{{"a.b.b.c", f1}, {"`a.b.b`.c", f2}};

json_col->Append(json1);

block.AppendColumn("j", json_col);

client.Insert("json_example", block);
}

std::this_thread::sleep_for(std::chrono::seconds(3));

client.Select("SELECT j::json FROM table(json_example)", [](const Block& block) {
for (size_t c = 0; c < block.GetRowCount(); ++c) {
auto json = block[0]->As<ColumnJson>();

auto a_b_b_c = (*json)["a.b.b.c"]->As<ColumnFloat64>();
auto abb_c = (*json)["`a.b.b`.c"]->As<ColumnFloat64>();
std::cout << "a.b.b.c[" << c << "]: " << a_b_b_c->At(c) << "\n";
std::cout << "`a.b.b`.c[" << c << "]: " << abb_c->At(c) << "\n";
}
});
}
1 change: 1 addition & 0 deletions tests/simple/TestFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ void testLowCardinalityStringType(Client& client);
void testMapType(Client& client);
void testTupleType(Client& client);
void testNestedType(Client& client);
void testJsonType(Client& client);
1 change: 1 addition & 0 deletions tests/simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static void RunTests(Client& client) {
testMapType(client);
testTupleType(client);
testNestedType(client);
testJsonType(client);
}

int main()
Expand Down
3 changes: 3 additions & 0 deletions timeplus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SET ( timeplus-cpp-lib-src
columns/string.cpp
columns/tuple.cpp
columns/uuid.cpp
columns/json.cpp

columns/itemview.cpp

Expand Down Expand Up @@ -72,6 +73,7 @@ SET ( timeplus-cpp-lib-src
columns/tuple.h
columns/utils.h
columns/uuid.h
columns/json.h

types/type_parser.h
types/types.h
Expand Down Expand Up @@ -213,6 +215,7 @@ INSTALL(FILES columns/string.h DESTINATION include/timeplus/columns/)
INSTALL(FILES columns/tuple.h DESTINATION include/timeplus/columns/)
INSTALL(FILES columns/utils.h DESTINATION include/timeplus/columns/)
INSTALL(FILES columns/uuid.h DESTINATION include/timeplus/columns/)
INSTALL(FILES columns/json.h DESTINATION include/timeplus/columns/)

# types
INSTALL(FILES types/type_parser.h DESTINATION include/timeplus/types/)
Expand Down
1 change: 1 addition & 0 deletions timeplus/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "columns/string.h"
#include "columns/tuple.h"
#include "columns/uuid.h"
#include "columns/json.h"

#include <chrono>
#include <cstdint>
Expand Down
4 changes: 4 additions & 0 deletions timeplus/columns/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "string.h"
#include "tuple.h"
#include "uuid.h"
#include "json.h"


#include "../types/type_parser.h"
Expand Down Expand Up @@ -135,6 +136,9 @@ static ColumnRef CreateTerminalColumn(const TypeAst& ast) {
case Type::MultiPolygon:
return std::make_shared<ColumnMultiPolygon>();

case Type::Json:
return std::make_shared<ColumnJson>();

default:
return nullptr;
}
Expand Down
Loading