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

zhaoc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 9408ad6  Fix predicate error when reading BetaRowset (#2067)
9408ad6 is described below

commit 9408ad67e9cfc8af43d17920a10310a1c0d61bbf
Author: kangpinghuang <[email protected]>
AuthorDate: Sun Oct 27 12:12:41 2019 +0800

    Fix predicate error when reading BetaRowset (#2067)
---
 be/src/olap/row_block2.cpp                 |   4 +-
 be/src/olap/rowset/segment_v2/row_ranges.h |   3 +
 be/test/olap/CMakeLists.txt                |   1 +
 be/test/olap/row_block_test.cpp            |   2 -
 be/test/olap/row_block_v2_test.cpp         | 177 +++++++++++++++++++++++++++++
 run-ut.sh                                  |   1 +
 6 files changed, 184 insertions(+), 4 deletions(-)

diff --git a/be/src/olap/row_block2.cpp b/be/src/olap/row_block2.cpp
index 5ba1689..e0fe7dd 100644
--- a/be/src/olap/row_block2.cpp
+++ b/be/src/olap/row_block2.cpp
@@ -62,7 +62,7 @@ Status RowBlockV2::convert_to_row_block(RowCursor* helper, 
RowBlock* dst) {
         if (is_nullable) {
             for (uint16_t i = 0; i < _selected_size; ++i) {
                 uint16_t row_idx = _selection_vector[i];
-                dst->get_row(row_idx, helper);
+                dst->get_row(i, helper);
                 bool is_null = BitmapTest(_column_null_bitmaps[cid], row_idx);
                 if (is_null) {
                     helper->set_null(cid);
@@ -75,7 +75,7 @@ Status RowBlockV2::convert_to_row_block(RowCursor* helper, 
RowBlock* dst) {
         } else {
             for (uint16_t i = 0; i < _selected_size; ++i) {
                 uint16_t row_idx = _selection_vector[i];
-                dst->get_row(row_idx, helper);
+                dst->get_row(i, helper);
                 helper->set_not_null(cid);
                 helper->set_field_content_shallow(cid,
                         reinterpret_cast<const 
char*>(column_block(cid).cell_ptr(row_idx)));
diff --git a/be/src/olap/rowset/segment_v2/row_ranges.h 
b/be/src/olap/rowset/segment_v2/row_ranges.h
index a6a57a2..40bf550 100644
--- a/be/src/olap/rowset/segment_v2/row_ranges.h
+++ b/be/src/olap/rowset/segment_v2/row_ranges.h
@@ -257,6 +257,9 @@ private:
     // trying to union the specified range to the last ranges in the list. The 
specified range shall be larger(*) than
     // the last one or might be overlapped with some of the last ones.
     void add(const RowRange& range) {
+        if (range.count() == 0) {
+            return;
+        }
         RowRange range_to_add = range;
         for (int i = _ranges.size() - 1; i >= 0; --i) {
             const RowRange last = _ranges[i];
diff --git a/be/test/olap/CMakeLists.txt b/be/test/olap/CMakeLists.txt
index 7685e7a..ebd3d40 100644
--- a/be/test/olap/CMakeLists.txt
+++ b/be/test/olap/CMakeLists.txt
@@ -22,6 +22,7 @@ set(LIBRARY_OUTPUT_PATH "${BUILD_DIR}/test/olap")
 set(EXECUTABLE_OUTPUT_PATH "${BUILD_DIR}/test/olap")
 
 ADD_BE_TEST(row_block_test)
+ADD_BE_TEST(row_block_v2_test)
 ADD_BE_TEST(bit_field_test)
 ADD_BE_TEST(byte_buffer_test)
 ADD_BE_TEST(run_length_byte_test)
diff --git a/be/test/olap/row_block_test.cpp b/be/test/olap/row_block_test.cpp
index 3894dd3..6136892 100644
--- a/be/test/olap/row_block_test.cpp
+++ b/be/test/olap/row_block_test.cpp
@@ -41,8 +41,6 @@ public:
     }
     void TearDown() {
     }
-    void SetRows(RowBlock& row_block) {
-    }
 };
 
 void init_tablet_schema(TabletSchema* tablet_schema) {
diff --git a/be/test/olap/row_block_v2_test.cpp 
b/be/test/olap/row_block_v2_test.cpp
new file mode 100644
index 0000000..7fe0b97
--- /dev/null
+++ b/be/test/olap/row_block_v2_test.cpp
@@ -0,0 +1,177 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gtest/gtest.h>
+
+#include "olap/row_block2.h"
+
+namespace doris {
+
+class TestRowBlockV2 : public testing::Test {
+public:
+    TestRowBlockV2() {}
+    void SetUp() {
+    }
+    void TearDown() {
+    }
+};
+
+void init_tablet_schema(TabletSchema* tablet_schema, bool is_nullable) {
+    TabletSchemaPB tablet_schema_pb;
+    {
+        // k1: bigint
+        {
+            ColumnPB* column_1 = tablet_schema_pb.add_column();
+            column_1->set_unique_id(1);
+            column_1->set_name("k1");
+            column_1->set_type("BIGINT");
+            column_1->set_is_key(true);
+            column_1->set_length(8);
+            column_1->set_is_nullable(is_nullable);
+            column_1->set_aggregation("NONE");
+        }
+        // k2: char
+        {
+            ColumnPB* column_2 = tablet_schema_pb.add_column();
+            column_2->set_unique_id(2);
+            column_2->set_name("k2");
+            column_2->set_type("CHAR");
+            column_2->set_is_key(true);
+            column_2->set_length(10);
+            column_2->set_is_nullable(is_nullable);
+            column_2->set_aggregation("NONE");
+        }
+        // k3: varchar
+        {
+            ColumnPB* column_3 = tablet_schema_pb.add_column();
+            column_3->set_unique_id(3);
+            column_3->set_name("k3");
+            column_3->set_type("VARCHAR");
+            column_3->set_is_key(true);
+            column_3->set_length(20);
+            column_3->set_is_nullable(is_nullable);
+            column_3->set_aggregation("NONE");
+        }
+        // v1: int
+        {
+            ColumnPB* column_4 = tablet_schema_pb.add_column();
+            column_4->set_unique_id(3);
+            column_4->set_name("v1");
+            column_4->set_type("INT");
+            column_4->set_is_key(false);
+            column_4->set_length(4);
+            column_4->set_is_nullable(false);
+            column_4->set_aggregation("SUM");
+        }
+    }
+    tablet_schema->init_from_pb(tablet_schema_pb);
+}
+
+TEST_F(TestRowBlockV2, test_convert) {
+    TabletSchema tablet_schema;
+    init_tablet_schema(&tablet_schema, true);
+    Schema schema(tablet_schema);
+    RowBlockV2 input_block(schema, 1024);
+    RowBlock output_block(&tablet_schema);
+    RowBlockInfo block_info;
+    block_info.row_num = 1024;
+    block_info.null_supported = true;
+    auto res = output_block.init(block_info);
+    ASSERT_EQ(OLAP_SUCCESS, res);
+    MemTracker tracker;
+    MemPool pool(&tracker);
+    for (int i = 0; i < input_block.capacity(); ++i) {
+        RowBlockRow row = input_block.row(i);
+
+        // column_1
+        row.set_is_null(0, false);
+        uint8_t* cell0 = row.mutable_cell_ptr(0);
+        (*(uint64_t*)cell0) = i;
+
+        // column_2
+        uint8_t* buf = pool.allocate(10);
+        memset(buf, 'a' + (i % 10), 10);
+        Slice str1(buf, 10);
+        row.set_is_null(1, false);
+        uint8_t* cell1 = row.mutable_cell_ptr(1);
+        (*(Slice*)cell1) = str1;
+
+        // column_3
+        uint8_t* buf2 = pool.allocate(10);
+        memset(buf2, 'A' + (i % 10), 10);
+        Slice str2(buf2, 10);
+        row.set_is_null(2, false);
+        uint8_t* cell3 = row.mutable_cell_ptr(2);
+        (*(Slice*)cell3) = str2;
+
+        // column_4
+         row.set_is_null(3, false);
+        uint8_t* cell4 = row.mutable_cell_ptr(3);
+        (*(uint32_t*)cell4) = 10 * i;
+    }
+
+    input_block.set_selected_size(5);
+    uint16_t* select_vector = input_block.selection_vector();
+    for (int i = 0; i < input_block.selected_size(); ++i) {
+        // 10, 20, 30, 40, 50
+        select_vector[i] = (i + 1) * 10;
+    }
+
+    RowCursor helper;
+    helper.init(tablet_schema);
+    auto st = input_block.convert_to_row_block(&helper, &output_block);
+    ASSERT_TRUE(st.ok());
+    ASSERT_EQ(5, output_block.limit());
+    for (int i = 0; i < 5; ++i) {
+        char* field1 = output_block.field_ptr(i, 0);
+        char* field2 = output_block.field_ptr(i, 1);
+        char* field3 = output_block.field_ptr(i, 2);
+        char* field4 = output_block.field_ptr(i, 3);
+        // test null bit
+        ASSERT_FALSE(*reinterpret_cast<bool*>(field1));
+        ASSERT_FALSE(*reinterpret_cast<bool*>(field2));
+        ASSERT_FALSE(*reinterpret_cast<bool*>(field3));
+        ASSERT_FALSE(*reinterpret_cast<bool*>(field4));
+
+        uint64_t k1 = *reinterpret_cast<uint64_t*>(field1 + 1);
+        ASSERT_EQ((i + 1) * 10, k1);
+
+        Slice k2 = *reinterpret_cast<Slice*>(field2 + 1);
+        char buf[10];
+        memset(buf, 'a' + ((i + 1) * 10) % 10, 10);
+        Slice k2_v(buf, 10);
+        ASSERT_EQ(k2_v, k2);
+
+        Slice k3 = *reinterpret_cast<Slice*>(field3 + 1);
+        char buf2[10];
+        memset(buf2, 'A' + ((i + 1) * 10) % 10, 10);
+        Slice k3_v(buf2, 10);
+        ASSERT_EQ(k3_v, k3);
+
+        uint32_t v1 = *reinterpret_cast<uint32_t*>(field4 + 1);
+        ASSERT_EQ((i + 1) * 10 * 10, v1);
+    }
+}
+
+}
+
+// @brief Test Stub
+int main(int argc, char** argv) {
+    testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS(); 
+}
+
diff --git a/run-ut.sh b/run-ut.sh
index c8f77ca..3048db1 100755
--- a/run-ut.sh
+++ b/run-ut.sh
@@ -233,6 +233,7 @@ ${DORIS_TEST_BINARY_DIR}/olap/lru_cache_test
 ${DORIS_TEST_BINARY_DIR}/olap/bloom_filter_test
 ${DORIS_TEST_BINARY_DIR}/olap/bloom_filter_index_test
 ${DORIS_TEST_BINARY_DIR}/olap/row_block_test
+${DORIS_TEST_BINARY_DIR}/olap/row_block_v2_test
 ${DORIS_TEST_BINARY_DIR}/olap/comparison_predicate_test
 ${DORIS_TEST_BINARY_DIR}/olap/in_list_predicate_test
 ${DORIS_TEST_BINARY_DIR}/olap/null_predicate_test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to