Skip to content

Commit

Permalink
Refactor show
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Hai <[email protected]>
  • Loading branch information
JinHai-CN committed Oct 10, 2024
1 parent 50681c7 commit 1887f18
Show file tree
Hide file tree
Showing 7 changed files with 335 additions and 617 deletions.
4 changes: 2 additions & 2 deletions src/executor/explain_physical_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ void ExplainPhysicalPlan::Explain(const PhysicalShow *show_node, SharedPtr<Vecto
result->emplace_back(MakeShared<String>(show_column_db_str));

String show_column_table_str = String(intent_size, ' ') + " - table/collection: ";
show_column_table_str += show_node->object_name();
show_column_table_str += *(show_node->object_name());
result->emplace_back(MakeShared<String>(show_column_table_str));

String output_columns_str = String(intent_size, ' ') + " - output columns: [column_name, column_type, constraint]";
Expand All @@ -1324,7 +1324,7 @@ void ExplainPhysicalPlan::Explain(const PhysicalShow *show_node, SharedPtr<Vecto
result->emplace_back(MakeShared<String>(show_column_db_str));

String show_column_table_str = String(intent_size, ' ') + " - table/collection: ";
show_column_table_str += show_node->object_name();
show_column_table_str += *(show_node->object_name());
result->emplace_back(MakeShared<String>(show_column_table_str));

String output_columns_str = String(intent_size, ' ') + " - output columns: [index_name, method_type, column_names, other_parameters]";
Expand Down
48 changes: 24 additions & 24 deletions src/executor/operator/physical_show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ void PhysicalShow::ExecuteShowTable(QueryContext *query_context, ShowOperatorSta
// Get tables from catalog
Txn *txn = query_context->GetTxn();

auto [table_info, status] = txn->GetTableInfo(db_name_, object_name_);
auto [table_info, status] = txn->GetTableInfo(db_name_, *object_name_);

if (!status.ok()) {
RecoverableError(status);
Expand Down Expand Up @@ -935,7 +935,7 @@ void PhysicalShow::ExecuteShowIndex(QueryContext *query_context, ShowOperatorSta
// Get tables from catalog
Txn *txn = query_context->GetTxn();

auto [table_index_info, status] = txn->GetTableIndexInfo(db_name_, object_name_, index_name_.value());
auto [table_index_info, status] = txn->GetTableIndexInfo(db_name_, *object_name_, index_name_.value());

if (!status.ok()) {
RecoverableError(status);
Expand Down Expand Up @@ -974,7 +974,7 @@ void PhysicalShow::ExecuteShowIndex(QueryContext *query_context, ShowOperatorSta

++column_id;
{
Value value = Value::MakeVarchar(object_name_);
Value value = Value::MakeVarchar(*object_name_);
ValueExpression value_expr(value);
value_expr.AppendToChunk(output_block_ptr->column_vectors[column_id]);
}
Expand Down Expand Up @@ -1126,13 +1126,13 @@ void PhysicalShow::ExecuteShowIndexSegment(QueryContext *query_context, ShowOper
// Get tables from catalog
Txn *txn = query_context->GetTxn();

auto [table_entry, status1] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, status1] = txn->GetTableByName(db_name_, *object_name_);
if (!status1.ok()) {
RecoverableError(status1);
return;
}

auto [table_index_entry, status2] = txn->GetIndexByName(db_name_, object_name_, index_name_.value());
auto [table_index_entry, status2] = txn->GetIndexByName(db_name_, *object_name_, index_name_.value());
if (!status2.ok()) {
RecoverableError(status2);
return;
Expand Down Expand Up @@ -1266,13 +1266,13 @@ void PhysicalShow::ExecuteShowIndexChunk(QueryContext *query_context, ShowOperat
// Get tables from catalog
Txn *txn = query_context->GetTxn();

auto [table_entry, status1] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, status1] = txn->GetTableByName(db_name_, *object_name_);
if (!status1.ok()) {
RecoverableError(status1);
return;
}

auto [table_index_entry, status2] = txn->GetIndexByName(db_name_, object_name_, index_name_.value());
auto [table_index_entry, status2] = txn->GetIndexByName(db_name_, *object_name_, index_name_.value());
if (!status2.ok()) {
RecoverableError(status2);
return;
Expand Down Expand Up @@ -1778,7 +1778,7 @@ void PhysicalShow::ExecuteShowProfiles(QueryContext *query_context, ShowOperator
void PhysicalShow::ExecuteShowColumns(QueryContext *query_context, ShowOperatorState *show_operator_state) {
auto txn = query_context->GetTxn();

auto [table_entry, status] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, status] = txn->GetTableByName(db_name_, *object_name_);
if (!status.ok()) {
show_operator_state->status_ = status.clone();
RecoverableError(status);
Expand Down Expand Up @@ -1872,7 +1872,7 @@ void PhysicalShow::ExecuteShowColumns(QueryContext *query_context, ShowOperatorS
void PhysicalShow::ExecuteShowSegments(QueryContext *query_context, ShowOperatorState *show_operator_state) {
auto txn = query_context->GetTxn();

auto [table_entry, status] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, status] = txn->GetTableByName(db_name_, *object_name_);
if (!status.ok()) {
show_operator_state->status_ = status.clone();
RecoverableError(status);
Expand Down Expand Up @@ -1937,7 +1937,7 @@ void PhysicalShow::ExecuteShowSegmentDetail(QueryContext *query_context, ShowOpe
auto txn = query_context->GetTxn();
TxnTimeStamp begin_ts = txn->BeginTS();

auto [table_entry, status] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, status] = txn->GetTableByName(db_name_, *object_name_);
if (!status.ok()) {
show_operator_state->status_ = status.clone();
RecoverableError(status);
Expand Down Expand Up @@ -2047,7 +2047,7 @@ void PhysicalShow::ExecuteShowBlocks(QueryContext *query_context, ShowOperatorSt
auto txn = query_context->GetTxn();
TxnTimeStamp begin_ts = txn->BeginTS();

auto [table_entry, status] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, status] = txn->GetTableByName(db_name_, *object_name_);
if (!status.ok()) {
show_operator_state->status_ = status.clone();
RecoverableError(status);
Expand Down Expand Up @@ -2119,7 +2119,7 @@ void PhysicalShow::ExecuteShowBlockDetail(QueryContext *query_context, ShowOpera
auto txn = query_context->GetTxn();
TxnTimeStamp begin_ts = txn->BeginTS();

auto [table_entry, status] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, status] = txn->GetTableByName(db_name_, *object_name_);
if (!status.ok()) {
show_operator_state->status_ = status.clone();
RecoverableError(status);
Expand Down Expand Up @@ -2213,7 +2213,7 @@ void PhysicalShow::ExecuteShowBlockColumn(QueryContext *query_context, ShowOpera
auto txn = query_context->GetTxn();
TxnTimeStamp begin_ts = txn->BeginTS();

auto [table_entry, status] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, status] = txn->GetTableByName(db_name_, *object_name_);
if (!status.ok()) {
show_operator_state->status_ = status.clone();
RecoverableError(status);
Expand Down Expand Up @@ -3125,7 +3125,7 @@ void PhysicalShow::ExecuteShowConfigs(QueryContext *query_context, ShowOperatorS
void PhysicalShow::ExecuteShowIndexes(QueryContext *query_context, ShowOperatorState *show_operator_state) {
auto txn = query_context->GetTxn();

auto [table_entry, table_status] = txn->GetTableByName(db_name_, object_name_);
auto [table_entry, table_status] = txn->GetTableByName(db_name_, *object_name_);
if (!table_status.ok()) {
show_operator_state->status_ = table_status;
// Error<UnrecoverableException>(table_status.message());
Expand Down Expand Up @@ -3294,7 +3294,7 @@ void PhysicalShow::ExecuteShowSessionVariable(QueryContext *query_context, ShowO
SharedPtr<DataType> bool_type = MakeShared<DataType>(LogicalType::kBoolean);
UniquePtr<DataBlock> output_block_ptr = DataBlock::MakeUniquePtr();

SessionVariable session_var = VarUtil::GetSessionVarByName(object_name_);
SessionVariable session_var = VarUtil::GetSessionVarByName(*object_name_);
BaseSession *session_ptr = query_context->current_session();
switch (session_var) {
case SessionVariable::kQueryCount: {
Expand Down Expand Up @@ -3393,7 +3393,7 @@ void PhysicalShow::ExecuteShowSessionVariable(QueryContext *query_context, ShowO
break;
}
default: {
operator_state->status_ = Status::NoSysVar(object_name_);
operator_state->status_ = Status::NoSysVar(*object_name_);
RecoverableError(operator_state->status_);
return;
}
Expand Down Expand Up @@ -3556,7 +3556,7 @@ void PhysicalShow::ExecuteShowGlobalVariable(QueryContext *query_context, ShowOp
SharedPtr<DataType> bool_type = MakeShared<DataType>(LogicalType::kBoolean);
UniquePtr<DataBlock> output_block_ptr = DataBlock::MakeUniquePtr();

GlobalVariable global_var = VarUtil::GetGlobalVarByName(object_name_);
GlobalVariable global_var = VarUtil::GetGlobalVarByName(*object_name_);
switch (global_var) {
case GlobalVariable::kQueryCount: {
Vector<SharedPtr<ColumnDef>> output_column_defs = {
Expand Down Expand Up @@ -4010,7 +4010,7 @@ void PhysicalShow::ExecuteShowGlobalVariable(QueryContext *query_context, ShowOp
break;
}
default: {
operator_state->status_ = Status::NoSysVar(object_name_);
operator_state->status_ = Status::NoSysVar(*object_name_);
RecoverableError(operator_state->status_);
return;
}
Expand Down Expand Up @@ -4561,13 +4561,13 @@ void PhysicalShow::ExecuteShowGlobalVariables(QueryContext *query_context, ShowO

void PhysicalShow::ExecuteShowConfig(QueryContext *query_context, ShowOperatorState *operator_state) {
Config *global_config = query_context->global_config();
auto [base_option, status] = global_config->GetConfigByName(object_name_);
auto [base_option, status] = global_config->GetConfigByName(*object_name_);
if (!status.ok()) {
operator_state->status_ = status;
return;
}
if (object_name_ == "time_zone_bias") {
operator_state->status_ = Status::InvalidConfig(fmt::format("Option: {} doesn't exist.", object_name_));
if (*object_name_ == "time_zone_bias") {
operator_state->status_ = Status::InvalidConfig(fmt::format("Option: {} doesn't exist.", *object_name_));
return;
}

Expand Down Expand Up @@ -4610,7 +4610,7 @@ void PhysicalShow::ExecuteShowConfig(QueryContext *query_context, ShowOperatorSt

StringOption *string_option = static_cast<StringOption *>(base_option);
String value_str;
if (object_name_ == "time_zone") {
if (*object_name_ == "time_zone") {
auto [time_zone_bias, _] = global_config->GetConfigByName("time_zone_bias");

IntegerOption *time_zone_bias_int = static_cast<IntegerOption *>(time_zone_bias);
Expand Down Expand Up @@ -5589,9 +5589,9 @@ void PhysicalShow::ExecuteShowPersistenceObject(QueryContext *query_context, Sho
}

HashMap<String, ObjStat> object_map = persistence_manager->GetAllObjects();
auto iter = object_map.find(object_name_);
auto iter = object_map.find(*object_name_);
if(iter == object_map.end()) {
Status status = Status::FileNotFound(object_name_);
Status status = Status::FileNotFound(*object_name_);
RecoverableError(status);
}

Expand Down
12 changes: 6 additions & 6 deletions src/executor/operator/physical_show.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public:
explicit PhysicalShow(u64 id,
ShowStmtType type,
String db_name,
String object_name,
Optional<String> object_name,
u64 table_index,
Optional<SegmentID> segment_id,
Optional<BlockID> block_id,
Expand All @@ -52,8 +52,8 @@ public:
Optional<TransactionID> txn_id,
SharedPtr<Vector<LoadMeta>> load_metas)
: PhysicalOperator(PhysicalOperatorType::kShow, nullptr, nullptr, id, load_metas), show_type_(type), db_name_(std::move(db_name)),
object_name_(std::move(object_name)), table_index_(table_index), segment_id_(segment_id), block_id_(block_id), chunk_id_(chunk_id), column_id_(column_id),
index_name_(index_name), session_id_(session_id), txn_id_(txn_id) {}
object_name_(std::move(object_name)), table_index_(table_index), segment_id_(segment_id), block_id_(block_id), chunk_id_(chunk_id),
column_id_(column_id), index_name_(index_name), session_id_(session_id), txn_id_(txn_id) {}

~PhysicalShow() override = default;

Expand All @@ -75,7 +75,7 @@ public:

inline const String &db_name() const { return db_name_; };

inline const String &object_name() const { return object_name_; };
inline const Optional<String> object_name() const { return object_name_; };

private:
void ExecuteShowViewDetail(QueryContext *query_context,
Expand Down Expand Up @@ -127,7 +127,7 @@ private:
void ExecuteShowConfig(QueryContext *query_context, ShowOperatorState *operator_state);

void ExecuteShowBuffer(QueryContext *query_context, ShowOperatorState *operator_state);

void ExecuteShowMemIndex(QueryContext *query_context, ShowOperatorState *operator_state);

void ExecuteShowQueries(QueryContext *query_context, ShowOperatorState *operator_state);
Expand Down Expand Up @@ -159,7 +159,7 @@ private:
private:
ShowStmtType show_type_{ShowStmtType::kInvalid};
String db_name_{};
String object_name_{};
Optional<String> object_name_{};
u64 table_index_{};

Optional<SegmentID> segment_id_{};
Expand Down
22 changes: 11 additions & 11 deletions src/planner/explain_logical_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,10 +1335,10 @@ Status ExplainLogicalPlan::Explain(const LogicalShow *show_node, SharedPtr<Vecto
case ShowStmtType::kIndexSegment: {
String show_str;
if (intent_size != 0) {
show_str = String(intent_size - 2, ' ');
show_str += "-> SHOW INDEX SEGMENT ";
show_str = String(intent_size - 2, ' ');
show_str += "-> SHOW INDEX SEGMENT ";
} else {
show_str = "SHOW INDEX SEGMENT ";
show_str = "SHOW INDEX SEGMENT ";
}
show_str += "(";
show_str += std::to_string(show_node->node_id());
Expand All @@ -1353,10 +1353,10 @@ Status ExplainLogicalPlan::Explain(const LogicalShow *show_node, SharedPtr<Vecto
case ShowStmtType::kIndexChunk: {
String show_str;
if (intent_size != 0) {
show_str = String(intent_size - 2, ' ');
show_str += "-> SHOW INDEX CHUNK ";
show_str = String(intent_size - 2, ' ');
show_str += "-> SHOW INDEX CHUNK ";
} else {
show_str = "SHOW INDEX CHUNK ";
show_str = "SHOW INDEX CHUNK ";
}
show_str += "(";
show_str += std::to_string(show_node->node_id());
Expand Down Expand Up @@ -1424,7 +1424,7 @@ Status ExplainLogicalPlan::Explain(const LogicalShow *show_node, SharedPtr<Vecto

String show_column_table_str = String(intent_size, ' ');
show_column_table_str += " - table/collection: ";
show_column_table_str += show_node->object_name();
show_column_table_str += *(show_node->object_name());
result->emplace_back(MakeShared<String>(show_column_table_str));

String output_columns_str = String(intent_size, ' ');
Expand Down Expand Up @@ -1756,7 +1756,7 @@ Status ExplainLogicalPlan::Explain(const LogicalShow *show_node, SharedPtr<Vecto
result->emplace_back(MakeShared<String>(show_str));

String output_columns_str = String(intent_size, ' ');
output_columns_str += fmt::format(" - variable: {}", show_node->object_name());
output_columns_str += fmt::format(" - variable: {}", *(show_node->object_name()));
result->emplace_back(MakeShared<String>(output_columns_str));
break;
}
Expand Down Expand Up @@ -1788,7 +1788,7 @@ Status ExplainLogicalPlan::Explain(const LogicalShow *show_node, SharedPtr<Vecto
result->emplace_back(MakeShared<String>(show_str));

String output_columns_str = String(intent_size, ' ');
output_columns_str += fmt::format(" - variable: {}", show_node->object_name());
output_columns_str += fmt::format(" - variable: {}", *(show_node->object_name()));
result->emplace_back(MakeShared<String>(output_columns_str));
break;
}
Expand Down Expand Up @@ -1820,7 +1820,7 @@ Status ExplainLogicalPlan::Explain(const LogicalShow *show_node, SharedPtr<Vecto
result->emplace_back(MakeShared<String>(show_str));

String output_columns_str = String(intent_size, ' ');
output_columns_str += fmt::format(" - config: {}", show_node->object_name());
output_columns_str += fmt::format(" - config: {}", *(show_node->object_name()));
result->emplace_back(MakeShared<String>(output_columns_str));
break;
}
Expand Down Expand Up @@ -2287,7 +2287,7 @@ Status ExplainLogicalPlan::Explain(const LogicalExport *export_node, SharedPtr<V
result->emplace_back(file_type);
break;
}
case CopyFileType::kPARQUET : {
case CopyFileType::kPARQUET: {
SharedPtr<String> file_type = MakeShared<String>(fmt::format("{} - type: PARQUET", String(intent_size, ' ')));
result->emplace_back(file_type);
break;
Expand Down
Loading

0 comments on commit 1887f18

Please sign in to comment.