You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sd...@apache.org on 2022/10/31 17:38:19 UTC

[ignite-3] branch ignite-18017 updated: IGNITE-18017 Add binary tuple tests

This is an automated email from the ASF dual-hosted git repository.

sdanilov pushed a commit to branch ignite-18017
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/ignite-18017 by this push:
     new ae7347bca3 IGNITE-18017 Add binary tuple tests
ae7347bca3 is described below

commit ae7347bca30a9def0df7d0e8b3ba6d9ffab4ca24
Author: Semyon Danilov <sa...@yandex.ru>
AuthorDate: Mon Oct 31 21:38:11 2022 +0400

    IGNITE-18017 Add binary tuple tests
---
 .../platforms/cpp/ignite/schema/tuple_assembler.h  | 56 ++++++++++++---
 modules/platforms/cpp/ignite/schema/tuple_test.cpp | 80 ++++++++++++++++++++++
 2 files changed, 127 insertions(+), 9 deletions(-)

diff --git a/modules/platforms/cpp/ignite/schema/tuple_assembler.h b/modules/platforms/cpp/ignite/schema/tuple_assembler.h
index 7fd47f77cd..50b18e5f8a 100644
--- a/modules/platforms/cpp/ignite/schema/tuple_assembler.h
+++ b/modules/platforms/cpp/ignite/schema/tuple_assembler.h
@@ -62,16 +62,11 @@ public:
    /** Append a null value. */
    void append(std::nullopt_t /*null*/) { appendNull(); }
 
-   /** Append next column element. */
-   void append(ignite::bytes_view value) {
-       buffer.emplace_back(value.begin(), value.end());
+   void add(ignite::ignite_type type, ignite::bytes_view bytes) {
+       buffer.emplace_back(bytes.begin(), bytes.end());
        bufferTuple.emplace_back(buffer.back());
-       builder.claim(bufferTuple.back()->size());
-   }
 
-   /** Append next column element. */
-   void append(std::string_view value) {
-       append(ignite::bytes_view {reinterpret_cast<const std::byte *>(value.data()), value.size()});
+       builder.claim(type, bytes);
    }
 
    /**
@@ -84,7 +79,50 @@ public:
    void append(T value) {
        char buf[sizeof value];
        memcpy(buf, &value, sizeof value);
-       append(ignite::bytes_view {reinterpret_cast<const std::byte *>(buf), sizeof value});
+       ignite::bytes_view bytes {reinterpret_cast<const std::byte *>(buf), sizeof value};
+
+       if constexpr (std::is_same<T, int8_t>::value) {
+           add(ignite::ignite_type::INT8, bytes);
+       }
+
+       if constexpr (std::is_same<T, int16_t>::value) {
+           add(ignite::ignite_type::INT16, bytes);
+       }
+
+       if constexpr (std::is_same<T, int32_t>::value) {
+           add(ignite::ignite_type::INT32, bytes);
+       }
+
+       if constexpr (std::is_same<T, int64_t>::value) {
+           add(ignite::ignite_type::INT64, bytes);
+       }
+
+       if constexpr (std::is_same<T, float>::value) {
+           add(ignite::ignite_type::FLOAT, bytes);
+       }
+
+       if constexpr (std::is_same<T, double>::value) {
+           add(ignite::ignite_type::DOUBLE, bytes);
+       }
+   }
+
+   void append(std::string_view value) {
+       ignite::bytes_view bytes {reinterpret_cast<const std::byte *>(value.data()), value.size()};
+
+       add(ignite::ignite_type::STRING, bytes);
+   }
+
+   void append(const ignite::big_integer& value) {
+       size_t size = value.byte_size();
+       std::byte ar[size];
+       value.store_bytes(ar);
+       ignite::bytes_view bytes {ar, size};
+
+       add(ignite::ignite_type::NUMBER, bytes);
+   }
+
+   void append(const ignite::bytes_view &binary_value) {
+       add(ignite::ignite_type::BINARY, binary_value);
    }
 
    /**
diff --git a/modules/platforms/cpp/ignite/schema/tuple_test.cpp b/modules/platforms/cpp/ignite/schema/tuple_test.cpp
index 10dfa44b7d..9b1f401010 100644
--- a/modules/platforms/cpp/ignite/schema/tuple_test.cpp
+++ b/modules/platforms/cpp/ignite/schema/tuple_test.cpp
@@ -161,6 +161,86 @@ TEST(TuplesTests, FixedKeyFixedValue) { // NOLINT(cert-err58-cpp)
     }
 }
 
+TEST(TupleTests, AllTypes) {
+    SchemaDescriptor schema;
+
+    schema.columns = {
+        {ignite_type::INT8, false},
+        {ignite_type::INT16, false},
+        {ignite_type::INT32, false},
+        {ignite_type::INT64, false},
+        {ignite_type::NUMBER, false},
+        // {ignite_type::DECIMAL, false},
+        {ignite_type::FLOAT, false},
+        {ignite_type::DOUBLE, false},
+        // {ignite_type::DATE, false},
+        // {ignite_type::TIME, false},
+        // {ignite_type::DATETIME, false},
+        // {ignite_type::TIMESTAMP, false},
+        {ignite_type::STRING, false},
+        // {ignite_type::UUID, false},
+        {ignite_type::BINARY, false},
+    };
+
+    binary_tuple_schema sch = schema.to_tuple_schema();
+    tuple_assembler ta(sch);
+
+    ta.start();
+
+    int8_t v1 = 1;
+    int16_t v2 = 2;
+    int32_t v3 = 3;
+    int64_t v4 = 4;
+    big_integer v5(12345);
+    big_decimal v6("12345.12345");
+    float v7 = .5f;
+    double v8 = .7;
+    ignite_date v9();
+    ignite_time v10();
+    ignite_date_time v11();
+    ignite_timestamp v12();
+    std::string v13("hello");
+    uuid v14();
+
+    std::string v15_tmp("\1\2\3"s);
+    bytes_view v15 {reinterpret_cast<const std::byte *>(v15_tmp.data()), v15_tmp.size()};
+
+    ta.append(v1);
+    ta.append(v2);
+    ta.append(v3);
+    ta.append(v4);
+    ta.append(v5);
+    // ta.append(v6);
+    ta.append(v7);
+    ta.append(v8);
+    // ta.append(v9);
+    // ta.append(v10);
+    // ta.append(v11);
+    // ta.append(v12);
+    ta.append(v13);
+    // ta.append(v14);
+    ta.append(v15);
+
+    const std::vector<std::byte> &binary_tuple = ta.build();
+    binary_tuple_parser tp(schema.length(), binary_tuple);
+
+    EXPECT_EQ(v1, read_tuple<int8_t>(tp.get_next().value()));
+    EXPECT_EQ(v2, read_tuple<int16_t>(tp.get_next().value()));
+    EXPECT_EQ(v3, read_tuple<int32_t>(tp.get_next().value()));
+    EXPECT_EQ(v4, read_tuple<int64_t>(tp.get_next().value()));
+    EXPECT_EQ(v5, read_tuple<big_integer>(tp.get_next().value()));
+    // EXPECT_EQ(v6, read_tuple<big_decimal>(tp.get_next().value()));
+    EXPECT_EQ(v7, read_tuple<float>(tp.get_next().value()));
+    EXPECT_EQ(v8, read_tuple<double>(tp.get_next().value()));
+    // EXPECT_EQ(v9, read_tuple<big_integer>(tp.get_next().value()));
+    // EXPECT_EQ(v10, read_tuple<big_integer>(tp.get_next().value()));
+    // EXPECT_EQ(v11, read_tuple<big_integer>(tp.get_next().value()));
+    // EXPECT_EQ(v12, read_tuple<big_integer>(tp.get_next().value()));
+    EXPECT_EQ(v13, read_tuple<std::string>(tp.get_next().value()));
+    // EXPECT_EQ(v14, read_tuple<big_integer>(tp.get_next().value()));
+    EXPECT_EQ(v15, tp.get_next().value());
+}
+
 TEST(TuplesTests, FixedKeyFixedNullableValue) { // NOLINT(cert-err58-cpp)
     SchemaDescriptor schema;