Skip to content

Commit

Permalink
Show Function
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 2a6ebb0 commit afbd1b6
Show file tree
Hide file tree
Showing 13 changed files with 1,783 additions and 1,688 deletions.
18 changes: 18 additions & 0 deletions src/executor/explain_physical_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,24 @@ void ExplainPhysicalPlan::Explain(const PhysicalShow *show_node, SharedPtr<Vecto
result->emplace_back(MakeShared<String>(output_columns_str));
break;
}
case ShowType::kShowFunction: {
String show_str;
if (intent_size != 0) {
show_str = String(intent_size - 2, ' ');
show_str += "-> SHOW FUNCTION";
} else {
show_str = "SHOW FUNCTION";
}
show_str += "(";
show_str += std::to_string(show_node->node_id());
show_str += ")";
result->emplace_back(MakeShared<String>(show_str));

String output_columns_str = String(intent_size, ' ');
output_columns_str += " - output columns: [value]";
result->emplace_back(MakeShared<String>(output_columns_str));
break;
}
case ShowType::kInvalid: {
String error_message = "Invalid show type";
UnrecoverableError(error_message);
Expand Down
9 changes: 9 additions & 0 deletions src/main/infinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,15 @@ QueryResult Infinity::ShowMemoryAllocations() {
return result;
}

QueryResult Infinity::ShowFunction(const String& function_name) {
UniquePtr<QueryContext> query_context_ptr = GetQueryContext();
UniquePtr<ShowStatement> show_statement = MakeUnique<ShowStatement>();
show_statement->show_type_ = ShowStmtType::kFunction;
show_statement->function_name_ = function_name;
QueryResult result = query_context_ptr->QueryStatement(show_statement.get());
return result;
}

QueryResult Infinity::Insert(const String &db_name, const String &table_name, Vector<String> *columns, Vector<Vector<ParsedExpr *> *> *values) {
UniquePtr<QueryContext> query_context_ptr = GetQueryContext();
UniquePtr<InsertStatement> insert_statement = MakeUnique<InsertStatement>();
Expand Down
1 change: 1 addition & 0 deletions src/main/infinity.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public:
QueryResult ShowMemory();
QueryResult ShowMemoryObjects();
QueryResult ShowMemoryAllocations();
QueryResult ShowFunction(const String& function_name);

QueryResult Insert(const String &db_name, const String &table_name, Vector<String> *columns, Vector<Vector<ParsedExpr *> *> *values);

Expand Down
3,373 changes: 1,687 additions & 1,686 deletions src/parser/parser.cpp

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,12 @@ show_statement: SHOW DATABASES {
| SHOW MEMORY ALLOCATION {
$$ = new infinity::ShowStatement();
$$->show_type_ = infinity::ShowStmtType::kMemoryAllocation;
}
| SHOW IDENTIFIER '(' ')' {
$$ = new infinity::ShowStatement();
$$->show_type_ = infinity::ShowStmtType::kFunction;
$$->function_name_ = $2;
free($2);
};

/*
Expand Down
4 changes: 4 additions & 0 deletions src/parser/statement/show_statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ std::string ShowStatement::ToString() const {
ss << "Show memory allocation";
break;
}
case ShowStmtType::kFunction: {
ss << "Show function";
break;
}
}
return ss.str();
}
Expand Down
2 changes: 2 additions & 0 deletions src/parser/statement/show_statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum class ShowStmtType {
kMemory,
kMemoryObjects,
kMemoryAllocation,
kFunction
};

class ShowStatement : public BaseStatement {
Expand All @@ -71,6 +72,7 @@ class ShowStatement : public BaseStatement {
std::string table_name_{};
std::optional<std::string> index_name_{};
std::optional<std::string> file_name_{};
std::optional<std::string> function_name_{};
std::optional<int64_t> segment_id_{};
std::optional<int64_t> block_id_{};
std::optional<int64_t> chunk_id_{};
Expand Down
4 changes: 4 additions & 0 deletions src/planner/explain_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,10 @@ Status ExplainAST::BuildShow(const ShowStatement *show_statement, SharedPtr<Vect
result->emplace_back(MakeShared<String>("SHOW MEMORY ALLOCATION"));
break;
}
case ShowStmtType::kFunction: {
result->emplace_back(MakeShared<String>("SHOW FUNCTION"));
break;
}
}
return Status::OK();
}
Expand Down
18 changes: 18 additions & 0 deletions src/planner/explain_logical_plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,24 @@ Status ExplainLogicalPlan::Explain(const LogicalShow *show_node, SharedPtr<Vecto
result->emplace_back(MakeShared<String>(show_str));
break;
}
case ShowType::kShowFunction: {
String show_str;
if (intent_size != 0) {
show_str = String(intent_size - 2, ' ');
show_str += "-> SHOW FUNCTION";
} else {
show_str = "SHOW FUNCTION";
}
show_str += "(";
show_str += std::to_string(show_node->node_id());
show_str += ")";
result->emplace_back(MakeShared<String>(show_str));

String output_columns_str = String(intent_size, ' ');
output_columns_str += " - output columns: [value]";
result->emplace_back(MakeShared<String>(output_columns_str));
break;
}
case ShowType::kInvalid: {
String error_message = "Invalid show type";
UnrecoverableError(error_message);
Expand Down
22 changes: 22 additions & 0 deletions src/planner/logical_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,9 @@ Status LogicalPlanner::BuildShow(ShowStatement *statement, SharedPtr<BindContext
case ShowStmtType::kMemoryAllocation: {
return BuildShowMemoryAllocation(statement, bind_context_ptr);
}
case ShowStmtType::kFunction: {
return BuildShowFunction(statement, bind_context_ptr);
}
default: {
String error_message = "Unexpected show statement type.";
UnrecoverableError(error_message);
Expand Down Expand Up @@ -1801,6 +1804,25 @@ Status LogicalPlanner::BuildShowMemoryAllocation(const ShowStatement *statement,
return Status::OK();
}

Status LogicalPlanner::BuildShowFunction(const ShowStatement *statement, SharedPtr<BindContext> &bind_context_ptr) {
SharedPtr<LogicalNode> logical_show = MakeShared<LogicalShow>(bind_context_ptr->GetNewLogicalNodeId(),
ShowType::kShowFunction,
"",
"",
bind_context_ptr->GenerateTableIndex(),
None,
None,
None,
None,
None,
None,
None,
statement->function_name_);

this->logical_plan_ = logical_show;
return Status::OK();
}

Status LogicalPlanner::BuildFlush(const FlushStatement *statement, SharedPtr<BindContext> &bind_context_ptr) {
switch (statement->type()) {
case FlushType::kData: {
Expand Down
2 changes: 2 additions & 0 deletions src/planner/logical_planner.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public:

Status BuildShowMemoryAllocation(const ShowStatement *statement, SharedPtr<BindContext> &bind_context_ptr);

Status BuildShowFunction(const ShowStatement *statement, SharedPtr<BindContext> &bind_context_ptr);

// Flush
Status BuildFlush(const FlushStatement *statement, SharedPtr<BindContext> &bind_context_ptr);

Expand Down
2 changes: 2 additions & 0 deletions src/planner/node/logical_show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ String ToString(ShowType type) {
return "Show memory objects";
case ShowType::kShowMemoryAllocation:
return "Show memory allocation";
case ShowType::kShowFunction:
return "Show function";
case ShowType::kInvalid: {
String error_message = "Invalid chunk scan type";
UnrecoverableError(error_message);
Expand Down
10 changes: 8 additions & 2 deletions src/planner/node/logical_show.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export enum class ShowType {
kShowMemory,
kShowMemoryObjects,
kShowMemoryAllocation,
kShowFunction,
};

export String ToString(ShowType type);
Expand All @@ -81,9 +82,11 @@ public:
Optional<ColumnID> column_id = None,
Optional<String> index_name = None,
Optional<TransactionID> session_id = None,
Optional<u64> txn_id = None)
Optional<u64> txn_id = None,
Optional<String> function_name = None)
: LogicalNode(node_id, LogicalNodeType::kShow), show_type_(type), schema_name_(std::move(schema_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) {}
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), function_name_(function_name) {}

[[nodiscard]] Vector<ColumnBinding> GetColumnBindings() const final;

Expand Down Expand Up @@ -117,6 +120,8 @@ public:

[[nodiscard]] inline const Optional<String> index_name() const { return index_name_; }

[[nodiscard]] inline const Optional<String> function_name() const { return function_name_; }

private:
ShowType show_type_{ShowType::kInvalid};
String schema_name_;
Expand All @@ -130,6 +135,7 @@ private:
Optional<String> index_name_{};
Optional<u64> session_id_{};
Optional<TransactionID> txn_id_{};
Optional<String> function_name_{};
};

} // namespace infinity

0 comments on commit afbd1b6

Please sign in to comment.