MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / BatchExecuteSQL

Method BatchExecuteSQL

src/sdk/sql_sdk_test.h:349–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347}
348
349void SQLSDKTest::BatchExecuteSQL(hybridse::sqlcase::SqlCase& sql_case, // NOLINT
350 std::shared_ptr<SQLRouter> router, const std::vector<std::string>& tbEndpoints) {
351 DLOG(INFO) << "BatchExecuteSQL BEGIN";
352 hybridse::sdk::Status status;
353 DLOG(INFO) << "format sql begin";
354 // execute SQL
355 std::string sql = sql_case.sql_str();
356 for (size_t i = 0; i < sql_case.inputs().size(); i++) {
357 std::string placeholder = "{" + std::to_string(i) + "}";
358 boost::replace_all(sql, placeholder, sql_case.inputs()[i].name_);
359 }
360 DLOG(INFO) << "format sql 1";
361 boost::replace_all(sql, "{auto}", hybridse::sqlcase::SqlCase::GenRand("auto_t"));
362 if (tbEndpoints.size() > 0) {
363 boost::replace_all(sql, "{tb_endpoint_0}", tbEndpoints.at(0));
364 }
365 if (tbEndpoints.size() > 1) {
366 boost::replace_all(sql, "{tb_endpoint_1}", tbEndpoints.at(1));
367 }
368 DLOG(INFO) << "format sql done";
369 LOG(INFO) << sql;
370 std::string lower_sql = sql;
371 boost::to_lower(lower_sql);
372 if (boost::algorithm::starts_with(lower_sql, "select")) {
373 auto rs = router->ExecuteSQL(sql_case.db(), sql, &status);
374 if (!sql_case.expect().success_) {
375 if ((rs)) {
376 FAIL() << "sql case expect success == false";
377 }
378 return;
379 }
380
381 if (!rs) FAIL() << "sql case expect success == true";
382 std::vector<hybridse::codec::Row> rows;
383 hybridse::type::TableDef output_table;
384 if (!sql_case.expect().schema_.empty() || !sql_case.expect().columns_.empty()) {
385 ASSERT_TRUE(sql_case.ExtractOutputSchema(output_table));
386 CheckSchema(output_table.columns(), *(rs->GetSchema()));
387 }
388
389 if (!sql_case.expect().data_.empty() || !sql_case.expect().rows_.empty()) {
390 ASSERT_TRUE(sql_case.ExtractOutputData(rows));
391 CheckRows(output_table.columns(), sql_case.expect().order_, rows, rs);
392 }
393
394 if (sql_case.expect().count_ > 0) {
395 ASSERT_EQ(sql_case.expect().count_, static_cast<int64_t>(rs->Size()));
396 }
397 } else if (boost::algorithm::starts_with(lower_sql, "create")) {
398 bool ok = router->ExecuteDDL(sql_case.db(), sql, &status);
399 router->RefreshCatalog();
400 ASSERT_EQ(sql_case.expect().success_, ok);
401 } else if (boost::algorithm::starts_with(lower_sql, "insert")) {
402 bool ok = router->ExecuteInsert(sql_case.db(), sql, &status);
403 ASSERT_EQ(sql_case.expect().success_, ok);
404 } else {
405 FAIL() << "sql not support in request mode";
406 }

Callers

nothing calls this directly

Calls 10

to_stringFunction · 0.85
ExecuteDDLMethod · 0.80
ExecuteInsertMethod · 0.80
GenRandFunction · 0.70
sizeMethod · 0.45
ExecuteSQLMethod · 0.45
emptyMethod · 0.45
GetSchemaMethod · 0.45
SizeMethod · 0.45
RefreshCatalogMethod · 0.45

Tested by

no test coverage detected