Skip to content

Commit

Permalink
Merge pull request #111 from project-tsurugi/metadata
Browse files Browse the repository at this point in the history
implement metadata functionality
  • Loading branch information
t-horikawa authored Feb 26, 2025
2 parents b8182d1 + 162b48b commit b3b8367
Show file tree
Hide file tree
Showing 15 changed files with 883 additions and 109 deletions.
42 changes: 37 additions & 5 deletions include/ogawayama/stub/api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 Project Tsurugi.
* Copyright 2019-2025 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,8 @@
#include <ogawayama/stub/error_code.h>
#include <ogawayama/stub/transaction_option.h>
#include <ogawayama/stub/Command.h>
#include <ogawayama/stub/table_metadata.h>
#include <ogawayama/stub/table_list.h>

#include <manager/message/receiver.h>
#include <manager/message/message.h>
Expand Down Expand Up @@ -260,7 +262,9 @@ class Transaction {
} // namespace ogawayama::stub

using TransactionPtr = std::unique_ptr<ogawayama::stub::Transaction>;

using TableMetadataPtr = std::unique_ptr<ogawayama::stub::table_metadata>;
using TableListPtr = std::unique_ptr<ogawayama::stub::table_list>;
using SearchPathPtr = std::unique_ptr<ogawayama::stub::search_path>;

namespace ogawayama::stub {

Expand Down Expand Up @@ -289,62 +293,90 @@ class Connection : public manager::message::Receiver {
Connection& operator=(Connection&&) = delete;

/**
* @brief begin a transaction and get Transaction class.
* @brief request begin and get Transaction class.
* @param transaction returns a transaction class
* @return error code defined in error_code.h
*/
ErrorCode begin(TransactionPtr&);

/**
* @brief begin a transaction and get Transaction class.
* @brief request begin with transaction option and get Transaction class.
* @param ptree the transaction option
* @param transaction returns a transaction class
* @return error code defined in error_code.h
*/
ErrorCode begin(const boost::property_tree::ptree&, TransactionPtr&);

/**
* @brief prepare SQL statement.
* @brief request prepare and get PreparedStatement class.
* @param SQL statement
* @param prepared statement returns a prepared statement class
* @return error code defined in error_code.h
*/
ErrorCode prepare(std::string_view, const placeholders_type&, PreparedStatementPtr&);

/**
* @brief request table metadata and get TableMetadata class.
* @param table_name the table name
* @param table_metadata returns a table_metadata class
* @return error code defined in error_code.h
*/
ErrorCode get_table_metadata(const std::string& table_name, TableMetadataPtr& table_metadata);

/**
* @brief request list tables and get table_list class.
* @param table_list returns a table_list class
* @return error code defined in error_code.h
*/
ErrorCode get_list_tables(TableListPtr& table_list);

/**
* @brief request get search path and get search_path class.
* @param sp returns a search_path class
* @return error code defined in error_code.h
*/
ErrorCode get_search_path(SearchPathPtr& sp);

/**
* @brief implements begin_ddl() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
[[deprecated("No longer supports DDL operations for tsurugidb with this kind of API")]]
[[nodiscard]] manager::message::Status receive_begin_ddl(int64_t mode) const override;

/**
* @brief implements end_ddl() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
[[deprecated("No longer supports DDL operations for tsurugidb with this kind of API")]]
[[nodiscard]] manager::message::Status receive_end_ddl() const override;

/**
* @brief implements receive_create_table() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
[[deprecated("No longer supports DDL operations for tsurugidb with this kind of API")]]
[[nodiscard]] manager::message::Status receive_create_table(manager::metadata::ObjectIdType object_id) const override;

/**
* @brief implements drop_table() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
[[deprecated("No longer supports DDL operations for tsurugidb with this kind of API")]]
[[nodiscard]] manager::message::Status receive_drop_table(manager::metadata::ObjectIdType object_id) const override;

/**
* @brief implements receive_create_index() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
[[deprecated("No longer supports DDL operations for tsurugidb with this kind of API")]]
[[nodiscard]] manager::message::Status receive_create_index(manager::metadata::ObjectIdType object_id) const override;

/**
* @brief implements drop_index() procedure
* @return Status defined in message-broker/include/manager/message/status.h
*/
[[deprecated("No longer supports DDL operations for tsurugidb with this kind of API")]]
[[nodiscard]] manager::message::Status receive_drop_index(manager::metadata::ObjectIdType object_id) const override;

/**
Expand Down
42 changes: 42 additions & 0 deletions include/ogawayama/stub/search_path.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2019-2025 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <string>
#include <vector>

#include <jogasaki/proto/sql/response.pb.h>

namespace ogawayama::stub {

class search_path {
public:
/**
* @brief returns a list of the schema name
* @return a std::vector of the schema name
*/
[[nodiscard]] virtual const std::vector<std::string>& get_schema_names() const = 0;

search_path() = default;
virtual ~search_path() = default;

constexpr search_path(search_path const&) = delete;
constexpr search_path(search_path&&) = delete;
search_path& operator = (search_path const&) = delete;
search_path& operator = (search_path&&) = delete;
};

} // namespace ogawayama::stub
52 changes: 52 additions & 0 deletions include/ogawayama/stub/table_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2019-2025 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <string>
#include <vector>
#include <sstream>

#include <jogasaki/proto/sql/response.pb.h>

#include "search_path.h"

namespace ogawayama::stub {

class table_list {
public:
/**
* @brief returns a list of the available table names in the database, except system tables
* @return a list of the available table names
*/
[[nodiscard]] virtual std::vector<std::string> get_table_names() const = 0;

/**
* @brief returns the schema name where the table defined
* @param sp the search path
* @return a std::vector of simple_names
*/
[[nodiscard]] virtual std::vector<std::string> get_simple_names(search_path& sp) const = 0;

table_list() = default;
virtual ~table_list() = default;

constexpr table_list(table_list const&) = delete;
constexpr table_list(table_list&&) = delete;
table_list& operator = (table_list const&) = delete;
table_list& operator = (table_list&&) = delete;
};

} // namespace ogawayama::stub
62 changes: 62 additions & 0 deletions include/ogawayama/stub/table_metadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2019-2025 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <string>
#include <optional>

#include <jogasaki/proto/sql/response.pb.h>

namespace ogawayama::stub {

class table_metadata {
public:
/**
* @brief returns the database name where the table defined
* @return the database name, or empty if it is not set
* @attention this method is not yet implemented
*/
[[nodiscard]] virtual std::optional<std::string> database_name() const = 0;

/**
* @brief returns the schema name where the table defined
* @return the schema name, or empty if it is not set
* @attention this method is not yet implemented
*/
[[nodiscard]] virtual std::optional<std::string> schema_name() const = 0;

/**
* @brief returns simple name of the table
* @return the simple name
*/
[[nodiscard]] virtual const std::string& table_name() const = 0;

/**
* @brief returns the column information of the relation
* @return the column descriptor list
*/
[[nodiscard]] virtual ::google::protobuf::RepeatedPtrField<jogasaki::proto::sql::common::Column> columns() const = 0;

table_metadata() = default;
virtual ~table_metadata() = default;

constexpr table_metadata(table_metadata const&) = delete;
constexpr table_metadata(table_metadata&&) = delete;
table_metadata& operator = (table_metadata const&) = delete;
table_metadata& operator = (table_metadata&&) = delete;
};

} // namespace ogawayama::stub
Loading

0 comments on commit b3b8367

Please sign in to comment.