patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -18,191 +18,178 @@
using namespace oceanbase::common;
using namespace oceanbase::sql;
class ObExprCoalesceTest : public ::testing::Test {
class ObExprCoalesceTest : public ::testing::Test
{
public:
ObExprCoalesceTest();
virtual ~ObExprCoalesceTest();
virtual void SetUp();
virtual void TearDown();
private:
// disallow copy
ObExprCoalesceTest(const ObExprCoalesceTest& other);
ObExprCoalesceTest& operator=(const ObExprCoalesceTest& other);
ObExprCoalesceTest(const ObExprCoalesceTest &other);
ObExprCoalesceTest& operator=(const ObExprCoalesceTest &other);
private:
// data members
};
ObExprCoalesceTest::ObExprCoalesceTest()
{}
{
}
ObExprCoalesceTest::~ObExprCoalesceTest()
{}
{
}
void ObExprCoalesceTest::SetUp()
{}
{
}
void ObExprCoalesceTest::TearDown()
{}
{
}
#define MAKE_OBJS_1(t1, v1) \
ObObj objs[1]; \
ObExprResType types[1]; \
objs[0].set_##t1(v1); \
types[0].set_##t1();
#define MAKE_OBJS_1(t1,v1) \
ObObj objs[1]; \
ObExprResType types[1]; \
objs[0].set_##t1(v1); \
types[0].set_##t1();
#define MAKE_OBJS_2(t1, v1, t2, v2) \
ObObj objs[2]; \
ObExprResType types[2]; \
objs[0].set_##t1(v1); \
objs[1].set_##t2(v2); \
types[0].set_##t1(); \
types[1].set_##t2();
#define MAKE_OBJS_2(t1,v1,t2,v2) \
ObObj objs[2]; \
ObExprResType types[2]; \
objs[0].set_##t1(v1); objs[1].set_##t2(v2); \
types[0].set_##t1(); types[1].set_##t2();
#define MAKE_OBJS_3(t1, v1, t2, v2, t3, v3) \
ObObj objs[3]; \
ObExprResType types[3]; \
objs[0].set_##t1(v1); \
objs[1].set_##t2(v2); \
objs[2].set_##t3(v3); \
types[0].set_##t1(); \
types[1].set_##t2(); \
types[2].set_##t3();
#define MAKE_OBJS_3(t1,v1,t2,v2,t3,v3) \
ObObj objs[3]; \
ObExprResType types[3]; \
objs[0].set_##t1(v1); objs[1].set_##t2(v2); objs[2].set_##t3(v3); \
types[0].set_##t1(); types[1].set_##t2(); types[2].set_##t3();
#define MAKE_OBJS_4(t1, v1, t2, v2, t3, v3, t4, v4) \
ObObj objs[4]; \
ObExprResType types[4]; \
objs[0].set_##t1(v1); \
objs[1].set_##t2(v2); \
objs[2].set_##t3(v3); \
objs[3].set_##t4(v4); \
types[0].set_##t1(); \
types[1].set_##t2(); \
types[2].set_##t3(); \
types[3].set_##t4();
#define MAKE_OBJS_4(t1,v1,t2,v2,t3,v3,t4,v4) \
ObObj objs[4]; \
ObExprResType types[4]; \
objs[0].set_##t1(v1); objs[1].set_##t2(v2); objs[2].set_##t3(v3); objs[3].set_##t4(v4); \
types[0].set_##t1(); types[1].set_##t2(); types[2].set_##t3(); types[3].set_##t4();
#define MAKE_OBJS_5(t1, v1, t2, v2, t3, v3, t4, v4, t5, v5) \
ObObj objs[5]; \
ObExprResType types[5]; \
objs[0].set_##t1(v1); \
objs[1].set_##t2(v2); \
objs[2].set_##t3(v3); \
objs[3].set_##t4(v4); \
objs[4].set_##t5(v5); \
types[0].set_##t1(); \
types[1].set_##t2(); \
types[2].set_##t3(); \
types[3].set_##t4(); \
types[4].set_##t5();
#define MAKE_OBJS_5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
ObObj objs[5]; \
ObExprResType types[5]; \
objs[0].set_##t1(v1); objs[1].set_##t2(v2); objs[2].set_##t3(v3); objs[3].set_##t4(v4); objs[4].set_##t5(v5); \
types[0].set_##t1(); types[1].set_##t2(); types[2].set_##t3(); types[3].set_##t4(); types[4].set_##t5();
#define CHECK_FUNC(obj, func, r, N) \
ObExprResType type; \
ObExprTypeCtx ctx; \
int err = obj.calc_result_typeN(type, types, N, ctx); \
EXPECT_TRUE(OB_SUCCESS == err); \
_OB_LOG(INFO, "err=%d type=%s", err, to_cstring(type)); \
obj.set_result_type(type); \
err = obj.calc_resultN(r, objs, N, &buf); \
_OB_LOG(INFO, "r=%s ref=%s", to_cstring(r), to_cstring(ref)); \
EXPECT_TRUE(OB_SUCCESS == err); \
EXPECT_TRUE(ref.get_type() == r.get_type()); \
if (ref.get_type() != ObNullType) { \
ObExprEqual eq; \
ObObj result; \
EXPECT_TRUE(OB_SUCCESS == ObExprEqual::calc(result, r, ref)); \
EXPECT_TRUE(result.get_type() == ObBoolType && result.get_bool() == true); \
}
#define CHECK_FUNC_FAIL(obj, func, r, N) \
ObExprResType type; \
ObExprTypeCtx ctx; \
int err = obj.calc_result_typeN(type, types, N, ctx); \
_OB_LOG(INFO, "err=%d type=%s", err, to_cstring(type)); \
obj.set_result_type(type); \
err = obj.calc_resultN(r, objs, N, &buf); \
#define CHECK_FUNC(obj, func, r, N) \
ObExprResType type; \
ObExprTypeCtx ctx; \
int err = obj.calc_result_typeN(type, types, N, ctx); \
EXPECT_TRUE(OB_SUCCESS == err); \
_OB_LOG(INFO, "err=%d type=%s", err, to_cstring(type)); \
obj.set_result_type(type); \
err = obj.calc_resultN(r,objs, N, &buf); \
_OB_LOG(INFO, "r=%s ref=%s", to_cstring(r), to_cstring(ref)); \
EXPECT_TRUE(OB_SUCCESS == err); \
EXPECT_TRUE(ref.get_type() == r.get_type()); \
if (ref.get_type() != ObNullType){\
ObExprEqual eq; \
ObObj result; \
EXPECT_TRUE(OB_SUCCESS == ObExprEqual::calc(result, r, ref)); \
EXPECT_TRUE(result.get_type() == ObBoolType && result.get_bool() == true); \
}
#define CHECK_FUNC_FAIL(obj, func, r, N) \
ObExprResType type; \
ObExprTypeCtx ctx; \
int err = obj.calc_result_typeN(type, types, N, ctx); \
_OB_LOG(INFO, "err=%d type=%s", err, to_cstring(type)); \
obj.set_result_type(type); \
err = obj.calc_resultN(r, objs, N, &buf); \
_OB_LOG(INFO, "r=%s ref=%s", to_cstring(r), to_cstring(ref)); \
EXPECT_TRUE(OB_SUCCESS != err);
#define T_1(obj, func, t1, v1, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_1(t1, v1) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj, func, r, 1) \
} \
while (0)
#define T_2(obj, func, t1, v1, t2, v2, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_2(t1, v1, t2, v2) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj, func, r, 2) \
} \
while (0)
#define F_2(obj, func, t1, v1, t2, v2, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_2(t1, v1, t2, v2) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC_FAIL(obj, func, r, 2) \
} \
while (0)
#define T_1(obj,func, t1, v1, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_1(t1,v1) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj,func, r, 1) \
}while(0)
#define T_3(obj, func, t1, v1, t2, v2, t3, v3, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_3(t1, v1, t2, v2, t3, v3) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj, func, r, 3) \
} \
while (0)
#define F_3(obj, func, t1, v1, t2, v2, t3, v3, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_3(t1, v1, t2, v2, t3, v3) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC_FAIL(obj, func, r, 3) \
} \
while (0)
#define T_2(obj,func, t1, v1, t2, v2, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_2(t1,v1,t2,v2) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj,func, r, 2) \
}while(0)
#define F_2(obj,func, t1, v1, t2, v2, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_2(t1,v1,t2,v2) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC_FAIL(obj,func, r, 2) \
}while(0)
#define T_3(obj,func, t1, v1, t2, v2, t3, v3, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_3(t1,v1,t2,v2,t3,v3) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj,func, r, 3) \
}while(0)
#define F_3(obj,func, t1, v1, t2, v2, t3, v3, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_3(t1,v1,t2,v2,t3,v3) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC_FAIL(obj,func, r, 3) \
}while(0)
#define T_4(obj, func, t1, v1, t2, v2, t3, v3, t4,v4,ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_4(t1,v1,t2,v2,t3,v3,t4,v4) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj, func, r, 4) \
}while(0)
#define F_4(obj,func, t1, v1, t2, v2, t3, v3,t4,v4, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_4(t1,v1,t2,v2,t3,v3,t4,v4) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC_FAIL(obj,func, r, 4) \
}while(0)
#define T_4(obj, func, t1, v1, t2, v2, t3, v3, t4, v4, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_4(t1, v1, t2, v2, t3, v3, t4, v4) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj, func, r, 4) \
} \
while (0)
#define F_4(obj, func, t1, v1, t2, v2, t3, v3, t4, v4, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_4(t1, v1, t2, v2, t3, v3, t4, v4) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC_FAIL(obj, func, r, 4) \
} \
while (0)
#define T_5(obj, func, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_5(t1, v1, t2, v2, t3, v3, t4, v4, t5, v5) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj, func, r, 5) \
} \
while (0)
{ \
ObObj r, ref; \
MAKE_OBJS_5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC(obj,func, r, 5) \
}while(0)
#define F_5(obj,func, t1, v1, t2, v2, t3, v3,t4,v4 ,t5,v5, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_5(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC_FAIL(obj,func, r, 5) \
}while(0)
#define F_5(obj, func, t1, v1, t2, v2, t3, v3, t4, v4, t5, v5, ref_type, ref_value) \
{ \
ObObj r, ref; \
MAKE_OBJS_5(t1, v1, t2, v2, t3, v3, t4, v4, t5, v5) \
ref.set_##ref_type(ref_value); \
CHECK_FUNC_FAIL(obj, func, r, 5) \
} \
while (0)
TEST_F(ObExprCoalesceTest, basic_test)
{
@ -210,6 +197,7 @@ TEST_F(ObExprCoalesceTest, basic_test)
ObExprStringBuf buf;
ASSERT_EQ(ObExprOperator::MORE_THAN_ZERO, coalesce_op.get_param_num());
T_1(coalesce_op, calc_resultN, null, 0, null, 0);
T_1(coalesce_op, calc_resultN, int, 10, int, 10);
T_1(coalesce_op, calc_resultN, float, 10, float, 10);
@ -222,18 +210,18 @@ TEST_F(ObExprCoalesceTest, basic_test)
T_2(coalesce_op, calc_resultN, null, 0, bool, false, bool, false);
T_2(coalesce_op, calc_resultN, bool, true, bool, false, bool, true);
// T_2(coalesce_op, calc_resultN, float, 10.0, null, 0, float, 10.0);
// T_2(coalesce_op, calc_resultN, null, 0, float, 10.0, float, 10.0);
// T_2(coalesce_op, calc_resultN, int, 12, float, 10.0, float, 12.0);
// T_2(coalesce_op, calc_resultN, int, 12, double, 10.0, double, 12.0);
// T_2(coalesce_op, calc_resultN, int, 12, int, 10, int, 12);
// T_2(coalesce_op, calc_resultN, double, 12, double, 10.0, double, 12.0);
// T_2(coalesce_op, calc_resultN, float, 12, double, 10.0, double, 12.0);
T_2(coalesce_op, calc_resultN, mtime, 1000, precise_datetime, 10002, precise_datetime, 1000);
//T_2(coalesce_op, calc_resultN, float, 10.0, null, 0, float, 10.0);
//T_2(coalesce_op, calc_resultN, null, 0, float, 10.0, float, 10.0);
//T_2(coalesce_op, calc_resultN, int, 12, float, 10.0, float, 12.0);
//T_2(coalesce_op, calc_resultN, int, 12, double, 10.0, double, 12.0);
//T_2(coalesce_op, calc_resultN, int, 12, int, 10, int, 12);
//T_2(coalesce_op, calc_resultN, double, 12, double, 10.0, double, 12.0);
//T_2(coalesce_op, calc_resultN, float, 12, double, 10.0, double, 12.0);
T_2(coalesce_op, calc_resultN, mtime,1000, precise_datetime, 10002, precise_datetime, 1000);
T_5(coalesce_op, calc_resultN, bool, true, bool, false, bool, true, bool, false, bool, false, bool, true);
T_5(coalesce_op, calc_resultN, int, 10, int, 20, int, 0, int, -20, int, -20, int, 10);
// T_5(coalesce_op, calc_resultN, int, 10, int, 20, float, 0, int, -20, int, -20, float, 10);
// T_5(coalesce_op, calc_resultN, int, 10, int, 20, float, 0, int, -20, double, -20, double, 10);
//T_5(coalesce_op, calc_resultN, int, 10, int, 20, float, 0, int, -20, int, -20, float, 10);
//T_5(coalesce_op, calc_resultN, int, 10, int, 20, float, 0, int, -20, double, -20, double, 10);
}
TEST_F(ObExprCoalesceTest, fail_test)
@ -242,26 +230,19 @@ TEST_F(ObExprCoalesceTest, fail_test)
ObExprStringBuf buf;
// not support datetime type anymore
// F_1(coalesce_op, calc_resultN, datetime,1000, datetime, 1000);
F_2(coalesce_op, calc_resultN, varchar, "2012-11-12", precise_datetime, 10002, varchar, "2012-11-12");
F_3(coalesce_op, calc_resultN, null, 0, varchar, "2012-11-12", precise_datetime, 10002, varchar, "2012-11-12");
F_3(coalesce_op,
calc_resultN,
null,
0,
precise_datetime,
10002,
varchar,
"xyz",
varchar,
"1970-01-01 08:00:00.010002");
//F_1(coalesce_op, calc_resultN, datetime,1000, datetime, 1000);
F_2(coalesce_op, calc_resultN, varchar,"2012-11-12", precise_datetime, 10002, varchar, "2012-11-12");
F_3(coalesce_op, calc_resultN, null, 0, varchar,"2012-11-12", precise_datetime, 10002, varchar, "2012-11-12");
F_3(coalesce_op, calc_resultN, null, 0, precise_datetime, 10002, varchar, "xyz", varchar, "1970-01-01 08:00:00.010002");
F_3(coalesce_op, calc_resultN, null, 0, varchar, "xyz", precise_datetime, 10002, varchar, "xyz");
F_4(coalesce_op, calc_resultN, null, 0, bool, true, varchar, "xyz", precise_datetime, 10002, varchar, "true");
}
int main(int argc, char** argv)
int main(int argc, char **argv)
{
oceanbase::common::ObLogger::get_logger().set_log_level("DEBUG");
::testing::InitGoogleTest(&argc, argv);
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}