Skip to content

Commit

Permalink
feat: display deployment options (#3682)
Browse files Browse the repository at this point in the history
  • Loading branch information
dl239 authored Jan 16, 2024
1 parent 930d33b commit 1a29c06
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hybridse/src/case/sql_case.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ const std::string SqlCase::case_name() const {
}
bool SqlCase::ExtractInputTableDef(type::TableDef& table,
int32_t input_idx) const {
if (inputs_.size() <= input_idx) {
if (inputs_.size() <= static_cast<size_t>(input_idx)) {
return false;
}
return ExtractInputTableDef(inputs_[input_idx], table);
Expand Down
15 changes: 15 additions & 0 deletions src/cmd/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,21 @@ __attribute__((unused)) static void PrintProcedureInfo(
sql = boost::regex_replace(sql, boost::regex(pattern_sp), "DEPLOY");
std::string pattern_blank = "(.*)(\\(.*\\) )(BEGIN )(.*)( END;)";
sql = boost::regex_replace(sql, boost::regex(pattern_blank), "$1$4");
if (!sp_info.GetOption()->empty()) {
std::stringstream ss;
ss << " OPTIONS(";
for (auto iter = sp_info.GetOption()->begin(); iter != sp_info.GetOption()->end(); iter++) {
if (iter != sp_info.GetOption()->begin()) {
ss << ", ";
}
ss << absl::AsciiStrToUpper(iter->first) << "=\"" << iter->second << "\"";
}
ss << ")";
std::string prefix = absl::StrCat("DEPLOY ", sp_info.GetSpName());
absl::string_view old_sql = sql;
old_sql.remove_prefix(prefix.size());
sql = absl::StrCat(prefix, ss.str(), old_sql);
}
}

PrintItemTable({"DB", type_name}, {vec}, stream);
Expand Down
12 changes: 9 additions & 3 deletions src/sdk/sql_cluster_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,19 @@ TEST_F(SQLClusterDDLTest, TestShowAndDropDeployment) {

router->ExecuteSQL(db, "deploy " + deploy_name + " select col1 from " + table_name + ";", &status);
ASSERT_TRUE(status.IsOK());
router->ExecuteSQL(db2, "deploy " + deploy_name + " select col1 from " + db + "." + table_name + ";", &status);
std::string sql = absl::StrCat("deploy ", deploy_name,
" OPTIONS(RANGE_BIAS=\"inf\", ROWS_BIAS=\"inf\") select col1 from ", db, ".", table_name, ";");
router->ExecuteSQL(db2, sql, &status);
ASSERT_TRUE(status.IsOK());

router->ExecuteSQL(db, "show deployment " + deploy_name + ";", &status);
auto rs = router->ExecuteSQL(db, "show deployment " + deploy_name + ";", &status);
ASSERT_TRUE(status.IsOK());
router->ExecuteSQL(db, "show deployment " + db2 + "." + deploy_name + ";", &status);
ASSERT_TRUE(rs->Next());
ASSERT_TRUE(rs->GetStringUnsafe(0).find("OPTIONS") == std::string::npos);
rs = router->ExecuteSQL(db, "show deployment " + db2 + "." + deploy_name + ";", &status);
ASSERT_TRUE(status.IsOK());
ASSERT_TRUE(rs->Next());
ASSERT_TRUE(rs->GetStringUnsafe(0).find("OPTIONS(RANGE_BIAS=\"inf\", ROWS_BIAS=\"inf\")") != std::string::npos);

router->ExecuteSQL(db, "drop deployment " + deploy_name + ";", &status);
ASSERT_TRUE(status.IsOK());
Expand Down

0 comments on commit 1a29c06

Please sign in to comment.