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

Function HandleSQL

src/cmd/sql_cmd.h:540–626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

538}
539
540void HandleSQL(const std::string &sql) {
541 hybridse::node::NodeManager node_manager;
542 hybridse::base::Status sql_status;
543 hybridse::node::NodePointVector parser_trees;
544 PlanAPI::CreateSyntaxTreeFromScript(sql, parser_trees, &node_manager, sql_status);
545
546 if (0 != sql_status.code) {
547 std::cout << sql_status.msg << std::endl;
548 return;
549 }
550 hybridse::node::SqlNode *node = parser_trees[0];
551 switch (node->GetType()) {
552 case hybridse::node::kCmdStmt: {
553 hybridse::node::CmdNode *cmd =
554 dynamic_cast<hybridse::node::CmdNode *>(node);
555 HandleCmd(cmd);
556 return;
557 }
558 case hybridse::node::kExplainStmt: {
559 std::string empty;
560 std::string mu_script = sql;
561 mu_script.replace(0u, 7u, empty);
562 ::hybridse::sdk::Status status;
563 auto info = sr->Explain(db, mu_script, &status);
564 if (!info) {
565 std::cout << "fail to get explain info" << std::endl;
566 return;
567 }
568 std::cout << info->GetPhysicalPlan() << std::endl;
569 return;
570 }
571 case hybridse::node::kCreateStmt:
572 case hybridse::node::kCreateSpStmt: {
573 if (db.empty()) {
574 std::cout << "please use database first" << std::endl;
575 return;
576 }
577 ::hybridse::sdk::Status status;
578 bool ok = sr->ExecuteDDL(db, sql, &status);
579 if (!ok) {
580 std::cout << "fail to execute ddl" << std::endl;
581 } else {
582 sr->RefreshCatalog();
583 }
584 return;
585 }
586 case hybridse::node::kCreateIndexStmt: {
587 if (db.empty()) {
588 std::cout << "please use database first" << std::endl;
589 return;
590 }
591 hybridse::node::CreateIndexNode *create_index_node =
592 dynamic_cast<hybridse::node::CreateIndexNode *>(node);
593 HandleCreateIndex(create_index_node);
594 return;
595 }
596 case hybridse::node::kInsertStmt: {
597 if (db.empty()) {

Callers 1

HandleCliFunction · 0.85

Calls 11

HandleCmdFunction · 0.85
HandleCreateIndexFunction · 0.85
PrintResultSetFunction · 0.85
ExplainMethod · 0.80
ExecuteDDLMethod · 0.80
ExecuteInsertMethod · 0.80
GetTypeMethod · 0.45
emptyMethod · 0.45
RefreshCatalogMethod · 0.45
ExecuteSQLMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected