Skip to content

Commit

Permalink
fix: fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dl239 committed Dec 15, 2023
1 parent 5eec977 commit b7916a5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions hybridse/include/node/node_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ enum CmdType {
kCmdShowCreateTable,
kCmdTruncate,
kCmdDropUser,
kCmdShowUser,
kCmdFake, // not a real cmd, for testing purpose only
kLastCmd = kCmdFake,
};
Expand Down
1 change: 1 addition & 0 deletions hybridse/src/planv2/ast_node_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,7 @@ static const absl::flat_hash_map<std::string_view, ShowTargetInfo> showTargetMap
{"TABLE STATUS", {node::CmdType::kCmdShowTableStatus, false, true}},
{"FUNCTIONS", {node::CmdType::kCmdShowFunctions}},
{"JOBLOG", {node::CmdType::kCmdShowJobLog, true}},
{"CURRENT_USER", {node::CmdType::kCmdShowUser}},
};

static const absl::flat_hash_map<std::string_view, node::ShowStmtType> SHOW_STMT_TYPE_MAP = {
Expand Down
3 changes: 3 additions & 0 deletions src/nameserver/name_server_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5468,6 +5468,9 @@ void NameServerImpl::OnLocked() {
if (FLAGS_system_table_replica_num > 0 && db_table_info_[INTERNAL_DB].count(JOB_INFO_NAME) == 0) {
CreateSystemTableOrExit(SystemTableType::kJobInfo);
}
if (FLAGS_system_table_replica_num > 0 && db_table_info_[INTERNAL_DB].count(USER_INFO_NAME) == 0) {
CreateSystemTableOrExit(SystemTableType::kUser);
}
}

if (FLAGS_system_table_replica_num > 0 && db_table_info_[INTERNAL_DB].count(PRE_AGG_META_NAME) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/node_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ hybridse::sdk::Status NodeAdapter::ExtractCondition(const hybridse::node::Binary

absl::StatusOr<std::string> NodeAdapter::ExtractUserOption(const hybridse::node::OptionsMap& map) {
if (map.empty()) {
return absl::InvalidArgumentError("no password option");
return "";
} else if (map.size() > 1) {
return absl::InvalidArgumentError("only password option allowed");
}
Expand Down
18 changes: 8 additions & 10 deletions src/sdk/sql_cluster_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,11 @@ std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::HandleSQLCmd(const h
return ResultSetSQL::MakeResultSet({"Tables"}, values, status);
}

case hybridse::node::kCmdShowUser: {
std::vector<std::string> value = { options_->user };
return ResultSetSQL::MakeResultSet({"User"}, {value}, status);
}

case hybridse::node::kCmdShowCreateTable: {
auto& args = cmd_node->GetArgs();
std::string cur_db = db;
Expand Down Expand Up @@ -2656,11 +2661,11 @@ std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::ExecuteSQL(
if (!result.ok()) {
*status = {StatusCode::kCmdError, result.status().message()};
} else if (!(*result)) {
if (!alter_node->IfExists()) {
if (!alter_node->IfExists() && alter_node->Name() != "root") {
*status = {StatusCode::kCmdError, absl::StrCat("user ", alter_node->Name(), " does not exists")};
}
} else {
if (alter_node->Options()) {
if (alter_node->Options() && !alter_node->Options()->empty()) {
auto ret = NodeAdapter::ExtractUserOption(*alter_node->Options());
if (!ret.ok()) {
*status = {StatusCode::kCmdError, ret.status().message()};
Expand Down Expand Up @@ -2937,13 +2942,6 @@ std::shared_ptr<hybridse::sdk::ResultSet> SQLClusterRouter::ExecuteSQL(
return GetTaskManagerJobResult(plan->GetLikeStr(), status);
} else if (target == "NAMESERVER") {
return GetNameServerJobResult(plan->GetLikeStr(), status);
} else if (target == "CURRENT_USER") {
schema::PBSchema job_schema;
auto col = job_schema.Add();
col->set_name("user");
col->set_data_type(::openmldb::type::DataType::kString);
std::vector<std::string> value = { options_->user };
return ResultSetSQL::MakeResultSet(job_schema, {value}, status);
} else {
*status = {StatusCode::kCmdError, absl::StrCat("invalid component ", target)};
}
Expand Down Expand Up @@ -3438,7 +3436,7 @@ hybridse::sdk::Status SQLClusterRouter::HandleDelete(const std::string& db, cons
return status;
}
status = SendDeleteRequst(table_info, &option);
if (status.IsOK()) {
if (status.IsOK() && db != nameserver::INTERNAL_DB) {
status = {StatusCode::kOk,
"DELETE is a dangerous operation. Once deleted, it is very difficult to recover. You may also note that:\n"
"- The deleted data will not be released immediately from the main memory; "
Expand Down

0 comments on commit b7916a5

Please sign in to comment.