You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by ji...@apache.org on 2017/09/20 01:24:07 UTC

[3/8] incubator-quickstep git commit: QUICKSTEP-78: Displayed Partition Info using \d.

QUICKSTEP-78: Displayed Partition Info using \d.


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/c4f7614d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/c4f7614d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/c4f7614d

Branch: refs/heads/fix-iwyu
Commit: c4f7614dcb1584319986bf8841c1426a89f138dc
Parents: b815b38
Author: Zuyu Zhang <zu...@cs.wisc.edu>
Authored: Mon Sep 11 16:35:45 2017 -0500
Committer: Zuyu Zhang <zu...@cs.wisc.edu>
Committed: Mon Sep 11 17:03:00 2017 -0500

----------------------------------------------------------------------
 catalog/CMakeLists.txt            |  2 ++
 catalog/PartitionScheme.cpp       | 14 +++++++++++++
 catalog/PartitionScheme.hpp       | 12 +++++++++++
 catalog/PartitionSchemeHeader.cpp | 38 ++++++++++++++++++++++++++++++++++
 catalog/PartitionSchemeHeader.hpp |  6 ++++++
 cli/CMakeLists.txt                |  1 +
 cli/CommandExecutorUtil.cpp       | 15 ++++++++++----
 cli/tests/command_executor/D.test | 17 +++++++++++++++
 8 files changed, 101 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c4f7614d/catalog/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/catalog/CMakeLists.txt b/catalog/CMakeLists.txt
index 1aa2b41..414d736 100644
--- a/catalog/CMakeLists.txt
+++ b/catalog/CMakeLists.txt
@@ -167,6 +167,8 @@ target_link_libraries(quickstep_catalog_PartitionScheme
                       quickstep_utility_Macros)
 target_link_libraries(quickstep_catalog_PartitionSchemeHeader
                       glog
+                      quickstep_catalog_CatalogAttribute
+                      quickstep_catalog_CatalogRelationSchema
                       quickstep_catalog_CatalogTypedefs
                       quickstep_catalog_Catalog_proto
                       quickstep_storage_StorageConstants

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c4f7614d/catalog/PartitionScheme.cpp
----------------------------------------------------------------------
diff --git a/catalog/PartitionScheme.cpp b/catalog/PartitionScheme.cpp
index 1d7dce0..f7aeb2c 100644
--- a/catalog/PartitionScheme.cpp
+++ b/catalog/PartitionScheme.cpp
@@ -21,6 +21,8 @@
 
 #include <cstddef>
 #include <limits>
+#include <sstream>
+#include <string>
 #include <unordered_set>
 #include <utility>
 #include <vector>
@@ -111,4 +113,16 @@ partition_id PartitionScheme::getPartitionForBlock(const block_id block) const {
   return std::numeric_limits<std::size_t>::max();
 }
 
+std::string PartitionScheme::toString(const CatalogRelationSchema &relation_schema) const {
+  std::ostringstream oss;
+  oss << "  |";
+  for (std::size_t i = 0; i < blocks_in_partition_.size(); ++i) {
+    SpinSharedMutexSharedLock<false> lock(blocks_in_partition_mutexes_[i]);
+    oss << ' ' << blocks_in_partition_[i].size() << " |";
+  }
+  oss << '\n';
+
+  return header_->toString(relation_schema) + oss.str();
+}
+
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c4f7614d/catalog/PartitionScheme.hpp
----------------------------------------------------------------------
diff --git a/catalog/PartitionScheme.hpp b/catalog/PartitionScheme.hpp
index b69a33f..739a723 100644
--- a/catalog/PartitionScheme.hpp
+++ b/catalog/PartitionScheme.hpp
@@ -22,6 +22,7 @@
 
 #include <cstddef>
 #include <memory>
+#include <string>
 #include <unordered_set>
 #include <utility>
 #include <vector>
@@ -39,6 +40,8 @@
 
 namespace quickstep {
 
+class CatalogRelationSchema;
+
 /** \addtogroup Catalog
  *  @{
  */
@@ -168,6 +171,15 @@ class PartitionScheme {
    **/
   partition_id getPartitionForBlock(const block_id block) const;
 
+  /**
+   * @brief Display the partition scheme as a string.
+   *
+   * @param relation_schema The relation schema that owns this scheme.
+   *
+   * @return the string of the partition scheme.
+   **/
+  std::string toString(const CatalogRelationSchema &relation_schema) const;
+
  private:
   std::unique_ptr<const PartitionSchemeHeader> header_;
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c4f7614d/catalog/PartitionSchemeHeader.cpp
----------------------------------------------------------------------
diff --git a/catalog/PartitionSchemeHeader.cpp b/catalog/PartitionSchemeHeader.cpp
index f7a0971..af69f8f 100644
--- a/catalog/PartitionSchemeHeader.cpp
+++ b/catalog/PartitionSchemeHeader.cpp
@@ -20,11 +20,15 @@
 #include "catalog/PartitionSchemeHeader.hpp"
 
 #include <cstddef>
+#include <sstream>
+#include <string>
 #include <unordered_set>
 #include <utility>
 #include <vector>
 
 #include "catalog/Catalog.pb.h"
+#include "catalog/CatalogAttribute.hpp"
+#include "catalog/CatalogRelationSchema.hpp"
 #include "catalog/CatalogTypedefs.hpp"
 #include "types/Type.hpp"
 #include "types/Type.pb.h"
@@ -165,6 +169,40 @@ serialization::PartitionSchemeHeader PartitionSchemeHeader::getProto() const {
   return proto;
 }
 
+std::string PartitionSchemeHeader::toString(const CatalogRelationSchema &relation_schema) const {
+  std::ostringstream oss;
+  oss << "PARTITION BY ";
+  switch (partition_type_) {
+    case PartitionType::kHash:
+      oss << "HASH";
+      break;
+    case PartitionType::kRandom:
+      oss << "RANDOM";
+      break;
+    case PartitionType::kRange:
+      oss << "RANGE";
+      break;
+    default:
+      LOG(FATAL) << "Invalid Partition Type.";
+  }
+
+  oss << " ( ";
+  if (!partition_attribute_ids_.empty()) {
+    const CatalogAttribute *attr = relation_schema.getAttributeById(partition_attribute_ids_[0]);
+    DCHECK(attr);
+    oss << attr->getName();
+
+    for (size_t i = 1; i < partition_attribute_ids_.size(); ++i) {
+      attr = relation_schema.getAttributeById(partition_attribute_ids_[i]);
+      DCHECK(attr);
+      oss << ", " << attr->getName();
+    }
+  }
+  oss << " ) PARTITIONS " << num_partitions_ << '\n';
+
+  return oss.str();
+}
+
 serialization::PartitionSchemeHeader RangePartitionSchemeHeader::getProto() const {
   serialization::PartitionSchemeHeader proto = PartitionSchemeHeader::getProto();
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c4f7614d/catalog/PartitionSchemeHeader.hpp
----------------------------------------------------------------------
diff --git a/catalog/PartitionSchemeHeader.hpp b/catalog/PartitionSchemeHeader.hpp
index 9bbbc0f..d34ca1f 100644
--- a/catalog/PartitionSchemeHeader.hpp
+++ b/catalog/PartitionSchemeHeader.hpp
@@ -23,6 +23,7 @@
 #include <cstddef>
 #include <memory>
 #include <random>
+#include <string>
 #include <utility>
 #include <vector>
 
@@ -41,6 +42,7 @@
 
 namespace quickstep {
 
+class CatalogRelationSchema;
 class Type;
 
 /** \addtogroup Catalog
@@ -164,6 +166,10 @@ class PartitionSchemeHeader {
   const PartitionAttributeIds partition_attribute_ids_;
 
  private:
+  std::string toString(const CatalogRelationSchema &relation_schema) const;
+
+  friend class PartitionScheme;
+
   DISALLOW_COPY_AND_ASSIGN(PartitionSchemeHeader);
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c4f7614d/cli/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index e802e8d..33d10e3 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -147,6 +147,7 @@ target_link_libraries(quickstep_cli_CommandExecutorUtil
                       quickstep_catalog_CatalogDatabase
                       quickstep_catalog_CatalogRelation
                       quickstep_catalog_IndexScheme
+                      quickstep_catalog_PartitionScheme
                       quickstep_cli_PrintToScreen
                       quickstep_parser_ParseString
                       quickstep_storage_StorageBlockLayout_proto

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c4f7614d/cli/CommandExecutorUtil.cpp
----------------------------------------------------------------------
diff --git a/cli/CommandExecutorUtil.cpp b/cli/CommandExecutorUtil.cpp
index d17617f..b3109f9 100644
--- a/cli/CommandExecutorUtil.cpp
+++ b/cli/CommandExecutorUtil.cpp
@@ -22,6 +22,7 @@
 #include <algorithm>
 #include <cstddef>
 #include <iomanip>
+#include <sstream>
 #include <string>
 #include <vector>
 
@@ -29,6 +30,7 @@
 #include "catalog/CatalogDatabase.hpp"
 #include "catalog/CatalogRelation.hpp"
 #include "catalog/IndexScheme.hpp"
+#include "catalog/PartitionScheme.hpp"
 #include "cli/PrintToScreen.hpp"
 #include "parser/ParseString.hpp"
 #include "storage/StorageBlockLayout.pb.h"
@@ -146,9 +148,9 @@ string ExecuteDescribeTable(
   }
 
   ostringstream oss;
-  oss << setw(kInitMaxColumnWidth) << "Table" << " \"" << table_name_val << "\"\n";
-  oss << std::left << setw(max_attr_column_width + 1) << " Column" << " |";
-  oss << setw(max_type_column_width + 1) << " Type" << '\n';
+  oss << setw(kInitMaxColumnWidth) << "Table" << " \"" << table_name_val << "\"\n"
+      << std::left << setw(max_attr_column_width + 1) << " Column" << " |"
+      << setw(max_type_column_width + 1) << " Type" << '\n';
 
   // Add room for one extra character to allow spacing between the column ending and the vertical bar
   oss << PrintToScreen::GenerateHBar({ max_attr_column_width + 1, max_type_column_width + 1 });
@@ -157,7 +159,7 @@ string ExecuteDescribeTable(
     oss << ' ' << setw(max_attr_column_width) << attr.getDisplayName() << " | "
         << setw(max_type_column_width) << attr.getType().getName() << '\n';
   }
-  // TODO(rogers): Add handlers for partitioning information.
+
   if (relation->hasIndexScheme()) {
     oss << setw(kInitMaxColumnWidth + 2) << " Indexes" << '\n';
     for (const auto &index : relation->getIndexScheme()) {
@@ -173,6 +175,11 @@ string ExecuteDescribeTable(
     }
   }
 
+  if (relation->hasPartitionScheme()) {
+    oss << setw(kInitMaxColumnWidth + 2) << " Partition Info\n  "
+        << relation->getPartitionScheme()->toString(*relation);
+  }
+
   return oss.str();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c4f7614d/cli/tests/command_executor/D.test
----------------------------------------------------------------------
diff --git a/cli/tests/command_executor/D.test b/cli/tests/command_executor/D.test
index 1b35b58..36e9a92 100644
--- a/cli/tests/command_executor/D.test
+++ b/cli/tests/command_executor/D.test
@@ -38,6 +38,11 @@ CREATE TABLE foo4 (col1 INT,
                    col5 CHAR(5));
 CREATE INDEX foo4_index_1 ON foo4 (col1, col2) USING CSBTREE;
 CREATE INDEX foo4_index_2 ON foo4 (col3, col4) USING CSBTREE;
+CREATE TABLE foo_hash_part (col1 INT,
+                            col2 FLOAT)
+PARTITION BY HASH(col1) PARTITIONS 4;
+INSERT INTO foo_hash_part
+SELECT i, i * 3.0 FROM generate_series(1, 100) AS gs(i);
 CREATE TABLE averylongtablenamethatseemstoneverend (col1 INT);
 DROP TABLE TEST;
 INSERT INTO averylongtablenamethatseemstoneverend VALUES (1);
@@ -102,6 +107,17 @@ INSERT INTO foo3 values(5, 1, 1.0, 1.0, 'XYZZ');
   "foo4_index_2" CSB_TREE (col3, col4)
   "foo4_index_1" CSB_TREE (col1, col2)
 ==
+\d foo_hash_part
+--
+ Table "foo_hash_part"
+ Column | Type  
++-------+-------+
+ col1   | Int   
+ col2   | Float 
+ Partition Info
+  PARTITION BY HASH ( col1 ) PARTITIONS 4
+  | 1 | 1 | 1 | 1 |
+==
 \d
 --
        List of relations
@@ -112,6 +128,7 @@ INSERT INTO foo3 values(5, 1, 1.0, 1.0, 'XYZZ');
  foo2                                  | table | 1      
  foo3                                  | table | 1      
  foo4                                  | table | 0      
+ foo_hash_part                         | table | 4      
  averylongtablenamethatseemstoneverend | table | 1      
 
 ==