You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by sp...@apache.org on 2016/12/11 17:46:10 UTC
[47/51] [abbrv] [partial] incubator-quickstep git commit: remove c++
files
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogDatabase.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogDatabase.hpp b/catalog/CatalogDatabase.hpp
deleted file mode 100644
index a0804a2..0000000
--- a/catalog/CatalogDatabase.hpp
+++ /dev/null
@@ -1,468 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#ifndef QUICKSTEP_CATALOG_CATALOG_DATABASE_HPP_
-#define QUICKSTEP_CATALOG_CATALOG_DATABASE_HPP_
-
-#include <exception>
-#include <string>
-#include <unordered_map>
-
-#include "catalog/Catalog.pb.h"
-#include "catalog/CatalogDatabaseLite.hpp"
-#include "catalog/CatalogRelation.hpp"
-#include "catalog/CatalogTypedefs.hpp"
-#include "storage/StorageConstants.hpp"
-#include "threading/Mutex.hpp"
-#include "threading/SharedMutex.hpp"
-#include "threading/SpinSharedMutex.hpp"
-#include "utility/Macros.hpp"
-#include "utility/PtrVector.hpp"
-#include "utility/StringUtil.hpp"
-
-#include "glog/logging.h"
-
-namespace quickstep {
-
-class Catalog;
-class CatalogRelationSchema;
-
-/** \addtogroup Catalog
- * @{
- */
-
-/**
- * @brief Exception thrown for a relation name collision.
- **/
-class RelationNameCollision : public std::exception {
- public:
- /**
- * @brief Constructor.
- *
- * @param db_name Name of the database in which the collision occurred.
- * @param rel_name Name of the relation for which there was a collision.
- **/
- RelationNameCollision(const std::string &db_name, const std::string &rel_name)
- : message_("RelationNameCollision: database ") {
- message_.append(db_name);
- message_.append(" already has a relation ");
- message_.append(rel_name);
- }
-
- ~RelationNameCollision() throw() {
- }
-
- virtual const char* what() const throw() {
- return message_.c_str();
- }
-
- private:
- std::string message_;
-};
-
-/**
- * @brief Exception thrown when a relation with the specified name can't be
- * found.
- **/
-class RelationNameNotFound : public std::exception {
- public:
- /**
- * @brief Constructor.
- *
- * @param db_name Name of the database in which the exception occurred.
- * @param rel_name The relation name which could not be found.
- **/
- RelationNameNotFound(const std::string &db_name, const std::string &rel_name)
- : message_("RelationNameNotFound: database ") {
- message_.append(db_name);
- message_.append(" has no relation named ");
- message_.append(rel_name);
- }
-
- ~RelationNameNotFound() throw() {
- }
-
- virtual const char* what() const throw() {
- return message_.c_str();
- }
-
- private:
- std::string message_;
-};
-
-/**
- * @brief Exception thrown when a relation with the specified ID can't be found.
- **/
-class RelationIdNotFound : public std::exception {
- public:
- /**
- * @brief Constructor
- *
- * @param db_name Name of the database in which the exception occurred.
- * @param id The relation ID which could not be found.
- **/
- RelationIdNotFound(const std::string &db_name, const relation_id id)
- : message_("RelationIdNotFound: database ") {
- message_.append(db_name);
- message_.append(" has no relation with ID ");
- message_.append(std::to_string(id));
- }
-
- ~RelationIdNotFound() throw() {
- }
-
- virtual const char* what() const throw() {
- return message_.c_str();
- }
-
- private:
- std::string message_;
-};
-
-/**
- * @brief A single database in the catalog.
- **/
-class CatalogDatabase : public CatalogDatabaseLite {
- public:
- typedef std::unordered_map<std::string, CatalogRelation*>::size_type size_type;
- typedef PtrVector<CatalogRelation, true>::const_skip_iterator const_iterator;
-
- enum class Status {
- kConsistent = 0,
- kPendingBlockDeletions
- };
-
- /**
- * @brief Create a new database.
- *
- * @param parent The catalog this database belongs to.
- * @param name This database's name.
- * @param id This database's ID (defaults to -1, which means invalid/unset).
- **/
- CatalogDatabase(Catalog *parent, const std::string &name, const database_id id = -1)
- : CatalogDatabaseLite(id),
- parent_(parent),
- name_(name),
- status_(Status::kConsistent) {
- }
-
- /**
- * @brief Reconstruct a database from its serialized Protocol Buffer form.
- *
- * @param proto The Protocol Buffer serialization of a database, previously
- * produced by getProto().
- **/
- explicit CatalogDatabase(const serialization::CatalogDatabase &proto);
-
- /**
- * @brief Check whether a serialization::CatalogDatabase is fully-formed and
- * all parts are valid.
- *
- * @param proto A serialized Protocol Buffer representation of a CatalogDatabase,
- * originally generated by getProto().
- * @return Whether proto is fully-formed and valid.
- **/
- static bool ProtoIsValid(const serialization::CatalogDatabase &proto);
-
- /**
- * @brief Destructor which recursively destroys children.
- **/
- ~CatalogDatabase() override {
- }
-
- bool hasRelationWithId(const relation_id id) const override {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- return hasRelationWithIdUnsafe(id);
- }
-
- const CatalogRelationSchema& getRelationSchemaById(const relation_id id) const override {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- DCHECK(hasRelationWithIdUnsafe(id));
- return rel_vec_[id];
- }
-
- /**
- * @exception RelationIdNotFound No relation with the given ID exists.
- **/
- void dropRelationById(const relation_id id) override;
-
- /**
- * @brief Get the parent catalog.
- *
- * @return Parent catalog.
- **/
- const Catalog& getParent() const {
- return *DCHECK_NOTNULL(parent_);
- }
-
- /**
- * @brief Get a mutable pointer to the parent catalog.
- *
- * @return Parent catalog.
- **/
- Catalog* getParentMutable() {
- return parent_;
- }
-
- /**
- * @brief Get this database's name.
- *
- * @return This database's name.
- **/
- const std::string& getName() const {
- return name_;
- }
-
- /**
- * @brief Get this database's status.
- *
- * @return This database's status.
- **/
- Status status() const {
- SpinSharedMutexSharedLock<false> lock(status_mutex_);
- return status_;
- }
-
- /**
- * @brief Whether this database is consistent.
- *
- * @return True if it is consistent. Otherwise, false.
- **/
- bool isStatusConsistent() const {
- SpinSharedMutexSharedLock<false> lock(status_mutex_);
- return status_ == Status::kConsistent;
- }
-
- /**
- * @brief Set this database's status.
- *
- * @param status The status to set.
- **/
- void setStatus(const Status status) {
- SpinSharedMutexExclusiveLock<false> lock(status_mutex_);
- status_ = status;
- }
-
- /**
- * @brief Check whether a relation with the given name exists. The search is case-insensitive.
- *
- * @param rel_name The name to check for.
- * @return Whether the relation exists.
- **/
- bool hasRelationWithName(const std::string &rel_name) const {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- return hasRelationWithNameUnsafe(rel_name);
- }
-
- /**
- * @brief Get a relation by name. The search is case-insensitive.
- *
- * @param rel_name The name to search for.
- * @return The relation with the given name. NULL if the relation is not found.
- **/
- const CatalogRelation* getRelationByName(const std::string &rel_name) const;
-
- /**
- * @brief Get a mutable pointer to a relation by name. The search is case-insensitive.
- *
- * @param rel_name The name to search for.
- * @return The relation with the given name. NULL if the relation is not found.
- **/
- CatalogRelation* getRelationByNameMutable(const std::string &rel_name);
-
- /**
- * @brief Get a relation by ID.
- *
- * @param id The id to search for.
- * @return The relation with the given ID.
- **/
- const CatalogRelation* getRelationById(const relation_id id) const {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- if (hasRelationWithIdUnsafe(id)) {
- return &rel_vec_[id];
- } else {
- return nullptr;
- }
- }
-
- /**
- * @brief Get a mutable pointer to a relation by ID.
- *
- * @param id The id to search for.
- * @return The relation with the given ID.
- **/
- CatalogRelation* getRelationByIdMutable(const relation_id id) {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- if (hasRelationWithIdUnsafe(id)) {
- return &(rel_vec_[id]);
- } else {
- return nullptr;
- }
- }
-
- /**
- * @brief Add a new relation to the database. If the relation already has an
- * ID and/or parent, it will be overwritten.
- *
- * @param new_rel The relation to be added.
- * @exception RelationNameCollision A relation with the same name as new_rel
- * is already present in the database.
- * @return The id assigned to the relation.
- **/
- relation_id addRelation(CatalogRelation *new_rel);
-
- /**
- * @brief Drop (delete) a relation by name.
- *
- * @param rel_name The name of the relation to drop.
- * @exception RelationNameNotFound No relation with the given name exists.
- **/
- void dropRelationByName(const std::string &rel_name);
-
- /**
- * @brief Serialize the database as Protocol Buffer.
- *
- * @return The Protocol Buffer representation of the database.
- **/
- serialization::CatalogDatabase getProto() const;
-
- /**
- * @brief Get the number of child relations.
- *
- * @return The number of child relations.
- **/
- size_type size() const {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- return rel_map_.size();
- }
-
- /**
- * @brief Get an iterator at the beginning of the child relations.
- *
- * @return An iterator on the first child relation.
- **/
- const_iterator begin() const {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- return rel_vec_.begin_skip();
- }
-
- /**
- * @brief Get an iterator at one-past-the-end of the child relations.
- *
- * @return An iterator one-past-the-end of the child relations.
- **/
- const_iterator end() const {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- return rel_vec_.end_skip();
- }
-
- private:
- /**
- * @brief Set the parent Catalog of this database. Used by Catalog (a friend
- * of this class) when adding a new database.
- *
- * @param parent The new parent for this CatalogDatabase.
- **/
- void setParent(Catalog *parent) {
- parent_ = parent;
- }
-
- /**
- * @brief Set the ID of this database. Used by Catalog (a friend of this
- * class) when adding a new database.
- *
- * @param id The new ID for this CatalogDatabase.
- **/
- void setID(const database_id id) {
- id_ = id;
- }
-
- /**
- * @brief Check whether a relation_id is within the range of IDs contained
- * in this CatalogDatabase.
- *
- * @param id The id to check.
- * @return true if id is in range, false otherwise.
- *
- * @note The caller of this function should make it sure that it holds at
- * least a shared lock before calling this function.
- *
- **/
- bool idInRange(const relation_id id) const {
- return ((id >= 0)
- && (static_cast<PtrVector<CatalogRelation>::size_type>(id) < rel_vec_.size()));
- }
-
- /**
- * @brief Check whether a relation with the given name exists. The search is case-insensitive.
- *
- * @note This method assumes that the caller has already acquired the
- * necessary locks before invoking it.
- *
- * @param rel_name The name to check for.
- * @return Whether the relation exists.
- **/
- inline bool hasRelationWithNameUnsafe(const std::string &rel_name) const {
- return (rel_map_.find(ToLower(rel_name)) != rel_map_.end());
- }
-
- /**
- * @brief Check whether a relation with the given id exists.
- *
- * @note This method assumes that the caller has already acquired the
- * necessary locks before invoking it.
- *
- * @param id The id to check for.
- * @return Whether the relation exists.
- **/
- inline bool hasRelationWithIdUnsafe(const relation_id id) const {
- return (idInRange(id) && !rel_vec_.elementIsNull(id));
- }
-
- Catalog *parent_;
-
- // The database name.
- const std::string name_;
-
- // Indicate the status of this database (i.e., consistent or not).
- Status status_;
- alignas(kCacheLineBytes) mutable SpinSharedMutex<false> status_mutex_;
-
- // A vector of relations. NULL if the relation has dropped from the database.
- PtrVector<CatalogRelation, true> rel_vec_;
-
- /**
- * @brief Map from relation name to the pointer to the corresponding relation.
- * The relation name stored in the map is in lowercase characters.
- */
- std::unordered_map<std::string, CatalogRelation*> rel_map_;
-
- // Concurrency protection for 'rel_vec_' and 'rel_map_'.
- alignas(kCacheLineBytes) mutable SpinSharedMutex<false> relations_mutex_;
-
- friend class Catalog;
-
- DISALLOW_COPY_AND_ASSIGN(CatalogDatabase);
-};
-
-/** @} */
-
-} // namespace quickstep
-
-#endif // QUICKSTEP_CATALOG_CATALOG_DATABASE_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogDatabaseCache.cpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogDatabaseCache.cpp b/catalog/CatalogDatabaseCache.cpp
deleted file mode 100644
index 7f7c495..0000000
--- a/catalog/CatalogDatabaseCache.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#include "catalog/CatalogDatabaseCache.hpp"
-
-#include <memory>
-#include <unordered_map>
-#include <utility>
-#include <vector>
-
-#include "catalog/Catalog.pb.h"
-#include "catalog/CatalogRelationSchema.hpp"
-#include "catalog/CatalogTypedefs.hpp"
-#include "threading/Mutex.hpp"
-#include "threading/SpinSharedMutex.hpp"
-
-#include "glog/logging.h"
-
-using std::make_unique;
-using std::move;
-using std::vector;
-
-namespace quickstep {
-
-bool CatalogDatabaseCache::ProtoIsValid(const serialization::CatalogDatabase &proto) {
- for (int i = 0; i < proto.relations_size(); ++i) {
- if (!CatalogRelationSchema::ProtoIsValid(proto.relations(i))) {
- return false;
- }
- }
-
- return proto.null_relations_size() == 0;
-}
-
-CatalogDatabaseCache::CatalogDatabaseCache(const serialization::CatalogDatabase &proto) {
- DCHECK(ProtoIsValid(proto))
- << "Attempted to create CatalogDatabaseCache from an invalid proto description:\n"
- << proto.DebugString();
-
- for (int i = 0; i < proto.relations_size(); ++i) {
- auto relation_schema = make_unique<const CatalogRelationSchema>(proto.relations(i));
- rel_map_.emplace(relation_schema->getID(), move(relation_schema));
- }
-}
-
-void CatalogDatabaseCache::update(const serialization::CatalogDatabase &proto) {
- DCHECK(ProtoIsValid(proto))
- << "Attempted to create CatalogDatabaseCache from an invalid proto description:\n"
- << proto.DebugString();
-
- vector<int> new_relation_schema_proto_indices;
- {
- SpinSharedMutexSharedLock<false> read_lock(relations_mutex_);
- for (int i = 0; i < proto.relations_size(); ++i) {
- const auto it = rel_map_.find(proto.relations(i).relation_id());
- if (it == rel_map_.end()) {
- new_relation_schema_proto_indices.push_back(i);
- } else {
- // TODO(quickstep-team): Support schema changes by adding the index of
- // changed schema proto in 'changed_relation_schema_proto_indices'.
- }
- }
- }
-
- SpinSharedMutexExclusiveLock<false> write_lock(relations_mutex_);
- for (const int i : new_relation_schema_proto_indices) {
- const serialization::CatalogRelationSchema &proto_relation = proto.relations(i);
- auto relation_schema = make_unique<const CatalogRelationSchema>(proto_relation);
- rel_map_.emplace(proto_relation.relation_id(), move(relation_schema));
- }
-
- // TODO(quickstep-team): Reset the schema for the changes in the following
- // steps for each index in 'changed_relation_schema_proto_indices':
- // 1. Drop the blocks belonged to 'proto.relations(i).relation_id()' in the
- // buffer pool.
- // 2. Reset the changed schema, while the scheduler ensures no queries will
- // load back the related blocks.
- // 3. Signal the scheduler to accept new queries for the changed schema.
-}
-
-void CatalogDatabaseCache::dropRelationById(const relation_id id) {
- SpinSharedMutexExclusiveLock<false> lock(relations_mutex_);
- auto it = rel_map_.find(id);
- if (it != rel_map_.end()) {
- rel_map_.erase(it);
- } else {
- LOG(ERROR) << "Dropping a non-exist relation schema by id " << id;
- }
-}
-
-} // namespace quickstep
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogDatabaseCache.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogDatabaseCache.hpp b/catalog/CatalogDatabaseCache.hpp
deleted file mode 100644
index 88ca61d..0000000
--- a/catalog/CatalogDatabaseCache.hpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#ifndef QUICKSTEP_CATALOG_CATALOG_DATABASE_CACHE_HPP_
-#define QUICKSTEP_CATALOG_CATALOG_DATABASE_CACHE_HPP_
-
-#include <cstddef>
-#include <memory>
-#include <unordered_map>
-#include <utility>
-
-#include "catalog/CatalogDatabaseLite.hpp"
-#include "catalog/CatalogTypedefs.hpp"
-#include "storage/StorageConstants.hpp"
-#include "threading/SharedMutex.hpp"
-#include "threading/SpinSharedMutex.hpp"
-#include "utility/Macros.hpp"
-
-#include "glog/logging.h"
-
-namespace quickstep {
-
-class CatalogRelationSchema;
-
-namespace serialization { class CatalogDatabase; }
-
-/** \addtogroup Catalog
- * @{
- */
-
-/**
- * @brief A database cache managed by Shiftboss in the distributed version.
- * During the runtime, it contains all the referenced relation schemas
- * to execute a query. For a SELECT query, the temporary query
- * result relation will be dropped after the CLI finishes processing the
- * result and notifies Shiftboss.
- *
- * @note A CatalogRelationSchema should be kept unless all associated blocks
- * have been deleted.
- **/
-class CatalogDatabaseCache : public CatalogDatabaseLite {
- public:
- /**
- * @brief Constructor.
- **/
- CatalogDatabaseCache() {}
-
- /**
- * @brief Constructor. Reconstruct a database cache from its serialized
- * Protocol Buffer form.
- *
- * @param proto The Protocol Buffer serialization of a database, previously
- * produced by the optimizer.
- **/
- explicit CatalogDatabaseCache(const serialization::CatalogDatabase &proto);
-
- /**
- * @brief Destructor which recursively destroys children.
- **/
- ~CatalogDatabaseCache() override {
- }
-
- bool hasRelationWithId(const relation_id id) const override {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- return rel_map_.find(id) != rel_map_.end();
- }
-
- const CatalogRelationSchema& getRelationSchemaById(const relation_id id) const override {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- const auto cit = rel_map_.find(id);
-
- DCHECK(cit != rel_map_.end());
- return *(cit->second);
- }
-
- void dropRelationById(const relation_id id) override;
-
- /**
- * @brief Get the number of child relations.
- *
- * @return The number of child relations.
- **/
- std::size_t size() const {
- SpinSharedMutexSharedLock<false> lock(relations_mutex_);
- return rel_map_.size();
- }
-
- /**
- * @brief Update the cache from its serialized Protocol Buffer form. If the
- * relation schema exists, it will be ignored.
- *
- * @param proto The Protocol Buffer serialization of a catalog cache,
- * previously produced in optimizer.
- **/
- void update(const serialization::CatalogDatabase &proto);
-
- private:
- /**
- * @brief Check whether a serialization::CatalogDatabase is fully-formed and
- * all parts are valid.
- *
- * @param proto A serialized Protocol Buffer representation of a CatalogDatabase,
- * originally generated by the optimizer.
- * @return Whether proto is fully-formed and valid.
- **/
- static bool ProtoIsValid(const serialization::CatalogDatabase &proto);
-
- /**
- * @brief Map from relation id to the pointer to the corresponding relation schema.
- */
- std::unordered_map<relation_id, std::unique_ptr<const CatalogRelationSchema>> rel_map_;
-
- // Concurrency protection for 'rel_map_'.
- alignas(kCacheLineBytes) mutable SpinSharedMutex<false> relations_mutex_;
-
- DISALLOW_COPY_AND_ASSIGN(CatalogDatabaseCache);
-};
-
-/** @} */
-
-} // namespace quickstep
-
-#endif // QUICKSTEP_CATALOG_CATALOG_DATABASE_CACHE_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogDatabaseLite.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogDatabaseLite.hpp b/catalog/CatalogDatabaseLite.hpp
deleted file mode 100644
index 0c846a0..0000000
--- a/catalog/CatalogDatabaseLite.hpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#ifndef QUICKSTEP_CATALOG_CATALOG_DATABASE_LITE_HPP_
-#define QUICKSTEP_CATALOG_CATALOG_DATABASE_LITE_HPP_
-
-#include "catalog/CatalogTypedefs.hpp"
-#include "utility/Macros.hpp"
-
-namespace quickstep {
-
-class CatalogRelationSchema;
-
-/** \addtogroup Catalog
- * @{
- */
-
-/**
- * @brief A base class that the catalog database implements for both the master
- * Catalog, and the CatalogCache in the distributed version.
- *
- * @note This class only contains virtual methods related to the relation id and
- * CatalogRelationSchema.
- **/
-class CatalogDatabaseLite {
- public:
- /**
- * @brief Virtual destructor which recursively destroys children.
- **/
- virtual ~CatalogDatabaseLite() {
- }
-
- /**
- * @brief Get this database's ID.
- *
- * @return This database's ID.
- **/
- database_id getID() const {
- return id_;
- }
-
- /**
- * @brief Check whether a relation with the given id exists.
- *
- * @param id The id to check for.
- * @return Whether the relation exists.
- **/
- virtual bool hasRelationWithId(const relation_id id) const = 0;
-
- /**
- * @brief Get a relation schema by ID.
- *
- * @param id The id to search for.
- * @return The relation schema with the given ID.
- **/
- virtual const CatalogRelationSchema& getRelationSchemaById(const relation_id id) const = 0;
-
- /**
- * @brief Drop (delete) a relation by id.
- *
- * @param id The ID of the relation to drop.
- **/
- virtual void dropRelationById(const relation_id id) = 0;
-
- protected:
- /**
- * @brief Create a new database.
- *
- * @param parent The catalog this database belongs to.
- * @param name This database's name.
- * @param id This database's ID (defaults to -1, which means invalid/unset).
- **/
- explicit CatalogDatabaseLite(const database_id id = -1)
- : id_(id) {
- }
-
- // The database id in Catalog.
- database_id id_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CatalogDatabaseLite);
-};
-
-/** @} */
-
-} // namespace quickstep
-
-#endif // QUICKSTEP_CATALOG_CATALOG_DATABASE_LITE_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogErrors.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogErrors.hpp b/catalog/CatalogErrors.hpp
deleted file mode 100644
index b156daa..0000000
--- a/catalog/CatalogErrors.hpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#ifndef QUICKSTEP_CATALOG_CATALOG_ERRORS_HPP_
-#define QUICKSTEP_CATALOG_CATALOG_ERRORS_HPP_
-
-#include <exception>
-#include <string>
-
-namespace quickstep {
-
-/** \addtogroup Catalog
- * @{
- */
-
-class CatalogIDOverflow : public std::exception {
- public:
- explicit CatalogIDOverflow(const std::string &item_type)
- : message_("CatalogIDOverflow: Exceeded the maximum number of ") {
- message_.append(item_type);
- message_.append("s in catalog.");
- }
-
- ~CatalogIDOverflow() throw() {}
-
- virtual const char* what() const throw() {
- return message_.c_str();
- }
-
- private:
- std::string message_;
-};
-
-/** @} */
-
-} // namespace quickstep
-
-#endif // QUICKSTEP_CATALOG_CATALOG_ERRORS_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogModule.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogModule.hpp b/catalog/CatalogModule.hpp
deleted file mode 100644
index e1ae851..0000000
--- a/catalog/CatalogModule.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-/** @defgroup Catalog
- *
- * The database catalog, which contains information about all of the relations
- * in the database, their attributes, and the storage blocks which store their
- * data.
- **/
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogRelation.cpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogRelation.cpp b/catalog/CatalogRelation.cpp
deleted file mode 100644
index c288532..0000000
--- a/catalog/CatalogRelation.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#include "catalog/CatalogRelation.hpp"
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "catalog/Catalog.pb.h"
-#include "catalog/CatalogAttribute.hpp"
-#include "catalog/CatalogConfig.h"
-#include "catalog/CatalogRelationSchema.hpp"
-
-#ifdef QUICKSTEP_HAVE_LIBNUMA
-#include "catalog/NUMAPlacementScheme.hpp"
-#endif
-
-#include "catalog/PartitionScheme.hpp"
-#include "storage/StorageBlockInfo.hpp"
-#include "storage/StorageBlockLayout.hpp"
-#include "storage/StorageBlockLayout.pb.h"
-#include "threading/SpinSharedMutex.hpp"
-#include "utility/PtrVector.hpp"
-
-#include "glog/logging.h"
-
-namespace quickstep {
-
-class Type;
-
-bool CatalogRelation::ProtoIsValid(const serialization::CatalogRelationSchema &proto) {
- // Check that proto is fully initialized.
- if (!CatalogRelationSchema::ProtoIsValid(proto) ||
- !proto.HasExtension(serialization::CatalogRelation::default_layout)) {
- return false;
- }
-
- // Check if the proto of the relation has a partition scheme.
- if (proto.HasExtension(serialization::CatalogRelation::partition_scheme)) {
- // Check if the partition scheme protobuf is valid.
- if (!PartitionScheme::ProtoIsValid(
- proto.GetExtension(serialization::CatalogRelation::partition_scheme))) {
- return false;
- }
-
-#ifdef QUICKSTEP_HAVE_LIBNUMA
- // Check if the proto of the relation has a NUMA placement scheme.
- if (proto.HasExtension(serialization::CatalogRelation::placement_scheme)) {
- // Check if the NUMA placement scheme protobuf is valid.
- if (!NUMAPlacementScheme::ProtoIsValid(
- proto.GetExtension(serialization::CatalogRelation::placement_scheme))) {
- return false;
- }
- }
-#endif
- }
-
- // Catalog Relation's proto is valid.
- return true;
-}
-
-CatalogRelation::CatalogRelation(const serialization::CatalogRelationSchema &proto)
- : CatalogRelationSchema(proto),
- default_layout_(nullptr) {
- DCHECK(ProtoIsValid(proto))
- << "Attempted to create CatalogRelation from an invalid proto description:\n"
- << proto.DebugString();
-
- // Deserializing the partition scheme for the relation.
- // This should be done after the attributes are added and before the
- // blocks of the relation are added.
- if (proto.HasExtension(serialization::CatalogRelation::partition_scheme)) {
- const serialization::PartitionScheme &proto_partition_scheme =
- proto.GetExtension(serialization::CatalogRelation::partition_scheme);
-
- const attribute_id partition_attribute_id = proto_partition_scheme.header().partition_attribute_id();
- DCHECK(hasAttributeWithId(partition_attribute_id));
- const Type &attr_type = attr_vec_[partition_attribute_id].getType();
-
- setPartitionScheme(PartitionScheme::ReconstructFromProto(proto_partition_scheme, attr_type));
-
- // Deserializing the NUMA placement scheme for the relation.
-#ifdef QUICKSTEP_HAVE_LIBNUMA
- if (proto.HasExtension(serialization::CatalogRelation::placement_scheme)) {
- setNUMAPlacementScheme(
- NUMAPlacementScheme::ReconstructFromProto(
- proto.GetExtension(serialization::CatalogRelation::placement_scheme),
- proto_partition_scheme.header().num_partitions()));
- }
-#endif
- }
-
- const StorageBlockLayoutDescription &proto_default_layout =
- proto.GetExtension(serialization::CatalogRelation::default_layout);
- DCHECK(StorageBlockLayout::DescriptionIsValid(*this, proto_default_layout));
-
- // Deserializing the index scheme defined for the relation, if any.
- if (proto.HasExtension(serialization::CatalogRelation::index_scheme)) {
- index_scheme_.reset(
- IndexScheme::ReconstructFromProto(proto.GetExtension(serialization::CatalogRelation::index_scheme)));
- // Ensure that indices present in the block layout are the same as in the index scheme.
- const std::size_t num_indices_expected = index_scheme_->getNumIndices();
- const std::size_t num_indices_checked = proto_default_layout.index_description_size();
- DCHECK_EQ(num_indices_expected, num_indices_checked);
- for (std::size_t i = 0; i < num_indices_checked; ++i) {
- const IndexSubBlockDescription &description_checked = proto_default_layout.index_description(i);
- DCHECK(index_scheme_->hasIndexWithDescription(description_checked))
- << "Block layout defines some indices not present in the catalog";
- }
- }
-
- // Deserializing the blocks of the relation.
- for (int i = 0; i < proto.ExtensionSize(serialization::CatalogRelation::blocks); ++i) {
- blocks_.emplace_back(static_cast<block_id>(proto.GetExtension(serialization::CatalogRelation::blocks, i)));
- }
-
- default_layout_.reset(new StorageBlockLayout(*this, proto_default_layout));
-
- if (proto.HasExtension(serialization::CatalogRelation::statistics)) {
- statistics_.reset(
- new CatalogRelationStatistics(
- proto.GetExtension(serialization::CatalogRelation::statistics)));
- } else {
- statistics_.reset(new CatalogRelationStatistics());
- }
-}
-
-serialization::CatalogRelationSchema CatalogRelation::getProto() const {
- serialization::CatalogRelationSchema proto = CatalogRelationSchema::getProto();
-
- proto.MutableExtension(serialization::CatalogRelation::default_layout)
- ->MergeFrom(getDefaultStorageBlockLayout().getDescription());
-
- {
- SpinSharedMutexSharedLock<false> lock(blocks_mutex_);
- for (const block_id block : blocks_) {
- proto.AddExtension(serialization::CatalogRelation::blocks, block);
- }
- }
-
- if (hasIndexScheme()) {
- proto.MutableExtension(serialization::CatalogRelation::index_scheme)->MergeFrom(index_scheme_->getProto());
- }
-
- // The partition scheme of the relation is stored in the protocol buffer format.
- if (hasPartitionScheme()) {
- proto.MutableExtension(serialization::CatalogRelation::partition_scheme)
- ->MergeFrom(partition_scheme_->getProto());
-#ifdef QUICKSTEP_HAVE_LIBNUMA
- if (hasNUMAPlacementScheme()) {
- proto.MutableExtension(serialization::CatalogRelation::placement_scheme)
- ->MergeFrom(placement_scheme_->getProto());
- }
-#endif
- }
-
- proto.MutableExtension(serialization::CatalogRelation::statistics)
- ->MergeFrom(statistics_->getProto());
-
- return proto;
-}
-
-void CatalogRelation::setPartitionScheme(PartitionScheme* partition_scheme) {
- DCHECK_EQ(0u, size_blocks());
- partition_scheme_.reset(partition_scheme);
-}
-
-void CatalogRelation::setDefaultStorageBlockLayout(StorageBlockLayout *default_layout) {
- DCHECK(&(default_layout->getRelation()) == this);
- default_layout_.reset(default_layout);
-}
-
-const StorageBlockLayout& CatalogRelation::getDefaultStorageBlockLayout() const {
- if (default_layout_ == nullptr) {
- default_layout_.reset(StorageBlockLayout::GenerateDefaultLayout(*this, isVariableLength()));
- }
-
- return *default_layout_;
-}
-
-} // namespace quickstep
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogRelation.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogRelation.hpp b/catalog/CatalogRelation.hpp
deleted file mode 100644
index c38e526..0000000
--- a/catalog/CatalogRelation.hpp
+++ /dev/null
@@ -1,438 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#ifndef QUICKSTEP_CATALOG_CATALOG_RELATION_HPP_
-#define QUICKSTEP_CATALOG_CATALOG_RELATION_HPP_
-
-#include <algorithm>
-#include <cstddef>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "catalog/Catalog.pb.h"
-#include "catalog/CatalogConfig.h"
-#include "catalog/CatalogRelationSchema.hpp"
-#include "catalog/CatalogRelationStatistics.hpp"
-#include "catalog/CatalogTypedefs.hpp"
-#include "catalog/IndexScheme.hpp"
-
-#ifdef QUICKSTEP_HAVE_LIBNUMA
-#include "catalog/NUMAPlacementScheme.hpp"
-#endif // QUICKSTEP_HAVE_LIBNUMA
-
-#include "catalog/PartitionScheme.hpp"
-#include "storage/StorageBlockInfo.hpp"
-#include "storage/StorageBlockLayout.hpp"
-#include "storage/StorageConstants.hpp"
-#include "threading/Mutex.hpp"
-#include "threading/SharedMutex.hpp"
-#include "threading/SpinSharedMutex.hpp"
-#include "utility/Macros.hpp"
-
-namespace quickstep {
-
-class CatalogDatabase;
-
-/** \addtogroup Catalog
- * @{
- */
-
-/**
- * @brief A relation in a database. This augments the schema information in
- * CatalogRelationSchema with information about physical StorageBlocks
- * and their layouts.
- **/
-class CatalogRelation : public CatalogRelationSchema {
- public:
- typedef CatalogRelationSchema::size_type size_type;
- typedef CatalogRelationSchema::const_iterator const_iterator;
-
- typedef std::vector<block_id>::size_type size_type_blocks;
-
- /**
- * @brief Create a new relation.
- *
- * @param parent The database this relation belongs to.
- * @param name This relation's name.
- * @param id This relation's ID (defaults to -1, which means invalid/unset).
- * @param temporary Whether this relation is temporary (stores an
- * intermediate result during query processing).
- **/
- CatalogRelation(CatalogDatabase* parent,
- const std::string &name,
- const relation_id id = -1,
- bool temporary = false)
- : CatalogRelationSchema(parent, name, id, temporary),
- default_layout_(nullptr),
- statistics_(new CatalogRelationStatistics()) {
- }
-
- /**
- * @brief Reconstruct a relation from its serialized Protocol Buffer form.
- *
- * @param proto The Protocol Buffer serialization of a relation,
- * previously produced by getProto().
- **/
- explicit CatalogRelation(const serialization::CatalogRelationSchema &proto);
-
- /**
- * @brief Destructor which recursively destroys children.
- **/
- ~CatalogRelation() override {
- }
-
- serialization::CatalogRelationSchema getProto() const override;
-
- /**
- * @brief Check if a partition scheme is available for the relation.
- *
- * @return True if the relation has a partition scheme, false otherwise.
- **/
- bool hasPartitionScheme() const {
- return partition_scheme_ != nullptr;
- }
-
- /**
- * @brief Get the partition scheme of the catalog relation.
- * @warning This is only safe if hasPartitionScheme() is true.
- *
- * @return A const reference to the partition scheme of the relation.
- **/
- const PartitionScheme& getPartitionScheme() const {
- return *partition_scheme_;
- }
-
- /**
- * @brief Set the partition scheme for the catalog relation.
- * @warning This method should be called only once when a relation is
- * is first created.
- *
- * @param partition_scheme The partition scheme object for a relation, which
- * becomes owned by this relation.
- **/
- void setPartitionScheme(PartitionScheme* partition_scheme);
-
- /**
- * @brief Get a mutable partition scheme of the relation.
- *
- * @return A pointer to the partition scheme.
- **/
- PartitionScheme* getPartitionSchemeMutable() {
- return partition_scheme_.get();
- }
-
- /**
- * @brief Check if a NUMA placement scheme is available for the relation.
- *
- * @return True if the relation has a NUMA placement scheme, false otherwise.
- **/
- bool hasNUMAPlacementScheme() const {
-#ifdef QUICKSTEP_HAVE_LIBNUMA
- return placement_scheme_ != nullptr;
-#else
- return false;
-#endif // QUICKSTEP_HAVE_LIBNUMA
- }
-
-#ifdef QUICKSTEP_HAVE_LIBNUMA
- /**
- * @brief Get the NUMA placement scheme of the catalog relation.
- * @warning This is only safe if hasNUMAPlacementScheme() is true.
- *
- * @return A const reference to the NUMA placement scheme of the relation.
- **/
- const NUMAPlacementScheme& getNUMAPlacementScheme() const {
- return *placement_scheme_;
- }
-
- /**
- * @brief Get a mutable NUMA placement scheme of the relation.
- *
- * @return A pointer to the NUMA placement scheme.
- **/
- NUMAPlacementScheme* getNUMAPlacementSchemeMutable() {
- return placement_scheme_.get();
- }
-
- /**
- * @brief Get the NUMA placement scheme of the relation.
- *
- * @return A pointer to a const NUMA placement scheme.
- **/
- const NUMAPlacementScheme* getNUMAPlacementSchemePtr() const {
- return placement_scheme_.get();
- }
-
- /**
- * @brief Set the NUMA placement scheme for the catalog relation.
- *
- * @param placement_scheme The NUMA placement scheme object for the relation,
- * which becomes owned by this relation.
- **/
- void setNUMAPlacementScheme(NUMAPlacementScheme *placement_scheme) {
- placement_scheme_.reset(placement_scheme);
- }
-#endif // QUICKSTEP_HAVE_LIBNUMA
-
- /**
- * @brief Check if an index scheme is available for the relation.
- *
- * @return True if the relation has a index scheme, false otherwise.
- **/
- bool hasIndexScheme() const {
- return index_scheme_ != nullptr;
- }
-
- /**
- * @brief Get the index scheme of the catalog relation.
- * @warning This is only safe if hasIndexScheme() is true.
- *
- * @return A const reference to the index scheme of the relation.
- **/
- const IndexScheme& getIndexScheme() const {
- return *index_scheme_;
- }
-
- /**
- * @brief Get a mutable index scheme of the relation.
- *
- * @return A pointer to the index scheme.
- **/
- IndexScheme* getIndexSchemeMutable() {
- return index_scheme_.get();
- }
-
- /**
- * @brief Register a StorageBlock as belonging to this relation.
- * @note Blocks are ordered in the same order they are added (preserving order
- * for full-table sorts).
- *
- * @param block the ID of the block to add.
- **/
- void addBlock(const block_id block) {
- SpinSharedMutexExclusiveLock<false> lock(blocks_mutex_);
- blocks_.emplace_back(block);
- }
-
- /**
- * @brief Remove a StorageBlock from this relation (idempotent).
- *
- * @param block the ID of the block to remove.
- **/
- void removeBlock(const block_id block) {
- SpinSharedMutexExclusiveLock<false> lock(blocks_mutex_);
- std::vector<block_id>::iterator it = std::find(blocks_.begin(), blocks_.end(), block);
- if (it != blocks_.end()) {
- blocks_.erase(it);
- }
- }
-
- /**
- * @brief Remove all StorageBlocks from this relation.
- **/
- void clearBlocks() {
- SpinSharedMutexExclusiveLock<false> lock(blocks_mutex_);
- blocks_.clear();
- }
-
- /**
- * @brief Check whether an index with the given exists or not.
- *
- * @param index_name Name of the index to be checked.
- * @return Whether the index exists or not.
- **/
- bool hasIndexWithName(const std::string &index_name) const {
- SpinSharedMutexSharedLock<false> lock(index_scheme_mutex_);
- return index_scheme_ && index_scheme_->hasIndexWithName(index_name);
- }
-
- /**
- * @brief Check whether an index with the given description
- * containing the same attribute id and index type
- * exists or not in the index map.
- *
- * @param index_descripton Index Description to check against.
- * @return Whether a similar index description was already defined or not.
- **/
- bool hasIndexWithDescription(const IndexSubBlockDescription &index_description) const {
- SpinSharedMutexSharedLock<false> lock(index_scheme_mutex_);
- return index_scheme_ && index_scheme_->hasIndexWithDescription(index_description);
- }
-
- /**
- * @brief Add an index to the index_map.
- *
- * @param index_name Name of the index to be added.
- * @param index_description Corresponding description of the index.
- * @return Whether the index was added successfully or not
- **/
- bool addIndex(const std::string &index_name,
- IndexSubBlockDescription &&index_description) { // NOLINT(whitespace/operators)
- SpinSharedMutexExclusiveLock<false> lock(index_scheme_mutex_);
- // Create an index_scheme, if it does not exist.
- if (index_scheme_ == nullptr) {
- index_scheme_.reset(new IndexScheme());
- }
-
- // Verify that index with the given name does not exist.
- if (index_scheme_->hasIndexWithName(index_name)) {
- return false;
- }
-
- // Verify that index with similar description does not exist.
- if (index_scheme_->hasIndexWithDescription(index_description)) {
- return false;
- }
-
- // Verify that the CatalogRelation has a valid layout.
- // This check is also required for some unit tests on catalog.
- if (default_layout_ == nullptr) {
- // Calling this function initializes the default_layout_.
- getDefaultStorageBlockLayout();
- }
-
- StorageBlockLayoutDescription *layout = default_layout_->getDescriptionMutable();
- layout->add_index_description()->MergeFrom(index_description);
- default_layout_->finalize();
-
- // Update the index_scheme.
- index_scheme_->addIndexMapEntry(index_name, std::move(index_description));
-
- return true; // Index added successfully, lock released.
- }
-
- /**
- * @brief Check whether a serialization::CatalogRelation is fully-formed and
- * all parts are valid.
- *
- * @param proto A serialized Protocol Buffer representation of a relation,
- * originally generated by getProto().
- * @return Whether proto is fully-formed and valid.
- **/
- static bool ProtoIsValid(const serialization::CatalogRelationSchema &proto);
-
- /**
- * @brief Get the number of child blocks.
- *
- * @return The number of child blocks.
- **/
- inline size_type_blocks size_blocks() const {
- SpinSharedMutexSharedLock<false> lock(blocks_mutex_);
- return blocks_.size();
- }
-
- /**
- * @brief Get the current set of blocks belonging to this relation.
- *
- * @return The block_ids of blocks belonging to this relation at the moment
- * this method is called.
- **/
- inline std::vector<block_id> getBlocksSnapshot() const {
- SpinSharedMutexSharedLock<false> lock(blocks_mutex_);
- return std::vector<block_id>(blocks_.begin(), blocks_.end());
- }
-
- /**
- * @brief Set the default StorageBlockLayout for this relation.
- * @note Deletes the previous default layout, if any.
- *
- * @param default_layout The new default StorageBlockLayout for this
- * relation, which becomes owned by this relation.
- **/
- void setDefaultStorageBlockLayout(StorageBlockLayout *default_layout);
-
- /**
- * @brief Get this relation's default StorageBlockLayout.
- * @note If no default has been set via setDefaultStorageBlockLayout(), then
- * one is created with StorageBlockLayout::generateDefaultLayout().
- *
- * @return The default StorageBlockLayout for this relation.
- **/
- const StorageBlockLayout& getDefaultStorageBlockLayout() const;
-
- /**
- * @brief Estimate the number of tuples in this relation.
- * @warning This is currently implemented as a very dumb heuristic. Estimates
- * should be considered a rough "best guess" only.
- *
- * @return The estimated number of tuples in this relation.
- **/
- std::size_t estimateTupleCardinality() const {
- return size_blocks()
- * getDefaultStorageBlockLayout().estimateTuplesPerBlock();
- }
-
- /**
- * @brief Get an immutable reference to the statistics of this catalog relation.
- *
- * @return A reference to the statistics of this catalog relation.
- */
- const CatalogRelationStatistics& getStatistics() const {
- return *statistics_;
- }
-
- /**
- * @brief Get a mutable pointer to the statistics of this catalog relation.
- *
- * @return A pointer to the statistics of this catalog relation.
- */
- CatalogRelationStatistics* getStatisticsMutable() {
- return statistics_.get();
- }
-
- private:
- // A list of blocks belonged to the relation.
- std::vector<block_id> blocks_;
- // The mutex used to protect 'blocks_' from concurrent accesses.
- mutable SpinSharedMutex<false> blocks_mutex_;
-
- // The default layout for newly-created blocks.
- mutable std::unique_ptr<StorageBlockLayout> default_layout_;
-
- // Partition Scheme associated with the Catalog Relation.
- // A relation may or may not have a Partition Scheme
- // assosiated with it.
- std::unique_ptr<PartitionScheme> partition_scheme_;
-
- // Index scheme associated with this relation.
- // Defines a set of indices defined for this relation.
- std::unique_ptr<IndexScheme> index_scheme_;
- // Mutex for locking the index scheme.
- alignas(kCacheLineBytes) mutable SpinSharedMutex<false> index_scheme_mutex_;
-
- std::unique_ptr<CatalogRelationStatistics> statistics_;
-
-#ifdef QUICKSTEP_HAVE_LIBNUMA
- // NUMA placement scheme object which has the mapping between the partitions
- // of the relation and the NUMA nodes/sockets. It also maintains a mapping
- // between the blocks of the relation and the NUMA nodes..
- std::unique_ptr<NUMAPlacementScheme> placement_scheme_;
-#endif // QUICKSTEP_HAVE_LIBNUMA
-
- friend class CatalogTest;
-
- DISALLOW_COPY_AND_ASSIGN(CatalogRelation);
-};
-
-/** @} */
-
-} // namespace quickstep
-
-#endif // QUICKSTEP_CATALOG_CATALOG_RELATION_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogRelationSchema.cpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogRelationSchema.cpp b/catalog/CatalogRelationSchema.cpp
deleted file mode 100644
index 5568cef..0000000
--- a/catalog/CatalogRelationSchema.cpp
+++ /dev/null
@@ -1,191 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#include "catalog/CatalogRelationSchema.hpp"
-
-#include <cstddef>
-#include <string>
-#include <unordered_map>
-#include <utility>
-
-#include "catalog/Catalog.pb.h"
-#include "catalog/CatalogAttribute.hpp"
-#include "catalog/CatalogErrors.hpp"
-#include "catalog/CatalogTypedefs.hpp"
-#include "types/Type.hpp"
-#include "utility/PtrVector.hpp"
-#include "utility/StringUtil.hpp"
-
-#include "glog/logging.h"
-
-using std::size_t;
-using std::string;
-using std::unordered_map;
-
-namespace quickstep {
-
-CatalogRelationSchema::CatalogRelationSchema(const serialization::CatalogRelationSchema &proto)
- : parent_(nullptr),
- id_(proto.relation_id()),
- name_(proto.name()),
- temporary_(proto.temporary()),
- num_nullable_attributes_(0),
- num_variable_length_attributes_(0),
- max_byte_length_(0),
- min_byte_length_(0),
- estimated_byte_length_(0),
- fixed_byte_length_(0),
- max_variable_byte_length_(0),
- min_variable_byte_length_(0),
- min_variable_byte_length_excluding_nullable_(0),
- estimated_variable_byte_length_(0),
- max_byte_lengths_(proto.attributes_size()),
- current_nullable_attribute_index_(-1),
- current_variable_length_attribute_index_(-1) {
- DCHECK(ProtoIsValid(proto))
- << "Attempted to create CatalogRelationSchema from an invalid proto description:\n"
- << proto.DebugString();
-
- // Deserializing the attributes for the relation schema.
- for (int i = 0; i < proto.attributes_size(); ++i) {
- if (proto.attributes(i).IsInitialized()) {
- addAttribute(new CatalogAttribute(proto.attributes(i)));
- } else {
- attr_vec_.push_back(nullptr);
- }
- }
-}
-
-bool CatalogRelationSchema::ProtoIsValid(const serialization::CatalogRelationSchema &proto) {
- if (!proto.IsInitialized()
- || proto.relation_id() == static_cast<relation_id>(-1)) {
- return false;
- }
-
- for (int i = 0; i < proto.attributes_size(); ++i) {
- if (!CatalogAttribute::ProtoIsValid(proto.attributes(i))) {
- return false;
- }
- }
-
- return true;
-}
-
-serialization::CatalogRelationSchema CatalogRelationSchema::getProto() const {
- serialization::CatalogRelationSchema proto;
-
- proto.set_relation_id(id_);
- proto.set_name(name_);
- proto.set_temporary(temporary_);
-
- for (PtrVector<CatalogAttribute, true>::const_iterator it = attr_vec_.begin();
- it != attr_vec_.end();
- ++it) {
- if (it.isNull()) {
- proto.add_attributes();
- } else {
- proto.add_attributes()->MergeFrom(it->getProto());
- }
- }
-
- return proto;
-}
-
-const CatalogAttribute* CatalogRelationSchema::getAttributeByName(
- const string &attr_name) const {
- unordered_map<string, CatalogAttribute*>::const_iterator it
- = attr_map_.find(ToLower(attr_name));
- if (it == attr_map_.end()) {
- return nullptr;
- } else {
- return it->second;
- }
-}
-
-CatalogAttribute* CatalogRelationSchema::getAttributeByNameMutable(
- const string &attr_name) {
- unordered_map<string, CatalogAttribute*>::const_iterator it
- = attr_map_.find(ToLower(attr_name));
- if (it == attr_map_.end()) {
- return nullptr;
- } else {
- return it->second;
- }
-}
-
-attribute_id CatalogRelationSchema::addAttribute(CatalogAttribute *new_attr) {
- const string lower_attr_name = ToLower(new_attr->getName());
- DCHECK(!hasAttributeWithName(lower_attr_name));
-
- if (attr_vec_.size() > static_cast<size_t>(kCatalogMaxID)) {
- throw CatalogIDOverflow("attribute");
- } else {
- attr_map_[lower_attr_name] = new_attr;
- attr_vec_.push_back(new_attr);
- new_attr->setParent(this);
- new_attr->setID(static_cast<attribute_id>(attr_vec_.size() - 1));
-
- const Type &attr_type = new_attr->getType();
-
- if (attr_type.isVariableLength()) {
- ++num_variable_length_attributes_;
- variable_length_attribute_indices_.push_back(++current_variable_length_attribute_index_);
-
- max_variable_byte_length_ += attr_type.maximumByteLength();
- min_variable_byte_length_ += attr_type.minimumByteLength();
- if (!attr_type.isNullable()) {
- min_variable_byte_length_excluding_nullable_ += attr_type.minimumByteLength();
- }
- estimated_variable_byte_length_ += attr_type.estimateAverageByteLength();
- } else {
- variable_length_attribute_indices_.push_back(kInvalidCatalogId);
-
- fixed_length_attribute_offsets_.resize(new_attr->getID() + 1, fixed_byte_length_);
- fixed_byte_length_ += attr_type.maximumByteLength();
- }
- max_byte_length_ += attr_type.maximumByteLength();
- min_byte_length_ += attr_type.minimumByteLength();
- estimated_byte_length_ += attr_type.estimateAverageByteLength();
-
- if (attr_type.isNullable()) {
- ++num_nullable_attributes_;
- nullable_attribute_indices_.push_back(++current_nullable_attribute_index_);
- } else {
- nullable_attribute_indices_.push_back(kInvalidCatalogId);
- }
-
- const attribute_id attr_id = new_attr->getID();
- // Ensure that we will not overrun the vector by resizing and initializing
- // new entries to zero.
- max_byte_lengths_.resize(attr_id + 1, 0);
- max_byte_lengths_[attr_id] = attr_type.maximumByteLength();
-
- return attr_id;
- }
-}
-
-attribute_id CatalogRelationSchema::getMaxAttributeId() const {
- if (size() > 0) {
- return attr_vec_.back().getID();
- } else {
- return -1;
- }
-}
-
-} // namespace quickstep
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogRelationSchema.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogRelationSchema.hpp b/catalog/CatalogRelationSchema.hpp
deleted file mode 100644
index d8b6128..0000000
--- a/catalog/CatalogRelationSchema.hpp
+++ /dev/null
@@ -1,545 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#ifndef QUICKSTEP_CATALOG_CATALOG_RELATION_SCHEMA_HPP_
-#define QUICKSTEP_CATALOG_CATALOG_RELATION_SCHEMA_HPP_
-
-#include <cstddef>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-#include "catalog/Catalog.pb.h"
-#include "catalog/CatalogAttribute.hpp"
-#include "catalog/CatalogTypedefs.hpp"
-#include "utility/Macros.hpp"
-#include "utility/PtrVector.hpp"
-#include "utility/StringUtil.hpp"
-
-#include "glog/logging.h"
-
-namespace quickstep {
-
-class CatalogDatabase;
-
-/** \addtogroup Catalog
- * @{
- */
-
-/**
- * @brief A relation in a database. This base class only includes information
- * about the relation's schema. See also CatalogRelation, which augments
- * this with additional information about physical blocks.
- **/
-class CatalogRelationSchema {
- public:
- typedef std::unordered_map<std::string, CatalogAttribute*>::size_type size_type;
- typedef PtrVector<CatalogAttribute, true>::const_skip_iterator const_iterator;
-
- /**
- * @brief Reconstruct a relation schema from its serialized Protocol Buffer
- * form.
- *
- * @param proto The Protocol Buffer serialization of a relation schema,
- * previously produced by getProto().
- **/
- explicit CatalogRelationSchema(const serialization::CatalogRelationSchema &proto);
-
- /**
- * @brief Destructor which recursively destroys children.
- **/
- virtual ~CatalogRelationSchema() {}
-
- /**
- * @brief Serialize the relation schema as Protocol Buffer.
- *
- * @return The Protocol Buffer representation of the relation schema.
- **/
- virtual serialization::CatalogRelationSchema getProto() const;
-
- /**
- * @brief Check whether a serialization::CatalogRelationSchema is fully-formed
- * and all parts are valid.
- *
- * @param proto A serialized Protocol Buffer representation of a relation
- * schema, originally generated by getProto().
- * @return Whether proto is fully-formed and valid.
- **/
- static bool ProtoIsValid(const serialization::CatalogRelationSchema &proto);
-
- /**
- * @brief Get the parent database.
- *
- * @return Parent database.
- **/
- const CatalogDatabase& getParent() const {
- return *parent_;
- }
-
- /**
- * @brief Get a mutable pointer to the parent database.
- *
- * @return Parent database.
- **/
- CatalogDatabase* getParentMutable() {
- return parent_;
- }
-
- /**
- * @brief Get this relation's ID.
- *
- * @return This relation's ID.
- **/
- relation_id getID() const {
- return id_;
- }
-
- /**
- * @brief Get this relation's name.
- *
- * @return This relation's name.
- **/
- const std::string& getName() const {
- return name_;
- }
-
- /**
- * @brief Check whether this relation is temporary or permanent.
- *
- * @return True if this relation is temporary, false otherwise.
- **/
- bool isTemporary() const {
- return temporary_;
- }
-
- /**
- * @brief Check whether an attribute with the given name exists.
- *
- * @param attr_name The name to check for.
- * @return Whether the attribute exists.
- **/
- bool hasAttributeWithName(const std::string &attr_name) const {
- return (attr_map_.find(ToLower(attr_name)) != attr_map_.end());
- }
-
- /**
- * @brief Check whether an attribute with the given id exists.
- *
- * @param id The id to check for.
- * @return Whether the attribute exists.
- **/
- bool hasAttributeWithId(const attribute_id id) const {
- return (idInRange(id) && !attr_vec_.elementIsNull(id));
- }
-
- /**
- * @brief Get an attribute by name. The search is case-insensitive.
- *
- * @param attr_name The name to search for.
- * @return The attribute with the given name. NULL if the attribute is not found.
- **/
- const CatalogAttribute* getAttributeByName(const std::string &attr_name) const;
-
- /**
- * @brief Get a mutable pointer to an attribute by name. The search is case-insensitive.
- *
- * @param attr_name The name to search for.
- * @return The attribute with the given name. NULL if the attribute is not found.
- **/
- CatalogAttribute* getAttributeByNameMutable(const std::string &attr_name);
-
- /**
- * @brief Get an attribute by ID.
- *
- * @param id The id to search for.
- * @return The attribute with the given ID.
- **/
- const CatalogAttribute* getAttributeById(const attribute_id id) const {
- if (hasAttributeWithId(id)) {
- return &attr_vec_[id];
- } else {
- return nullptr;
- }
- }
-
- /**
- * @brief Get a mutable pointer to an attribute by ID.
- *
- * @param id The id to search for.
- * @return The attribute with the given ID.
- * @exception AttributeIdNotFound No attribute with the given ID exists.
- **/
- CatalogAttribute* getAttributeByIdMutable(const attribute_id id) {
- if (hasAttributeWithId(id)) {
- return &(attr_vec_[id]);
- } else {
- return nullptr;
- }
- }
-
- /**
- * @brief Add a new attribute to the relation. If the attribute already has
- * an ID and/or parent, it will be overwritten.
- *
- * @param new_attr The attribute to be added.
- * @return The id assigned to the attribute.
- * @exception AttributeNameCollision An attribute with the same name as
- * new_attr is already present in the relation.
- **/
- attribute_id addAttribute(CatalogAttribute *new_attr);
-
- /**
- * @brief Check whether tuples of the relation are variable-length.
- *
- * @return Whether the relation is variable length (i.e. whether any child
- * attributes are variable length).
- **/
- bool isVariableLength() const {
- return num_variable_length_attributes_ > 0;
- }
-
- /**
- * @brief Check how many attributes of the relation are variable-length.
- *
- * @return The number of variable-length attributes in the relation.
- **/
- inline unsigned numVariableLengthAttributes() const {
- return num_variable_length_attributes_;
- }
-
- /**
- * @brief Get the index of a variable-length attribute among all the
- * variable-length attributes in this relation.
- *
- * @param id The id of the desired attribute.
- * @return The attribute's index amongst all of the variable-length
- * attributes, or -1 if the attribute is fixed-length.
- **/
- inline int getVariableLengthAttributeIndex(const attribute_id id) const {
- DCHECK(hasAttributeWithId(id));
- return variable_length_attribute_indices_[id];
- }
-
- /**
- * @brief Get the maximum length of tuples of this relation, in bytes.
- *
- * @return The maximum length of tuples of this relation, in bytes (equal to
- * getFixedByteLength() if relation is fixed-length).
- **/
- std::size_t getMaximumByteLength() const {
- return max_byte_length_;
- }
-
- /**
- * @brief Get the minimum length of tuples of this relation, in bytes.
- *
- * @return The minimum length of tuples of this relation, in bytes (equal
- * to getFixedByteLength() and getMaximumByteLength() if relation is
- * fixed-length).
- **/
- std::size_t getMinimumByteLength() const {
- return min_byte_length_;
- }
-
- /**
- * @brief Get the estimated average length of tuples of this relation, in
- * bytes.
- *
- * @return The estimated average length of tuples of this relation, in bytes
- * (equal to getFixedByteLength(), getMinimumByteLength(), and
- * getMaximumByteLength() if relation is fixed-length).
- **/
- std::size_t getEstimatedByteLength() const {
- return estimated_byte_length_;
- }
-
- /**
- * @brief Get the total length of the fixed-length attributes in this
- * relation, in bytes.
- *
- * @return The total length of fixed-length attributes in this relation, in
- * bytes.
- **/
- std::size_t getFixedByteLength() const {
- return fixed_byte_length_;
- }
-
- /**
- * @brief Get the total maximum length of the variable-length attributes of
- * this relation, in bytes.
- *
- * @return The total maximum length of the variable-length attributes of this
- * relation, in bytes (0 if the relation is fixed-length).
- **/
- std::size_t getMaximumVariableByteLength() const {
- return max_variable_byte_length_;
- }
-
- /**
- * @brief Get the total minimum length of the variable-length attributes of
- * this relation, in bytes.
- *
- * @return The total minimum length of the variable-length attributes of this
- * relation, in bytes (0 if the relation is fixed-length).
- **/
- std::size_t getMinimumVariableByteLength() const {
- return min_variable_byte_length_;
- }
-
- /**
- * @brief Get the total minimum length of the non-nullable variable-length
- * attributes of this relation, in bytes.
- *
- * @return The total minimum length of the non-nullable variable-length
- * attributes of this relation, in bytes (0 if the relation is
- * fixed-length).
- **/
- std::size_t getMinimumVariableByteLengthExcludingNullable() const {
- return min_variable_byte_length_excluding_nullable_;
- }
-
- /**
- * @brief Get the estimated average length of all the variable-length
- * attributes of this relation, in bytes.
- *
- * @return The total estimated average length of variable-length attributes
- * of this relation, in bytes (0 if the relation is fixed-length).
- **/
- std::size_t getEstimatedVariableByteLength() const {
- return estimated_variable_byte_length_;
- }
-
- /**
- * @brief Get the byte offset of a fixed-length attribute in this relation.
- * @warning This method should only be called for attributes which are
- * fixed-length. For debug builds, this is checked with an assert.
- * For release builds, it is unchecked.
- *
- * @param id The id of the desired attribute.
- * @return The byte-offset of the specified fixed-length attribute (as it
- * would be in a conventional row-store) in this relation.
- **/
- inline std::size_t getFixedLengthAttributeOffset(const attribute_id id) const {
- DCHECK(hasAttributeWithId(id));
- DCHECK_EQ(-1, variable_length_attribute_indices_[id]);
- return fixed_length_attribute_offsets_[id];
- }
-
- /**
- * @brief Check whether any attributes of the relation are nullable.
- *
- * @return Whether the relation has any nullable attributes.
- **/
- inline bool hasNullableAttributes() const {
- return num_nullable_attributes_ > 0;
- }
-
- /**
- * @brief Check how many attributes of the relation are nullable.
- *
- * @return The number of nullable attributes in the relation.
- **/
- inline unsigned numNullableAttributes() const {
- return num_nullable_attributes_;
- }
-
- /**
- * @brief Get the index of a nullable attribute among all the nullable
- * attributes in this relation.
- *
- * @param id The id of the desired attribute.
- * @return The attribute's index amongst all of the nullable attributes
- * (intended for indexing into a NULL bitmap), or -1 if the attribute
- * is not nullable.
- **/
- inline int getNullableAttributeIndex(const attribute_id id) const {
- DCHECK(hasAttributeWithId(id));
- return nullable_attribute_indices_[id];
- }
-
- /**
- * @brief Get the number of child attributes.
- *
- * @return The number of child attributes.
- **/
- size_type size() const {
- return attr_map_.size();
- }
-
- /**
- * @brief Determine whether the sequence of attribute IDs has gaps in it.
- *
- * @return Whether the sequence of attribute IDs has any gaps.
- **/
- bool gapsInAttributeSequence() const {
- return (attr_map_.size() != attr_vec_.size());
- }
-
- /**
- * @brief Get the highest attribute ID in this relation.
- *
- * @return The highest attribute ID in this relation (-1 if no attributes
- * exist).
- **/
- attribute_id getMaxAttributeId() const;
-
- /**
- * @brief Get an iterator at the beginning of the child attributes.
- *
- * @return An iterator on the first child attribute.
- **/
- inline const_iterator begin() const {
- return attr_vec_.begin_skip();
- }
-
- /**
- * @brief Get an iterator at one-past-the-end of the child attributes.
- *
- * @return An iterator one-past-the-end of the child attributes.
- **/
- inline const_iterator end() const {
- return attr_vec_.end_skip();
- }
-
- /**
- * @brief Get a vector of the maximum byte lengths for each attribute.
- * @details An index in the vector corresponds with the attribute's id.
- *
- * @return A vector of the maximum byte lengths for each attribute.
- */
- const std::vector<std::size_t>& getMaximumAttributeByteLengths() const {
- return max_byte_lengths_;
- }
-
- protected:
- /**
- * @brief Create a new relation.
- *
- * @param parent The database this relation belongs to.
- * @param name This relation's name.
- * @param id This relation's ID (defaults to -1, which means invalid/unset).
- * @param temporary Whether this relation is temporary (stores an
- * intermediate result during query processing).
- **/
- CatalogRelationSchema(CatalogDatabase* parent,
- const std::string &name,
- const relation_id id = -1,
- const bool temporary = false)
- : parent_(parent),
- id_(id),
- name_(name),
- temporary_(temporary),
- num_nullable_attributes_(0),
- num_variable_length_attributes_(0),
- max_byte_length_(0),
- min_byte_length_(0),
- estimated_byte_length_(0),
- fixed_byte_length_(0),
- max_variable_byte_length_(0),
- min_variable_byte_length_(0),
- min_variable_byte_length_excluding_nullable_(0),
- estimated_variable_byte_length_(0),
- current_nullable_attribute_index_(-1),
- current_variable_length_attribute_index_(-1) {
- }
-
- /**
- * @brief Set the parent CatalogDatabase of this relation. Used by
- * CatalogDatabase (a friend of this class) when adding a new
- * relation.
- *
- * @param parent The new parent for this CatalogRelationSchema.
- **/
- void setParent(CatalogDatabase *parent) {
- parent_ = parent;
- }
-
- /**
- * @brief Set the ID of this relation. Used by CatalogDatabase (a friend of
- * this class) when adding a new relation.
- *
- * @param id The new ID for this CatalogRelationSchema.
- **/
- void setID(const relation_id id) {
- id_ = id;
- }
-
- /**
- * @brief Check whether an attribute_id is within the range of IDs contained
- * in this CatalogRelationSchema.
- *
- * @param id The id to check.
- * @return true if id is in range, false otherwise.
- **/
- bool idInRange(const attribute_id id) const {
- return ((id >= 0)
- && (static_cast<PtrVector<CatalogAttribute>::size_type>(id) < attr_vec_.size()));
- }
-
- CatalogDatabase *parent_;
-
- // The relation id in CatalogDatabase.
- relation_id id_;
-
- // The relation name.
- const std::string name_;
-
- // Whether a temporary relation.
- const bool temporary_;
-
- // A vector of attributes, and NULL if it has removed from the relation
- // schema.
- PtrVector<CatalogAttribute, true> attr_vec_;
-
- // A map from a lower case attribute name to a pointer to the attribute.
- std::unordered_map<std::string, CatalogAttribute*> attr_map_;
-
- // These schema parameters are cached so we don't have to recalculate them
- // every time.
- unsigned num_nullable_attributes_;
- unsigned num_variable_length_attributes_;
- std::size_t max_byte_length_,
- min_byte_length_,
- estimated_byte_length_,
- fixed_byte_length_,
- max_variable_byte_length_,
- min_variable_byte_length_,
- min_variable_byte_length_excluding_nullable_,
- estimated_variable_byte_length_;
- std::vector<std::size_t> fixed_length_attribute_offsets_;
- std::vector<std::size_t> max_byte_lengths_;
-
- // Entries are -1 for non-nullable attributes.
- std::vector<int> nullable_attribute_indices_;
- int current_nullable_attribute_index_;
-
- std::vector<int> variable_length_attribute_indices_;
- int current_variable_length_attribute_index_;
-
- private:
- friend class CatalogDatabase;
-
- DISALLOW_COPY_AND_ASSIGN(CatalogRelationSchema);
-};
-
-/** @} */
-
-} // namespace quickstep
-
-#endif // QUICKSTEP_CATALOG_CATALOG_RELATION_SCHEMA_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogRelationStatistics.cpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogRelationStatistics.cpp b/catalog/CatalogRelationStatistics.cpp
deleted file mode 100644
index 6a51570..0000000
--- a/catalog/CatalogRelationStatistics.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#include "catalog/CatalogRelationStatistics.hpp"
-
-#include "catalog/Catalog.pb.h"
-
-namespace quickstep {
-
-CatalogRelationStatistics::CatalogRelationStatistics(
- const serialization::CatalogRelationStatistics &proto) {
- if (proto.has_num_tuples()) {
- num_tuples_ = proto.num_tuples();
- }
- for (int i = 0; i < proto.num_distinct_values_map_size(); ++i) {
- const auto &entry = proto.num_distinct_values_map(i);
- num_distinct_values_map_.emplace(entry.attr_id(),
- entry.num_distinct_values());
- }
-}
-
-serialization::CatalogRelationStatistics CatalogRelationStatistics::getProto() const {
- serialization::CatalogRelationStatistics proto;
- if (num_tuples_ != 0) {
- proto.set_num_tuples(num_tuples_);
- }
- for (const auto &pair : num_distinct_values_map_) {
- auto entry = proto.add_num_distinct_values_map();
- entry->set_attr_id(pair.first);
- entry->set_num_distinct_values(pair.second);
- }
- return proto;
-}
-
-} // namespace quickstep
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogRelationStatistics.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogRelationStatistics.hpp b/catalog/CatalogRelationStatistics.hpp
deleted file mode 100644
index f2056f3..0000000
--- a/catalog/CatalogRelationStatistics.hpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#ifndef QUICKSTEP_CATALOG_CATALOG_RELATION_STATISTICS_HPP_
-#define QUICKSTEP_CATALOG_CATALOG_RELATION_STATISTICS_HPP_
-
-#include <cstddef>
-#include <unordered_map>
-#include <utility>
-
-#include "catalog/Catalog.pb.h"
-#include "catalog/CatalogTypedefs.hpp"
-#include "utility/Macros.hpp"
-
-namespace quickstep {
-
-/** \addtogroup Catalog
- * @{
- */
-
-/**
- * @brief Statistics of a catalog relation. E.g. total number of tuples,
- * number of distinct values for each column.
- **/
-class CatalogRelationStatistics {
- public:
- /**
- * @brief Constructor.
- **/
- CatalogRelationStatistics()
- : num_tuples_(0) {}
-
- /**
- * @brief Reconstruct a CatalogRelationStatistics object from its serialized
- * Protocol Buffer form.
- *
- * @param proto The Protocol Buffer serialization of a CatalogRelationStatistics
- * object, previously produced by getProto().
- **/
- explicit CatalogRelationStatistics(const serialization::CatalogRelationStatistics &proto);
-
- /**
- * @brief Serialize the CatalogRelationStatistics object as Protocol Buffer.
- *
- * @return The Protocol Buffer representation of the CatalogRelationStatistics
- * object.
- **/
- serialization::CatalogRelationStatistics getProto() const;
-
- /**
- * @brief Set the number of tuples statistic.
- *
- * @param num_tuples The number of tuples statistic.
- */
- void setNumTuples(std::size_t num_tuples) {
- num_tuples_ = num_tuples;
- }
-
- /**
- * @brief Get the number of tuples statistic.
- *
- * @return The number of tuples. Returns 0 if the statistic is not set.
- */
- std::size_t getNumTuples() const {
- return num_tuples_;
- }
-
- /**
- * @brief Set the number of distinct values statistic for a column (catalog attribute).
- *
- * @param attr_id The id of the column.
- * @param num_distinct_values The number of distinct values statistic.
- */
- void setNumDistinctValues(attribute_id attr_id, std::size_t num_distinct_values) {
- num_distinct_values_map_[attr_id] = num_distinct_values;
- }
-
- /**
- * @brief Get the number of distinct values statistic for a column (catalog attribute).
- *
- * @param The id of the column.
- * @return The number of distinct values statistic for the column. Returns 0
- * if the statistic is not set.
- */
- std::size_t getNumDistinctValues(attribute_id attr_id) const {
- const auto it = num_distinct_values_map_.find(attr_id);
- if (it == num_distinct_values_map_.end()) {
- return static_cast<std::size_t>(0);
- } else {
- return it->second;
- }
- }
-
- private:
- // Total number of tuples in the relation.
- std::size_t num_tuples_;
-
- // Number of distinct values for each column.
- std::unordered_map<attribute_id, std::size_t> num_distinct_values_map_;
-
- DISALLOW_COPY_AND_ASSIGN(CatalogRelationStatistics);
-};
-
-/** @} */
-
-} // namespace quickstep
-
-#endif // QUICKSTEP_CATALOG_CATALOG_RELATION_STATISTICS_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/CatalogTypedefs.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogTypedefs.hpp b/catalog/CatalogTypedefs.hpp
deleted file mode 100644
index 70bac84..0000000
--- a/catalog/CatalogTypedefs.hpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#ifndef QUICKSTEP_CATALOG_CATALOG_TYPEDEFS_HPP_
-#define QUICKSTEP_CATALOG_CATALOG_TYPEDEFS_HPP_
-
-#include <climits>
-#include <cstddef>
-
-// In all cases, a negative value indicates an invalid/unset id, except for
-// partition_id.
-
-namespace quickstep {
-
-/** \addtogroup Catalog
- * @{
- */
-
-typedef int database_id;
-typedef int relation_id;
-typedef int attribute_id;
-typedef std::size_t partition_id;
-typedef int numa_node_id;
-
-// This depends on all the above id types being typedefed to int, except for
-// partition_id.
-const int kCatalogMaxID = INT_MAX;
-
-// Catalog ids use negative values as invalid ids. Mark -1 as constant invalid
-// id for the catalog ids.
-constexpr int kInvalidCatalogId = -1;
-
-// Used to indicate no preference for a NUMA Node ID.
-constexpr numa_node_id kAnyNUMANodeID = -1;
-
-constexpr attribute_id kInvalidAttributeID = -1;
-
-/** @} */
-
-} // namespace quickstep
-
-#endif // QUICKSTEP_CATALOG_CATALOG_TYPEDEFS_HPP_
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/catalog/IndexScheme.cpp
----------------------------------------------------------------------
diff --git a/catalog/IndexScheme.cpp b/catalog/IndexScheme.cpp
deleted file mode 100644
index c686c39..0000000
--- a/catalog/IndexScheme.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- **/
-
-#include "catalog/IndexScheme.hpp"
-
-#include <memory>
-#include <string>
-
-#include "catalog/Catalog.pb.h"
-#include "storage/IndexSubBlockDescriptionFactory.hpp"
-#include "storage/StorageBlockLayout.pb.h"
-
-#include "glog/logging.h"
-
-namespace quickstep {
-
-bool IndexScheme::ProtoIsValid(const serialization::IndexScheme &proto) {
- // Check that proto is fully initialized.
- if (!proto.IsInitialized()) {
- return false;
- }
-
- // Check that each index entry contains initialized valid index description.
- for (int i = 0; i < proto.index_entries_size(); ++i) {
- const serialization::IndexScheme_IndexEntry &index_entry = proto.index_entries(i);
- if (!IndexSubBlockDescriptionFactory::ProtoIsValid(index_entry.index_description())) {
- return false;
- }
- }
- return true;
-}
-
-IndexScheme* IndexScheme::ReconstructFromProto(const serialization::IndexScheme &proto) {
- DCHECK(ProtoIsValid(proto))
- << "Attempted to create IndexScheme from an invalid proto description:\n"
- << proto.DebugString();
-
- std::unique_ptr<IndexScheme> index_scheme(new IndexScheme());
-
- for (int index_num = 0; index_num < proto.index_entries_size(); ++index_num) {
- const serialization::IndexScheme_IndexEntry &index_entry = proto.index_entries(index_num);
- // Make sure that index with same name does not already exist.
- DCHECK(index_scheme->index_map_.find(index_entry.index_name())
- == index_scheme->index_map_.end())
- << "Attempted to create IndexScheme from proto with duplicate index names.";
- // Store the index_name and corresponding index description in map.
- index_scheme->index_map_.emplace(index_entry.index_name(), index_entry.index_description());
- }
- return index_scheme.release();
-}
-
-serialization::IndexScheme IndexScheme::getProto() const {
- serialization::IndexScheme proto;
- // Set the entries of the index scheme.
- for (auto cit = index_map_.cbegin(); cit != index_map_.cend(); ++cit) {
- // Create an index entry.
- serialization::IndexScheme_IndexEntry *index_entry = proto.add_index_entries();
-
- // Populate the details of the index entry.
- index_entry->set_index_name(cit->first);
- index_entry->mutable_index_description()->MergeFrom(cit->second);
- }
- return proto;
-}
-
-} // namespace quickstep