[FEAT MERGE] impl vectorization 2.0
Co-authored-by: Naynahs <cfzy002@126.com> Co-authored-by: hwx65 <1780011298@qq.com> Co-authored-by: oceanoverflow <oceanoverflow@gmail.com>
This commit is contained in:
@ -27,7 +27,7 @@
|
||||
#include "lib/string/ob_sql_string.h"
|
||||
#include "../ob_row_generate.h"
|
||||
#include "common/rowkey/ob_rowkey.h"
|
||||
#include "unittest/storage/mock_ob_table_read_info.h"
|
||||
#include "test_column_decoder.h"
|
||||
|
||||
|
||||
namespace oceanbase
|
||||
@ -265,6 +265,12 @@ public:
|
||||
sql::ObPushdownWhiteFilterNode &filter_node,
|
||||
common::ObBitmap &result_bitmap,
|
||||
common::ObFixedArray<ObObj, ObIAllocator> &objs);
|
||||
void test_batch_decode_to_vector(
|
||||
const bool is_condensed,
|
||||
const bool has_null,
|
||||
const bool align_row_id,
|
||||
const VectorFormat vector_format);
|
||||
|
||||
protected:
|
||||
ObRowGenerate row_generate_;
|
||||
ObMicroBlockEncodingCtx ctx_;
|
||||
@ -539,6 +545,147 @@ int TestRawDecoder::test_filter_pushdown_with_pd_info(
|
||||
return ret;
|
||||
}
|
||||
|
||||
void TestRawDecoder::test_batch_decode_to_vector(
|
||||
const bool is_condensed,
|
||||
const bool has_null,
|
||||
const bool align_row_id,
|
||||
const VectorFormat vector_format)
|
||||
{
|
||||
FLOG_INFO("start one batch decode to vector test", K(is_condensed), K(has_null), K(align_row_id), K(vector_format));
|
||||
ObArenaAllocator test_allocator;
|
||||
encoder_.reuse();
|
||||
// Generate data and encode
|
||||
void *row_buf = test_allocator.alloc(sizeof(ObDatumRow) * ROW_CNT);
|
||||
ASSERT_TRUE(nullptr != row_buf);
|
||||
ObDatumRow *rows = new (row_buf) ObDatumRow[ROW_CNT];
|
||||
for (int64_t i = 0; i < ROW_CNT; ++i) {
|
||||
ASSERT_EQ(OB_SUCCESS, rows[i].init(test_allocator, full_column_cnt_));
|
||||
}
|
||||
ObDatumRow row;
|
||||
ASSERT_EQ(OB_SUCCESS, row.init(test_allocator, full_column_cnt_));
|
||||
for (int64_t i = 0; i < ROW_CNT - 35; ++i) {
|
||||
ASSERT_EQ(OB_SUCCESS, row_generate_.get_next_row(row));
|
||||
ASSERT_EQ(OB_SUCCESS, encoder_.append_row(row)) << "i: " << i << std::endl;
|
||||
rows[i].deep_copy(row, test_allocator);
|
||||
}
|
||||
|
||||
if (has_null) {
|
||||
for (int64_t j = 0; j < full_column_cnt_; ++j) {
|
||||
row.storage_datums_[j].set_null();
|
||||
}
|
||||
for (int64_t i = ROW_CNT - 35; i < 40; ++i) {
|
||||
ASSERT_EQ(OB_SUCCESS, encoder_.append_row(row)) << "i: " << i << std::endl;
|
||||
rows[i].deep_copy(row, test_allocator);
|
||||
}
|
||||
} else {
|
||||
ASSERT_EQ(OB_SUCCESS, row_generate_.get_next_row(row));
|
||||
for (int64_t i = ROW_CNT - 35; i < 40; ++i) {
|
||||
ASSERT_EQ(OB_SUCCESS, encoder_.append_row(row)) << "i: " << i << std::endl;
|
||||
rows[i].deep_copy(row, test_allocator);
|
||||
}
|
||||
}
|
||||
|
||||
for (int64_t i = 40; i < 60; ++i) {
|
||||
ASSERT_EQ(OB_SUCCESS, row_generate_.get_next_row(row));
|
||||
ASSERT_EQ(OB_SUCCESS, encoder_.append_row(row)) << "i: " << i << std::endl;
|
||||
rows[i].deep_copy(row, test_allocator);
|
||||
}
|
||||
|
||||
for (int64_t i = 60; i < ROW_CNT; ++i) {
|
||||
ASSERT_EQ(OB_SUCCESS, row_generate_.get_next_row(0 - i, row));
|
||||
ASSERT_EQ(OB_SUCCESS, encoder_.append_row(row)) << "i: " << i << std::endl;
|
||||
rows[i].deep_copy(row, test_allocator);
|
||||
}
|
||||
|
||||
if (is_condensed) {
|
||||
encoder_.ctx_.encoder_opt_.enable_bit_packing_ = false;
|
||||
} else {
|
||||
encoder_.ctx_.encoder_opt_.enable_bit_packing_ = true;
|
||||
}
|
||||
|
||||
char *buf = NULL;
|
||||
int64_t size = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, encoder_.build_block(buf, size));
|
||||
ObMicroBlockDecoder decoder;
|
||||
ObMicroBlockData data(encoder_.data_buffer_.data(), encoder_.data_buffer_.length());
|
||||
ASSERT_EQ(OB_SUCCESS, decoder.init(data, read_info_));
|
||||
|
||||
ObArenaAllocator frame_allocator;
|
||||
sql::ObExecContext exec_context(test_allocator);
|
||||
sql::ObEvalCtx eval_ctx(exec_context);
|
||||
const char *ptr_arr[ROW_CNT];
|
||||
uint32_t len_arr[ROW_CNT];
|
||||
|
||||
for (int64_t i = 0; i < full_column_cnt_; ++i) {
|
||||
bool need_test_column = true;
|
||||
ObObjMeta col_meta = col_descs_.at(i).col_type_;
|
||||
const int16_t precision = col_meta.is_decimal_int() ? col_meta.get_stored_precision() : PRECISION_UNKNOWN_YET;
|
||||
VecValueTypeClass vec_tc = common::get_vec_value_tc(
|
||||
col_meta.get_type(),
|
||||
col_meta.get_scale(),
|
||||
precision);
|
||||
if (i >= ROWKEY_CNT && i < read_info_.get_rowkey_count()) {
|
||||
need_test_column = false;
|
||||
} else if (vector_format == VEC_FIXED) {
|
||||
VecValueTypeClass fixed_tc_arr[] = {VEC_TC_INTEGER, VEC_TC_UINTEGER, VEC_TC_FLOAT, VEC_TC_DOUBLE,
|
||||
VEC_TC_FIXED_DOUBLE, VEC_TC_DATETIME, VEC_TC_DATE, VEC_TC_TIME, VEC_TC_YEAR, VEC_TC_UNKNOWN,
|
||||
VEC_TC_BIT, VEC_TC_ENUM_SET, VEC_TC_TIMESTAMP_TZ, VEC_TC_TIMESTAMP_TINY, VEC_TC_INTERVAL_YM,
|
||||
VEC_TC_INTERVAL_DS, VEC_TC_DEC_INT32, VEC_TC_DEC_INT64, VEC_TC_DEC_INT128, VEC_TC_DEC_INT256,
|
||||
VEC_TC_DEC_INT512};
|
||||
VecValueTypeClass *vec = std::find(std::begin(fixed_tc_arr), std::end(fixed_tc_arr), vec_tc);
|
||||
if (vec == std::end(fixed_tc_arr)) {
|
||||
need_test_column = false;
|
||||
}
|
||||
} else if (vector_format == VEC_DISCRETE) {
|
||||
VecValueTypeClass var_tc_arr[] = {VEC_TC_NUMBER, VEC_TC_EXTEND, VEC_TC_STRING, VEC_TC_ENUM_SET_INNER,
|
||||
VEC_TC_RAW, VEC_TC_ROWID, VEC_TC_LOB, VEC_TC_JSON, VEC_TC_GEO, VEC_TC_UDT};
|
||||
VecValueTypeClass *vec = std::find(std::begin(var_tc_arr), std::end(var_tc_arr), vec_tc);
|
||||
if (vec == std::end(var_tc_arr)) {
|
||||
need_test_column = false;
|
||||
}
|
||||
} else if (vector_format == VEC_CONTINUOUS) {
|
||||
// not support shallow copy to continuous vector for now
|
||||
need_test_column = VEC_TC_NUMBER == vec_tc;
|
||||
} else {
|
||||
need_test_column = true;
|
||||
}
|
||||
|
||||
if (!need_test_column) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sql::ObExpr col_expr;
|
||||
int64_t test_row_cnt = align_row_id ? ROW_CNT : ROW_CNT / 2;
|
||||
ASSERT_EQ(OB_SUCCESS, VectorDecodeTestUtil::generate_column_output_expr(
|
||||
ROW_CNT, col_meta, vector_format, eval_ctx, col_expr, frame_allocator));
|
||||
int32_t col_offset = i;
|
||||
LOG_INFO("Current col: ", K(i), K(col_meta), K(*decoder.decoders_[col_offset].ctx_),
|
||||
K(precision), K(vec_tc), K(need_test_column));
|
||||
|
||||
int64_t row_ids[test_row_cnt];
|
||||
int64_t row_id_idx = 0;
|
||||
for (int64_t datum_idx = 0; datum_idx < ROW_CNT; ++datum_idx) {
|
||||
if (!align_row_id && 0 == datum_idx % 2) {
|
||||
// skip
|
||||
} else if (row_id_idx == test_row_cnt) {
|
||||
// skip
|
||||
} else {
|
||||
row_ids[row_id_idx] = datum_idx;
|
||||
++row_id_idx;
|
||||
}
|
||||
}
|
||||
|
||||
ObVectorDecodeCtx vector_ctx(ptr_arr, len_arr, row_ids, test_row_cnt, 0, col_expr.get_vector_header(eval_ctx));
|
||||
ASSERT_EQ(OB_SUCCESS, decoder.decoders_[col_offset].decode_vector(decoder.row_index_, vector_ctx));
|
||||
for (int64_t vec_idx = 0; vec_idx < test_row_cnt; ++vec_idx) {
|
||||
ASSERT_TRUE(VectorDecodeTestUtil::verify_vector_and_datum_match(*(col_expr.get_vector_header(eval_ctx).get_vector()),
|
||||
vec_idx, rows[row_ids[vec_idx]].storage_datums_[col_offset]));
|
||||
}
|
||||
// ASSERT_EQ(OB_SUCCESS, VectorDecodeTestUtil::test_batch_decode_perf(decoder, col_offset, col_meta, 100000, vector_format));
|
||||
decoder.decoder_allocator_.reuse();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestRawDecoder, filter_pushdown_all_eq_ne)
|
||||
{
|
||||
// Generate data and encode
|
||||
@ -1019,6 +1166,25 @@ TEST_F(TestRawDecoder, batch_decode_to_datum)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TestRawDecoder, batch_decode_to_vector)
|
||||
{
|
||||
#define TEST_ONE_WITH_ALIGN(row_aligned, vec_format) \
|
||||
test_batch_decode_to_vector(false, true, row_aligned, vec_format); \
|
||||
test_batch_decode_to_vector(false, false, row_aligned, vec_format); \
|
||||
test_batch_decode_to_vector(true, true, row_aligned, vec_format); \
|
||||
test_batch_decode_to_vector(true, false, row_aligned, vec_format);
|
||||
|
||||
#define TEST_ONE(vec_format) \
|
||||
TEST_ONE_WITH_ALIGN(true, vec_format) \
|
||||
TEST_ONE_WITH_ALIGN(false, vec_format)
|
||||
|
||||
TEST_ONE(VEC_UNIFORM);
|
||||
TEST_ONE(VEC_FIXED);
|
||||
TEST_ONE(VEC_DISCRETE);
|
||||
TEST_ONE(VEC_CONTINUOUS);
|
||||
#undef TEST_ONE
|
||||
#undef TEST_ONE_WITH_ALIGN
|
||||
}
|
||||
|
||||
TEST_F(TestRawDecoder, opt_batch_decode_to_datum)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user