patch 4.0
This commit is contained in:
@ -11,6 +11,8 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "sql/ob_sql_init.h"
|
||||
#include "sql/engine/aggregate/ob_hash_groupby.h"
|
||||
#include "sql/engine/aggregate/ob_aggregate_test_utils.h"
|
||||
@ -18,37 +20,42 @@
|
||||
#include "storage/memtable/ob_row_compactor.h"
|
||||
#include "sql/engine/test_engine_util.h"
|
||||
#include "storage/blocksstable/ob_data_file_prepare.h"
|
||||
#include "share/ob_simple_mem_limit_getter.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::sql;
|
||||
using namespace oceanbase::blocksstable;
|
||||
|
||||
class ObHashGroupbyTest : public TestDataFilePrepare {
|
||||
static ObSimpleMemLimitGetter getter;
|
||||
|
||||
class ObHashGroupbyTest: public TestDataFilePrepare
|
||||
{
|
||||
public:
|
||||
ObHashGroupbyTest();
|
||||
virtual ~ObHashGroupbyTest();
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
|
||||
private:
|
||||
// disallow copy
|
||||
ObHashGroupbyTest(const ObHashGroupbyTest& other);
|
||||
ObHashGroupbyTest& operator=(const ObHashGroupbyTest& other);
|
||||
|
||||
ObHashGroupbyTest(const ObHashGroupbyTest &other);
|
||||
ObHashGroupbyTest& operator=(const ObHashGroupbyTest &other);
|
||||
private:
|
||||
// data members
|
||||
};
|
||||
ObHashGroupbyTest::ObHashGroupbyTest() : TestDataFilePrepare("TestDisk_groupby", 2 << 20, 5000)
|
||||
{}
|
||||
ObHashGroupbyTest::ObHashGroupbyTest() : TestDataFilePrepare(&getter,
|
||||
"TestDisk_groupby", 2<<20, 5000)
|
||||
{
|
||||
}
|
||||
|
||||
ObHashGroupbyTest::~ObHashGroupbyTest()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void ObHashGroupbyTest::SetUp()
|
||||
{
|
||||
TestDataFilePrepare::SetUp();
|
||||
int ret = ObTmpFileManager::get_instance().init();
|
||||
ASSERT_EQ(OB_SUCCESS, ret);
|
||||
ASSERT_EQ(OB_SUCCESS, ret);
|
||||
}
|
||||
|
||||
void ObHashGroupbyTest::TearDown()
|
||||
@ -56,12 +63,13 @@ void ObHashGroupbyTest::TearDown()
|
||||
ObTmpFileManager::get_instance().destroy();
|
||||
TestDataFilePrepare::TearDown();
|
||||
}
|
||||
class TestHashGroupBy : public ObHashGroupBy {
|
||||
class TestHashGroupBy : public ObHashGroupBy
|
||||
{
|
||||
public:
|
||||
TestHashGroupBy() : ObHashGroupBy(alloc_)
|
||||
{}
|
||||
virtual ~TestHashGroupBy()
|
||||
{}
|
||||
{
|
||||
}
|
||||
virtual ~TestHashGroupBy() {}
|
||||
};
|
||||
|
||||
TEST_F(ObHashGroupbyTest, test_utf8mb4_bin_agg)
|
||||
@ -69,8 +77,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_bin_agg)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = false;
|
||||
@ -78,7 +86,7 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_bin_agg)
|
||||
ObCollationType agg_cs_type = CS_TYPE_UTF8MB4_BIN;
|
||||
ObCollationType group_cs_type = CS_TYPE_INVALID;
|
||||
TestAggregateFactory::init(ctx, hash_groupby, col_count, is_distinct, is_number, agg_cs_type, group_cs_type);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(fake_table, COL(1), COL("r"), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL("s"), COL(1));
|
||||
ADD_ROW(fake_table, COL(3), COL("t"), COL(1));
|
||||
@ -86,7 +94,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_bin_agg)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(4), COL("ß"), COL("r"));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, hash_groupby);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby, col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby,
|
||||
col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, hash_groupby);
|
||||
}
|
||||
|
||||
@ -95,8 +104,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_genaral_ci_agg)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = false;
|
||||
@ -105,7 +114,7 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_genaral_ci_agg)
|
||||
ObCollationType group_cs_type = CS_TYPE_INVALID;
|
||||
|
||||
TestAggregateFactory::init(ctx, hash_groupby, col_count, is_distinct, is_number, agg_cs_type, group_cs_type);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(fake_table, COL(1), COL("r"), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL("s"), COL(1));
|
||||
ADD_ROW(fake_table, COL(3), COL("t"), COL(1));
|
||||
@ -113,7 +122,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_genaral_ci_agg)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(4), COL("t"), COL("r"));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, hash_groupby);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby, col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby,
|
||||
col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, hash_groupby);
|
||||
}
|
||||
|
||||
@ -122,8 +132,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_general_ci_group)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = false;
|
||||
@ -132,7 +142,7 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_general_ci_group)
|
||||
ObCollationType group_cs_type = CS_TYPE_UTF8MB4_GENERAL_CI;
|
||||
|
||||
TestAggregateFactory::init(ctx, hash_groupby, col_count, is_distinct, is_number, agg_cs_type, group_cs_type);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(fake_table, COL(1), COL(2), COL("ß"));
|
||||
ADD_ROW(fake_table, COL(2), COL(4), COL("s"));
|
||||
ADD_ROW(fake_table, COL(3), COL(6), COL("ß"));
|
||||
@ -140,7 +150,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_general_ci_group)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(4), COL(8), COL(2), COL(20.0), COL(5.0));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, hash_groupby);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby, col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby,
|
||||
col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, hash_groupby);
|
||||
}
|
||||
|
||||
@ -149,8 +160,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_bin_agg_distinct)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = true;
|
||||
@ -159,7 +170,7 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_bin_agg_distinct)
|
||||
ObCollationType group_cs_type = CS_TYPE_INVALID;
|
||||
|
||||
TestAggregateFactory::init(ctx, hash_groupby, col_count, is_distinct, is_number, agg_cs_type, group_cs_type);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(fake_table, COL(1), COL("r"), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL("s"), COL(1));
|
||||
ADD_ROW(fake_table, COL(3), COL("t"), COL(1));
|
||||
@ -167,7 +178,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_bin_agg_distinct)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(4), COL("ß"), COL("r"), COL(4));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, hash_groupby);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby, col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby,
|
||||
col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, hash_groupby);
|
||||
}
|
||||
|
||||
@ -176,8 +188,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_general_ci_agg_distinct)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = true;
|
||||
@ -186,7 +198,7 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_general_ci_agg_distinct)
|
||||
ObCollationType group_cs_type = CS_TYPE_INVALID;
|
||||
|
||||
TestAggregateFactory::init(ctx, hash_groupby, col_count, is_distinct, is_number, agg_cs_type, group_cs_type);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(fake_table, COL(1), COL("r"), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL("s"), COL(1));
|
||||
ADD_ROW(fake_table, COL(3), COL("t"), COL(1));
|
||||
@ -194,7 +206,8 @@ TEST_F(ObHashGroupbyTest, test_utf8mb4_general_ci_agg_distinct)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(3), COL("t"), COL("r"), COL(3));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, hash_groupby);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby, col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, hash_groupby,
|
||||
col_count, hash_groupby.get_column_count(), agg_cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, hash_groupby);
|
||||
}
|
||||
|
||||
@ -203,13 +216,13 @@ TEST_F(ObHashGroupbyTest, test_groupby_without_distinct)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
ObCollationType agg_cs_type = CS_TYPE_UTF8MB4_BIN;
|
||||
|
||||
TestAggregateFactory::init(ctx, hash_groupby, 3, false);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(fake_table, COL(1), COL(1), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL(2), COL(2));
|
||||
ADD_ROW(fake_table, COL(5), COL(2), COL(3));
|
||||
@ -234,12 +247,12 @@ TEST_F(ObHashGroupbyTest, test_groupby_varchar)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
|
||||
TestAggregateFactory::init(ctx, hash_groupby, 3, false);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(fake_table, COL(1), COL("1"), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL("2"), COL(2));
|
||||
ADD_ROW(fake_table, COL(5), COL("2"), COL(3));
|
||||
@ -264,12 +277,12 @@ TEST_F(ObHashGroupbyTest, test_groupby_with_distinct)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
|
||||
TestAggregateFactory::init(ctx, hash_groupby, 3, true);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(fake_table, COL(1), COL(1), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL(1), COL(1));
|
||||
ADD_ROW(fake_table, COL(3), COL(2), COL(1));
|
||||
@ -296,7 +309,7 @@ TEST_F(ObHashGroupbyTest, test_invalid_argument)
|
||||
ObArenaAllocator alloc;
|
||||
ObFakeTable fake_table(alloc);
|
||||
TestHashGroupBy hash_groupby;
|
||||
const ObNewRow* row = NULL;
|
||||
const ObNewRow *row = NULL;
|
||||
|
||||
ASSERT_EQ(OB_NOT_INIT, hash_groupby.open(ctx));
|
||||
hash_groupby.reset();
|
||||
@ -321,15 +334,16 @@ TEST_F(ObHashGroupbyTest, test_invalid_argument1)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
TestHashGroupBy hash_groupby;
|
||||
ObArenaAllocator alloc;
|
||||
ObAggregateExpression col_expr(alloc);
|
||||
|
||||
TestAggregateFactory::init(ctx, hash_groupby, 3, false);
|
||||
// prepare rows, equal in the first row
|
||||
//prepare rows, equal in the first row
|
||||
ADD_ROW(fake_table, COL(1), COL(2), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL(2), COL(1));
|
||||
|
||||
}
|
||||
|
||||
TEST_F(ObHashGroupbyTest, test_serialize_and_deserialize)
|
||||
@ -354,16 +368,16 @@ TEST_F(ObHashGroupbyTest, test_serialize_and_deserialize)
|
||||
ASSERT_EQ(0, strcmp(to_cstring(hash_groupby), to_cstring(deserialize_op)));
|
||||
}
|
||||
|
||||
void __attribute__((constructor(101))) init_SessionDIBuffer()
|
||||
void __attribute__((constructor(101))) init_SessionDIBuffer()
|
||||
{
|
||||
oceanbase::common::ObDITls<ObSessionDIBuffer>::get_instance();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
init_global_memory_pool();
|
||||
init_sql_factories();
|
||||
oceanbase::common::ObLogger::get_logger().set_log_level("INFO");
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::InitGoogleTest(&argc,argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
Reference in New Issue
Block a user