init push

This commit is contained in:
oceanbase-admin
2021-05-31 22:56:52 +08:00
commit cea7de1475
7020 changed files with 5689869 additions and 0 deletions

View File

@ -0,0 +1,3 @@
sql_unittest(test_expr_generator)
sql_unittest(test_code_generator)
sql_unittest(test_static_engine_cg)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,311 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include <iterator>
#include <gtest/gtest.h>
#define private public
#define protected public
#include "sql/test_sql_utils.h"
#include "lib/container/ob_array.h"
#include "sql/code_generator/ob_code_generator.h"
#include "sql/ob_sql_init.h"
#include "sql/engine/dml/ob_table_insert.h"
#include "sql/optimizer/test_optimizer_utils.h"
#include "sql/plan_cache/ob_cache_object_factory.h"
#include "sql/engine/ob_phy_operator.h"
#include "sql/engine/ob_double_children_phy_operator.h"
#include "sql/engine/ob_multi_children_phy_operator.h"
#include "observer/ob_req_time_service.h"
#undef private
#undef protected
using namespace oceanbase::common;
namespace test {
class MockVisitor : public ObPhyOperatorVisitor {
public:
MockVisitor() : level_(0)
{}
~MockVisitor()
{}
virtual int pre_visit(const ObSingleChildPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObSingleChildPhyOperator& op)
{
level_--;
const_cast<ObSingleChildPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
virtual int pre_visit(const ObDoubleChildrenPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObDoubleChildrenPhyOperator& op)
{
level_--;
const_cast<ObDoubleChildrenPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
virtual int pre_visit(const ObMultiChildrenPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObMultiChildrenPhyOperator& op)
{
level_--;
const_cast<ObMultiChildrenPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
virtual int pre_visit(const ObNoChildrenPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObNoChildrenPhyOperator& op)
{
level_--;
const_cast<ObNoChildrenPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
virtual int pre_visit(const ObPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObPhyOperator& op)
{
level_--;
const_cast<ObPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
private:
int level_;
};
class TestCodeGenerator : public TestOptimizerUtils {
public:
TestCodeGenerator();
virtual ~TestCodeGenerator();
virtual void SetUp();
virtual void TearDown();
private:
// disallow copy
DISALLOW_COPY_AND_ASSIGN(TestCodeGenerator);
protected:
// function members
void do_optimize(ObStmt& stmt, ObLogPlan*& plan, ObPhyPlanType distr_method);
void do_code_generate(const ObLogPlan& log_plan, ObCodeGenerator& code_gen, ObPhysicalPlan& phy_plan);
int do_rewrite(ObStmt*& stmt, ObPhysicalPlan* phy_plan);
protected:
// data members
oceanbase::share::ObLocationFetcher fetcher_;
ParamStore params_;
ObAddr addr_;
ObOptimizerContext* optimizer_ctx_;
ObTransformerCtx* transformer_ctx_;
ObSchemaChecker schema_checker_;
ObQueryHint query_hint_;
};
TestCodeGenerator::TestCodeGenerator() : fetcher_(), optimizer_ctx_(NULL), transformer_ctx_(NULL)
{
memcpy(schema_file_path_, "./test_code_generator.schema", sizeof("./test_code_generator.schema"));
}
TestCodeGenerator::~TestCodeGenerator()
{}
void TestCodeGenerator::SetUp()
{
TestOptimizerUtils::SetUp();
schema_checker_.init(sql_schema_guard_);
ObArenaAllocator tmp_alloc;
params_.block_alloc_ = ObWrapperAllocator(tmp_alloc);
exec_ctx_.get_sql_ctx()->session_info_ = &session_info_;
optimizer_ctx_ = new ObOptimizerContext(&session_info_,
&exec_ctx_,
// schema_mgr_,
&sql_schema_guard_,
&stat_manager_,
NULL,
&partition_service_,
allocator_,
&part_cache_,
&params_,
addr_,
NULL,
OB_MERGED_VERSION_INIT,
query_hint_,
expr_factory_,
NULL);
ASSERT_TRUE(optimizer_ctx_);
transformer_ctx_ = new ObTransformerCtx();
ASSERT_TRUE(transformer_ctx_);
transformer_ctx_->allocator_ = &allocator_;
transformer_ctx_->session_info_ = &session_info_;
transformer_ctx_->schema_checker_ = &schema_checker_;
transformer_ctx_->expr_factory_ = &expr_factory_;
transformer_ctx_->stmt_factory_ = &stmt_factory_;
transformer_ctx_->exec_ctx_ = &exec_ctx_;
transformer_ctx_->partition_location_cache_ = &part_cache_;
transformer_ctx_->stat_mgr_ = &stat_manager_;
transformer_ctx_->partition_service_ = &partition_service_;
transformer_ctx_->sql_schema_guard_ = &sql_schema_guard_;
transformer_ctx_->self_addr_ = &addr_;
}
void TestCodeGenerator::TearDown()
{
// destroy
destroy();
if (NULL != optimizer_ctx_) {
delete optimizer_ctx_;
optimizer_ctx_ = NULL;
}
if (NULL != transformer_ctx_) {
delete transformer_ctx_;
transformer_ctx_ = NULL;
}
}
int TestCodeGenerator::do_rewrite(ObStmt*& stmt, ObPhysicalPlan* phy_plan)
{
int ret = OB_SUCCESS;
transformer_ctx_->phy_plan_ = phy_plan;
ObTransformerImpl trans(transformer_ctx_);
if (stmt->is_select_stmt()) {
ObDMLStmt* dml_stmt = static_cast<ObDMLStmt*>(stmt);
if (OB_FAIL(trans.transform(dml_stmt))) {
_OB_LOG(WARN, "fail to transform stmt, ret = %d", ret);
} else {
stmt = dml_stmt;
}
}
return ret;
}
void TestCodeGenerator::do_optimize(ObStmt& stmt, ObLogPlan*& plan, ObPhyPlanType distr)
{
ParamStore& params_i = *(&params_);
int64_t count = params_i.count();
UNUSED(count);
ObTableLocation table_location;
OK(optimizer_ctx_->get_table_location_list().push_back(table_location));
if (distr == OB_PHY_PLAN_REMOTE) {
SQL_CG_LOG(DEBUG, "setting local address to 2.2.2.2");
optimizer_ctx_->set_local_server_ipv4_addr("2.2.2.2", 8888);
} else {
SQL_CG_LOG(DEBUG, "setting local address to 1.1.1.1");
optimizer_ctx_->set_local_server_ipv4_addr("1.1.1.1", 8888);
}
ObQueryHint query_hint = dynamic_cast<ObDMLStmt&>(stmt).get_stmt_hint().get_query_hint();
optimizer_ctx_->set_query_hint(query_hint);
optimizer_ctx_->set_root_stmt(dynamic_cast<ObDMLStmt*>(&stmt));
ObOptimizer optimizer(*optimizer_ctx_);
OK(optimizer.optimize(dynamic_cast<ObDMLStmt&>(stmt), plan));
char buf[1024];
plan->to_string(buf, 1024);
_OB_LOG(INFO, "logical_plan=%s", buf);
}
void TestCodeGenerator::do_code_generate(const ObLogPlan& log_plan, ObCodeGenerator& code_gen, ObPhysicalPlan& phy_plan)
{
OK(code_gen.generate(log_plan, phy_plan));
}
TEST_F(TestCodeGenerator, basic_test)
{
const char* test_file = "./test_code_generator.test";
const char* result_file = "./test_code_generator.result";
const char* tmp_file = "./test_code_generator.tmp";
// run tests
std::ifstream if_tests(test_file);
ASSERT_TRUE(if_tests.is_open());
std::ofstream of_result(tmp_file);
ASSERT_TRUE(of_result.is_open());
std::string line;
ObStmt* stmt = NULL;
ObLogPlan* logical_plan = NULL;
ObPhysicalPlan* phy_plan = NULL;
int64_t line_no = 1;
while (std::getline(if_tests, line)) {
if (line.size() <= 0)
continue;
if (line.at(0) == '#')
continue;
_OB_LOG(DEBUG, "================================================================");
of_result << "[" << line_no++ << "] ";
of_result << line << std::endl;
bool is_print = true;
params_.reset();
OB_LOG(INFO, "case:", K(line.c_str()));
ObPhysicalPlanCtx* pctx = exec_ctx_.get_physical_plan_ctx();
ASSERT_TRUE(NULL != pctx);
ObCodeGenerator code_gen(
false /*use_jit*/, false /*use static typing engine*/, CLUSTER_VERSION_3000, &(pctx->get_datum_param_store()));
ObCacheObjectFactory::alloc(phy_plan);
ASSERT_TRUE(NULL != (phy_plan));
ASSERT_NO_FATAL_FAILURE(do_resolve(line.c_str(), stmt, is_print, JSON_FORMAT, OB_SUCCESS, false));
ASSERT_EQ(OB_SUCCESS, do_rewrite(stmt, phy_plan));
ASSERT_NO_FATAL_FAILURE(do_optimize(*stmt, logical_plan, OB_PHY_PLAN_REMOTE));
ASSERT_NO_FATAL_FAILURE(do_code_generate(*logical_plan, code_gen, *phy_plan));
of_result << CSJ(*phy_plan) << std::endl;
ObPhyOperator* main_query = phy_plan->get_main_query();
ASSERT_TRUE(NULL != main_query);
MockVisitor visitor;
ASSERT_EQ(OB_SUCCESS, main_query->accept(visitor));
//@todo ObPhysicalPlan::free(phy_plan);
phy_plan = NULL;
stmt_factory_.destory();
expr_factory_.destory();
}
of_result.close();
// verify results
UNUSED(result_file);
// ASSERT_NO_FATAL_FAILURE(TestSqlUtils::is_equal_content(tmp_file, result_file));
}
} // namespace test
int main(int argc, char** argv)
{
system("rm -rf test_code_generator.log");
observer::ObReqTimeGuard req_timeinfo_guard;
OB_LOGGER.set_log_level("DEBUG");
OB_LOGGER.set_file_name("test_code_generator.log", true);
::oceanbase::sql::init_sql_factories();
::testing::InitGoogleTest(&argc, argv);
test::parse_cmd_line_param(argc, argv, test::clp);
return RUN_ALL_TESTS();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
create database information_schema;
create database mysql;
create database rongxuan;
use rongxuan;
CREATE TABLE T1(C1 DECIMAL PRIMARY KEY, C2 DECIMAL, C3 DECIMAL);
CREATE TABLE T2(C1 INT PRIMARY KEY, C2 INT, C3 VARCHAR(32))
CREATE TABLE TEST(A SMALLINT NOT NULL PRIMARY KEY, B CHAR(10));
CREATE TABLE tt (pk bigint, col_char_12_key char(12), col_bigint bigint, col_char_12 char(12), col_bigint_key bigint, primary key (pk), key idx1(col_bigint_key )) ;
CREATE TABLE t3 (a timestamp, b int, c int primary key);
CREATE TABLE yu1(c1 char(20), c2 bigint, pk bigint primary key);
CREATE TABLE yu2(c1 char(20), pk bigint primary key, c2 char(20)) partition by key();
create table yu3 (id int primary key);
create table yu4(id int primary key, binaryvalue varbinary(255));
create table tt1(c1 int primary key auto_increment, c2 int, c3 int)
create table t5(c1 int primary key, c2 int, c3 int, unique key(c2) storing (c4), c4 int);
create table t0(pk int primary key, c1 int, c2 int, a3 int);
create table t7(c1 int primary key, c2 int);
create table t8(c1 int primary key, c2 int);
create table t9(c1 int primary key, c2 int not null default 1, c3 int default 2);
create table insert_distributed(c1 int, c2 int, primary key(c1, c2)) partition by hash(c2) partitions 5;

View File

@ -0,0 +1,139 @@
select c1, c1+c2 from t1 where c1 > 100 limit 1, 10
select c1, c1+c2 from t1 where c3 > 100 order by c2, c1
select c1, sum(c1+c2) from t1 where c3 > 100 group by c2, c1
insert into t1 values (1, 2, 3), (4, 5, 6);
delete from t1 where c1 > 5
select * from t1,t2 where t1.c1+1= t2.c1
select t1.c1, t2.c2, t2.c3 from t1,t2 where t1.c1 > t2.c1 + t2.c2
update t1 vt1 set c2=c1+1 where c1 > 1 order by c1 desc limit 0, 10
UPDATE oceanbase.__all_root_table SET sql_port = 51997, zone = 'test', partition_cnt = 1, role = 0, row_count = 0, data_size = 0, data_version = 1, data_checksum = 0, row_checksum = 0, column_checksum = '' WHERE tenant_id = 1 AND table_id = 2 AND partition_id = 0 AND svr_ip = '10.232.36.175' AND svr_port = 51951;
select distinct c2, c1+c2 from t1;
select * from t1 union select * from t2;
select * from t1 union all select * from t2;
select * from t1 except select * from t2;
select * from t1 intersect select * from t2;
select /*+ frozen_version(10) */ * from t1;
#select * from t1 order by c1 desc;
select * from t1 where exists(select c1 from t2 limit 0);
select * from t1 where c1>(select c1 from t2 limit 1);
select * from (select c1, c2 from t1 limit 1) t;
select max(a) from test where a < (select max(a) from test);
select * from test where b = trim(' abc ') and b = trim(' xyz ');
(select a, b, c+1 from t3) union (select a, b, c+1 from t3);
insert into t1 values(1,2,3),(2,3,4) on duplicate key update c2=values(c1) + values(c2);
insert into tt1 values(),();
insert into tt1() values(),();
select (select 1, 2, 3)=ROW(1, 2, 3);
select (select 1)=ANY(select 1);
(select * from yu1) union all (select * from yu2);
select yu3.id, (select yu4.binaryvalue from yu4 where yu4.id=yu3.id) as value from yu3;
select (case c1 when 1 then 2 else 2 end) d from t1 order by d;
select c1, c1 from t1 union select c1, c2 from t1;
select c1, c1 from t1 union all select c1, c2 from t1;
select c2, c2 as c from t1 union select c2, c2 from t1;
select c1 from t1 having (select count(t1.c1) from t2)>0;
select c1 from t1 where (select count(t1.c1) from t2)>0;
select c1 as cc from t1 order by (select cc from t2);
select c1 from t1 where c1 > (select c1 from t2 where t2.c1 >t1.c1 and t2.c2 >t1.c2);
select c1 from t1 where (select c1 from t2) > 1 and 1< (select 1);
select c3 from t5 where c2 > 10;
select c3,c4 from t5 where c2 > 10;
######################### test for hierarchical query ###################################
### single table ###
# same output #
#select prior c2, c1 from t0 start with c1 = 1 connect by prior c1 = c2;
#select prior c2, c2 from t0 connect by prior (c1 + 1) = (c1 + 1);
#select prior (c2 + 1), (c2 + 1) from t0 connect by prior c1 = c1;
#select prior 1 from t0 where prior (c2 + 1) = (c2 + 1) connect by prior c1 = c1;
#
## overlap output #
#select prior pk from t0 where c1 = 0 start with c1 = 1 connect by prior c1 = c2;
#
## different output #
#select prior a3, pk from t0 start with c1 = 1 connect by prior c1 = c2;
#
## complex output #
#select c1 + c2 from t0 where prior c2 = c1 connect by prior c1 = c2;
#select prior(c1 + c2) from t0 where prior c2 = c1 connect by prior c1 = c2;
#select abs(a3) + a3 from t0 where prior c2 = c1 connect by prior c1 = c2;
#select prior (abs(a3) + a3) from t0 where prior c2 = c1 connect by prior c1 = c2;
#
#select c1 + c2 from t0 where prior c2 < c1 connect by prior c1 > c2;
#select prior(c1 + c2) from t0 where prior c2 < c1 connect by prior c1 > c2;
#select prior(c1 + c2), (c1 + c2) from t0 where prior c2 < c1 connect by prior c1 > c2;
#select abs(a3) + a3 from t0 where prior c2 < c1 connect by prior c1 > c2;
#select prior (abs(a3) + a3) from t0 where prior c2 < c1 connect by prior c1 > c2;
#
#### multi table ###
#
## same output #
#select prior t9.c3, t0.pk from t0 join t9 connect by prior t0.pk = t9.c3;
#select prior t0.a3, t0.pk from t0 join t9 connect by prior t0.pk = t0.a3;
#
## overlap output #
#select prior t9.c3, t0.pk, prior t0.c2 from t0 join t9 where t9.c1 > 1 connect by prior t0.pk = t9.c3;
#select t9.c1 from t0 join t9 where prior t9.c3 + t0.pk + prior t0.c2 connect by prior t0.pk = t9.c3;
#
## different output #
#select prior t0.c1, t9.c2 from t0 join t9 connect by prior t0.pk = t9.c3;
#select prior t0.c1 from t0 join t9 where t9.c2 > 1 connect by prior t0.pk = t9.c3;
#select t0.c1, prior t9.c2 from t0 join t9 connect by prior t0.pk = t9.c3;
#select t0.c1 from t0 join t9 where prior t9.c2 > 1 connect by prior t0.pk = t9.c3;
#
## complex output #
#select prior (t0.c1 + t0.c2) from t0 join t9 where t0.pk > prior t9.c3 connect by prior t0.pk = t9.c3;
#select prior (t0.c1 + t9.c2) from t0 join t9 where t0.pk > prior t9.c3 connect by prior t0.pk = t9.c3;
#select t0.c1 + t0.c2 from t0 join t9 where t0.pk > prior t9.c3 connect by prior t0.pk = t9.c3;
#select t0.c1 + t9.c2 from t0 join t9 where t0.pk > prior t9.c3 connect by prior t0.pk = t9.c3;
#
#### test for pseudo column ###
### bug select 1 from t0 connect by prior 1 = 1;
### bug select level from t0 connect by prior 1 = 1;
#select level, c1 from t0 connect by prior 1 = 1;
#select level from t0 connect by prior c1 = c2;
#
##select level + 1 from t0 connect by prior 1 = 1;
#select max(level) - 1 , c1 from t0 connect by prior 1 = 1;
#select level from t0 where level > 1 connect by prior c1 = c2;
#
#select level, t0.c1 from t0 join t9 connect by prior 1 = 1;
#select level from t0 join t9 connect by prior t0.c1 = t0.c2;
#select t0.c1 from t0 join t9 where level > 1 connect by prior t0.c1 = t0.c2;
#select max(level + t0.c1) from t0 join t9 connect by prior t0.c1 = t0.c2;
#select max(level-1) from t0 join t9 where level > 1 connect by prior t0.c1 = t0.c2;
#
#
## test different where condition #
#select c1 from t0 where level connect by prior c1 = c2;
#select c1 from t0 where level > 1 and level < 2 connect by prior c1 = c2;
#select c1 from t0 where level > 1 or level < 2 connect by prior c1 = c2;
#select c1 from t0 where level > 1 or level < 2 and level < 2*level connect by prior c1 = c2;
#select c1 from t0 where level > level * c2 or level < c1 connect by prior c1 = c2;
#
## test same output #
#select c1 from t0 where level + 1 connect by prior c1 = c2;
#select c1 from t0 where level + c1 > 1 connect by prior c1 = c2;
#select max(c1 + level) from t0 where level + c1 > 1 connect by prior c1 = c2;
#select max(c1 + level +abs(level)) from t0 where level + c1 > 1 connect by prior c1 = c2;
#select level + 1 from t0 where level + c1 > 1 connect by prior c1 = c2;
#
#select c1 from t0 where connect_by_isleaf + 1 connect by prior c1 = c2;
#select c1 from t0 where connect_by_isleaf + c1 > 1 connect by prior c1 = c2;
#select max(c1 + connect_by_isleaf) from t0 where connect_by_isleaf + c1 > 1 connect by prior c1 = c2;
#select max(c1 + connect_by_isleaf +abs(connect_by_isleaf)) from t0 where connect_by_isleaf + c1 > 1 connect by prior c1 = c2;
#select connect_by_isleaf + 1 from t0 where connect_by_isleaf + c1 > 1 connect by prior c1 = c2;
#
#select c1 from t0 where connect_by_iscycle + 1 connect by nocycle prior c1 = c2;
#select c1 from t0 where connect_by_iscycle + c1 > 1 connect by nocycle prior c1 = c2;
#select max(c1 + connect_by_iscycle) from t0 where connect_by_iscycle + c1 > 1 connect by nocycle prior c1 = c2;
#select max(c1 + connect_by_iscycle +abs(connect_by_iscycle)) from t0 where connect_by_iscycle + c1 > 1 connect by nocycle prior c1 = c2;
#select connect_by_iscycle + 1 from t0 where connect_by_iscycle + c1 > 1 connect by nocycle prior c1 = c2;
#
#select 1 from t0 connect by prior 1 = 1;
#select 1 from t0 join t7 on 1 = 1 connect by prior 1 = 1;
#select 1 from t0 left join t7 on 1 = 1 connect by prior 1 = 1;
#
## test for connect by prior expr #
#select 1 from t0 connect by prior (c1 + c2) = c2;
#select 1 from t0 connect by prior (abs(c1)) = c2;

View File

@ -0,0 +1,135 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include <gtest/gtest.h>
#include "sql/test_sql_utils.h"
#include "lib/utility/ob_test_util.h"
#include "sql/code_generator/ob_expr_generator_impl.h"
#include "sql/code_generator/ob_column_index_provider.h"
#include "sql/resolver/expr/ob_raw_expr_util.h"
#include "sql/code_generator/ob_code_generator_impl.h"
#include "sql/code_generator/ob_expr_generator_impl.h"
#include "sql/engine/ob_physical_plan.h"
#include "sql/ob_sql_init.h"
#include "lib/json/ob_json_print_utils.h"
#include <fstream>
#include <iterator>
using namespace oceanbase::common;
using namespace oceanbase::sql;
class TestExprGenerator : public ::testing::Test {
public:
TestExprGenerator();
virtual ~TestExprGenerator();
virtual void SetUp();
virtual void TearDown();
private:
// disallow copy
DISALLOW_COPY_AND_ASSIGN(TestExprGenerator);
protected:
// function members
void generate_expr(const char* expr_str, const char*& post_expr);
protected:
// data members
ObPhysicalPlan phy_plan_;
};
TestExprGenerator::TestExprGenerator()
{}
TestExprGenerator::~TestExprGenerator()
{}
void TestExprGenerator::SetUp()
{}
void TestExprGenerator::TearDown()
{}
void TestExprGenerator::generate_expr(const char* expr_str, const char*& post_expr)
{
ObArray<ObQualifiedName> columns;
ObArray<ObVarInfo> sys_vars;
ObArray<ObSubQueryInfo> sub_query_info;
ObArray<ObAggFunRawExpr*> aggr_exprs;
ObArray<ObWinFunRawExpr*> win_exprs;
ObArenaAllocator allocator(ObModIds::TEST);
ObRawExprFactory expr_factory(allocator);
ObTimeZoneInfo tz_info;
ObNameCaseMode case_mode = OB_NAME_CASE_INVALID;
ObExprResolveContext ctx(expr_factory, &tz_info, case_mode);
ctx.connection_charset_ = ObCharset::get_default_charset();
ctx.dest_collation_ = ObCharset::get_default_collation(ctx.connection_charset_);
ObRawExpr* expr = NULL;
OK(ObRawExprUtils::make_raw_expr_from_str(
expr_str, strlen(expr_str), ctx, expr, columns, sys_vars, &sub_query_info, aggr_exprs, win_exprs));
RowDesc row_desc;
OK(row_desc.init());
for (int64_t i = 0; i < columns.count(); ++i) {
OK(row_desc.add_column(columns[i].ref_expr_));
}
ObSqlExpression* sql_expr = NULL;
ObColumnExpression col_expr(allocator);
ObAggregateExpression aggr_expr(allocator);
if (expr->is_aggr_expr()) {
sql_expr = &aggr_expr;
} else {
sql_expr = &col_expr;
}
ObExprGeneratorImpl expr_generator(0, 0, NULL, row_desc);
OK(expr_generator.generate(*expr, *sql_expr));
phy_plan_.set_regexp_op_count(expr_generator.get_cur_regexp_op_count());
post_expr = CSJ(sql_expr);
}
TEST_F(TestExprGenerator, DISABLED_basic_test)
{
const char* test_file = "test_expr_generator.test";
const char* result_file = "test_expr_generator.result";
const char* tmp_file = "test_expr_generator.tmp";
const char* post_expr = NULL;
// run tests
std::string line;
std::ifstream if_tests(test_file);
ASSERT_TRUE(if_tests.is_open());
std::ofstream of_result(tmp_file);
ASSERT_TRUE(of_result.is_open());
while (std::getline(if_tests, line)) {
of_result << line << std::endl;
generate_expr(line.c_str(), post_expr);
of_result << post_expr << std::endl;
}
of_result.close();
// verify results
std::ifstream if_result(tmp_file);
ASSERT_TRUE(if_result.is_open());
std::istream_iterator<std::string> it_result(if_result);
std::ifstream if_expected(result_file);
ASSERT_TRUE(if_expected.is_open());
std::istream_iterator<std::string> it_expected(if_expected);
ASSERT_TRUE(std::equal(it_result, std::istream_iterator<std::string>(), it_expected));
std::remove("./test_resolver.tmp");
}
int main(int argc, char** argv)
{
system("rm -rf test_expr_generator.log");
OB_LOGGER.set_log_level("INFO");
OB_LOGGER.set_file_name("test_expr_generator.log", true);
::oceanbase::sql::init_sql_factories();
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -0,0 +1,652 @@
c1 > c2
{
"result_index":-1,
"post_expr": [
{
"column_index":0,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"column_index":1,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"op": {
"expr_type":"T_OP_GT",
"expr_name":">",
"param_num":2,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
}
]
}
c1 > 10 and c2 < 100
{
"result_index":-1,
"post_expr": [
{
"column_index":0,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"BIGINT":10
},
"accuracy": {
"length":2,
"precision":2,
"scale":0
}
},
{
"op": {
"expr_type":"T_OP_GT",
"expr_name":">",
"param_num":2,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
},
{
"column_index":1,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"BIGINT":100
},
"accuracy": {
"length":3,
"precision":3,
"scale":0
}
},
{
"op": {
"expr_type":"T_OP_LT",
"expr_name":"<",
"param_num":2,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
},
{
"op": {
"expr_type":"T_OP_AND",
"expr_name":"&&",
"param_num":-1,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
}
]
}
c1+c2+100
{
"result_index":-1,
"post_expr": [
{
"column_index":0,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"column_index":1,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"op": {
"expr_type":"T_OP_ADD",
"expr_name":"+",
"param_num":2,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
},
{
"const": {
"BIGINT":100
},
"accuracy": {
"length":3,
"precision":3,
"scale":0
}
},
{
"op": {
"expr_type":"T_OP_ADD",
"expr_name":"+",
"param_num":2,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
}
]
}
sum(c1+c2)
{
"result_index":-1,
"aggr_func":"SUM",
"distinct":false,
"post_expr": [
{
"column_index":0,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"column_index":1,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"op": {
"expr_type":"T_OP_ADD",
"expr_name":"+",
"param_num":2,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
}
]
}
case c1 when 1 then 'a' when 2 then 'b' else 'c' end
{
"result_index":-1,
"post_expr": [
{
"column_index":0,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"BIGINT":1
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
}
},
{
"const": {
"VARCHAR":"a",
"collation":"utf8mb4_general_ci"
},
"accuracy": {
"length":1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"BIGINT":2
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
}
},
{
"const": {
"VARCHAR":"b",
"collation":"utf8mb4_general_ci"
},
"accuracy": {
"length":1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"VARCHAR":"c",
"collation":"utf8mb4_general_ci"
},
"accuracy": {
"length":1,
"precision":-1,
"scale":-1
}
},
{
"op": {
"expr_type":"T_OP_ARG_CASE",
"expr_name":"arg_case",
"param_num":-3,
"dimension":-1,
"real_param_num":6,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
}
]
}
case when c1 > 1 then 'a' when c1 < 100 then 'b' else 'c' end
{
"result_index":-1,
"post_expr": [
{
"column_index":0,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"BIGINT":1
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
}
},
{
"op": {
"expr_type":"T_OP_GT",
"expr_name":">",
"param_num":2,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
},
{
"const": {
"VARCHAR":"a",
"collation":"utf8mb4_general_ci"
},
"accuracy": {
"length":1,
"precision":-1,
"scale":-1
}
},
{
"column_index":1,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"BIGINT":100
},
"accuracy": {
"length":3,
"precision":3,
"scale":0
}
},
{
"op": {
"expr_type":"T_OP_LT",
"expr_name":"<",
"param_num":2,
"dimension":-1,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
},
{
"const": {
"VARCHAR":"b",
"collation":"utf8mb4_general_ci"
},
"accuracy": {
"length":1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"VARCHAR":"c",
"collation":"utf8mb4_general_ci"
},
"accuracy": {
"length":1,
"precision":-1,
"scale":-1
}
},
{
"op": {
"expr_type":"T_OP_CASE",
"expr_name":"case",
"param_num":-3,
"dimension":-1,
"real_param_num":5,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
}
]
}
(c1, c2) >= (1, 2)
{
"result_index":-1,
"post_expr": [
{
"column_index":0,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"column_index":1,
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
}
},
{
"const": {
"BIGINT":1
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
}
},
{
"const": {
"BIGINT":2
},
"accuracy": {
"length":1,
"precision":1,
"scale":0
}
},
{
"op": {
"expr_type":"T_OP_GE",
"expr_name":">=",
"param_num":2,
"dimension":2,
"real_param_num":2,
"result_type": {
"meta": {
"type":"",
"collation":"binary",
"coercibility":"NUMERIC"
},
"accuracy": {
"length":-1,
"precision":-1,
"scale":-1
},
"flag":0,
"calc_type": {
"type":"NULL",
"collation":"invalid_type",
"coercibility":"INVALID"
}
},
"input_type": [
]
}
}
]
}

View File

@ -0,0 +1,7 @@
c1 > c2
c1 > 10 and c2 < 100
c1+c2+100
sum(c1+c2)
case c1 when 1 then 'a' when 2 then 'b' else 'c' end
case when c1 > 1 then 'a' when c1 < 100 then 'b' else 'c' end
(c1, c2) >= (1, 2)

View File

@ -0,0 +1,322 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include <iterator>
#include <gtest/gtest.h>
#define private public
#include "sql/test_sql_utils.h"
#include "lib/container/ob_array.h"
#include "sql/code_generator/ob_code_generator.h"
#include "sql/ob_sql_init.h"
#include "sql/engine/dml/ob_table_insert.h"
#include "sql/optimizer/test_optimizer_utils.h"
#include "sql/plan_cache/ob_cache_object_factory.h"
#include "sql/engine/ob_phy_operator.h"
#include "sql/engine/ob_double_children_phy_operator.h"
#include "sql/engine/ob_multi_children_phy_operator.h"
#include "share/ob_worker.h"
#undef private
using namespace oceanbase::common;
using namespace oceanbase::share;
namespace test {
class MockVisitor : public ObPhyOperatorVisitor {
public:
MockVisitor() : level_(0)
{}
~MockVisitor()
{}
virtual int pre_visit(const ObSingleChildPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObSingleChildPhyOperator& op)
{
level_--;
const_cast<ObSingleChildPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
virtual int pre_visit(const ObDoubleChildrenPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObDoubleChildrenPhyOperator& op)
{
level_--;
const_cast<ObDoubleChildrenPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
virtual int pre_visit(const ObMultiChildrenPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObMultiChildrenPhyOperator& op)
{
level_--;
const_cast<ObMultiChildrenPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
virtual int pre_visit(const ObNoChildrenPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObNoChildrenPhyOperator& op)
{
level_--;
const_cast<ObNoChildrenPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
virtual int pre_visit(const ObPhyOperator& op)
{
int ret = OB_SUCCESS;
OB_LOG(INFO, "output:", K(level_), "type", op.get_type());
level_++;
return ret;
}
virtual int post_visit(const ObPhyOperator& op)
{
level_--;
const_cast<ObPhyOperator&>(op).reuse();
return OB_SUCCESS;
}
private:
int level_;
};
class TestCodeGenerator : public TestOptimizerUtils {
public:
TestCodeGenerator();
virtual ~TestCodeGenerator();
virtual void SetUp();
virtual void TearDown();
private:
// disallow copy
DISALLOW_COPY_AND_ASSIGN(TestCodeGenerator);
protected:
// function members
void do_optimize(ObStmt& stmt, ObLogPlan*& plan, ObPhyPlanType distr_method);
void do_code_generate(const ObLogPlan& log_plan, ObCodeGenerator& code_gen, ObPhysicalPlan& phy_plan);
int do_rewrite(ObStmt*& stmt, ObPhysicalPlan* phy_plan);
protected:
// data members
oceanbase::share::ObLocationFetcher fetcher_;
ParamStore params_;
ObAddr addr_;
ObOptimizerContext* optimizer_ctx_;
ObTransformerCtx* transformer_ctx_;
ObSchemaChecker schema_checker_;
ObQueryHint query_hint_;
};
TestCodeGenerator::TestCodeGenerator() : fetcher_(), optimizer_ctx_(NULL), transformer_ctx_(NULL)
{
memcpy(schema_file_path_, "./test_code_generator.schema", sizeof("./test_code_generator.schema"));
}
TestCodeGenerator::~TestCodeGenerator()
{}
void TestCodeGenerator::SetUp()
{
TestOptimizerUtils::SetUp();
schema_checker_.init(schema_guard_);
session_info_.set_use_static_typing_engine(true);
exec_ctx_.get_sql_ctx()->schema_guard_ = &schema_guard_;
exec_ctx_.get_sql_ctx()->session_info_ = &session_info_;
optimizer_ctx_ = new ObOptimizerContext(&session_info_,
&exec_ctx_,
// schema_mgr_,
&sql_schema_guard_,
&stat_manager_,
NULL,
&partition_service_,
allocator_,
&part_cache_,
&params_,
addr_,
NULL,
OB_MERGED_VERSION_INIT,
query_hint_,
expr_factory_,
NULL);
ASSERT_TRUE(optimizer_ctx_);
transformer_ctx_ = new ObTransformerCtx();
ASSERT_TRUE(transformer_ctx_);
transformer_ctx_->allocator_ = &allocator_;
transformer_ctx_->session_info_ = &session_info_;
transformer_ctx_->schema_checker_ = &schema_checker_;
transformer_ctx_->expr_factory_ = &expr_factory_;
transformer_ctx_->stmt_factory_ = &stmt_factory_;
transformer_ctx_->exec_ctx_ = &exec_ctx_;
transformer_ctx_->partition_location_cache_ = &part_cache_;
transformer_ctx_->stat_mgr_ = &stat_manager_;
transformer_ctx_->partition_service_ = &partition_service_;
transformer_ctx_->sql_schema_guard_ = &sql_schema_guard_;
transformer_ctx_->self_addr_ = &addr_;
}
void TestCodeGenerator::TearDown()
{
// destroy
destroy();
if (NULL != optimizer_ctx_) {
delete optimizer_ctx_;
optimizer_ctx_ = NULL;
}
if (NULL != transformer_ctx_) {
delete transformer_ctx_;
transformer_ctx_ = NULL;
}
}
int TestCodeGenerator::do_rewrite(ObStmt*& stmt, ObPhysicalPlan* phy_plan)
{
int ret = OB_SUCCESS;
transformer_ctx_->phy_plan_ = phy_plan;
ObTransformerImpl trans(transformer_ctx_);
if (stmt->is_select_stmt()) {
ObDMLStmt* dml_stmt = static_cast<ObDMLStmt*>(stmt);
if (OB_FAIL(trans.transform(dml_stmt))) {
_OB_LOG(WARN, "fail to transform stmt, ret = %d", ret);
} else {
stmt = dml_stmt;
}
}
return ret;
}
void TestCodeGenerator::do_optimize(ObStmt& stmt, ObLogPlan*& plan, ObPhyPlanType distr)
{
ObTableLocation table_location;
OK(optimizer_ctx_->get_table_location_list().push_back(table_location));
if (distr == OB_PHY_PLAN_REMOTE) {
SQL_CG_LOG(DEBUG, "setting local address to 2.2.2.2");
optimizer_ctx_->set_local_server_ipv4_addr("2.2.2.2", 8888);
} else {
SQL_CG_LOG(DEBUG, "setting local address to 1.1.1.1");
optimizer_ctx_->set_local_server_ipv4_addr("1.1.1.1", 8888);
}
ObQueryHint query_hint = dynamic_cast<ObDMLStmt&>(stmt).get_stmt_hint().get_query_hint();
optimizer_ctx_->set_query_hint(query_hint);
optimizer_ctx_->set_root_stmt(dynamic_cast<ObDMLStmt*>(&stmt));
ObOptimizer optimizer(*optimizer_ctx_);
OK(optimizer.optimize(dynamic_cast<ObDMLStmt&>(stmt), plan));
char buf[1024];
plan->to_string(buf, 1024);
_OB_LOG(INFO, "logical_plan=%s", buf);
}
void TestCodeGenerator::do_code_generate(const ObLogPlan& log_plan, ObCodeGenerator& code_gen, ObPhysicalPlan& phy_plan)
{
OK(code_gen.generate(log_plan, phy_plan));
}
TEST_F(TestCodeGenerator, basic_test)
{
const char* test_file = "./test_static_engine_cg.test";
const char* result_file = "./test_static_engine_cg.result";
const char* tmp_file = "./test_static_engine_cg.tmp";
// run tests
std::ifstream if_tests(test_file);
ASSERT_TRUE(if_tests.is_open());
std::ofstream of_result(tmp_file);
ASSERT_TRUE(of_result.is_open());
std::string line;
ObStmt* stmt = NULL;
ObLogPlan* logical_plan = NULL;
ObPhysicalPlan* phy_plan = NULL;
int64_t line_no = 1;
while (std::getline(if_tests, line)) {
if (line.size() <= 0)
continue;
if (line.at(0) == '#')
continue;
_OB_LOG(DEBUG, "================================================================");
of_result << "[" << line_no++ << "] ";
of_result << line << std::endl;
bool is_print = true;
params_.reset();
OB_LOG(INFO, "case:", K(line.c_str()));
// if sql start with "oracle", use oracle compact mode.
auto mode = ObWorker::CompatMode::MYSQL;
std::string oracle("oracle");
// trim left
line.erase(line.begin(), std::find_if(line.begin(), line.end(), [](int ch) { return !std::isspace(ch); }));
if (strncasecmp(oracle.c_str(), line.c_str(), oracle.size()) == 0) {
mode = ObWorker::CompatMode::ORACLE;
line.erase(line.begin(), line.begin() + oracle.size());
}
share::CompatModeGuard g(mode);
ObPhysicalPlanCtx* pctx = exec_ctx_.get_physical_plan_ctx();
ASSERT_TRUE(NULL != pctx);
ObCodeGenerator code_gen(
false /*use_jit*/, true /*use static typing engine*/, CLUSTER_VERSION_3000, &(pctx->get_datum_param_store()));
ObCacheObjectFactory::alloc(phy_plan);
ASSERT_TRUE(NULL != (phy_plan));
ASSERT_NO_FATAL_FAILURE(do_resolve(line.c_str(), stmt, is_print, JSON_FORMAT, OB_SUCCESS, false));
ASSERT_EQ(OB_SUCCESS, do_rewrite(stmt, phy_plan));
ASSERT_NO_FATAL_FAILURE(do_optimize(*stmt, logical_plan, OB_PHY_PLAN_LOCAL));
ASSERT_NO_FATAL_FAILURE(do_code_generate(*logical_plan, code_gen, *phy_plan));
of_result << CSJ(*phy_plan) << std::endl;
ASSERT_TRUE(NULL != phy_plan->get_root_op_spec());
// new engine do not generate old phy operators
// ObPhyOperator *main_query = phy_plan->get_main_query();
// ASSERT_TRUE(NULL != main_query);
// MockVisitor visitor;
// ASSERT_EQ(OB_SUCCESS, main_query->accept(visitor));
//@todo ObPhysicalPlan::free(phy_plan);
phy_plan = NULL;
stmt_factory_.destory();
expr_factory_.destory();
}
of_result.close();
// verify results
UNUSED(result_file);
// The results not compare now, only for debug,
// the results will be compared when the farm is added later
// ASSERT_NO_FATAL_FAILURE(TestSqlUtils::is_equal_content(tmp_file, result_file));
}
} // namespace test
int main(int argc, char** argv)
{
system("rm -rf test_static_engine_cg.log");
OB_LOGGER.set_log_level("DEBUG");
OB_LOGGER.set_file_name("test_static_engine_cg.log", true);
::oceanbase::sql::init_sql_factories();
::testing::InitGoogleTest(&argc, argv);
test::parse_cmd_line_param(argc, argv, test::clp);
return RUN_ALL_TESTS();
}

View File

@ -0,0 +1,2 @@
select c1+c2 from t1 limit 1;
explain select c1+c2 from t1 limit 1;