patch 4.0
This commit is contained in:
@ -11,42 +11,48 @@
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "sql/ob_sql_init.h"
|
||||
#include "sql/engine/aggregate/ob_scalar_aggregate.h"
|
||||
#include "sql/engine/aggregate/ob_aggregate_test_utils.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;
|
||||
static ObSimpleMemLimitGetter getter;
|
||||
|
||||
class TestScalarAggregateTest : public TestDataFilePrepare {
|
||||
class TestScalarAggregateTest: public TestDataFilePrepare
|
||||
{
|
||||
public:
|
||||
TestScalarAggregateTest();
|
||||
virtual ~TestScalarAggregateTest();
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
|
||||
private:
|
||||
// disallow copy
|
||||
TestScalarAggregateTest(const TestScalarAggregateTest& other);
|
||||
TestScalarAggregateTest& operator=(const TestScalarAggregateTest& other);
|
||||
|
||||
TestScalarAggregateTest(const TestScalarAggregateTest &other);
|
||||
TestScalarAggregateTest& operator=(const TestScalarAggregateTest &other);
|
||||
private:
|
||||
// data members
|
||||
};
|
||||
TestScalarAggregateTest::TestScalarAggregateTest() : TestDataFilePrepare("TestDisk_scalar_groupby", 2 << 20, 5000)
|
||||
{}
|
||||
TestScalarAggregateTest::TestScalarAggregateTest() : TestDataFilePrepare(&getter,
|
||||
"TestDisk_scalar_groupby", 2<<20, 5000)
|
||||
{
|
||||
}
|
||||
|
||||
TestScalarAggregateTest::~TestScalarAggregateTest()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void TestScalarAggregateTest::SetUp()
|
||||
{
|
||||
TestDataFilePrepare::SetUp();
|
||||
int ret = ObTmpFileManager::get_instance().init();
|
||||
ASSERT_EQ(OB_SUCCESS, ret);
|
||||
ASSERT_EQ(OB_SUCCESS, ret);
|
||||
}
|
||||
|
||||
void TestScalarAggregateTest::TearDown()
|
||||
@ -55,12 +61,11 @@ void TestScalarAggregateTest::TearDown()
|
||||
TestDataFilePrepare::TearDown();
|
||||
}
|
||||
|
||||
class TestScalarAggregate : public ObScalarAggregate {
|
||||
class TestScalarAggregate : public ObScalarAggregate
|
||||
{
|
||||
public:
|
||||
TestScalarAggregate() : ObScalarAggregate(alloc_)
|
||||
{}
|
||||
~TestScalarAggregate()
|
||||
{}
|
||||
TestScalarAggregate() :ObScalarAggregate(alloc_) {}
|
||||
~TestScalarAggregate() {}
|
||||
};
|
||||
|
||||
TEST_F(TestScalarAggregateTest, test_utf8mb4_bin)
|
||||
@ -68,8 +73,8 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_bin)
|
||||
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();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = false;
|
||||
@ -77,7 +82,7 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_bin)
|
||||
ObCollationType cs_type = CS_TYPE_UTF8MB4_BIN;
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, col_count, is_distinct, is_number, 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(2));
|
||||
ADD_ROW(fake_table, COL(3), COL("t"), COL(3));
|
||||
@ -85,7 +90,8 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_bin)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(4), COL("ß"), COL("r"), COL(4));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, scalar_aggr_op);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op, col_count, scalar_aggr_op.get_column_count(), cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op,
|
||||
col_count, scalar_aggr_op.get_column_count(), cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, scalar_aggr_op);
|
||||
}
|
||||
|
||||
@ -94,8 +100,8 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_genaral_ci)
|
||||
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();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = false;
|
||||
@ -103,7 +109,7 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_genaral_ci)
|
||||
ObCollationType cs_type = CS_TYPE_UTF8MB4_GENERAL_CI;
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, col_count, is_distinct, is_number, 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(2));
|
||||
ADD_ROW(fake_table, COL(3), COL("t"), COL(3));
|
||||
@ -111,7 +117,8 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_genaral_ci)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(4), COL("t"), COL("r"), COL(3));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, scalar_aggr_op);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op, col_count, scalar_aggr_op.get_column_count(), cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op,
|
||||
col_count, scalar_aggr_op.get_column_count(), cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, scalar_aggr_op);
|
||||
}
|
||||
|
||||
@ -120,8 +127,8 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_bin_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();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = true;
|
||||
@ -129,7 +136,7 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_bin_distinct)
|
||||
ObCollationType cs_type = CS_TYPE_UTF8MB4_BIN;
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, col_count, is_distinct, is_number, 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(2));
|
||||
ADD_ROW(fake_table, COL(3), COL("t"), COL(3));
|
||||
@ -141,7 +148,8 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_bin_distinct)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(4), COL("ß"), COL("r"), COL(4));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, scalar_aggr_op);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op, col_count, scalar_aggr_op.get_column_count(), cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op,
|
||||
col_count, scalar_aggr_op.get_column_count(), cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, scalar_aggr_op);
|
||||
}
|
||||
|
||||
@ -150,8 +158,8 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_genaral_ci_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();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
int64_t col_count = 3;
|
||||
bool is_distinct = true;
|
||||
@ -159,7 +167,7 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_genaral_ci_distinct)
|
||||
ObCollationType cs_type = CS_TYPE_UTF8MB4_GENERAL_CI;
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, col_count, is_distinct, is_number, 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(2));
|
||||
ADD_ROW(fake_table, COL(3), COL("t"), COL(3));
|
||||
@ -171,7 +179,8 @@ TEST_F(TestScalarAggregateTest, test_utf8mb4_genaral_ci_distinct)
|
||||
ADD_ROW(result_table, COL(0), COL(0), COL(0), COL(3), COL("t"), COL("r"), COL(3));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, scalar_aggr_op);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op, col_count, scalar_aggr_op.get_column_count(), cs_type);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op,
|
||||
col_count, scalar_aggr_op.get_column_count(), cs_type);
|
||||
TestAggregateFactory::close_operator(ctx, scalar_aggr_op);
|
||||
}
|
||||
|
||||
@ -180,12 +189,12 @@ TEST_F(TestScalarAggregateTest, test_aggr_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();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, 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));
|
||||
@ -207,12 +216,12 @@ TEST_F(TestScalarAggregateTest, test_aggr_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();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, 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));
|
||||
@ -234,22 +243,12 @@ TEST_F(TestScalarAggregateTest, test_aggr_empty_set)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
ObFakeTable& result_table = TestAggregateFactory::get_result_table();
|
||||
ObFakeTable &result_table = TestAggregateFactory::get_result_table();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, 3, true);
|
||||
// fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(result_table,
|
||||
COL(null),
|
||||
COL(null),
|
||||
COL(null),
|
||||
COL(0),
|
||||
COL(null),
|
||||
COL(null),
|
||||
COL(0),
|
||||
COL(null),
|
||||
COL(null),
|
||||
COL(0));
|
||||
//fake table: index_col(primary key), aggr_col, groupby_col
|
||||
ADD_ROW(result_table, COL(null), COL(null), COL(null), COL(0), COL(null), COL(null), COL(0), COL(null), COL(null), COL(0));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, scalar_aggr_op);
|
||||
EXCEPT_RESULT(ctx, result_table, scalar_aggr_op, CS_TYPE_UTF8MB4_BIN);
|
||||
@ -261,23 +260,19 @@ TEST_F(TestScalarAggregateTest, test_aggr_bug_6131507)
|
||||
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();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, 3);
|
||||
// fake table: c, b, a(primary key)
|
||||
//fake table: c, b, a(primary key)
|
||||
ADD_ROW(fake_table, COL(null), COL(4), COL(1));
|
||||
ADD_ROW(fake_table, COL(null), COL(3), COL(3));
|
||||
ADD_ROW(fake_table, COL(null), COL(3), COL(4));
|
||||
|
||||
ADD_ROW(result_table,
|
||||
COL(null),
|
||||
COL(4),
|
||||
COL(1),
|
||||
COL(null),
|
||||
COL(3.33333333333333333333333333333333333333333333),
|
||||
COL(2.66666666666666666666666666666666666666666667));
|
||||
ADD_ROW(result_table, COL(null), COL(4), COL(1), COL(null),
|
||||
COL(3.33333333333333333333333333333333333333333333),
|
||||
COL(2.66666666666666666666666666666666666666666667));
|
||||
|
||||
TestAggregateFactory::open_operator(ctx, scalar_aggr_op);
|
||||
EXCEPT_RESULT_WITH_IDX(ctx, result_table, scalar_aggr_op, 0, 3, CS_TYPE_UTF8MB4_BIN);
|
||||
@ -292,7 +287,7 @@ TEST_F(TestScalarAggregateTest, test_invalid_argument)
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx1));
|
||||
ObFakeTable fake_table;
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
const ObNewRow* row = NULL;
|
||||
const ObNewRow *row = NULL;
|
||||
|
||||
ASSERT_EQ(OB_NOT_INIT, scalar_aggr_op.open(ctx));
|
||||
scalar_aggr_op.reset();
|
||||
@ -317,14 +312,14 @@ TEST_F(TestScalarAggregateTest, test_invalid_argument1)
|
||||
int ret = OB_SUCCESS;
|
||||
ObExecContext ctx;
|
||||
ASSERT_EQ(OB_SUCCESS, create_test_session(ctx));
|
||||
const ObNewRow* row = NULL;
|
||||
ObFakeTable& fake_table = TestAggregateFactory::get_fake_table();
|
||||
const ObNewRow *row = NULL;
|
||||
ObFakeTable &fake_table = TestAggregateFactory::get_fake_table();
|
||||
TestScalarAggregate scalar_aggr_op;
|
||||
ObArenaAllocator alloc;
|
||||
ObAggregateExpression col_expr(alloc);
|
||||
|
||||
TestAggregateFactory::init(ctx, scalar_aggr_op, 3, false);
|
||||
// prepare rows, equal in the first row
|
||||
//prepare rows, equal in the first row
|
||||
ADD_ROW(fake_table, COL(1), COL("123"), COL(1));
|
||||
ADD_ROW(fake_table, COL(2), COL("456"), COL(1));
|
||||
|
||||
@ -332,7 +327,7 @@ TEST_F(TestScalarAggregateTest, test_invalid_argument1)
|
||||
ASSERT_EQ(OB_SUCCESS, scalar_aggr_op.open(ctx));
|
||||
ASSERT_EQ(OB_EXCEED_MEM_LIMIT, scalar_aggr_op.get_next_row(ctx, row));
|
||||
scalar_aggr_op.reset();
|
||||
// ASSERT_EQ(OB_NOT_INIT, scalar_aggr_op.add_aggr_column(&col_expr));
|
||||
//ASSERT_EQ(OB_NOT_INIT, scalar_aggr_op.add_aggr_column(&col_expr));
|
||||
}
|
||||
|
||||
TEST_F(TestScalarAggregateTest, test_serialize_and_deserialize)
|
||||
@ -357,11 +352,11 @@ TEST_F(TestScalarAggregateTest, test_serialize_and_deserialize)
|
||||
ASSERT_EQ(0, strcmp(to_cstring(scalar_aggr_op), to_cstring(deserialize_op)));
|
||||
}
|
||||
|
||||
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