patch 4.0
This commit is contained in:
@ -14,30 +14,29 @@
|
||||
#include <iterator>
|
||||
#include <gtest/gtest.h>
|
||||
#include "sql/test_sql_utils.h"
|
||||
#include "common/ob_partition_key.h"
|
||||
#include "lib/container/ob_array.h"
|
||||
#include "sql/ob_sql_init.h"
|
||||
#include "sql/optimizer/test_optimizer_utils.h"
|
||||
#include "sql/code_generator/ob_code_generator_impl.h"
|
||||
#include "sql/plan_cache/ob_cache_object_factory.h"
|
||||
#include "observer/ob_req_time_service.h"
|
||||
namespace test {
|
||||
class TestEngine : public TestOptimizerUtils {
|
||||
namespace test
|
||||
{
|
||||
class TestEngine: public TestOptimizerUtils
|
||||
{
|
||||
public:
|
||||
TestEngine();
|
||||
virtual ~TestEngine();
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
|
||||
private:
|
||||
// disallow copy
|
||||
DISALLOW_COPY_AND_ASSIGN(TestEngine);
|
||||
|
||||
protected:
|
||||
// function members
|
||||
void do_code_generate(const ObLogPlan& log_plan, ObPhysicalPlan& phy_plan);
|
||||
int test_phy_plan(ObPhysicalPlan& plan);
|
||||
|
||||
void do_code_generate(const ObLogPlan &log_plan,
|
||||
ObPhysicalPlan &phy_plan);
|
||||
int test_phy_plan(ObPhysicalPlan &plan);
|
||||
protected:
|
||||
// data members
|
||||
};
|
||||
@ -48,7 +47,8 @@ TestEngine::TestEngine()
|
||||
}
|
||||
|
||||
TestEngine::~TestEngine()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void TestEngine::SetUp()
|
||||
{
|
||||
@ -60,13 +60,14 @@ void TestEngine::TearDown()
|
||||
destroy();
|
||||
}
|
||||
|
||||
void TestEngine::do_code_generate(const ObLogPlan& log_plan, ObPhysicalPlan& phy_plan)
|
||||
void TestEngine::do_code_generate(const ObLogPlan &log_plan,
|
||||
ObPhysicalPlan &phy_plan)
|
||||
{
|
||||
ObCodeGeneratorImpl code_gen(CLUSTER_VERSION_1500);
|
||||
OK(code_gen.generate(log_plan, phy_plan));
|
||||
}
|
||||
|
||||
int TestEngine::test_phy_plan(ObPhysicalPlan& plan)
|
||||
int TestEngine::test_phy_plan(ObPhysicalPlan &plan)
|
||||
{
|
||||
UNUSED(plan);
|
||||
int ret = OB_SUCCESS;
|
||||
@ -81,22 +82,16 @@ TEST_F(TestEngine, basic_test)
|
||||
std::ifstream if_tests(test_file);
|
||||
ASSERT_TRUE(if_tests.is_open());
|
||||
std::string line;
|
||||
ObLogPlan* log_plan = NULL;
|
||||
ObPhysicalPlan* phy_plan = NULL;
|
||||
ObLogPlan *log_plan = NULL;
|
||||
ObPhysicalPlan *phy_plan = NULL;
|
||||
bool is_select = false;
|
||||
|
||||
ObPartitionArray participants;
|
||||
ObPartitionKey key;
|
||||
participants.push_back(key);
|
||||
session_info_.get_trans_desc().set_stmt_participants(participants);
|
||||
|
||||
while (std::getline(if_tests, line)) {
|
||||
// handle query
|
||||
ObResultSet result(session_info_);
|
||||
if (line.size() <= 0)
|
||||
continue;
|
||||
if (line.at(0) == '#')
|
||||
continue;
|
||||
ObArenaAllocator allocator(ObModIds::TEST);
|
||||
ObResultSet result(session_info_, allocator);
|
||||
if (line.size() <= 0) continue;
|
||||
if (line.at(0) == '#') continue;
|
||||
ObString sql = ObString::make_string(line.c_str());
|
||||
ASSERT_NO_FATAL_FAILURE(generate_logical_plan(result, sql, line.c_str(), log_plan, is_select, true));
|
||||
ASSERT_TRUE(NULL != log_plan);
|
||||
@ -108,20 +103,20 @@ TEST_F(TestEngine, basic_test)
|
||||
|
||||
// init exec ctx
|
||||
exec_ctx_.~ObExecContext();
|
||||
new (&exec_ctx_) ObExecContext();
|
||||
new (&exec_ctx_) ObExecContext(allocator);
|
||||
exec_ctx_.init_phy_op(phy_plan->get_phy_operator_size());
|
||||
ObTaskExecutorCtx& task_exec_ctx = exec_ctx_.get_task_exec_ctx();
|
||||
ObExecuteResult& exe_result = task_exec_ctx.get_execute_result();
|
||||
ObTaskExecutorCtx &task_exec_ctx = exec_ctx_.get_task_exec_ctx();
|
||||
ObExecuteResult &exe_result = task_exec_ctx.get_execute_result();
|
||||
task_exec_ctx.set_min_cluster_version(CLUSTER_VERSION_1500);
|
||||
task_exec_ctx.set_partition_location_cache(&part_cache_);
|
||||
task_exec_ctx.set_partition_service(&partition_service_);
|
||||
GCTX.par_ser_ = &partition_service_;
|
||||
task_exec_ctx.set_self_addr(optctx_->get_local_server_addr());
|
||||
common::ObSEArray<ObTablePartitionInfo*, 4> table_partition_info;
|
||||
common::ObSEArray<ObTablePartitionInfo *, 4> table_partition_info;
|
||||
EXPECT_TRUE(OB_SUCCESS == log_plan->get_global_table_partition_info(table_partition_info));
|
||||
task_exec_ctx.set_table_locations(table_partition_info);
|
||||
|
||||
EXPECT_TRUE(OB_SUCCESS == exec_ctx_.create_physical_plan_ctx());
|
||||
exec_ctx_.set_addr(optctx_->get_local_server_addr());
|
||||
GCTX.self_addr_seq_.set_addr(optctx_->get_local_server_addr());
|
||||
exec_ctx_.set_my_session(&session_info_);
|
||||
exec_ctx_.set_sql_ctx(&sql_ctx_);
|
||||
|
||||
@ -130,8 +125,8 @@ TEST_F(TestEngine, basic_test)
|
||||
ASSERT_EQ(OB_SUCCESS, ob_exe.execute_plan(exec_ctx_));
|
||||
ASSERT_EQ(OB_SUCCESS, exe_result.open(exec_ctx_));
|
||||
if (phy_plan->get_stmt_type() == stmt::T_SELECT) {
|
||||
const ObNewRow* tmp_row = NULL;
|
||||
while (OB_SUCCESS == (ret = exe_result.get_next_row(exec_ctx_, tmp_row))) {
|
||||
const ObNewRow *tmp_row = NULL;
|
||||
while(OB_SUCCESS == (ret = exe_result.get_next_row(exec_ctx_, tmp_row))) {
|
||||
SQL_EXE_LOG(INFO, "get a row", K(*tmp_row));
|
||||
}
|
||||
ASSERT_EQ(OB_ITER_END, ret);
|
||||
@ -143,15 +138,15 @@ TEST_F(TestEngine, basic_test)
|
||||
ObCacheObjectFactory::free(phy_plan);
|
||||
}
|
||||
}
|
||||
} // namespace test
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
system("rm -f test_engine.log");
|
||||
observer::ObReqTimeGuard req_timeinfo_guard;
|
||||
OB_LOGGER.set_log_level("INFO");
|
||||
OB_LOGGER.set_file_name("test_engine.log", true);
|
||||
::oceanbase::sql::init_sql_factories();
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::InitGoogleTest(&argc,argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
Reference in New Issue
Block a user