You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2021/01/04 01:29:42 UTC
[incubator-doris] branch master updated: [UT] Add ut for column
predicate of comlumnblock (#5123)
This is an automated email from the ASF dual-hosted git repository.
morningman 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 5807413 [UT] Add ut for column predicate of comlumnblock (#5123)
5807413 is described below
commit 5807413ad05b28e55697691b04df8b5900e38261
Author: HappenLee <ha...@hotmail.com>
AuthorDate: Mon Jan 4 09:29:30 2021 +0800
[UT] Add ut for column predicate of comlumnblock (#5123)
Add ut for column predicate of ColumnBlock
---
be/test/olap/comparison_predicate_test.cpp | 637 ++++++++++++++++++++++++-----
be/test/olap/in_list_predicate_test.cpp | 501 +++++++++++++++++------
be/test/olap/null_predicate_test.cpp | 384 ++++++++++++-----
3 files changed, 1213 insertions(+), 309 deletions(-)
diff --git a/be/test/olap/comparison_predicate_test.cpp b/be/test/olap/comparison_predicate_test.cpp
index 1973ebf..7ba3d70 100644
--- a/be/test/olap/comparison_predicate_test.cpp
+++ b/be/test/olap/comparison_predicate_test.cpp
@@ -23,6 +23,7 @@
#include "olap/column_predicate.h"
#include "olap/field.h"
+#include "olap/row_block2.h"
#include "olap/wrapper_field.h"
#include "runtime/mem_pool.h"
#include "runtime/string_value.hpp"
@@ -120,9 +121,15 @@ static std::string to_datetime_string(uint64_t& datetime_value) {
_vectorized_batch = new VectorizedRowBatch(tablet_schema, ids, size); \
_vectorized_batch->set_size(size); \
} \
+ \
+ void init_row_block(const TabletSchema* tablet_schema, int size) { \
+ Schema schema(*tablet_schema); \
+ _row_block.reset(new RowBlockV2(schema, size)); \
+ } \
std::shared_ptr<MemTracker> _mem_tracker; \
std::unique_ptr<MemPool> _mem_pool; \
VectorizedRowBatch* _vectorized_batch; \
+ std::unique_ptr<RowBlockV2> _row_block; \
};
TEST_PREDICATE_DEFINITION(TestEqualPredicate)
@@ -184,31 +191,43 @@ TEST_EQUAL_PREDICATE(int128_t, LARGEINT, "LARGEINT")
TEST_F(TestEqualPredicate, FLOAT_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("FLOAT_COLUMN"), "FLOAT", "REPLACE", 1, false, true,
- &tablet_schema);
+ SetTabletSchema(std::string("FLOAT_COLUMN"), "FLOAT", "REPLACE", 1, true, true, &tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ float value = 5.0;
+ ColumnPredicate* pred = new EqualPredicate<float>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
float* col_data = reinterpret_cast<float*>(_mem_pool->allocate(size * sizeof(float)));
col_vector->set_col_data(col_data);
for (int i = 0; i < size; ++i) {
*(col_data + i) = i;
}
- float value = 5.0;
- ColumnPredicate* pred = new EqualPredicate<float>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
uint16_t* sel = _vectorized_batch->selected();
ASSERT_FLOAT_EQ(*(col_data + sel[0]), 5.0);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<float*>(col_block_view.data()) = i;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_FLOAT_EQ(*(float*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 5.0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -226,36 +245,66 @@ TEST_F(TestEqualPredicate, FLOAT_COLUMN) {
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_FLOAT_EQ(*(col_data + sel[0]), 5.0);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<float*>(col_block_view.data()) = i;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_FLOAT_EQ(*(float*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 5.0);
+
delete pred;
}
TEST_F(TestEqualPredicate, DOUBLE_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DOUBLE_COLUMN"), "DOUBLE", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DOUBLE_COLUMN"), "DOUBLE", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ double value = 5.0;
+ ColumnPredicate* pred = new EqualPredicate<double>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
double* col_data = reinterpret_cast<double*>(_mem_pool->allocate(size * sizeof(double)));
col_vector->set_col_data(col_data);
for (int i = 0; i < size; ++i) {
*(col_data + i) = i;
}
- double value = 5.0;
- ColumnPredicate* pred = new EqualPredicate<double>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
uint16_t* sel = _vectorized_batch->selected();
ASSERT_DOUBLE_EQ(*(col_data + sel[0]), 5.0);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<double*>(col_block_view.data()) = i;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_DOUBLE_EQ(*(double*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 5.0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -273,22 +322,41 @@ TEST_F(TestEqualPredicate, DOUBLE_COLUMN) {
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_DOUBLE_EQ(*(col_data + sel[0]), 5.0);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<double*>(col_block_view.data()) = i;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_DOUBLE_EQ(*(double*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 5.0);
+
delete pred;
}
TEST_F(TestEqualPredicate, DECIMAL_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DECIMAL_COLUMN"), "DECIMAL", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DECIMAL_COLUMN"), "DECIMAL", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ decimal12_t value(5, 5);
+ ColumnPredicate* pred = new EqualPredicate<decimal12_t>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
decimal12_t* col_data =
reinterpret_cast<decimal12_t*>(_mem_pool->allocate(size * sizeof(decimal12_t)));
@@ -297,14 +365,26 @@ TEST_F(TestEqualPredicate, DECIMAL_COLUMN) {
(*(col_data + i)).integer = i;
(*(col_data + i)).fraction = i;
}
- decimal12_t value(5, 5);
- ColumnPredicate* pred = new EqualPredicate<decimal12_t>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
uint16_t* sel = _vectorized_batch->selected();
ASSERT_EQ(*(col_data + sel[0]), value);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->integer = i;
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->fraction = i;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(*(decimal12_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -317,19 +397,36 @@ TEST_F(TestEqualPredicate, DECIMAL_COLUMN) {
(*(col_data + i)).fraction = i;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(*(col_data + sel[0]), value);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->integer = i;
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->fraction = i;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(*(decimal12_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value);
+
delete pred;
}
TEST_F(TestEqualPredicate, STRING_COLUMN) {
TabletSchema char_tablet_schema;
- SetTabletSchema(std::string("STRING_COLUMN"), "CHAR", "REPLACE", 5, false, true,
+ SetTabletSchema(std::string("STRING_COLUMN"), "CHAR", "REPLACE", 5, true, true,
&char_tablet_schema);
// test WrapperField.from_string() for char type
WrapperField* field = WrapperField::create(char_tablet_schema.column(0));
@@ -343,22 +440,28 @@ TEST_F(TestEqualPredicate, STRING_COLUMN) {
ASSERT_EQ(0, tmp[4]);
TabletSchema tablet_schema;
- SetTabletSchema(std::string("STRING_COLUMN"), "VARCHAR", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("STRING_COLUMN"), "VARCHAR", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+
+ StringValue value;
+ const char* value_buffer = "dddd";
+ value.len = 4;
+ value.ptr = const_cast<char*>(value_buffer);
+
+ ColumnPredicate* pred = new EqualPredicate<StringValue>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
StringValue* col_data =
reinterpret_cast<StringValue*>(_mem_pool->allocate(size * sizeof(StringValue)));
col_vector->set_col_data(col_data);
-
char* string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
for (int i = 0; i < size; ++i) {
for (int j = 0; j <= i; ++j) {
@@ -368,20 +471,33 @@ TEST_F(TestEqualPredicate, STRING_COLUMN) {
(*(col_data + i)).ptr = string_buffer;
string_buffer += i + 1;
}
-
- StringValue value;
- const char* value_buffer = "dddd";
- value.len = 4;
- value.ptr = const_cast<char*>(value_buffer);
-
- ColumnPredicate* pred = new EqualPredicate<StringValue>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
uint16_t* sel = _vectorized_batch->selected();
ASSERT_EQ(sel[0], 3);
ASSERT_EQ(*(col_data + sel[0]), value);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(60));
+ memset(string_buffer, 0, 60);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = i + 1;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += i + 1;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -399,29 +515,53 @@ TEST_F(TestEqualPredicate, STRING_COLUMN) {
}
string_buffer += i + 1;
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(*(col_data + sel[0]), value);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = i + 1;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += i + 1;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value);
+
delete field;
delete pred;
}
TEST_F(TestEqualPredicate, DATE_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DATE_COLUMN"), "DATA", "REPLACE", 1, false, true, &tablet_schema);
+ SetTabletSchema(std::string("DATE_COLUMN"), "DATE", "REPLACE", 1, true, true, &tablet_schema);
int size = 6;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ uint24_t value = datetime::to_date_timestamp("2017-09-10");
+ ColumnPredicate* pred = new EqualPredicate<uint24_t>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
uint24_t* col_data = reinterpret_cast<uint24_t*>(_mem_pool->allocate(size * sizeof(uint24_t)));
col_vector->set_col_data(col_data);
@@ -437,9 +577,6 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) {
uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
*(col_data + i) = timestamp;
}
-
- uint24_t value = datetime::to_date_timestamp("2017-09-10");
- ColumnPredicate* pred = new EqualPredicate<uint24_t>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
uint16_t* sel = _vectorized_batch->selected();
@@ -447,7 +584,23 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) {
ASSERT_EQ(*(col_data + sel[0]), value);
ASSERT_EQ(datetime::to_date_string(*(col_data + sel[0])), "2017-09-10");
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(datetime::to_date_string(
+ *(uint24_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-10");
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -460,7 +613,6 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) {
*(col_data + i) = timestamp;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
@@ -468,22 +620,44 @@ TEST_F(TestEqualPredicate, DATE_COLUMN) {
sel = _vectorized_batch->selected();
ASSERT_EQ(*(col_data + sel[0]), value);
ASSERT_EQ(datetime::to_date_string(*(col_data + sel[0])), "2017-09-10");
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(datetime::to_date_string(
+ *(uint24_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-10");
+
delete pred;
}
TEST_F(TestEqualPredicate, DATETIME_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DATETIME_COLUMN"), "DATETIME", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DATETIME_COLUMN"), "DATETIME", "REPLACE", 1, true, true,
&tablet_schema);
int size = 6;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ uint64_t value = datetime::to_datetime_timestamp("2017-09-10 01:00:00");
+ ColumnPredicate* pred = new EqualPredicate<uint64_t>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
uint64_t* col_data = reinterpret_cast<uint64_t*>(_mem_pool->allocate(size * sizeof(uint64_t)));
col_vector->set_col_data(col_data);
@@ -499,9 +673,6 @@ TEST_F(TestEqualPredicate, DATETIME_COLUMN) {
uint64_t timestamp = datetime::to_datetime_timestamp(date_array[i].c_str());
*(col_data + i) = timestamp;
}
-
- uint64_t value = datetime::to_datetime_timestamp("2017-09-10 01:00:00");
- ColumnPredicate* pred = new EqualPredicate<uint64_t>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
uint16_t* sel = _vectorized_batch->selected();
@@ -509,7 +680,23 @@ TEST_F(TestEqualPredicate, DATETIME_COLUMN) {
ASSERT_EQ(*(col_data + sel[0]), value);
ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[0])), "2017-09-10 01:00:00");
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ uint64_t timestamp = datetime::to_datetime_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint64_t*>(col_block_view.data()) = timestamp;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(datetime::to_datetime_string(
+ *(uint64_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-10 01:00:00");
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -522,7 +709,6 @@ TEST_F(TestEqualPredicate, DATETIME_COLUMN) {
*(col_data + i) = timestamp;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
@@ -530,6 +716,26 @@ TEST_F(TestEqualPredicate, DATETIME_COLUMN) {
sel = _vectorized_batch->selected();
ASSERT_EQ(*(col_data + sel[0]), value);
ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[0])), "2017-09-10 01:00:00");
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ uint64_t timestamp = datetime::to_datetime_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint64_t*>(col_block_view.data()) = timestamp;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(datetime::to_datetime_string(
+ *(uint64_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-10 01:00:00");
+
delete pred;
}
@@ -597,25 +803,25 @@ TEST_LESS_PREDICATE(int128_t, LARGEINT, "LARGEINT")
TEST_F(TestLessPredicate, FLOAT_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("FLOAT_COLUMN"), "FLOAT", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("FLOAT_COLUMN"), "FLOAT", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ float value = 5.0;
+ ColumnPredicate* pred = new LessPredicate<float>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
float* col_data = reinterpret_cast<float*>(_mem_pool->allocate(size * sizeof(float)));
col_vector->set_col_data(col_data);
for (int i = 0; i < size; ++i) {
*(col_data + i) = i;
}
- float value = 5.0;
- ColumnPredicate* pred = new LessPredicate<float>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 5);
uint16_t* sel = _vectorized_batch->selected();
@@ -625,7 +831,24 @@ TEST_F(TestLessPredicate, FLOAT_COLUMN) {
}
ASSERT_FLOAT_EQ(sum, 10.0);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<float*>(col_block_view.data()) = i;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 5);
+ sum = 0;
+ for (int i = 0; i < 5; ++i) {
+ sum += *(float*)col_block.cell(_row_block->selection_vector()[i]).cell_ptr();
+ }
+ ASSERT_FLOAT_EQ(sum, 10.0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -637,7 +860,6 @@ TEST_F(TestLessPredicate, FLOAT_COLUMN) {
*(col_data + i) = i;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
@@ -648,30 +870,51 @@ TEST_F(TestLessPredicate, FLOAT_COLUMN) {
sum += *(col_data + sel[i]);
}
ASSERT_FLOAT_EQ(sum, 4.0);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<float*>(col_block_view.data()) = i;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 2);
+ sum = 0;
+ for (int i = 0; i < 2; ++i) {
+ sum += *(float*)col_block.cell(_row_block->selection_vector()[i]).cell_ptr();
+ }
+ ASSERT_FLOAT_EQ(sum, 4.0);
+
delete pred;
}
TEST_F(TestLessPredicate, DOUBLE_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DOUBLE_COLUMN"), "DOUBLE", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DOUBLE_COLUMN"), "DOUBLE", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ double value = 5.0;
+ ColumnPredicate* pred = new LessPredicate<double>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
double* col_data = reinterpret_cast<double*>(_mem_pool->allocate(size * sizeof(double)));
col_vector->set_col_data(col_data);
for (int i = 0; i < size; ++i) {
*(col_data + i) = i;
}
- double value = 5.0;
- ColumnPredicate* pred = new LessPredicate<double>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 5);
uint16_t* sel = _vectorized_batch->selected();
@@ -681,7 +924,24 @@ TEST_F(TestLessPredicate, DOUBLE_COLUMN) {
}
ASSERT_DOUBLE_EQ(sum, 10.0);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<double*>(col_block_view.data()) = i;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 5);
+ sum = 0;
+ for (int i = 0; i < 5; ++i) {
+ sum += *(double*)col_block.cell(_row_block->selection_vector()[i]).cell_ptr();
+ }
+ ASSERT_DOUBLE_EQ(sum, 10.0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -693,7 +953,6 @@ TEST_F(TestLessPredicate, DOUBLE_COLUMN) {
*(col_data + i) = i;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
@@ -704,22 +963,45 @@ TEST_F(TestLessPredicate, DOUBLE_COLUMN) {
sum += *(col_data + sel[i]);
}
ASSERT_DOUBLE_EQ(sum, 4.0);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<double*>(col_block_view.data()) = i;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 2);
+ sum = 0;
+ for (int i = 0; i < 2; ++i) {
+ sum += *(double*)col_block.cell(_row_block->selection_vector()[i]).cell_ptr();
+ }
+ ASSERT_DOUBLE_EQ(sum, 4.0);
+
delete pred;
}
TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DECIMAL_COLUMN"), "DECIMAL", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DECIMAL_COLUMN"), "DECIMAL", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ decimal12_t value(5, 5);
+ ColumnPredicate* pred = new LessPredicate<decimal12_t>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
decimal12_t* col_data =
reinterpret_cast<decimal12_t*>(_mem_pool->allocate(size * sizeof(decimal12_t)));
@@ -728,8 +1010,6 @@ TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
(*(col_data + i)).integer = i;
(*(col_data + i)).fraction = i;
}
- decimal12_t value(5, 5);
- ColumnPredicate* pred = new LessPredicate<decimal12_t>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 5);
uint16_t* sel = _vectorized_batch->selected();
@@ -740,7 +1020,27 @@ TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
ASSERT_EQ(sum.integer, 10);
ASSERT_EQ(sum.fraction, 10);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->integer = i;
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->fraction = i;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 5);
+ sum.integer = 0;
+ sum.fraction = 0;
+ for (int i = 0; i < _vectorized_batch->size(); ++i) {
+ sum += *(col_data + sel[i]);
+ }
+ ASSERT_EQ(sum.integer, 10);
+ ASSERT_EQ(sum.fraction, 10);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -753,7 +1053,6 @@ TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
(*(col_data + i)).fraction = i;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
@@ -765,27 +1064,56 @@ TEST_F(TestLessPredicate, DECIMAL_COLUMN) {
}
ASSERT_EQ(sum.integer, 4);
ASSERT_EQ(sum.fraction, 4);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->integer = i;
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->fraction = i;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 2);
+ sum.integer = 0;
+ sum.fraction = 0;
+ for (int i = 0; i < _vectorized_batch->size(); ++i) {
+ sum += *(col_data + sel[i]);
+ }
+ ASSERT_EQ(sum.integer, 4);
+ ASSERT_EQ(sum.fraction, 4);
+
delete pred;
}
TEST_F(TestLessPredicate, STRING_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("STRING_COLUMN"), "VARCHAR", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("STRING_COLUMN"), "VARCHAR", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+
+ StringValue value;
+ const char* value_buffer = "dddd";
+ value.len = 4;
+ value.ptr = const_cast<char*>(value_buffer);
+ ColumnPredicate* pred = new LessPredicate<StringValue>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
StringValue* col_data =
reinterpret_cast<StringValue*>(_mem_pool->allocate(size * sizeof(StringValue)));
col_vector->set_col_data(col_data);
-
char* string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
for (int i = 0; i < size; ++i) {
for (int j = 0; j <= i; ++j) {
@@ -795,19 +1123,35 @@ TEST_F(TestLessPredicate, STRING_COLUMN) {
(*(col_data + i)).ptr = string_buffer;
string_buffer += i + 1;
}
-
- StringValue value;
- const char* value_buffer = "dddd";
- value.len = 4;
- value.ptr = const_cast<char*>(value_buffer);
-
- ColumnPredicate* pred = new LessPredicate<StringValue>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
ASSERT_TRUE(strncmp((*(col_data + sel[0])).ptr, "a", 1) == 0);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(60));
+ memset(string_buffer, 0, 60);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = i + 1;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += i + 1;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_TRUE(
+ strncmp((*(StringValue*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr())
+ .ptr,
+ "a", 1) == 0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -831,21 +1175,49 @@ TEST_F(TestLessPredicate, STRING_COLUMN) {
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_TRUE(strncmp((*(col_data + sel[0])).ptr, "bb", 2) == 0);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = i + 1;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += i + 1;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_TRUE(
+ strncmp((*(StringValue*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr())
+ .ptr,
+ "bb", 2) == 0);
+
delete pred;
}
TEST_F(TestLessPredicate, DATE_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DATE_COLUMN"), "DATE", "REPLACE", 1, false, true, &tablet_schema);
+ SetTabletSchema(std::string("DATE_COLUMN"), "DATE", "REPLACE", 1, true, true, &tablet_schema);
int size = 6;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ uint24_t value = datetime::to_date_timestamp("2017-09-10");
+ ColumnPredicate* pred = new LessPredicate<uint24_t>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
uint24_t* col_data = reinterpret_cast<uint24_t*>(_mem_pool->allocate(size * sizeof(uint24_t)));
col_vector->set_col_data(col_data);
@@ -861,15 +1233,28 @@ TEST_F(TestLessPredicate, DATE_COLUMN) {
uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
*(col_data + i) = timestamp;
}
-
- uint24_t value = datetime::to_date_timestamp("2017-09-10");
- ColumnPredicate* pred = new LessPredicate<uint24_t>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
ASSERT_EQ(datetime::to_date_string(*(col_data + sel[0])), "2017-09-07");
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_EQ(datetime::to_date_string(
+ *(uint24_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-07");
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -882,30 +1267,52 @@ TEST_F(TestLessPredicate, DATE_COLUMN) {
*(col_data + i) = timestamp;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(datetime::to_date_string(*(col_data + sel[0])), "2017-09-08");
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(datetime::to_date_string(
+ *(uint24_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-08");
+
delete pred;
}
TEST_F(TestLessPredicate, DATETIME_COLUMN) {
TabletSchema tablet_schema;
TabletColumn tablet_column;
- SetTabletSchema(std::string("DATETIME_COLUMN"), "DATETIME", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DATETIME_COLUMN"), "DATETIME", "REPLACE", 1, true, true,
&tablet_schema);
int size = 6;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+
+ uint64_t value = datetime::to_datetime_timestamp("2017-09-10 01:00:00");
+ ColumnPredicate* pred = new LessPredicate<uint64_t>(0, value);
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
uint64_t* col_data = reinterpret_cast<uint64_t*>(_mem_pool->allocate(size * sizeof(uint64_t)));
col_vector->set_col_data(col_data);
@@ -921,15 +1328,28 @@ TEST_F(TestLessPredicate, DATETIME_COLUMN) {
uint64_t timestamp = datetime::to_datetime_timestamp(date_array[i].c_str());
*(col_data + i) = timestamp;
}
-
- uint64_t value = datetime::to_datetime_timestamp("2017-09-10 01:00:00");
- ColumnPredicate* pred = new LessPredicate<uint64_t>(0, value);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[0])), "2017-09-07 00:00:00");
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ uint64_t timestamp = datetime::to_datetime_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint64_t*>(col_block_view.data()) = timestamp;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_EQ(datetime::to_datetime_string(
+ *(uint64_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-07 00:00:00");
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -942,13 +1362,32 @@ TEST_F(TestLessPredicate, DATETIME_COLUMN) {
*(col_data + i) = timestamp;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[0])), "2017-09-08 00:01:00");
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ uint64_t timestamp = datetime::to_datetime_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint64_t*>(col_block_view.data()) = timestamp;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(datetime::to_datetime_string(
+ *(uint64_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-08 00:01:00");
+
delete pred;
}
diff --git a/be/test/olap/in_list_predicate_test.cpp b/be/test/olap/in_list_predicate_test.cpp
index d8ff61a..b57152b 100644
--- a/be/test/olap/in_list_predicate_test.cpp
+++ b/be/test/olap/in_list_predicate_test.cpp
@@ -87,7 +87,7 @@ static std::string to_datetime_string(uint64_t& datetime_value) {
class TestInListPredicate : public testing::Test {
public:
- TestInListPredicate() : _vectorized_batch(NULL) {
+ TestInListPredicate() : _vectorized_batch(NULL), _row_block(nullptr) {
_mem_tracker.reset(new MemTracker(-1));
_mem_pool.reset(new MemPool(_mem_tracker.get()));
}
@@ -123,9 +123,16 @@ public:
_vectorized_batch = new VectorizedRowBatch(tablet_schema, ids, size);
_vectorized_batch->set_size(size);
}
+
+ void init_row_block(const TabletSchema* tablet_schema, int size) {
+ Schema schema(*tablet_schema);
+ _row_block.reset(new RowBlockV2(schema, size));
+ }
+
std::shared_ptr<MemTracker> _mem_tracker;
std::unique_ptr<MemPool> _mem_pool;
VectorizedRowBatch* _vectorized_batch;
+ std::unique_ptr<RowBlockV2> _row_block;
};
#define TEST_IN_LIST_PREDICATE(TYPE, TYPE_NAME, FIELD_TYPE) \
@@ -255,28 +262,27 @@ TEST_IN_LIST_PREDICATE_V2(int128_t, LARGEINT, "LARGEINT")
TEST_F(TestInListPredicate, FLOAT_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("FLOAT_COLUMN"), "FLOAT", "REPLACE", 1, false, true,
- &tablet_schema);
+ SetTabletSchema(std::string("FLOAT_COLUMN"), "FLOAT", "REPLACE", 1, true, true, &tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::set<float> values;
+ values.insert(4.1);
+ values.insert(5.1);
+ values.insert(6.1);
+ ColumnPredicate* pred = new InListPredicate<float>(0, std::move(values));
+
+ // for VectorizedBatch no null
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
float* col_data = reinterpret_cast<float*>(_mem_pool->allocate(size * sizeof(float)));
col_vector->set_col_data(col_data);
for (int i = 0; i < size; ++i) {
*(col_data + i) = i + 0.1;
}
- std::set<float> values;
- values.insert(4.1);
- values.insert(5.1);
- values.insert(6.1);
- ColumnPredicate* pred = new InListPredicate<float>(0, std::move(values));
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
@@ -284,7 +290,22 @@ TEST_F(TestInListPredicate, FLOAT_COLUMN) {
ASSERT_FLOAT_EQ(*(col_data + sel[1]), 5.1);
ASSERT_FLOAT_EQ(*(col_data + sel[2]), 6.1);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<float*>(col_block_view.data()) = i + 0.1f;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_FLOAT_EQ(*(float*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 4.1);
+ ASSERT_FLOAT_EQ(*(float*)col_block.cell(_row_block->selection_vector()[1]).cell_ptr(), 5.1);
+ ASSERT_FLOAT_EQ(*(float*)col_block.cell(_row_block->selection_vector()[2]).cell_ptr(), 6.1);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -302,34 +323,51 @@ TEST_F(TestInListPredicate, FLOAT_COLUMN) {
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_FLOAT_EQ(*(col_data + sel[0]), 5.1);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<float*>(col_block_view.data()) = i + 0.1;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_FLOAT_EQ(*(float*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 5.1);
+
delete pred;
}
TEST_F(TestInListPredicate, DOUBLE_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DOUBLE_COLUMN"), "DOUBLE", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DOUBLE_COLUMN"), "DOUBLE", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::set<double> values;
+ values.insert(4.1);
+ values.insert(5.1);
+ values.insert(6.1);
+
+ ColumnPredicate* pred = new InListPredicate<double>(0, std::move(values));
+
+ // for VectorizedBatch no null
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
double* col_data = reinterpret_cast<double*>(_mem_pool->allocate(size * sizeof(double)));
col_vector->set_col_data(col_data);
for (int i = 0; i < size; ++i) {
*(col_data + i) = i + 0.1;
}
- std::set<double> values;
- values.insert(4.1);
- values.insert(5.1);
- values.insert(6.1);
-
- ColumnPredicate* pred = new InListPredicate<double>(0, std::move(values));
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
@@ -337,7 +375,22 @@ TEST_F(TestInListPredicate, DOUBLE_COLUMN) {
ASSERT_DOUBLE_EQ(*(col_data + sel[1]), 5.1);
ASSERT_DOUBLE_EQ(*(col_data + sel[2]), 6.1);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<double*>(col_block_view.data()) = i + 0.1;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_DOUBLE_EQ(*(double*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 4.1);
+ ASSERT_DOUBLE_EQ(*(double*)col_block.cell(_row_block->selection_vector()[1]).cell_ptr(), 5.1);
+ ASSERT_DOUBLE_EQ(*(double*)col_block.cell(_row_block->selection_vector()[2]).cell_ptr(), 6.1);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -355,22 +408,49 @@ TEST_F(TestInListPredicate, DOUBLE_COLUMN) {
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_DOUBLE_EQ(*(col_data + sel[0]), 5.1);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<double*>(col_block_view.data()) = i + 0.1;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_DOUBLE_EQ(*(double*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), 5.1);
+
delete pred;
}
TEST_F(TestInListPredicate, DECIMAL_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DECIMAL_COLUMN"), "DECIMAL", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DECIMAL_COLUMN"), "DECIMAL", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::set<decimal12_t> values;
+
+ decimal12_t value1(4, 4);
+ values.insert(value1);
+ decimal12_t value2(5, 5);
+ values.insert(value2);
+ decimal12_t value3(6, 6);
+ values.insert(value3);
+
+ ColumnPredicate* pred = new InListPredicate<decimal12_t>(0, std::move(values));
+
+ // for VectorizedBatch no null
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
decimal12_t* col_data =
reinterpret_cast<decimal12_t*>(_mem_pool->allocate(size * sizeof(decimal12_t)));
@@ -379,18 +459,6 @@ TEST_F(TestInListPredicate, DECIMAL_COLUMN) {
(*(col_data + i)).integer = i;
(*(col_data + i)).fraction = i;
}
-
- std::set<decimal12_t> values;
- decimal12_t value1(4, 4);
- values.insert(value1);
-
- decimal12_t value2(5, 5);
- values.insert(value2);
-
- decimal12_t value3(6, 6);
- values.insert(value3);
-
- ColumnPredicate* pred = new InListPredicate<decimal12_t>(0, std::move(values));
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
@@ -398,7 +466,23 @@ TEST_F(TestInListPredicate, DECIMAL_COLUMN) {
ASSERT_EQ(*(col_data + sel[1]), value2);
ASSERT_EQ(*(col_data + sel[2]), value3);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->integer = i;
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->fraction = i;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_EQ(*(decimal12_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value1);
+ ASSERT_EQ(*(decimal12_t*)col_block.cell(_row_block->selection_vector()[1]).cell_ptr(), value2);
+ ASSERT_EQ(*(decimal12_t*)col_block.cell(_row_block->selection_vector()[2]).cell_ptr(), value3);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -411,45 +495,41 @@ TEST_F(TestInListPredicate, DECIMAL_COLUMN) {
(*(col_data + i)).fraction = i;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(*(col_data + sel[0]), value2);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->integer = i;
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->fraction = i;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(*(decimal12_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value2);
+
delete pred;
}
TEST_F(TestInListPredicate, CHAR_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("STRING_COLUMN"), "CHAR", "REPLACE", 1, false, true,
- &tablet_schema);
+ SetTabletSchema(std::string("STRING_COLUMN"), "CHAR", "REPLACE", 1, true, true, &tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
- InitVectorizedBatch(&tablet_schema, return_columns, size);
- ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
- col_vector->set_no_nulls(true);
- StringValue* col_data =
- reinterpret_cast<StringValue*>(_mem_pool->allocate(size * sizeof(StringValue)));
- col_vector->set_col_data(col_data);
-
- char* string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(60));
- memset(string_buffer, 0, 60);
- for (int i = 0; i < size; ++i) {
- for (int j = 0; j <= 5; ++j) {
- string_buffer[j] = 'a' + i;
- }
- (*(col_data + i)).len = 5;
- (*(col_data + i)).ptr = string_buffer;
- string_buffer += 5;
- }
-
std::set<StringValue> values;
StringValue value1;
const char* value1_buffer = "aaaaa";
@@ -470,6 +550,25 @@ TEST_F(TestInListPredicate, CHAR_COLUMN) {
values.insert(value3);
ColumnPredicate* pred = new InListPredicate<StringValue>(0, std::move(values));
+
+ // for VectorizedBatch no null
+ InitVectorizedBatch(&tablet_schema, return_columns, size);
+ ColumnVector* col_vector = _vectorized_batch->column(0);
+ col_vector->set_no_nulls(true);
+ StringValue* col_data =
+ reinterpret_cast<StringValue*>(_mem_pool->allocate(size * sizeof(StringValue)));
+ col_vector->set_col_data(col_data);
+
+ char* string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(60));
+ memset(string_buffer, 0, 60);
+ for (int i = 0; i < size; ++i) {
+ for (int j = 0; j <= 5; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ (*(col_data + i)).len = 5;
+ (*(col_data + i)).ptr = string_buffer;
+ string_buffer += 5;
+ }
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
@@ -477,7 +576,29 @@ TEST_F(TestInListPredicate, CHAR_COLUMN) {
ASSERT_EQ(*(col_data + sel[1]), value2);
ASSERT_EQ(*(col_data + sel[2]), value3);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(60));
+ memset(string_buffer, 0, 60);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= 5; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = 5;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += 5;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value1);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[1]).cell_ptr(), value2);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[2]).cell_ptr(), value3);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -496,44 +617,47 @@ TEST_F(TestInListPredicate, CHAR_COLUMN) {
}
string_buffer += 5;
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(*(col_data + sel[0]), value2);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= 5; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = 5;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += 5;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value2);
+
delete pred;
}
TEST_F(TestInListPredicate, VARCHAR_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("STRING_COLUMN"), "VARCHAR", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("STRING_COLUMN"), "VARCHAR", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
- InitVectorizedBatch(&tablet_schema, return_columns, size);
- ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
- col_vector->set_no_nulls(true);
- StringValue* col_data =
- reinterpret_cast<StringValue*>(_mem_pool->allocate(size * sizeof(StringValue)));
- col_vector->set_col_data(col_data);
-
- char* string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
- for (int i = 0; i < size; ++i) {
- for (int j = 0; j <= i; ++j) {
- string_buffer[j] = 'a' + i;
- }
- (*(col_data + i)).len = i + 1;
- (*(col_data + i)).ptr = string_buffer;
- string_buffer += i + 1;
- }
-
std::set<StringValue> values;
StringValue value1;
const char* value1_buffer = "a";
@@ -554,6 +678,24 @@ TEST_F(TestInListPredicate, VARCHAR_COLUMN) {
values.insert(value3);
ColumnPredicate* pred = new InListPredicate<StringValue>(0, std::move(values));
+
+ // for VectorizedBatch no null
+ InitVectorizedBatch(&tablet_schema, return_columns, size);
+ ColumnVector* col_vector = _vectorized_batch->column(0);
+ col_vector->set_no_nulls(true);
+ StringValue* col_data =
+ reinterpret_cast<StringValue*>(_mem_pool->allocate(size * sizeof(StringValue)));
+ col_vector->set_col_data(col_data);
+
+ char* string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
+ for (int i = 0; i < size; ++i) {
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ (*(col_data + i)).len = i + 1;
+ (*(col_data + i)).ptr = string_buffer;
+ string_buffer += i + 1;
+ }
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
@@ -561,7 +703,29 @@ TEST_F(TestInListPredicate, VARCHAR_COLUMN) {
ASSERT_EQ(*(col_data + sel[1]), value2);
ASSERT_EQ(*(col_data + sel[2]), value3);
- // for has nulls
+ // for ColumnBlock no null
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(60));
+ memset(string_buffer, 0, 60);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = i + 1;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += i + 1;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value1);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[1]).cell_ptr(), value2);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[2]).cell_ptr(), value3);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -579,28 +743,60 @@ TEST_F(TestInListPredicate, VARCHAR_COLUMN) {
}
string_buffer += i + 1;
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(*(col_data + sel[0]), value2);
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = i + 1;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += i + 1;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(*(StringValue*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr(), value2);
+
delete pred;
}
TEST_F(TestInListPredicate, DATE_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DATE_COLUMN"), "DATE", "REPLACE", 1, false, true, &tablet_schema);
+ SetTabletSchema(std::string("DATE_COLUMN"), "DATE", "REPLACE", 1, true, true, &tablet_schema);
int size = 6;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::set<uint24_t> values;
+ uint24_t value1 = datetime::timestamp_from_date("2017-09-09");
+ values.insert(value1);
+
+ uint24_t value2 = datetime::timestamp_from_date("2017-09-10");
+ values.insert(value2);
+
+ uint24_t value3 = datetime::timestamp_from_date("2017-09-11");
+ values.insert(value3);
+ ColumnPredicate* pred = new InListPredicate<uint24_t>(0, std::move(values));
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
uint24_t* col_data = reinterpret_cast<uint24_t*>(_mem_pool->allocate(size * sizeof(uint24_t)));
col_vector->set_col_data(col_data);
@@ -616,18 +812,6 @@ TEST_F(TestInListPredicate, DATE_COLUMN) {
uint24_t timestamp = datetime::timestamp_from_date(date_array[i].c_str());
*(col_data + i) = timestamp;
}
-
- std::set<uint24_t> values;
- uint24_t value1 = datetime::timestamp_from_date("2017-09-09");
- values.insert(value1);
-
- uint24_t value2 = datetime::timestamp_from_date("2017-09-10");
- values.insert(value2);
-
- uint24_t value3 = datetime::timestamp_from_date("2017-09-11");
- values.insert(value3);
-
- ColumnPredicate* pred = new InListPredicate<uint24_t>(0, std::move(values));
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
@@ -635,7 +819,29 @@ TEST_F(TestInListPredicate, DATE_COLUMN) {
ASSERT_EQ(datetime::to_date_string(*(col_data + sel[1])), "2017-09-10");
ASSERT_EQ(datetime::to_date_string(*(col_data + sel[2])), "2017-09-11");
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ uint24_t timestamp = datetime::timestamp_from_date(date_array[i].c_str());
+ *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_EQ(datetime::to_date_string(
+ *(uint24_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-09");
+ ASSERT_EQ(datetime::to_date_string(
+ *(uint24_t*)col_block.cell(_row_block->selection_vector()[1]).cell_ptr()),
+ "2017-09-10");
+ ASSERT_EQ(datetime::to_date_string(
+ *(uint24_t*)col_block.cell(_row_block->selection_vector()[2]).cell_ptr()),
+ "2017-09-11");
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -648,29 +854,59 @@ TEST_F(TestInListPredicate, DATE_COLUMN) {
*(col_data + i) = timestamp;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(datetime::to_date_string(*(col_data + sel[0])), "2017-09-10");
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ uint24_t timestamp = datetime::timestamp_from_date(date_array[i].c_str());
+ *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(datetime::to_date_string(
+ *(uint24_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-10");
+
delete pred;
}
TEST_F(TestInListPredicate, DATETIME_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DATETIME_COLUMN"), "DATETIME", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DATETIME_COLUMN"), "DATETIME", "REPLACE", 1, true, true,
&tablet_schema);
int size = 6;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::set<uint64_t> values;
+ uint64_t value1 = datetime::timestamp_from_datetime("2017-09-09 00:00:01");
+ values.insert(value1);
+
+ uint64_t value2 = datetime::timestamp_from_datetime("2017-09-10 01:00:00");
+ values.insert(value2);
+
+ uint64_t value3 = datetime::timestamp_from_datetime("2017-09-11 01:01:00");
+ values.insert(value3);
+
+ ColumnPredicate* pred = new InListPredicate<uint64_t>(0, std::move(values));
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
uint64_t* col_data = reinterpret_cast<uint64_t*>(_mem_pool->allocate(size * sizeof(uint64_t)));
col_vector->set_col_data(col_data);
@@ -686,18 +922,6 @@ TEST_F(TestInListPredicate, DATETIME_COLUMN) {
uint64_t timestamp = datetime::timestamp_from_datetime(date_array[i].c_str());
*(col_data + i) = timestamp;
}
-
- std::set<uint64_t> values;
- uint64_t value1 = datetime::timestamp_from_datetime("2017-09-09 00:00:01");
- values.insert(value1);
-
- uint64_t value2 = datetime::timestamp_from_datetime("2017-09-10 01:00:00");
- values.insert(value2);
-
- uint64_t value3 = datetime::timestamp_from_datetime("2017-09-11 01:01:00");
- values.insert(value3);
-
- ColumnPredicate* pred = new InListPredicate<uint64_t>(0, std::move(values));
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 3);
uint16_t* sel = _vectorized_batch->selected();
@@ -705,7 +929,29 @@ TEST_F(TestInListPredicate, DATETIME_COLUMN) {
ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[1])), "2017-09-10 01:00:00");
ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[2])), "2017-09-11 01:01:00");
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ uint64_t timestamp = datetime::timestamp_from_datetime(date_array[i].c_str());
+ *reinterpret_cast<uint64_t*>(col_block_view.data()) = timestamp;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 3);
+ ASSERT_EQ(datetime::to_datetime_string(
+ *(uint64_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-09 00:00:01");
+ ASSERT_EQ(datetime::to_datetime_string(
+ *(uint64_t*)col_block.cell(_row_block->selection_vector()[1]).cell_ptr()),
+ "2017-09-10 01:00:00");
+ ASSERT_EQ(datetime::to_datetime_string(
+ *(uint64_t*)col_block.cell(_row_block->selection_vector()[2]).cell_ptr()),
+ "2017-09-11 01:01:00");
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -718,13 +964,32 @@ TEST_F(TestInListPredicate, DATETIME_COLUMN) {
*(col_data + i) = timestamp;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 1);
sel = _vectorized_batch->selected();
ASSERT_EQ(datetime::to_datetime_string(*(col_data + sel[0])), "2017-09-10 01:00:00");
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ uint64_t timestamp = datetime::timestamp_from_datetime(date_array[i].c_str());
+ *reinterpret_cast<uint64_t*>(col_block_view.data()) = timestamp;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 1);
+ ASSERT_EQ(datetime::to_datetime_string(
+ *(uint64_t*)col_block.cell(_row_block->selection_vector()[0]).cell_ptr()),
+ "2017-09-10 01:00:00");
+
delete pred;
}
diff --git a/be/test/olap/null_predicate_test.cpp b/be/test/olap/null_predicate_test.cpp
index d16dbda..bf53ec2 100644
--- a/be/test/olap/null_predicate_test.cpp
+++ b/be/test/olap/null_predicate_test.cpp
@@ -23,6 +23,7 @@
#include "olap/column_predicate.h"
#include "olap/field.h"
+#include "olap/row_block2.h"
#include "runtime/mem_pool.h"
#include "runtime/string_value.hpp"
#include "runtime/vectorized_row_batch.h"
@@ -56,13 +57,13 @@ static uint64_t to_datetime_timestamp(const std::string& value_string) {
class TestNullPredicate : public testing::Test {
public:
- TestNullPredicate() : _vectorized_batch(NULL) {
+ TestNullPredicate() : _vectorized_batch(nullptr), _row_block(nullptr) {
_mem_tracker.reset(new MemTracker(-1));
_mem_pool.reset(new MemPool(_mem_tracker.get()));
}
~TestNullPredicate() {
- if (_vectorized_batch != NULL) {
+ if (_vectorized_batch != nullptr) {
delete _vectorized_batch;
}
}
@@ -92,53 +93,87 @@ public:
_vectorized_batch = new VectorizedRowBatch(tablet_schema, ids, size);
_vectorized_batch->set_size(size);
}
+
+ void init_row_block(const TabletSchema* tablet_schema, int size) {
+ Schema schema(*tablet_schema);
+ _row_block.reset(new RowBlockV2(schema, size));
+ }
+
std::shared_ptr<MemTracker> _mem_tracker;
std::unique_ptr<MemPool> _mem_pool;
VectorizedRowBatch* _vectorized_batch;
+ std::unique_ptr<RowBlockV2> _row_block;
};
-#define TEST_IN_LIST_PREDICATE(TYPE, TYPE_NAME, FIELD_TYPE) \
- TEST_F(TestNullPredicate, TYPE_NAME##_COLUMN) { \
- TabletSchema tablet_schema; \
- SetTabletSchema(std::string("TYPE_NAME##_COLUMN"), FIELD_TYPE, "REPLACE", 1, false, true, \
- &tablet_schema); \
- int size = 10; \
- std::vector<uint32_t> return_columns; \
- for (int i = 0; i < tablet_schema.num_columns(); ++i) { \
- return_columns.push_back(i); \
- } \
- InitVectorizedBatch(&tablet_schema, return_columns, size); \
- ColumnVector* col_vector = _vectorized_batch->column(0); \
- \
- /* for no nulls */ \
- col_vector->set_no_nulls(true); \
- TYPE* col_data = reinterpret_cast<TYPE*>(_mem_pool->allocate(size * sizeof(TYPE))); \
- col_vector->set_col_data(col_data); \
- for (int i = 0; i < size; ++i) { \
- *(col_data + i) = i; \
- } \
- \
- ColumnPredicate* pred = new NullPredicate(0, true); \
- pred->evaluate(_vectorized_batch); \
- ASSERT_EQ(_vectorized_batch->size(), 0); \
- \
- /* for has nulls */ \
- col_vector->set_no_nulls(false); \
- bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size)); \
- memset(is_null, 0, size); \
- col_vector->set_is_null(is_null); \
- for (int i = 0; i < size; ++i) { \
- if (i % 2 == 0) { \
- is_null[i] = true; \
- } else { \
- *(col_data + i) = i; \
- } \
- } \
- _vectorized_batch->set_size(size); \
- _vectorized_batch->set_selected_in_use(false); \
- pred->evaluate(_vectorized_batch); \
- ASSERT_EQ(_vectorized_batch->size(), 5); \
- delete pred; \
+#define TEST_IN_LIST_PREDICATE(TYPE, TYPE_NAME, FIELD_TYPE) \
+ TEST_F(TestNullPredicate, TYPE_NAME##_COLUMN) { \
+ TabletSchema tablet_schema; \
+ SetTabletSchema(std::string("TYPE_NAME##_COLUMN"), FIELD_TYPE, "REPLACE", 1, true, true, \
+ &tablet_schema); \
+ int size = 10; \
+ std::vector<uint32_t> return_columns; \
+ for (int i = 0; i < tablet_schema.num_columns(); ++i) { \
+ return_columns.push_back(i); \
+ } \
+ std::unique_ptr<ColumnPredicate> pred(new NullPredicate(0, true)); \
+ \
+ /* for VectorizedBatch nulls */ \
+ InitVectorizedBatch(&tablet_schema, return_columns, size); \
+ init_row_block(&tablet_schema, size); \
+ ColumnVector* col_vector = _vectorized_batch->column(0); \
+ col_vector->set_no_nulls(true); \
+ TYPE* col_data = reinterpret_cast<TYPE*>(_mem_pool->allocate(size * sizeof(TYPE))); \
+ col_vector->set_col_data(col_data); \
+ for (int i = 0; i < size; ++i) { \
+ *(col_data + i) = i; \
+ } \
+ pred->evaluate(_vectorized_batch); \
+ ASSERT_EQ(_vectorized_batch->size(), 0); \
+ \
+ /* for ColumnBlock nulls */ \
+ init_row_block(&tablet_schema, size); \
+ ColumnBlock col_block = _row_block->column_block(0); \
+ auto select_size = _row_block->selected_size(); \
+ ColumnBlockView col_block_view(&col_block); \
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) { \
+ col_block_view.set_null_bits(1, false); \
+ *reinterpret_cast<TYPE*>(col_block_view.data()) = i; \
+ } \
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size); \
+ ASSERT_EQ(select_size, 0); \
+ \
+ /* for has nulls */ \
+ col_vector->set_no_nulls(false); \
+ bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size)); \
+ memset(is_null, 0, size); \
+ col_vector->set_is_null(is_null); \
+ for (int i = 0; i < size; ++i) { \
+ if (i % 2 == 0) { \
+ is_null[i] = true; \
+ } else { \
+ *(col_data + i) = i; \
+ } \
+ } \
+ _vectorized_batch->set_size(size); \
+ _vectorized_batch->set_selected_in_use(false); \
+ pred->evaluate(_vectorized_batch); \
+ ASSERT_EQ(_vectorized_batch->size(), 5); \
+ \
+ /* for ColumnBlock has nulls */ \
+ col_block_view = ColumnBlockView(&col_block); \
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) { \
+ if (i % 2 == 0) { \
+ col_block_view.set_null_bits(1, true); \
+ } else { \
+ col_block_view.set_null_bits(1, false); \
+ *reinterpret_cast<TYPE*>(col_block_view.data()) = i; \
+ } \
+ } \
+ _row_block->clear(); \
+ select_size = _row_block->selected_size(); \
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size); \
+ ASSERT_EQ(select_size, 5); \
+ pred.reset(); \
}
TEST_IN_LIST_PREDICATE(int8_t, TINYINT, "TINYINT")
@@ -149,28 +184,39 @@ TEST_IN_LIST_PREDICATE(int128_t, LARGEINT, "LARGEINT")
TEST_F(TestNullPredicate, FLOAT_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("FLOAT_COLUMN"), "FLOAT", "REPLACE", 1, false, true,
- &tablet_schema);
+ SetTabletSchema(std::string("FLOAT_COLUMN"), "FLOAT", "REPLACE", 1, true, true, &tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::unique_ptr<ColumnPredicate> pred(new NullPredicate(0, true));
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
float* col_data = reinterpret_cast<float*>(_mem_pool->allocate(size * sizeof(float)));
col_vector->set_col_data(col_data);
for (int i = 0; i < size; ++i) {
*(col_data + i) = i + 0.1;
}
- ColumnPredicate* pred = new NullPredicate(0, true);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 0);
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<float*>(col_block_view.data()) = i + 0.1;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -186,34 +232,59 @@ TEST_F(TestNullPredicate, FLOAT_COLUMN) {
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 5);
- delete pred;
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<float*>(col_block_view.data()) = i + 0.1;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 5);
}
TEST_F(TestNullPredicate, DOUBLE_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DOUBLE_COLUMN"), "DOUBLE", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DOUBLE_COLUMN"), "DOUBLE", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::unique_ptr<ColumnPredicate> pred(new NullPredicate(0, true));
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
double* col_data = reinterpret_cast<double*>(_mem_pool->allocate(size * sizeof(double)));
col_vector->set_col_data(col_data);
for (int i = 0; i < size; ++i) {
*(col_data + i) = i + 0.1;
}
-
- ColumnPredicate* pred = new NullPredicate(0, true);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 0);
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<double*>(col_block_view.data()) = i + 0.1;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -229,22 +300,37 @@ TEST_F(TestNullPredicate, DOUBLE_COLUMN) {
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 5);
- delete pred;
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 2 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ *reinterpret_cast<double*>(col_block_view.data()) = i + 0.1;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 5);
}
TEST_F(TestNullPredicate, DECIMAL_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DECIMAL_COLUMN"), "DECIMAL", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DECIMAL_COLUMN"), "DECIMAL", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::unique_ptr<ColumnPredicate> pred(new NullPredicate(0, true));
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
decimal12_t* col_data =
reinterpret_cast<decimal12_t*>(_mem_pool->allocate(size * sizeof(decimal12_t)));
@@ -253,12 +339,23 @@ TEST_F(TestNullPredicate, DECIMAL_COLUMN) {
(*(col_data + i)).integer = i;
(*(col_data + i)).fraction = i;
}
-
- ColumnPredicate* pred = new NullPredicate(0, true);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 0);
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->integer = i;
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->fraction = i;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -271,32 +368,46 @@ TEST_F(TestNullPredicate, DECIMAL_COLUMN) {
(*(col_data + i)).fraction = i;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 4);
- delete pred;
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 3 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->integer = i;
+ reinterpret_cast<decimal12_t*>(col_block_view.data())->fraction = i;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 4);
}
TEST_F(TestNullPredicate, STRING_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("STRING_COLUMN"), "VARCHAR", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("STRING_COLUMN"), "VARCHAR", "REPLACE", 1, true, true,
&tablet_schema);
int size = 10;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::unique_ptr<ColumnPredicate> pred(new NullPredicate(0, true));
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
StringValue* col_data =
reinterpret_cast<StringValue*>(_mem_pool->allocate(size * sizeof(StringValue)));
col_vector->set_col_data(col_data);
-
char* string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
for (int i = 0; i < size; ++i) {
for (int j = 0; j <= i; ++j) {
@@ -306,11 +417,30 @@ TEST_F(TestNullPredicate, STRING_COLUMN) {
(*(col_data + i)).ptr = string_buffer;
string_buffer += i + 1;
}
-
- ColumnPredicate* pred = new NullPredicate(0, true);
ASSERT_EQ(_vectorized_batch->size(), 10);
+ pred->evaluate(_vectorized_batch);
+ ASSERT_EQ(_vectorized_batch->size(), 0);
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = i + 1;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += i + 1;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -328,26 +458,46 @@ TEST_F(TestNullPredicate, STRING_COLUMN) {
}
string_buffer += i + 1;
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 4);
- delete pred;
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ string_buffer = reinterpret_cast<char*>(_mem_pool->allocate(55));
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 3 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ for (int j = 0; j <= i; ++j) {
+ string_buffer[j] = 'a' + i;
+ }
+ reinterpret_cast<StringValue*>(col_block_view.data())->len = i + 1;
+ reinterpret_cast<StringValue*>(col_block_view.data())->ptr = string_buffer;
+ string_buffer += i + 1;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 4);
}
TEST_F(TestNullPredicate, DATE_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DATE_COLUMN"), "DATE", "REPLACE", 1, false, true, &tablet_schema);
+ SetTabletSchema(std::string("DATE_COLUMN"), "DATE", "REPLACE", 1, true, true, &tablet_schema);
int size = 6;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::unique_ptr<ColumnPredicate> pred(new NullPredicate(0, true));
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
uint24_t* col_data = reinterpret_cast<uint24_t*>(_mem_pool->allocate(size * sizeof(uint24_t)));
col_vector->set_col_data(col_data);
@@ -363,12 +513,23 @@ TEST_F(TestNullPredicate, DATE_COLUMN) {
uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
*(col_data + i) = timestamp;
}
-
- ColumnPredicate* pred = new NullPredicate(0, true);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 0);
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -381,31 +542,45 @@ TEST_F(TestNullPredicate, DATE_COLUMN) {
*(col_data + i) = timestamp;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 2);
- delete pred;
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 3 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ uint24_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint24_t*>(col_block_view.data()) = timestamp;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 2);
}
TEST_F(TestNullPredicate, DATETIME_COLUMN) {
TabletSchema tablet_schema;
- SetTabletSchema(std::string("DATETIME_COLUMN"), "DATETIME", "REPLACE", 1, false, true,
+ SetTabletSchema(std::string("DATETIME_COLUMN"), "DATETIME", "REPLACE", 1, true, true,
&tablet_schema);
int size = 6;
std::vector<uint32_t> return_columns;
for (int i = 0; i < tablet_schema.num_columns(); ++i) {
return_columns.push_back(i);
}
+ std::unique_ptr<ColumnPredicate> pred(new NullPredicate(0, true));
+
+ // for VectorizedBatch no nulls
InitVectorizedBatch(&tablet_schema, return_columns, size);
ColumnVector* col_vector = _vectorized_batch->column(0);
-
- // for no nulls
col_vector->set_no_nulls(true);
uint64_t* col_data = reinterpret_cast<uint64_t*>(_mem_pool->allocate(size * sizeof(uint64_t)));
col_vector->set_col_data(col_data);
-
std::vector<std::string> date_array;
date_array.push_back("2017-09-07 00:00:00");
date_array.push_back("2017-09-08 00:01:00");
@@ -417,12 +592,23 @@ TEST_F(TestNullPredicate, DATETIME_COLUMN) {
uint64_t timestamp = datetime::to_datetime_timestamp(date_array[i].c_str());
*(col_data + i) = timestamp;
}
-
- ColumnPredicate* pred = new NullPredicate(0, true);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 0);
- // for has nulls
+ // for ColumnBlock no nulls
+ init_row_block(&tablet_schema, size);
+ ColumnBlock col_block = _row_block->column_block(0);
+ auto select_size = _row_block->selected_size();
+ ColumnBlockView col_block_view(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ col_block_view.set_null_bits(1, false);
+ uint64_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint64_t*>(col_block_view.data()) = timestamp;
+ }
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 0);
+
+ // for VectorizedBatch has nulls
col_vector->set_no_nulls(false);
bool* is_null = reinterpret_cast<bool*>(_mem_pool->allocate(size));
memset(is_null, 0, size);
@@ -435,12 +621,26 @@ TEST_F(TestNullPredicate, DATETIME_COLUMN) {
*(col_data + i) = timestamp;
}
}
-
_vectorized_batch->set_size(size);
_vectorized_batch->set_selected_in_use(false);
pred->evaluate(_vectorized_batch);
ASSERT_EQ(_vectorized_batch->size(), 2);
- delete pred;
+
+ // for ColumnBlock has nulls
+ col_block_view = ColumnBlockView(&col_block);
+ for (int i = 0; i < size; ++i, col_block_view.advance(1)) {
+ if (i % 3 == 0) {
+ col_block_view.set_null_bits(1, true);
+ } else {
+ col_block_view.set_null_bits(1, false);
+ uint64_t timestamp = datetime::to_date_timestamp(date_array[i].c_str());
+ *reinterpret_cast<uint64_t*>(col_block_view.data()) = timestamp;
+ }
+ }
+ _row_block->clear();
+ select_size = _row_block->selected_size();
+ pred->evaluate(&col_block, _row_block->selection_vector(), &select_size);
+ ASSERT_EQ(select_size, 2);
}
} // namespace doris
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org