From 330d171193b925c4fd63a6df75d51a14572d7ad0 Mon Sep 17 00:00:00 2001 From: aceforeverd Date: Thu, 14 Sep 2023 17:55:42 +0800 Subject: [PATCH] feat: support const project online (#3376) --- cases/query/const_query.yaml | 42 ++++++-------------- hybridse/include/case/sql_case.h | 8 ++-- hybridse/include/sdk/base.h | 2 +- hybridse/include/vm/physical_op.h | 2 +- hybridse/src/case/sql_case.cc | 53 +++++++++++++++---------- hybridse/src/case/sql_case_test.cc | 4 +- hybridse/src/plan/planner.cc | 7 +++- hybridse/src/testing/engine_test_base.h | 14 ++++++- hybridse/src/vm/runner.cc | 7 ++-- hybridse/src/vm/transform.cc | 9 +++-- src/cmd/sql_cmd_test.cc | 6 ++- src/sdk/sql_cluster_test.cc | 8 ++-- src/sdk/sql_request_row.h | 3 +- src/sdk/sql_sdk_base_test.cc | 44 +++++++++++--------- src/sdk/sql_sdk_test.cc | 8 ++-- src/sdk/sql_standalone_sdk_test.cc | 8 ++-- src/test/base_test.cc | 2 +- 17 files changed, 124 insertions(+), 103 deletions(-) diff --git a/cases/query/const_query.yaml b/cases/query/const_query.yaml index 304f0486073..38bbbeb5e47 100644 --- a/cases/query/const_query.yaml +++ b/cases/query/const_query.yaml @@ -14,10 +14,12 @@ debugs: [] version: 0.5.0 +# FIXME: support request procedure for const project +# requires GetTablet impl for non-table procedure cases: - id: 0 desc: select const number - mode: request-unsupport + mode: procedure-unsupport db: db1 sql: | select 1 as id, 2 as col1, 3.3 as col2; @@ -29,7 +31,7 @@ cases: - [1, 2, 3.3] - id: 1 desc: select str - mode: request-unsupport + mode: procedure-unsupport db: db1 sql: | select 1 as id, "hello_world" as col1; @@ -41,7 +43,7 @@ cases: - [1, "hello_world"] - id: 2 desc: const substr pos len - mode: request-unsupport + mode: procedure-unsupport db: db1 sql: | select 1 as id, substring("hello_world", 3, 6) as col1; @@ -53,7 +55,7 @@ cases: - [1, "llo_wo"] - id: 3 desc: const substr pos - mode: request-unsupport + mode: procedure-unsupport db: db1 sql: | select 1 as id, substring("hello_world", 3) as col1; @@ -65,7 +67,7 @@ cases: - [1, "llo_world"] - id: 4 desc: const concat 1 - mode: request-unsupport + mode: procedure-unsupport db: db1 sql: | select 1 as id, concat("hello", "world", "abc") as col1; @@ -76,13 +78,8 @@ cases: - [1, "helloworldabc"] - id: 5 desc: cast常量 using CAST operator - mode: request-unsupport + mode: procedure-unsupport db: db1 - inputs: - - columns: ["c1 int", "c2 string", "c5 bigint"] - indexs: ["index1:c1:c5"] - rows: - - [1, "2020-05-22 10:43:40", 1] sql: | select CAST (10 as int) as c1, CAST (10 as bigint) as c2, CAST (10 as float) as c3, CAST (10 as double) as c4, CAST (1590115460000 as timestamp) as c5, CAST ("2020-05-20" as date) as c6, CAST (10 as string) as c7; expect: @@ -91,13 +88,8 @@ cases: - [10, 10, 10.0, 10.0, 1590115460000, '2020-05-20', "10"] - id: 6 desc: cast NULL常量 using CAST operator - mode: request-unsupport + mode: procedure-unsupport db: db1 - inputs: - - columns: ["c1 int", "c2 string", "c5 bigint"] - indexs: ["index1:c1:c5"] - rows: - - [1, "2020-05-22 10:43:40", 1] sql: | select CAST (NULL as int) as c1, CAST (NULL as bigint) as c2, CAST (NULL as float) as c3, CAST (NULL as double) as c4, CAST (NULL as timestamp) as c5, CAST (NULL as date) as c6, CAST (NULL as string) as c7; expect: @@ -106,13 +98,8 @@ cases: - [NULL, NULL, NULL, NULL, NULL, NULL, NULL] - id: 7 desc: cast常量 using type() function - mode: request-unsupport + mode: procedure-unsupport db: db1 - inputs: - - columns: ["c1 int", "c2 string", "c5 bigint"] - indexs: ["index1:c1:c5"] - rows: - - [1, "2020-05-22 10:43:40", 1] sql: | select int(10) as c1, bigint(10) as c2, float(10) as c3, double(10) as c4, timestamp(1590115460000) as c5, date("2020-05-20") as c6, string(10) as c7; expect: @@ -121,13 +108,8 @@ cases: - [10, 10, 10.0, 10.0, 1590115460000, '2020-05-20', "10"] - id: 8 desc: cast NULL常量 using type(NULL) function - mode: request-unsupport + mode: procedure-unsupport db: db1 - inputs: - - columns: ["c1 int", "c2 string", "c5 bigint"] - indexs: ["index1:c1:c5"] - rows: - - [1, "2020-05-22 10:43:40", 1] sql: | select int(NULL) as c1, bigint(NULL) as c2, float(NULL) as c3, double(NULL) as c4, timestamp(NULL) as c5, date(NULL) as c6, string(NULL) as c7; expect: @@ -136,7 +118,7 @@ cases: - [NULL, NULL, NULL, NULL, NULL, NULL, NULL] - id: 9 desc: differnt const node type - mode: request-unsupport + mode: procedure-unsupport db: db1 sql: | select true c1, int16(3) c2, 13 c3, 10.0 c4, 'a string' c5, date(timestamp(1590115420000)) c6, timestamp(1590115420000) c7; diff --git a/hybridse/include/case/sql_case.h b/hybridse/include/case/sql_case.h index 0c7756da02c..7cc05bba1d5 100644 --- a/hybridse/include/case/sql_case.h +++ b/hybridse/include/case/sql_case.h @@ -205,10 +205,10 @@ class SqlCase { static std::string GenRand(const std::string& prefix) { return prefix + std::to_string(rand() % 10000000 + 1); // NOLINT } - absl::StatusOr BuildCreateSpSqlFromInput(int32_t input_idx, absl::string_view sql, - const std::set& common_idx); - absl::StatusOr BuildCreateSpSqlFromSchema(const type::TableDef& table, absl::string_view select_sql, - const std::set& common_idx); + absl::StatusOr BuildCreateSpSql(absl::string_view sql, const std::set& common_idx, + std::optional input_idx); + absl::StatusOr BuildCreateSpSql(absl::string_view select_sql, const std::set& common_idx, + std::optional table); friend std::ostream& operator<<(std::ostream& output, const SqlCase& thiz); static bool IS_PERF() { diff --git a/hybridse/include/sdk/base.h b/hybridse/include/sdk/base.h index fcf9adcb0d1..90d8ff75680 100644 --- a/hybridse/include/sdk/base.h +++ b/hybridse/include/sdk/base.h @@ -71,7 +71,7 @@ struct Status { cm.append("] "); cm.append(msg); return cm; - }; + } int code; // msg use prepend and append, it's better to use absl::Cord, but we may directly use msg diff --git a/hybridse/include/vm/physical_op.h b/hybridse/include/vm/physical_op.h index 1fa22650995..c884d0bb7e5 100644 --- a/hybridse/include/vm/physical_op.h +++ b/hybridse/include/vm/physical_op.h @@ -738,7 +738,7 @@ class PhysicalConstProjectNode : public PhysicalOpNode { fn_infos_.push_back(&project_.fn_info()); } virtual ~PhysicalConstProjectNode() {} - virtual void Print(std::ostream &output, const std::string &tab) const; + void Print(std::ostream &output, const std::string &tab) const override; static PhysicalConstProjectNode *CastFrom(PhysicalOpNode *node); const ColumnProjects &project() const { return project_; } diff --git a/hybridse/src/case/sql_case.cc b/hybridse/src/case/sql_case.cc index 3d16b213b5a..c98defb679b 100644 --- a/hybridse/src/case/sql_case.cc +++ b/hybridse/src/case/sql_case.cc @@ -751,6 +751,9 @@ const std::string SqlCase::case_name() const { } bool SqlCase::ExtractInputTableDef(type::TableDef& table, int32_t input_idx) const { + if (inputs_.size() <= input_idx) { + return false; + } return ExtractInputTableDef(inputs_[input_idx], table); } bool SqlCase::ExtractInputTableDef(const TableInfo& input, @@ -1639,35 +1642,41 @@ void InitCases(std::string yaml_path, std::vector& cases, // NOLINT const std::vector& filters) { SqlCase::CreateSqlCasesFromYaml(hybridse::sqlcase::FindSqlCaseBaseDirPath(), yaml_path, cases, filters); } -absl::StatusOr SqlCase::BuildCreateSpSqlFromInput(int32_t input_idx, - absl::string_view select_sql, - const std::set& common_idx) { - type::TableDef table; - if (!ExtractInputTableDef(table, input_idx)) { - return absl::FailedPreconditionError("Fail to extract table schema"); - } +absl::StatusOr SqlCase::BuildCreateSpSql(absl::string_view select_sql, const std::set& common_idx, + std::optional input_idx) { + if (input_idx.has_value()) { + type::TableDef table; + if (!ExtractInputTableDef(table, input_idx.value())) { + return absl::FailedPreconditionError("Fail to extract table schema"); + } - return BuildCreateSpSqlFromSchema(table, select_sql, common_idx); + return BuildCreateSpSql(select_sql, common_idx, &table); + } + std::optional tab = {}; + return BuildCreateSpSql(select_sql, common_idx, tab); } -absl::StatusOr SqlCase::BuildCreateSpSqlFromSchema(const type::TableDef& table, - absl::string_view select_sql, - const std::set& common_idx) { - auto sql_view = absl::StripAsciiWhitespace(select_sql); - std::string query_stmt(sql_view); - if (query_stmt.back() != ';') { +absl::StatusOr SqlCase::BuildCreateSpSql(absl::string_view select_sql, const std::set& common_idx, + std::optional tab) { + auto sql_view = absl::StripAsciiWhitespace(select_sql); + std::string query_stmt(sql_view); + if (query_stmt.back() != ';') { absl::StrAppend(&query_stmt, ";"); } std::string sql = absl::Substitute("CREATE PROCEDURE $0 (\n", sp_name_); - for (int i = 0; i < table.columns_size(); i++) { - auto column = table.columns(i); - if (!common_idx.empty() && common_idx.count(i)) { - absl::StrAppend(&sql, "const "); - } - absl::SubstituteAndAppend(&sql, "$0 $1", column.name(), TypeString(column.type())); - if (i < table.columns_size() - 1) { - absl::StrAppend(&sql, ",\n"); + if (tab.has_value()) { + auto table = tab.value(); + + for (int i = 0; i < table->columns_size(); i++) { + auto column = table->columns(i); + if (!common_idx.empty() && common_idx.count(i)) { + absl::StrAppend(&sql, "const "); + } + absl::SubstituteAndAppend(&sql, "$0 $1", column.name(), TypeString(column.type())); + if (i < table->columns_size() - 1) { + absl::StrAppend(&sql, ",\n"); + } } } absl::SubstituteAndAppend(&sql, ")\nBEGIN\n$0\nEND;", query_stmt); diff --git a/hybridse/src/case/sql_case_test.cc b/hybridse/src/case/sql_case_test.cc index 6cc980253ea..c6603544a3d 100644 --- a/hybridse/src/case/sql_case_test.cc +++ b/hybridse/src/case/sql_case_test.cc @@ -1168,7 +1168,7 @@ TEST_F(SqlCaseTest, BuildCreateSpSqlFromInputTest) { sql_case.sp_name_ = "sp"; std::string sql = " select c1, c2, c3, c4 from t1 "; std::string sp_sql = ""; - auto s = sql_case.BuildCreateSpSqlFromInput(0, sql, {}); + auto s = sql_case.BuildCreateSpSql(sql, {}, 0); ASSERT_TRUE(s.ok()) << s.status(); ASSERT_EQ(R"s(CREATE PROCEDURE sp ( c1 string, @@ -1190,7 +1190,7 @@ END;)s", sql_case.inputs_.push_back(input); std::string sql = "select c1, c2, c3, c4 from t1;"; std::string sp_sql = ""; - auto s = sql_case.BuildCreateSpSqlFromInput(0, sql, {0, 1, 3}); + auto s = sql_case.BuildCreateSpSql(sql, {0, 1, 3}, 0); ASSERT_TRUE(s.ok()) << s.status(); ASSERT_EQ(R"s(CREATE PROCEDURE sp1 ( const c1 string, diff --git a/hybridse/src/plan/planner.cc b/hybridse/src/plan/planner.cc index 3cef58a131f..c0a68e3104e 100644 --- a/hybridse/src/plan/planner.cc +++ b/hybridse/src/plan/planner.cc @@ -490,6 +490,7 @@ absl::StatusOr Planner::IsTable(node::PlanNode *node) { // - SELECT // - JOIN // - WINDOW +// - CONST PROJECT // - UnSupport Ops:: // - CREATE TABLE // - INSERT TABLE @@ -500,8 +501,10 @@ absl::StatusOr Planner::IsTable(node::PlanNode *node) { // - Not Impl // - Order By base::Status Planner::ValidateOnlineServingOp(node::PlanNode *node) { - CHECK_TRUE(nullptr != node, common::kNullInputPointer, - "Fail to validate request table: input node is null") + if (node == nullptr) { + // null is fine, e.g the const project + return {}; + } switch (node->type_) { case node::kPlanTypeProject: { auto project_node = dynamic_cast(node); diff --git a/hybridse/src/testing/engine_test_base.h b/hybridse/src/testing/engine_test_base.h index f9317201f00..e759169f0fd 100644 --- a/hybridse/src/testing/engine_test_base.h +++ b/hybridse/src/testing/engine_test_base.h @@ -271,6 +271,12 @@ class RequestEngineTestRunner : public EngineTestRunner { std::string request_db_name = request_session->GetRequestDbName(); CHECK_TRUE(parameter_rows_.empty(), common::kUnSupport, "Request do not support parameterized query currently") Row parameter = parameter_rows_.empty() ? Row() : parameter_rows_[0]; + if (request_rows_.empty()) { + // send empty request, trigger e.g const project in request mode + CHECK_TRUE(request_name.empty() && request_db_name.empty(), common::kUnsupportSql, + "no request data for request table: <", request_db_name, ".", request_name, ">") + request_rows_.push_back(Row()); + } for (auto in_row : request_rows_) { Row out_row; int run_ret = request_session->Run(in_row, &out_row); @@ -278,7 +284,7 @@ class RequestEngineTestRunner : public EngineTestRunner { return_code_ = ENGINE_TEST_RET_EXECUTION_ERROR; return Status(common::kRunError, "Run request session failed"); } - if (!has_batch_request) { + if (!has_batch_request && !request_name.empty()) { CHECK_TRUE(AddRowIntoTable(request_db_name, request_name, in_row), common::kTablePutFailed, "Fail add row into table ", request_db_name, ".", request_name); } @@ -423,6 +429,12 @@ class BatchRequestEngineTestRunner : public EngineTestRunner { offset += row_num; } } + + if (request_rows_.empty()) { + // batch request rows will empty for const projects + // workaround by add the one empty row + request_rows_.push_back(Row()); + } return Status::OK(); } diff --git a/hybridse/src/vm/runner.cc b/hybridse/src/vm/runner.cc index 28525b8face..a15a2626bf3 100644 --- a/hybridse/src/vm/runner.cc +++ b/hybridse/src/vm/runner.cc @@ -1074,11 +1074,10 @@ std::shared_ptr Runner::BatchRequestRun(RunnerContext& ctx) { return cached; } } - std::shared_ptr outputs = - std::make_shared(); + + std::shared_ptr outputs = std::make_shared(); std::vector> inputs(producers_.size()); - std::vector> batch_inputs( - producers_.size()); + std::vector> batch_inputs(producers_.size()); for (size_t idx = producers_.size(); idx > 0; idx--) { batch_inputs[idx - 1] = producers_[idx - 1]->BatchRequestRun(ctx); } diff --git a/hybridse/src/vm/transform.cc b/hybridse/src/vm/transform.cc index 0e89ccd9291..60549447e42 100644 --- a/hybridse/src/vm/transform.cc +++ b/hybridse/src/vm/transform.cc @@ -2300,7 +2300,9 @@ Status RequestModeTransformer::TransformProjectPlanOp( "Input node or output node is null"); PhysicalOpNode* depend = nullptr; - CHECK_STATUS(TransformPlanOp(node->GetChildren()[0], &depend)); + if (!node->GetChildren().empty() && nullptr != node->GetChildren()[0]) { + CHECK_STATUS(TransformPlanOp(node->GetChildren()[0], &depend)); + } CHECK_STATUS(CompleteProjectList(node, depend)); @@ -2468,8 +2470,6 @@ Status RequestModeTransformer::ValidateRequestTable( return Status::OK(); } case vm::kPhysicalOpConstProject: { - FAIL_STATUS(kPlanError, - "Non-support Const Project in request mode", in->GetTreeString()); break; } default: { @@ -2487,6 +2487,9 @@ Status RequestModeTransformer::TransformProjectOp( node::ProjectListNode* project_list, PhysicalOpNode* depend, bool append_input, PhysicalOpNode** output) { PhysicalOpNode* new_depend = depend; + if (nullptr == depend) { + return CreatePhysicalConstProjectNode(project_list, output); + } if (nullptr != project_list->GetW()) { CHECK_STATUS(TransformWindowOp(depend, project_list->GetW(), &new_depend)); } diff --git a/src/cmd/sql_cmd_test.cc b/src/cmd/sql_cmd_test.cc index bd66e6db4dc..1896ac7c674 100644 --- a/src/cmd/sql_cmd_test.cc +++ b/src/cmd/sql_cmd_test.cc @@ -3740,12 +3740,16 @@ struct DeploymentEnv { }); } + // A bacth request increase deployment cnt by 1 + // yet may greatly impact deploy response time, if the batch size is huge + // maybe it requires a revision void CallDeployProcedureBatch() { hybridse::sdk::Status status; std::shared_ptr rr = std::make_shared(); GetRequestRow(&rr, dp_name_); - auto common_column_indices = std::make_shared(rr->GetSchema()); + auto common_column_indices = std::make_shared(); auto row_batch = std::make_shared(rr->GetSchema(), common_column_indices); + ASSERT_TRUE(row_batch->AddRow(rr)); sr->CallSQLBatchRequestProcedure(db_, dp_name_, row_batch, &status); ASSERT_TRUE(status.IsOK()) << status.msg << "\n" << status.trace; } diff --git a/src/sdk/sql_cluster_test.cc b/src/sdk/sql_cluster_test.cc index f8cccac1832..359ac431573 100644 --- a/src/sdk/sql_cluster_test.cc +++ b/src/sdk/sql_cluster_test.cc @@ -1012,7 +1012,7 @@ TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkDistributeBatchRequestSinglePartitionT TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkDistributeBatchRequestProcedureTest) { auto sql_case = GetParam(); - if (!IsBatchRequestSupportMode(sql_case.mode())) { + if (!IsBatchRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -1030,7 +1030,7 @@ TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkDistributeBatchRequestProcedureTest) { TEST_P(SQLSDKQueryTest, SqlSdkDistributeRequestProcedureTest) { auto sql_case = GetParam(); LOG(INFO) << "ID: " << sql_case.id() << ", DESC: " << sql_case.desc(); - if (!IsRequestSupportMode(sql_case.mode())) { + if (!IsRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -1041,7 +1041,7 @@ TEST_P(SQLSDKQueryTest, SqlSdkDistributeRequestProcedureTest) { } TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkDistributeBatchRequestProcedureAsyncTest) { auto sql_case = GetParam(); - if (!IsRequestSupportMode(sql_case.mode())) { + if (!IsBatchRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -1059,7 +1059,7 @@ TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkDistributeBatchRequestProcedureAsyncTe TEST_P(SQLSDKQueryTest, SqlSdkDistributeRequestProcedureAsyncTest) { auto sql_case = GetParam(); LOG(INFO) << "ID: " << sql_case.id() << ", DESC: " << sql_case.desc(); - if (!IsRequestSupportMode(sql_case.mode())) { + if (!IsRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } diff --git a/src/sdk/sql_request_row.h b/src/sdk/sql_request_row.h index af16a43da65..e09160f58e4 100644 --- a/src/sdk/sql_request_row.h +++ b/src/sdk/sql_request_row.h @@ -119,6 +119,7 @@ class SQLRequestRowBatch { class ColumnIndicesSet { public: + ColumnIndicesSet() {} explicit ColumnIndicesSet(std::shared_ptr schema) : bound_(schema->GetColumnCnt()) {} bool Empty() const { return common_column_indices_.empty(); } @@ -127,7 +128,7 @@ class ColumnIndicesSet { private: friend class SQLRequestRowBatch; - size_t bound_; + size_t bound_ = 0; std::set common_column_indices_; }; diff --git a/src/sdk/sql_sdk_base_test.cc b/src/sdk/sql_sdk_base_test.cc index 5d715f37fc4..d66ecc8c75f 100644 --- a/src/sdk/sql_sdk_base_test.cc +++ b/src/sdk/sql_sdk_base_test.cc @@ -105,7 +105,7 @@ void SQLSDKTest::CreateProcedure(hybridse::sqlcase::SqlCase& sql_case, // NOLIN std::shared_ptr router, bool is_batch) { DLOG(INFO) << "Create Procedure BEGIN"; hybridse::sdk::Status status; - if (sql_case.inputs()[0].name_.empty()) { + if (!sql_case.inputs().empty() && sql_case.inputs()[0].name_.empty()) { sql_case.set_input_name( hybridse::sqlcase::SqlCase::GenRand("auto_t") + std::to_string(static_cast(time(NULL))), 0); } @@ -126,13 +126,16 @@ void SQLSDKTest::CreateProcedure(hybridse::sqlcase::SqlCase& sql_case, // NOLIN hybridse::type::TableDef batch_request_schema; ASSERT_TRUE(sql_case.ExtractTableDef(sql_case.batch_request().columns_, sql_case.batch_request().indexs_, batch_request_schema)); - auto s = sql_case.BuildCreateSpSqlFromSchema(batch_request_schema, sql, - sql_case.batch_request().common_column_indices_); + auto s = sql_case.BuildCreateSpSql(sql, sql_case.batch_request().common_column_indices_, &batch_request_schema); ASSERT_TRUE(s.ok()) << s.status(); create_sp = s.value(); } else { std::set common_idx; - auto s = sql_case.BuildCreateSpSqlFromInput(0, sql, common_idx); + std::optional idx = {}; + if (!sql_case.inputs().empty()) { + idx = 0; + } + auto s = sql_case.BuildCreateSpSql(sql, common_idx, idx); ASSERT_TRUE(s.ok()) << s.status(); create_sp = s.value(); } @@ -405,33 +408,38 @@ void SQLSDKQueryTest::RequestExecuteSQL(hybridse::sqlcase::SqlCase& sql_case, / hybridse::type::TableDef insert_table; std::vector insert_rows; std::vector inserts; - if (!has_batch_request) { - ASSERT_TRUE(sql_case.ExtractInputTableDef(insert_table, 0)); - ASSERT_TRUE(sql_case.ExtractInputData(insert_rows, 0)); - sql_case.BuildInsertSqlListFromInput(0, &inserts); + if (!sql_case.inputs().empty()) { + if (!has_batch_request) { + ASSERT_TRUE(sql_case.ExtractInputTableDef(insert_table, 0)); + ASSERT_TRUE(sql_case.ExtractInputData(insert_rows, 0)); + sql_case.BuildInsertSqlListFromInput(0, &inserts); + } else { + ASSERT_TRUE(sql_case.ExtractInputTableDef(sql_case.batch_request_, insert_table)); + ASSERT_TRUE(sql_case.ExtractInputData(sql_case.batch_request_, insert_rows)); + } + CheckSchema(insert_table.columns(), *(request_row->GetSchema().get())); + DLOG(INFO) << "Request Row:\n"; + PrintRows(insert_table.columns(), insert_rows); } else { - ASSERT_TRUE(sql_case.ExtractInputTableDef(sql_case.batch_request_, insert_table)); - ASSERT_TRUE(sql_case.ExtractInputData(sql_case.batch_request_, insert_rows)); + // prepare a empty row in case result check for const projects + insert_rows.push_back(hybridse::codec::Row()); } - CheckSchema(insert_table.columns(), *(request_row->GetSchema().get())); - LOG(INFO) << "Request Row:\n"; - PrintRows(insert_table.columns(), insert_rows); hybridse::codec::RowView row_view(insert_table.columns()); std::vector> results; - LOG(INFO) << "Request execute sql start!"; + DLOG(INFO) << "Request execute sql start!"; for (size_t i = 0; i < insert_rows.size(); i++) { row_view.Reset(insert_rows[i].buf()); CovertHybridSERowToRequestRow(&row_view, request_row); std::shared_ptr rs; if (is_procedure) { if (is_asyn) { - LOG(INFO) << "-------asyn procedure----------"; + DLOG(INFO) << "-------asyn procedure----------"; auto future = router->CallProcedure(sql_case.db(), sql_case.sp_name_, 1000, request_row, &status); if (!future || status.code != 0) FAIL() << "sql case expect success == true" << status.msg; rs = future->GetResultSet(&status); } else { - LOG(INFO) << "--------syn procedure----------"; + DLOG(INFO) << "--------syn procedure----------"; rs = router->CallProcedure(sql_case.db(), sql_case.sp_name_, request_row, &status); } } else { @@ -439,8 +447,8 @@ void SQLSDKQueryTest::RequestExecuteSQL(hybridse::sqlcase::SqlCase& sql_case, / } if (!rs || status.code != 0) FAIL() << "sql case expect success == true" << status.msg; results.push_back(rs); - if (!has_batch_request) { - LOG(INFO) << "insert request: \n" << inserts[i]; + if (!has_batch_request && !sql_case.inputs().empty()) { + DLOG(INFO) << "insert request: \n" << inserts[i]; bool ok = router->ExecuteInsert(insert_table.catalog(), inserts[i], &status); ASSERT_TRUE(ok); } diff --git a/src/sdk/sql_sdk_test.cc b/src/sdk/sql_sdk_test.cc index cbb6235ea4c..4b6a67de11f 100644 --- a/src/sdk/sql_sdk_test.cc +++ b/src/sdk/sql_sdk_test.cc @@ -141,7 +141,7 @@ TEST_P(SQLSDKQueryTest, SqlSdkBatchTest) { TEST_P(SQLSDKQueryTest, SqlSdkRequestProcedureTest) { auto sql_case = GetParam(); LOG(INFO) << "ID: " << sql_case.id() << ", DESC: " << sql_case.desc(); - if (!IsRequestSupportMode(sql_case.mode())) { + if (!IsRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -153,7 +153,7 @@ TEST_P(SQLSDKQueryTest, SqlSdkRequestProcedureTest) { TEST_P(SQLSDKQueryTest, SqlSdkRequestProcedureAsynTest) { auto sql_case = GetParam(); LOG(INFO) << "ID: " << sql_case.id() << ", DESC: " << sql_case.desc(); - if (!IsRequestSupportMode(sql_case.mode())) { + if (!IsRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -193,7 +193,7 @@ TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkBatchRequestTest) { } TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkBatchRequestProcedureTest) { auto sql_case = GetParam(); - if (!IsBatchRequestSupportMode(sql_case.mode())) { + if (!IsBatchRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -209,7 +209,7 @@ TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkBatchRequestProcedureTest) { TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkBatchRequestProcedureAsynTest) { auto sql_case = GetParam(); - if (!IsBatchRequestSupportMode(sql_case.mode())) { + if (!IsBatchRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } diff --git a/src/sdk/sql_standalone_sdk_test.cc b/src/sdk/sql_standalone_sdk_test.cc index ac24fd374df..e61cf1ea76c 100644 --- a/src/sdk/sql_standalone_sdk_test.cc +++ b/src/sdk/sql_standalone_sdk_test.cc @@ -127,7 +127,7 @@ TEST_P(SQLSDKQueryTest, SqlSdkBatchTest) { TEST_P(SQLSDKQueryTest, SqlSdkRequestProcedureTest) { auto sql_case = GetParam(); LOG(INFO) << "ID: " << sql_case.id() << ", DESC: " << sql_case.desc(); - if (!IsRequestSupportMode(sql_case.mode())) { + if (!IsRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -139,7 +139,7 @@ TEST_P(SQLSDKQueryTest, SqlSdkRequestProcedureTest) { TEST_P(SQLSDKQueryTest, SqlSdkRequestProcedureAsynTest) { auto sql_case = GetParam(); LOG(INFO) << "ID: " << sql_case.id() << ", DESC: " << sql_case.desc(); - if (!IsRequestSupportMode(sql_case.mode())) { + if (!IsRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -164,7 +164,7 @@ TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkBatchRequestTest) { } TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkBatchRequestProcedureTest) { auto sql_case = GetParam(); - if (!IsBatchRequestSupportMode(sql_case.mode())) { + if (!IsBatchRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } @@ -180,7 +180,7 @@ TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkBatchRequestProcedureTest) { TEST_P(SQLSDKBatchRequestQueryTest, SqlSdkBatchRequestProcedureAsynTest) { auto sql_case = GetParam(); - if (!IsBatchRequestSupportMode(sql_case.mode())) { + if (!IsBatchRequestSupportMode(sql_case.mode()) || "procedure-unsupport" == sql_case.mode()) { LOG(WARNING) << "Unsupport mode: " << sql_case.mode(); return; } diff --git a/src/test/base_test.cc b/src/test/base_test.cc index 26aa3a2713e..0e85ccfb396 100644 --- a/src/test/base_test.cc +++ b/src/test/base_test.cc @@ -215,7 +215,7 @@ void SQLCaseTest::PrintRows(const hybridse::vm::Schema &schema, const std::vecto } } oss << t << std::endl; - LOG(INFO) << "\n" << oss.str() << "\n"; + DLOG(INFO) << "\n" << oss.str() << "\n"; } const std::vector SQLCaseTest::SortRows(const hybridse::vm::Schema &schema,