You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by zu...@apache.org on 2017/01/13 01:03:46 UTC

[1/4] incubator-quickstep git commit: Fixed the bug in addBlockToPartition. [Forced Update!]

Repository: incubator-quickstep
Updated Branches:
  refs/heads/quickstep_partition_parser_support 3750babdf -> 33680b92c (forced update)


Fixed the bug in addBlockToPartition.


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

Branch: refs/heads/quickstep_partition_parser_support
Commit: 8d25d43b46ffb4b7b43efc0ed4f49a74fb9607b6
Parents: 86411b9
Author: Zuyu Zhang <zu...@apache.org>
Authored: Wed Jan 11 13:36:39 2017 -0800
Committer: Zuyu Zhang <zu...@apache.org>
Committed: Wed Jan 11 13:36:39 2017 -0800

----------------------------------------------------------------------
 query_execution/PolicyEnforcerBase.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/8d25d43b/query_execution/PolicyEnforcerBase.cpp
----------------------------------------------------------------------
diff --git a/query_execution/PolicyEnforcerBase.cpp b/query_execution/PolicyEnforcerBase.cpp
index b799d5f..1a2ab46 100644
--- a/query_execution/PolicyEnforcerBase.cpp
+++ b/query_execution/PolicyEnforcerBase.cpp
@@ -105,8 +105,7 @@ void PolicyEnforcerBase::processMessage(const TaggedMessage &tagged_message) {
       relation->addBlock(block);
 
       if (proto.has_partition_id()) {
-        relation->getPartitionSchemeMutable()->addBlockToPartition(
-            proto.partition_id(), block);
+        relation->getPartitionSchemeMutable()->addBlockToPartition(block, proto.partition_id());
       }
       return;
     }


[2/4] incubator-quickstep git commit: Refactored the method to reconstruct PartitionSchemeHeader.

Posted by zu...@apache.org.
Refactored the method to reconstruct PartitionSchemeHeader.


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

Branch: refs/heads/quickstep_partition_parser_support
Commit: c8c5d45bd3553e05ef3f87996925c49f964e8682
Parents: 8d25d43
Author: Zuyu Zhang <zu...@apache.org>
Authored: Tue Jan 10 14:10:24 2017 -0800
Committer: Zuyu Zhang <zu...@apache.org>
Committed: Wed Jan 11 13:36:57 2017 -0800

----------------------------------------------------------------------
 catalog/CMakeLists.txt                     |  3 +++
 catalog/Catalog.proto                      |  3 ++-
 catalog/CatalogRelation.cpp                |  8 ++------
 catalog/PartitionScheme.cpp                |  5 ++---
 catalog/PartitionScheme.hpp                |  6 +-----
 catalog/PartitionSchemeHeader.cpp          | 15 +++++++++++++--
 catalog/PartitionSchemeHeader.hpp          |  7 ++++---
 catalog/tests/PartitionScheme_unittest.cpp |  4 ++--
 storage/InsertDestination.cpp              |  7 +------
 9 files changed, 30 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/catalog/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/catalog/CMakeLists.txt b/catalog/CMakeLists.txt
index 143d12f..7de9a67 100644
--- a/catalog/CMakeLists.txt
+++ b/catalog/CMakeLists.txt
@@ -168,6 +168,9 @@ target_link_libraries(quickstep_catalog_PartitionSchemeHeader
                       glog
                       quickstep_catalog_CatalogTypedefs
                       quickstep_catalog_Catalog_proto
+                      quickstep_types_Type
+                      quickstep_types_TypeFactory
+                      quickstep_types_Type_proto
                       quickstep_types_TypedValue
                       quickstep_types_TypedValue_proto
                       quickstep_types_operations_comparisons_Comparison

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/catalog/Catalog.proto
----------------------------------------------------------------------
diff --git a/catalog/Catalog.proto b/catalog/Catalog.proto
index a54862f..89cb7e5 100644
--- a/catalog/Catalog.proto
+++ b/catalog/Catalog.proto
@@ -49,7 +49,8 @@ message PartitionSchemeHeader {
 message RangePartitionSchemeHeader {
   extend PartitionSchemeHeader {
     // All required.
-    repeated TypedValue partition_range_boundaries = 32;
+    optional Type partition_attr_type = 32;
+    repeated TypedValue partition_range_boundaries = 33;
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/catalog/CatalogRelation.cpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogRelation.cpp b/catalog/CatalogRelation.cpp
index c288532..41c503c 100644
--- a/catalog/CatalogRelation.cpp
+++ b/catalog/CatalogRelation.cpp
@@ -43,8 +43,6 @@
 
 namespace quickstep {
 
-class Type;
-
 bool CatalogRelation::ProtoIsValid(const serialization::CatalogRelationSchema &proto) {
   // Check that proto is fully initialized.
   if (!CatalogRelationSchema::ProtoIsValid(proto) ||
@@ -90,11 +88,9 @@ CatalogRelation::CatalogRelation(const serialization::CatalogRelationSchema &pro
     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();
+    DCHECK(hasAttributeWithId(proto_partition_scheme.header().partition_attribute_id()));
 
-    setPartitionScheme(PartitionScheme::ReconstructFromProto(proto_partition_scheme, attr_type));
+    setPartitionScheme(PartitionScheme::ReconstructFromProto(proto_partition_scheme));
 
     // Deserializing the NUMA placement scheme for the relation.
 #ifdef QUICKSTEP_HAVE_LIBNUMA

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/catalog/PartitionScheme.cpp
----------------------------------------------------------------------
diff --git a/catalog/PartitionScheme.cpp b/catalog/PartitionScheme.cpp
index d6e3469..1d7dce0 100644
--- a/catalog/PartitionScheme.cpp
+++ b/catalog/PartitionScheme.cpp
@@ -55,8 +55,7 @@ bool PartitionScheme::ProtoIsValid(
   return true;
 }
 
-PartitionScheme* PartitionScheme::ReconstructFromProto(const serialization::PartitionScheme &proto,
-                                                       const Type &attr_type) {
+PartitionScheme* PartitionScheme::ReconstructFromProto(const serialization::PartitionScheme &proto) {
   DCHECK(ProtoIsValid(proto))
       << "Attempted to create PartitionScheme from an invalid proto description:\n"
       << proto.DebugString();
@@ -74,7 +73,7 @@ PartitionScheme* PartitionScheme::ReconstructFromProto(const serialization::Part
   }
 
   return new PartitionScheme(
-      PartitionSchemeHeader::ReconstructFromProto(proto.header(), attr_type),
+      PartitionSchemeHeader::ReconstructFromProto(proto.header()),
       move(blocks_in_partition));
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/catalog/PartitionScheme.hpp
----------------------------------------------------------------------
diff --git a/catalog/PartitionScheme.hpp b/catalog/PartitionScheme.hpp
index c882a5e..b69a33f 100644
--- a/catalog/PartitionScheme.hpp
+++ b/catalog/PartitionScheme.hpp
@@ -39,8 +39,6 @@
 
 namespace quickstep {
 
-class Type;
-
 /** \addtogroup Catalog
  *  @{
  */
@@ -82,11 +80,9 @@ class PartitionScheme {
    *
    * @param proto The Protocol Buffer serialization of a Partition Scheme,
    *        previously produced by getProto().
-   * @param attr_type The attribute type of the partitioning attribute.
    * @return The deserialized partition scheme object.
    **/
-  static PartitionScheme* ReconstructFromProto(const serialization::PartitionScheme &proto,
-                                               const Type &attr_type);
+  static PartitionScheme* ReconstructFromProto(const serialization::PartitionScheme &proto);
 
   /**
    * @brief Check whether a serialization::PartitionScheme is fully-formed and

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/catalog/PartitionSchemeHeader.cpp
----------------------------------------------------------------------
diff --git a/catalog/PartitionSchemeHeader.cpp b/catalog/PartitionSchemeHeader.cpp
index 26c317d..a4a9063 100644
--- a/catalog/PartitionSchemeHeader.cpp
+++ b/catalog/PartitionSchemeHeader.cpp
@@ -24,6 +24,9 @@
 #include <vector>
 
 #include "catalog/Catalog.pb.h"
+#include "types/Type.hpp"
+#include "types/Type.pb.h"
+#include "types/TypeFactory.hpp"
 #include "types/TypedValue.hpp"
 #include "types/TypedValue.pb.h"
 
@@ -59,7 +62,8 @@ bool PartitionSchemeHeader::ProtoIsValid(
     case serialization::PartitionSchemeHeader::RANGE: {
       const std::size_t num_ranges =
           proto.ExtensionSize(serialization::RangePartitionSchemeHeader::partition_range_boundaries);
-      return num_ranges == proto.num_partitions() - 1;
+      return num_ranges == proto.num_partitions() - 1 &&
+             proto.HasExtension(serialization::RangePartitionSchemeHeader::partition_attr_type);
     }
     default:
       // Partition type is unknown.
@@ -68,7 +72,7 @@ bool PartitionSchemeHeader::ProtoIsValid(
 }
 
 PartitionSchemeHeader* PartitionSchemeHeader::ReconstructFromProto(
-    const serialization::PartitionSchemeHeader &proto, const Type &attr_type) {
+    const serialization::PartitionSchemeHeader &proto) {
   DCHECK(ProtoIsValid(proto))
       << "Attempted to create PartitionSchemeHeader from an invalid proto description:\n"
       << proto.DebugString();
@@ -78,6 +82,10 @@ PartitionSchemeHeader* PartitionSchemeHeader::ReconstructFromProto(
       return new HashPartitionSchemeHeader(proto.num_partitions(), proto.partition_attribute_id());
     }
     case serialization::PartitionSchemeHeader::RANGE: {
+      const Type &attr_type =
+          TypeFactory::ReconstructFromProto(proto.GetExtension(
+              serialization::RangePartitionSchemeHeader::partition_attr_type));
+
       std::vector<TypedValue> partition_ranges;
       for (int i = 0;
            i < proto.ExtensionSize(serialization::RangePartitionSchemeHeader::partition_range_boundaries);
@@ -123,6 +131,9 @@ serialization::PartitionSchemeHeader RangePartitionSchemeHeader::getProto() cons
   proto.set_num_partitions(num_partitions_);
   proto.set_partition_attribute_id(partition_attribute_id_);
 
+  proto.MutableExtension(serialization::RangePartitionSchemeHeader::partition_attr_type)
+      ->MergeFrom(partition_attr_type_->getProto());
+
   for (std::size_t i = 0; i < partition_range_boundaries_.size(); ++i) {
     proto.AddExtension(serialization::RangePartitionSchemeHeader::partition_range_boundaries)
         ->MergeFrom(partition_range_boundaries_[i].getProto());

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/catalog/PartitionSchemeHeader.hpp
----------------------------------------------------------------------
diff --git a/catalog/PartitionSchemeHeader.hpp b/catalog/PartitionSchemeHeader.hpp
index 89efc6d..c1d65d1 100644
--- a/catalog/PartitionSchemeHeader.hpp
+++ b/catalog/PartitionSchemeHeader.hpp
@@ -65,12 +65,10 @@ class PartitionSchemeHeader {
    *
    * @param proto The Protocol Buffer serialization of a PartitionSchemeHeader,
    *        previously produced by getProto().
-   * @param attr_type The attribute type of the partitioning attribute.
    * @return The reconstructed PartitionSchemeHeader object.
    **/
   static PartitionSchemeHeader* ReconstructFromProto(
-      const serialization::PartitionSchemeHeader &proto,
-      const Type &attr_type);
+      const serialization::PartitionSchemeHeader &proto);
 
   /**
    * @brief Check whether a serialization::PartitionSchemeHeader is fully-formed
@@ -227,6 +225,7 @@ class RangePartitionSchemeHeader : public PartitionSchemeHeader {
                              const attribute_id attribute,
                              std::vector<TypedValue> &&partition_range)
       : PartitionSchemeHeader(PartitionType::kRange, num_partitions, attribute),
+        partition_attr_type_(&partition_attribute_type),
         partition_range_boundaries_(std::move(partition_range)) {
     DCHECK_EQ(num_partitions - 1, partition_range_boundaries_.size());
 
@@ -298,6 +297,8 @@ class RangePartitionSchemeHeader : public PartitionSchemeHeader {
     }
   }
 
+  const Type* partition_attr_type_;
+
   // The boundaries for each range in the RangePartitionSchemeHeader.
   // The upper bound of the range is stored here.
   const std::vector<TypedValue> partition_range_boundaries_;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/catalog/tests/PartitionScheme_unittest.cpp
----------------------------------------------------------------------
diff --git a/catalog/tests/PartitionScheme_unittest.cpp b/catalog/tests/PartitionScheme_unittest.cpp
index d10b26e..97a9092 100644
--- a/catalog/tests/PartitionScheme_unittest.cpp
+++ b/catalog/tests/PartitionScheme_unittest.cpp
@@ -511,7 +511,7 @@ TEST(PartitionSchemeTest, CheckHashPartitionSchemeSerialization) {
   }
   std::unique_ptr<PartitionScheme> part_scheme_from_proto;
   part_scheme_from_proto.reset(
-      PartitionScheme::ReconstructFromProto(part_scheme->getProto(), TypeFactory::GetType(kInt)));
+      PartitionScheme::ReconstructFromProto(part_scheme->getProto()));
 
   const PartitionSchemeHeader &header = part_scheme->getPartitionSchemeHeader();
   const PartitionSchemeHeader &header_from_proto = part_scheme_from_proto->getPartitionSchemeHeader();
@@ -561,7 +561,7 @@ TEST(PartitionSchemeTest, CheckRangePartitionSchemeSerialization) {
   std::unique_ptr<PartitionScheme> part_scheme_from_proto;
 
   part_scheme_from_proto.reset(
-      PartitionScheme::ReconstructFromProto(part_scheme->getProto(), type));
+      PartitionScheme::ReconstructFromProto(part_scheme->getProto()));
 
   const PartitionSchemeHeader &header = part_scheme->getPartitionSchemeHeader();
   const PartitionSchemeHeader &header_from_proto = part_scheme_from_proto->getPartitionSchemeHeader();

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/c8c5d45b/storage/InsertDestination.cpp
----------------------------------------------------------------------
diff --git a/storage/InsertDestination.cpp b/storage/InsertDestination.cpp
index 067edf6..19bb356 100644
--- a/storage/InsertDestination.cpp
+++ b/storage/InsertDestination.cpp
@@ -56,8 +56,6 @@ using std::vector;
 
 namespace quickstep {
 
-class Type;
-
 InsertDestination::InsertDestination(const CatalogRelationSchema &relation,
                                      const StorageBlockLayout *layout,
                                      StorageManager *storage_manager,
@@ -132,11 +130,8 @@ InsertDestination* InsertDestination::ReconstructFromProto(
         partitions.push_back(move(partition));
       }
 
-      const serialization::PartitionSchemeHeader &proto_partition_scheme_header = proto_partition_scheme.header();
-      const Type &attr_type =
-          relation.getAttributeById(proto_partition_scheme_header.partition_attribute_id())->getType();
       return new PartitionAwareInsertDestination(
-          PartitionSchemeHeader::ReconstructFromProto(proto_partition_scheme_header, attr_type),
+          PartitionSchemeHeader::ReconstructFromProto(proto_partition_scheme.header()),
           relation,
           layout,
           storage_manager,


[3/4] incubator-quickstep git commit: Refactored SelectOperator::getAllWorkOrders.

Posted by zu...@apache.org.
Refactored SelectOperator::getAllWorkOrders.


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

Branch: refs/heads/quickstep_partition_parser_support
Commit: 222942320c6f441ca3b1b974de8a7e80babc081f
Parents: c8c5d45
Author: Zuyu Zhang <zu...@apache.org>
Authored: Wed Jan 11 18:27:59 2017 -0800
Committer: Zuyu Zhang <zu...@apache.org>
Committed: Thu Jan 12 13:48:26 2017 -0800

----------------------------------------------------------------------
 relational_operators/SelectOperator.cpp | 192 +++++++++------------------
 relational_operators/SelectOperator.hpp |  14 --
 2 files changed, 61 insertions(+), 145 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/22294232/relational_operators/SelectOperator.cpp
----------------------------------------------------------------------
diff --git a/relational_operators/SelectOperator.cpp b/relational_operators/SelectOperator.cpp
index 236ee7c..f5c9ee9 100644
--- a/relational_operators/SelectOperator.cpp
+++ b/relational_operators/SelectOperator.cpp
@@ -22,6 +22,7 @@
 #include <memory>
 #include <vector>
 
+#include "catalog/CatalogTypedefs.hpp"
 #include "query_execution/QueryContext.hpp"
 #include "query_execution/WorkOrderProtosContainer.hpp"
 #include "query_execution/WorkOrdersContainer.hpp"
@@ -43,104 +44,6 @@ namespace quickstep {
 
 class Predicate;
 
-void SelectOperator::addWorkOrders(WorkOrdersContainer *container,
-                                   QueryContext *query_context,
-                                   StorageManager *storage_manager,
-                                   const Predicate *predicate,
-                                   const std::vector<std::unique_ptr<const Scalar>> *selection,
-                                   InsertDestination *output_destination) {
-  if (input_relation_is_stored_) {
-    for (const block_id input_block_id : input_relation_block_ids_) {
-      container->addNormalWorkOrder(
-          new SelectWorkOrder(
-              query_id_,
-              input_relation_,
-              input_block_id,
-              predicate,
-              simple_projection_,
-              simple_selection_,
-              selection,
-              output_destination,
-              storage_manager,
-              CreateLIPFilterAdaptiveProberHelper(lip_deployment_index_, query_context)),
-          op_index_);
-    }
-  } else {
-    while (num_workorders_generated_ < input_relation_block_ids_.size()) {
-      container->addNormalWorkOrder(
-          new SelectWorkOrder(
-              query_id_,
-              input_relation_,
-              input_relation_block_ids_[num_workorders_generated_],
-              predicate,
-              simple_projection_,
-              simple_selection_,
-              selection,
-              output_destination,
-              storage_manager,
-              CreateLIPFilterAdaptiveProberHelper(lip_deployment_index_, query_context)),
-          op_index_);
-      ++num_workorders_generated_;
-    }
-  }
-}
-
-#ifdef QUICKSTEP_HAVE_LIBNUMA
-void SelectOperator::addPartitionAwareWorkOrders(WorkOrdersContainer *container,
-                                                 QueryContext *query_context,
-                                                 StorageManager *storage_manager,
-                                                 const Predicate *predicate,
-                                                 const std::vector<std::unique_ptr<const Scalar>> *selection,
-                                                 InsertDestination *output_destination) {
-  DCHECK(placement_scheme_ != nullptr);
-  const std::size_t num_partitions = input_relation_.getPartitionScheme().getPartitionSchemeHeader().getNumPartitions();
-  if (input_relation_is_stored_) {
-    for (std::size_t part_id = 0; part_id < num_partitions; ++part_id) {
-      for (const block_id input_block_id :
-           input_relation_block_ids_in_partition_[part_id]) {
-        container->addNormalWorkOrder(
-            new SelectWorkOrder(
-                query_id_,
-                input_relation_,
-                input_block_id,
-                predicate,
-                simple_projection_,
-                simple_selection_,
-                selection,
-                output_destination,
-                storage_manager,
-                CreateLIPFilterAdaptiveProberHelper(lip_deployment_index_, query_context),
-                placement_scheme_->getNUMANodeForBlock(input_block_id)),
-            op_index_);
-      }
-    }
-  } else {
-    for (std::size_t part_id = 0; part_id < num_partitions; ++part_id) {
-      while (num_workorders_generated_in_partition_[part_id] <
-             input_relation_block_ids_in_partition_[part_id].size()) {
-        block_id block_in_partition
-            = input_relation_block_ids_in_partition_[part_id][num_workorders_generated_in_partition_[part_id]];
-        container->addNormalWorkOrder(
-            new SelectWorkOrder(
-                query_id_,
-                input_relation_,
-                block_in_partition,
-                predicate,
-                simple_projection_,
-                simple_selection_,
-                selection,
-                output_destination,
-                storage_manager,
-                CreateLIPFilterAdaptiveProberHelper(lip_deployment_index_, query_context),
-                placement_scheme_->getNUMANodeForBlock(block_in_partition)),
-            op_index_);
-        ++num_workorders_generated_in_partition_[part_id];
-      }
-    }
-  }
-}
-#endif
-
 bool SelectOperator::getAllWorkOrders(
     WorkOrdersContainer *container,
     QueryContext *query_context,
@@ -159,48 +62,75 @@ bool SelectOperator::getAllWorkOrders(
       query_context->getInsertDestination(output_destination_index_);
 
   if (input_relation_is_stored_) {
-    if (!started_) {
-      if (input_relation_.hasPartitionScheme()) {
+    if (started_) {
+      return true;
+    }
+
+    if (input_relation_.hasPartitionScheme()) {
+      const std::size_t num_partitions =
+          input_relation_.getPartitionScheme().getPartitionSchemeHeader().getNumPartitions();
+
+      for (std::size_t part_id = 0; part_id < num_partitions; ++part_id) {
+        for (const block_id input_block_id : input_relation_block_ids_in_partition_[part_id]) {
+          numa_node_id numa_node = 0;
 #ifdef QUICKSTEP_HAVE_LIBNUMA
-        if (input_relation_.hasNUMAPlacementScheme()) {
-          addPartitionAwareWorkOrders(container,
-                                      query_context,
-                                      storage_manager,
-                                      predicate,
-                                      selection,
-                                      output_destination);
+          if (input_relation_.hasNUMAPlacementScheme()) {
+            numa_node = placement_scheme_->getNUMANodeForBlock(input_block_id);
+          }
+#endif  // QUICKSTEP_HAVE_LIBNUMA
+          container->addNormalWorkOrder(
+              new SelectWorkOrder(query_id_, input_relation_, input_block_id, predicate, simple_projection_,
+                                  simple_selection_, selection, output_destination, storage_manager,
+                                  CreateLIPFilterAdaptiveProberHelper(lip_deployment_index_, query_context), numa_node),
+              op_index_);
         }
-#endif
-      } else {
-        addWorkOrders(container,
-                      query_context,
-                      storage_manager,
-                      predicate,
-                      selection,
-                      output_destination);
       }
-      started_ = true;
+    } else {
+      for (const block_id input_block_id : input_relation_block_ids_) {
+        container->addNormalWorkOrder(
+            new SelectWorkOrder(query_id_, input_relation_, input_block_id, predicate, simple_projection_,
+                                simple_selection_, selection, output_destination, storage_manager,
+                                CreateLIPFilterAdaptiveProberHelper(lip_deployment_index_, query_context)),
+            op_index_);
+      }
     }
-    return started_;
+    started_ = true;
+    return true;
   } else {
     if (input_relation_.hasPartitionScheme()) {
+      const std::size_t num_partitions =
+          input_relation_.getPartitionScheme().getPartitionSchemeHeader().getNumPartitions();
+
+      for (std::size_t part_id = 0; part_id < num_partitions; ++part_id) {
+        while (num_workorders_generated_in_partition_[part_id] <
+               input_relation_block_ids_in_partition_[part_id].size()) {
+          const block_id block_in_partition
+              = input_relation_block_ids_in_partition_[part_id][num_workorders_generated_in_partition_[part_id]];
+
+          numa_node_id numa_node = 0;
 #ifdef QUICKSTEP_HAVE_LIBNUMA
-        if (input_relation_.hasNUMAPlacementScheme()) {
-          addPartitionAwareWorkOrders(container,
-                                      query_context,
-                                      storage_manager,
-                                      predicate,
-                                      selection,
-                                      output_destination);
+          if (input_relation_.hasNUMAPlacementScheme()) {
+            numa_node = placement_scheme_->getNUMANodeForBlock(block_in_partition);
+          }
+#endif  // QUICKSTEP_HAVE_LIBNUMA
+          container->addNormalWorkOrder(
+              new SelectWorkOrder(query_id_, input_relation_, block_in_partition, predicate, simple_projection_,
+                                  simple_selection_, selection, output_destination, storage_manager,
+                                  CreateLIPFilterAdaptiveProberHelper(lip_deployment_index_, query_context), numa_node),
+              op_index_);
+          ++num_workorders_generated_in_partition_[part_id];
         }
-#endif
+      }
     } else {
-        addWorkOrders(container,
-                      query_context,
-                      storage_manager,
-                      predicate,
-                      selection,
-                      output_destination);
+      while (num_workorders_generated_ < input_relation_block_ids_.size()) {
+        container->addNormalWorkOrder(
+            new SelectWorkOrder(query_id_, input_relation_, input_relation_block_ids_[num_workorders_generated_],
+                                predicate, simple_projection_, simple_selection_, selection, output_destination,
+                                storage_manager,
+                                CreateLIPFilterAdaptiveProberHelper(lip_deployment_index_, query_context)),
+            op_index_);
+        ++num_workorders_generated_;
+      }
     }
     return done_feeding_input_relation_;
   }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/22294232/relational_operators/SelectOperator.hpp
----------------------------------------------------------------------
diff --git a/relational_operators/SelectOperator.hpp b/relational_operators/SelectOperator.hpp
index 2ace458..6741f45 100644
--- a/relational_operators/SelectOperator.hpp
+++ b/relational_operators/SelectOperator.hpp
@@ -248,20 +248,6 @@ class SelectOperator : public RelationalOperator {
     return output_relation_.getID();
   }
 
-  void addWorkOrders(WorkOrdersContainer *container,
-                     QueryContext *query_context,
-                     StorageManager *storage_manager,
-                     const Predicate *predicate,
-                     const std::vector<std::unique_ptr<const Scalar>> *selection,
-                     InsertDestination *output_destination);
-
-  void addPartitionAwareWorkOrders(WorkOrdersContainer *container,
-                                   QueryContext *query_context,
-                                   StorageManager *storage_manager,
-                                   const Predicate *predicate,
-                                   const std::vector<std::unique_ptr<const Scalar>> *selection,
-                                   InsertDestination *output_destination);
-
  private:
   /**
    * @brief Create Work Order proto.


[4/4] incubator-quickstep git commit: Added optimizer support for CreateTable w/ hash partitions.

Posted by zu...@apache.org.
Added optimizer support for CreateTable w/ hash partitions.


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

Branch: refs/heads/quickstep_partition_parser_support
Commit: 33680b92c2ca92f1f9a721fa3b8de0d4d3b00a7b
Parents: 2229423
Author: Zuyu Zhang <zu...@apache.org>
Authored: Tue Jan 10 17:00:08 2017 -0800
Committer: Zuyu Zhang <zu...@apache.org>
Committed: Thu Jan 12 13:56:57 2017 -0800

----------------------------------------------------------------------
 query_optimizer/CMakeLists.txt                  |   2 +
 query_optimizer/ExecutionGenerator.cpp          |  46 ++++++--
 query_optimizer/logical/CMakeLists.txt          |   1 +
 query_optimizer/logical/CreateTable.hpp         |  22 +++-
 query_optimizer/physical/CMakeLists.txt         |   1 +
 query_optimizer/physical/CreateTable.hpp        |  22 +++-
 query_optimizer/resolver/CMakeLists.txt         |   3 +
 query_optimizer/resolver/Resolver.cpp           | 106 ++++++++++++++-----
 query_optimizer/resolver/Resolver.hpp           |  12 +++
 query_optimizer/strategy/OneToOne.cpp           |   3 +-
 .../tests/execution_generator/CMakeLists.txt    |   6 ++
 .../tests/execution_generator/Create.test       |   9 ++
 .../tests/execution_generator/Partition.test    |  54 ++++++++++
 .../tests/logical_generator/Create.test         |  10 ++
 .../tests/physical_generator/Create.test        |  18 ++++
 query_optimizer/tests/resolver/Create.test      |  10 ++
 16 files changed, 279 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/CMakeLists.txt b/query_optimizer/CMakeLists.txt
index 10c52a1..1a15271 100644
--- a/query_optimizer/CMakeLists.txt
+++ b/query_optimizer/CMakeLists.txt
@@ -63,6 +63,8 @@ target_link_libraries(quickstep_queryoptimizer_ExecutionGenerator
                       quickstep_catalog_CatalogRelation
                       quickstep_catalog_CatalogRelationSchema
                       quickstep_catalog_CatalogTypedefs
+                      quickstep_catalog_PartitionScheme
+                      quickstep_catalog_PartitionSchemeHeader
                       quickstep_expressions_Expressions_proto
                       quickstep_expressions_aggregation_AggregateFunction
                       quickstep_expressions_aggregation_AggregateFunction_proto

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/ExecutionGenerator.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/ExecutionGenerator.cpp b/query_optimizer/ExecutionGenerator.cpp
index 29e67f7..2133722 100644
--- a/query_optimizer/ExecutionGenerator.cpp
+++ b/query_optimizer/ExecutionGenerator.cpp
@@ -44,6 +44,8 @@
 #include "catalog/CatalogRelation.hpp"
 #include "catalog/CatalogRelationSchema.hpp"
 #include "catalog/CatalogTypedefs.hpp"
+#include "catalog/PartitionScheme.hpp"
+#include "catalog/PartitionSchemeHeader.hpp"
 #include "expressions/Expressions.pb.h"
 #include "expressions/aggregation/AggregateFunction.hpp"
 #include "expressions/aggregation/AggregateFunction.pb.h"
@@ -1017,6 +1019,11 @@ void ExecutionGenerator::convertCreateTable(
     catalog_relation->setDefaultStorageBlockLayout(layout.release());
   }
 
+  if (physical_plan->partition_scheme_header_proto()) {
+    catalog_relation->setPartitionScheme(new PartitionScheme(
+        PartitionSchemeHeader::ReconstructFromProto(*physical_plan->partition_scheme_header_proto())));
+  }
+
   execution_plan_->addRelationalOperator(
       new CreateTableOperator(query_handle_->query_id(),
                               catalog_relation.release(),
@@ -1139,14 +1146,21 @@ void ExecutionGenerator::convertInsertTuple(
       query_context_proto_->insert_destinations_size();
   S::InsertDestination *insert_destination_proto = query_context_proto_->add_insert_destinations();
 
-  insert_destination_proto->set_insert_destination_type(S::InsertDestinationType::BLOCK_POOL);
   insert_destination_proto->set_relation_id(input_relation.getID());
   insert_destination_proto->mutable_layout()->MergeFrom(
       input_relation.getDefaultStorageBlockLayout().getDescription());
 
-  const vector<block_id> blocks(input_relation.getBlocksSnapshot());
-  for (const block_id block : blocks) {
-    insert_destination_proto->AddExtension(S::BlockPoolInsertDestination::blocks, block);
+  if (input_relation.hasPartitionScheme()) {
+    insert_destination_proto->set_insert_destination_type(S::InsertDestinationType::PARTITION_AWARE);
+    insert_destination_proto->MutableExtension(S::PartitionAwareInsertDestination::partition_scheme)
+        ->MergeFrom(input_relation.getPartitionScheme().getProto());
+  } else {
+    insert_destination_proto->set_insert_destination_type(S::InsertDestinationType::BLOCK_POOL);
+
+    const vector<block_id> blocks(input_relation.getBlocksSnapshot());
+    for (const block_id block : blocks) {
+      insert_destination_proto->AddExtension(S::BlockPoolInsertDestination::blocks, block);
+    }
   }
 
   const QueryPlan::DAGNodeIndex insert_operator_index =
@@ -1197,15 +1211,21 @@ void ExecutionGenerator::convertInsertSelection(
   const QueryContext::insert_destination_id insert_destination_index =
       query_context_proto_->insert_destinations_size();
   S::InsertDestination *insert_destination_proto = query_context_proto_->add_insert_destinations();
-
-  insert_destination_proto->set_insert_destination_type(S::InsertDestinationType::BLOCK_POOL);
   insert_destination_proto->set_relation_id(destination_relation.getID());
   insert_destination_proto->mutable_layout()->MergeFrom(
       destination_relation.getDefaultStorageBlockLayout().getDescription());
 
-  const vector<block_id> blocks(destination_relation.getBlocksSnapshot());
-  for (const block_id block : blocks) {
-    insert_destination_proto->AddExtension(S::BlockPoolInsertDestination::blocks, block);
+  if (destination_relation.hasPartitionScheme()) {
+    insert_destination_proto->set_insert_destination_type(S::InsertDestinationType::PARTITION_AWARE);
+    insert_destination_proto->MutableExtension(S::PartitionAwareInsertDestination::partition_scheme)
+        ->MergeFrom(destination_relation.getPartitionScheme().getProto());
+  } else {
+    insert_destination_proto->set_insert_destination_type(S::InsertDestinationType::BLOCK_POOL);
+
+    const vector<block_id> blocks(destination_relation.getBlocksSnapshot());
+    for (const block_id block : blocks) {
+      insert_destination_proto->AddExtension(S::BlockPoolInsertDestination::blocks, block);
+    }
   }
 
   const CatalogRelationInfo *selection_relation_info =
@@ -1274,7 +1294,13 @@ void ExecutionGenerator::convertUpdateTable(
       query_context_proto_->insert_destinations_size();
   S::InsertDestination *relocation_destination_proto = query_context_proto_->add_insert_destinations();
 
-  relocation_destination_proto->set_insert_destination_type(S::InsertDestinationType::BLOCK_POOL);
+  if (input_relation->hasPartitionScheme()) {
+    relocation_destination_proto->set_insert_destination_type(S::InsertDestinationType::PARTITION_AWARE);
+    relocation_destination_proto->MutableExtension(S::PartitionAwareInsertDestination::partition_scheme)
+        ->MergeFrom(input_relation->getPartitionScheme().getProto());
+  } else {
+    relocation_destination_proto->set_insert_destination_type(S::InsertDestinationType::BLOCK_POOL);
+  }
   relocation_destination_proto->set_relation_id(input_rel_id);
 
   // Convert the predicate proto.

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/logical/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/logical/CMakeLists.txt b/query_optimizer/logical/CMakeLists.txt
index c67f96f..8aca550 100644
--- a/query_optimizer/logical/CMakeLists.txt
+++ b/query_optimizer/logical/CMakeLists.txt
@@ -86,6 +86,7 @@ target_link_libraries(quickstep_queryoptimizer_logical_CreateIndex
                       quickstep_utility_Macros)
 target_link_libraries(quickstep_queryoptimizer_logical_CreateTable
                       glog
+                      quickstep_catalog_Catalog_proto
                       quickstep_queryoptimizer_OptimizerTree
                       quickstep_queryoptimizer_expressions_AttributeReference
                       quickstep_queryoptimizer_logical_Logical

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/logical/CreateTable.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/logical/CreateTable.hpp b/query_optimizer/logical/CreateTable.hpp
index cc7c6d7..d4f16b6 100644
--- a/query_optimizer/logical/CreateTable.hpp
+++ b/query_optimizer/logical/CreateTable.hpp
@@ -24,6 +24,7 @@
 #include <string>
 #include <vector>
 
+#include "catalog/Catalog.pb.h"
 #include "query_optimizer/OptimizerTree.hpp"
 #include "query_optimizer/expressions/AttributeReference.hpp"
 #include "query_optimizer/logical/Logical.hpp"
@@ -72,10 +73,17 @@ class CreateTable : public Logical {
     return block_properties_;
   }
 
+  /**
+   * @return Shared pointer to the serialized partition scheme header.
+   */
+  const std::shared_ptr<const serialization::PartitionSchemeHeader> partition_scheme_header_proto() const {
+    return partition_scheme_header_proto_;
+  }
+
   LogicalPtr copyWithNewChildren(
       const std::vector<LogicalPtr> &new_children) const override {
     DCHECK_EQ(getNumChildren(), new_children.size());
-    return Create(relation_name_, attributes_, block_properties_);
+    return Create(relation_name_, attributes_, block_properties_, partition_scheme_header_proto_);
   }
 
   std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override {
@@ -100,8 +108,9 @@ class CreateTable : public Logical {
   static CreateTablePtr Create(
       const std::string &relation_name,
       const std::vector<expressions::AttributeReferencePtr> &attributes,
-      const std::shared_ptr<const StorageBlockLayoutDescription> &block_properties) {
-    return CreateTablePtr(new CreateTable(relation_name, attributes, block_properties));
+      const std::shared_ptr<const StorageBlockLayoutDescription> &block_properties,
+      const std::shared_ptr<const serialization::PartitionSchemeHeader> &partition_scheme_header_proto) {
+    return CreateTablePtr(new CreateTable(relation_name, attributes, block_properties, partition_scheme_header_proto));
   }
 
  protected:
@@ -117,17 +126,20 @@ class CreateTable : public Logical {
   CreateTable(
       const std::string &relation_name,
       const std::vector<expressions::AttributeReferencePtr> &attributes,
-      const std::shared_ptr<const StorageBlockLayoutDescription> &block_properties)
+      const std::shared_ptr<const StorageBlockLayoutDescription> &block_properties,
+      const std::shared_ptr<const serialization::PartitionSchemeHeader> &partition_scheme_header_proto)
       : relation_name_(relation_name),
         attributes_(attributes),
         block_properties_(block_properties),
         block_properties_representation_(
-            getOptimizerRepresentationForProto<OptimizerTreeBaseNodePtr>(block_properties_.get())) {}
+            getOptimizerRepresentationForProto<OptimizerTreeBaseNodePtr>(block_properties_.get())),
+        partition_scheme_header_proto_(partition_scheme_header_proto) {}
 
   std::string relation_name_;
   std::vector<expressions::AttributeReferencePtr> attributes_;
   std::shared_ptr<const StorageBlockLayoutDescription> block_properties_;
   std::shared_ptr<const OptimizerProtoRepresentation<OptimizerTreeBaseNodePtr> > block_properties_representation_;
+  std::shared_ptr<const serialization::PartitionSchemeHeader> partition_scheme_header_proto_;
 
   DISALLOW_COPY_AND_ASSIGN(CreateTable);
 };

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/physical/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/CMakeLists.txt b/query_optimizer/physical/CMakeLists.txt
index 5c2cd0b..7f26943 100644
--- a/query_optimizer/physical/CMakeLists.txt
+++ b/query_optimizer/physical/CMakeLists.txt
@@ -85,6 +85,7 @@ target_link_libraries(quickstep_queryoptimizer_physical_CreateIndex
                       quickstep_utility_Macros)
 target_link_libraries(quickstep_queryoptimizer_physical_CreateTable
                       glog
+                      quickstep_catalog_Catalog_proto
                       quickstep_queryoptimizer_OptimizerTree
                       quickstep_queryoptimizer_expressions_AttributeReference
                       quickstep_queryoptimizer_expressions_ExpressionUtil

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/physical/CreateTable.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/CreateTable.hpp b/query_optimizer/physical/CreateTable.hpp
index 8e3bbd4..f982e32 100644
--- a/query_optimizer/physical/CreateTable.hpp
+++ b/query_optimizer/physical/CreateTable.hpp
@@ -24,6 +24,7 @@
 #include <string>
 #include <vector>
 
+#include "catalog/Catalog.pb.h"
 #include "query_optimizer/OptimizerTree.hpp"
 #include "query_optimizer/expressions/AttributeReference.hpp"
 #include "query_optimizer/expressions/ExpressionUtil.hpp"
@@ -75,10 +76,17 @@ class CreateTable : public Physical {
     return block_properties_;
   }
 
+  /**
+   * @return Shared pointer to the serialized partition scheme header.
+   */
+  const std::shared_ptr<const serialization::PartitionSchemeHeader> partition_scheme_header_proto() const {
+    return partition_scheme_header_proto_;
+  }
+
   PhysicalPtr copyWithNewChildren(
       const std::vector<PhysicalPtr> &new_children) const override {
     DCHECK_EQ(getNumChildren(), new_children.size());
-    return Create(relation_name_, attributes_, block_properties_);
+    return Create(relation_name_, attributes_, block_properties_, partition_scheme_header_proto_);
   }
 
   std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override {
@@ -107,8 +115,9 @@ class CreateTable : public Physical {
   static CreateTablePtr Create(
       const std::string &relation_name,
       const std::vector<expressions::AttributeReferencePtr> &attributes,
-      const std::shared_ptr<const StorageBlockLayoutDescription> &block_properties) {
-    return CreateTablePtr(new CreateTable(relation_name, attributes, block_properties));
+      const std::shared_ptr<const StorageBlockLayoutDescription> &block_properties,
+      const std::shared_ptr<const serialization::PartitionSchemeHeader> &partition_scheme_header_proto) {
+    return CreateTablePtr(new CreateTable(relation_name, attributes, block_properties, partition_scheme_header_proto));
   }
 
  protected:
@@ -124,17 +133,20 @@ class CreateTable : public Physical {
   CreateTable(
       const std::string &relation_name,
       const std::vector<expressions::AttributeReferencePtr> &attributes,
-      const std::shared_ptr<const StorageBlockLayoutDescription> &block_properties)
+      const std::shared_ptr<const StorageBlockLayoutDescription> &block_properties,
+      const std::shared_ptr<const serialization::PartitionSchemeHeader> &partition_scheme_header_proto)
       : relation_name_(relation_name),
         attributes_(attributes),
         block_properties_(block_properties),
         block_properties_representation_(
-            getOptimizerRepresentationForProto<OptimizerTreeBaseNodePtr>(block_properties_.get())) {}
+            getOptimizerRepresentationForProto<OptimizerTreeBaseNodePtr>(block_properties_.get())),
+        partition_scheme_header_proto_(partition_scheme_header_proto) {}
 
   std::string relation_name_;
   std::vector<expressions::AttributeReferencePtr> attributes_;
   std::shared_ptr<const StorageBlockLayoutDescription> block_properties_;
   std::shared_ptr<const OptimizerProtoRepresentation<OptimizerTreeBaseNodePtr> > block_properties_representation_;
+  std::shared_ptr<const serialization::PartitionSchemeHeader> partition_scheme_header_proto_;
 
   DISALLOW_COPY_AND_ASSIGN(CreateTable);
 };

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/resolver/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/resolver/CMakeLists.txt b/query_optimizer/resolver/CMakeLists.txt
index 5251ccc..a34273e 100644
--- a/query_optimizer/resolver/CMakeLists.txt
+++ b/query_optimizer/resolver/CMakeLists.txt
@@ -34,6 +34,8 @@ target_link_libraries(quickstep_queryoptimizer_resolver_NameResolver
 target_link_libraries(quickstep_queryoptimizer_resolver_Resolver
                       glog
                       quickstep_catalog_CatalogDatabase
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_catalog_Catalog_proto
                       quickstep_expressions_aggregation_AggregateFunction
                       quickstep_expressions_aggregation_AggregateFunctionFactory
                       quickstep_expressions_tablegenerator_GeneratorFunction
@@ -53,6 +55,7 @@ target_link_libraries(quickstep_queryoptimizer_resolver_Resolver
                       quickstep_parser_ParseLimit
                       quickstep_parser_ParseLiteralValue
                       quickstep_parser_ParseOrderBy
+                      quickstep_parser_ParsePartitionClause
                       quickstep_parser_ParsePredicate
                       quickstep_parser_ParsePredicateExists
                       quickstep_parser_ParsePredicateInTableQuery

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/resolver/Resolver.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/resolver/Resolver.cpp b/query_optimizer/resolver/Resolver.cpp
index 2580342..3c9faee 100644
--- a/query_optimizer/resolver/Resolver.cpp
+++ b/query_optimizer/resolver/Resolver.cpp
@@ -29,7 +29,9 @@
 #include <vector>
 #include <utility>
 
+#include "catalog/Catalog.pb.h"
 #include "catalog/CatalogDatabase.hpp"
+#include "catalog/CatalogTypedefs.hpp"
 #include "expressions/aggregation/AggregateFunction.hpp"
 #include "expressions/aggregation/AggregateFunctionFactory.hpp"
 #include "expressions/table_generator/GeneratorFunction.hpp"
@@ -49,6 +51,7 @@
 #include "parser/ParseLimit.hpp"
 #include "parser/ParseLiteralValue.hpp"
 #include "parser/ParseOrderBy.hpp"
+#include "parser/ParsePartitionClause.hpp"
 #include "parser/ParsePredicate.hpp"
 #include "parser/ParsePredicateExists.hpp"
 #include "parser/ParsePredicateInTableQuery.hpp"
@@ -129,12 +132,15 @@
 
 #include "glog/logging.h"
 
+using std::make_unique;
+
 namespace quickstep {
 namespace optimizer {
 namespace resolver {
 
 namespace E = ::quickstep::optimizer::expressions;
 namespace L = ::quickstep::optimizer::logical;
+namespace S = ::quickstep::serialization;
 
 struct Resolver::ExpressionResolutionInfo {
   /**
@@ -478,9 +484,32 @@ L::LogicalPtr Resolver::resolveCreateTable(
   std::shared_ptr<const StorageBlockLayoutDescription>
       block_properties(resolveBlockProperties(create_table_statement));
 
-  return L::CreateTable::Create(relation_name, attributes, block_properties);
+  std::shared_ptr<const S::PartitionSchemeHeader> partition_scheme_header_proto(
+      resolvePartitionClause(create_table_statement));
+
+  return L::CreateTable::Create(relation_name, attributes, block_properties, partition_scheme_header_proto);
+}
+
+namespace {
+
+attribute_id GetAttributeIdFromName(const PtrList<ParseAttributeDefinition>&attribute_definition_list,
+                                    const std::string &attribute_name) {
+  const std::string lower_attribute_name = ToLower(attribute_name);
+
+  attribute_id attr_id = 0;
+  for (const ParseAttributeDefinition &attribute_definition : attribute_definition_list) {
+    if (lower_attribute_name == ToLower(attribute_definition.name()->value())) {
+      return attr_id;
+    }
+
+    ++attr_id;
+  }
+
+  return kInvalidAttributeID;
 }
 
+}  // namespace
+
 StorageBlockLayoutDescription* Resolver::resolveBlockProperties(
     const ParseStatementCreateTable &create_table_statement) {
   const ParseBlockProperties *block_properties
@@ -540,25 +569,6 @@ StorageBlockLayoutDescription* Resolver::resolveBlockProperties(
     THROW_SQL_ERROR_AT(type_parse_string) << "Unrecognized storage type.";
   }
 
-  // Helper lambda function which will be used in COMPRESS and SORT resolution.
-  // Returns the column id from the name of the given attribute. Returns -1 if
-  // the attribute is not found.
-  auto columnIdFromAttributeName = [&create_table_statement](
-      const std::string& attribute_name) -> int {
-    const std::string search_name = ToLower(attribute_name);
-    int i = 0;
-    for (const ParseAttributeDefinition &attribute_definition :
-     create_table_statement.attribute_definition_list()) {
-      const std::string lower_attribute_name =
-        ToLower(attribute_definition.name()->value());
-      if (lower_attribute_name.compare(search_name) == 0) {
-        return i;
-      }
-      i++;
-    }
-    return -1;
-  };
-
   // Resolve the SORT property.
   const ParseString *sort_parse_string = block_properties->getSort();
   if (block_requires_sort) {
@@ -566,10 +576,10 @@ StorageBlockLayoutDescription* Resolver::resolveBlockProperties(
       THROW_SQL_ERROR_AT(type_parse_string)
           << "The SORT property must be specified as an attribute name.";
     } else {
-      const std::string &sort_name = sort_parse_string->value();
       // Lookup the name and map to a column id.
-      int sort_id = columnIdFromAttributeName(sort_name);
-      if (sort_id == -1) {
+      const attribute_id sort_id = GetAttributeIdFromName(create_table_statement.attribute_definition_list(),
+                                                          sort_parse_string->value());
+      if (sort_id == kInvalidAttributeID) {
         THROW_SQL_ERROR_AT(sort_parse_string)
           << "The SORT property did not match any attribute name.";
       } else {
@@ -609,8 +619,9 @@ StorageBlockLayoutDescription* Resolver::resolveBlockProperties(
           << "The COMPRESS property must be specified as ALL or a list of attributes.";
       }
       for (const ParseString &compressed_attribute_name : *compress_parse_strings) {
-        int column_id = columnIdFromAttributeName(compressed_attribute_name.value());
-        if (column_id == -1) {
+        const attribute_id column_id = GetAttributeIdFromName(create_table_statement.attribute_definition_list(),
+                                                              compressed_attribute_name.value());
+        if (column_id == kInvalidAttributeID) {
           THROW_SQL_ERROR_AT(&compressed_attribute_name)
               << "The given attribute was not found.";
         } else {
@@ -671,6 +682,51 @@ StorageBlockLayoutDescription* Resolver::resolveBlockProperties(
   return storage_block_description.release();
 }
 
+const S::PartitionSchemeHeader* Resolver::resolvePartitionClause(
+    const ParseStatementCreateTable &create_table_statement) {
+  const ParsePartitionClause *partition_clause = create_table_statement.opt_partition_clause();
+  if (partition_clause == nullptr) {
+    return nullptr;
+  }
+
+  const ParseString *partition_type_string = partition_clause->partition_type();
+  if (partition_type_string == nullptr) {
+    THROW_SQL_ERROR_AT(partition_clause)
+        << "Partition type must be specified and be a string.";
+  }
+
+  const PtrList<ParseString> &attribute_name_list = partition_clause->attribute_name_list();
+  if (attribute_name_list.size() != 1) {
+    THROW_SQL_ERROR_AT(partition_clause)
+        << "Partition is supported on only one attribute.";
+  }
+
+  const ParseString &partition_attribute_name = *(attribute_name_list.begin());
+  const attribute_id attr_id = GetAttributeIdFromName(create_table_statement.attribute_definition_list(),
+                                                      partition_attribute_name.value());
+  if (attr_id == kInvalidAttributeID) {
+    THROW_SQL_ERROR_AT(&partition_attribute_name)
+        << "The given attribute was not found.";
+  }
+
+  auto proto = make_unique<S::PartitionSchemeHeader>();
+  proto->set_num_partitions(partition_clause->num_partitions()->long_value());
+  proto->set_partition_attribute_id(attr_id);
+
+  const std::string partition_type = ToLower(partition_type_string->value());
+  if (partition_type == kHashPartitionType) {
+    proto->set_partition_type(S::PartitionSchemeHeader::HASH);
+  } else if (partition_type == kRangePartitionType) {
+    proto->set_partition_type(S::PartitionSchemeHeader::RANGE);
+    THROW_SQL_ERROR_AT(partition_clause)
+        << "Range partition is not supported.";
+  } else {
+    THROW_SQL_ERROR_AT(partition_type_string) << "Unrecognized partition type: " << partition_type;
+  }
+
+  return proto.release();
+}
+
 L::LogicalPtr Resolver::resolveCreateIndex(
     const ParseStatementCreateIndex &create_index_statement) {
   // Resolve relation reference.

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/resolver/Resolver.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/resolver/Resolver.hpp b/query_optimizer/resolver/Resolver.hpp
index 855e6ba..e4351e0 100644
--- a/query_optimizer/resolver/Resolver.hpp
+++ b/query_optimizer/resolver/Resolver.hpp
@@ -74,6 +74,8 @@ class PtrList;
 class StorageBlockLayoutDescription;
 class Type;
 
+namespace serialization { class PartitionSchemeHeader; }
+
 }  // namespace quickstep
 
 namespace quickstep {
@@ -213,6 +215,16 @@ class Resolver {
       const ParseStatementCreateTable &create_table_statement);
 
   /**
+   * @brief Resolves the PARTITION clause of a CREATE TABLE statement to a
+   *        the serialized PartitionSchemeHeader describing the user input.
+   *
+   * @param create_table_statement The create table statement.
+   * @return A pointer to a user-owned serialized PartitionSchemeHeader.
+   */
+  const serialization::PartitionSchemeHeader* resolvePartitionClause(
+      const ParseStatementCreateTable &create_table_statement);
+
+  /**
    * @brief Resolves a DELETE query and returns a logical plan.
    *
    * @param delete_statement The DELETE parse tree.

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/strategy/OneToOne.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/strategy/OneToOne.cpp b/query_optimizer/strategy/OneToOne.cpp
index 78003f4..7d0c4cb 100644
--- a/query_optimizer/strategy/OneToOne.cpp
+++ b/query_optimizer/strategy/OneToOne.cpp
@@ -121,7 +121,8 @@ bool OneToOne::generatePlan(const L::LogicalPtr &logical_input,
           std::static_pointer_cast<const L::CreateTable>(logical_input);
       *physical_output = P::CreateTable::Create(create_table->relation_name(),
                                                 create_table->attributes(),
-                                                create_table->block_properties());
+                                                create_table->block_properties(),
+                                                create_table->partition_scheme_header_proto());
       return true;
     }
     case L::LogicalType::kDeleteTuples: {

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/tests/execution_generator/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/execution_generator/CMakeLists.txt b/query_optimizer/tests/execution_generator/CMakeLists.txt
index 1ea6a17..2705130 100644
--- a/query_optimizer/tests/execution_generator/CMakeLists.txt
+++ b/query_optimizer/tests/execution_generator/CMakeLists.txt
@@ -107,6 +107,11 @@ add_test(quickstep_queryoptimizer_tests_executiongenerator_join
          "${CMAKE_CURRENT_SOURCE_DIR}/Join.test"
          "${CMAKE_CURRENT_BINARY_DIR}/Join.test"
          "${CMAKE_CURRENT_BINARY_DIR}/Join/")
+add_test(quickstep_queryoptimizer_tests_executiongenerator_partition
+         "../quickstep_queryoptimizer_tests_ExecutionGeneratorTest"
+         "${CMAKE_CURRENT_SOURCE_DIR}/Partition.test"
+         "${CMAKE_CURRENT_BINARY_DIR}/Partition.test"
+         "${CMAKE_CURRENT_BINARY_DIR}/Partition/")
 add_test(quickstep_queryoptimizer_tests_executiongenerator_select
          "../quickstep_queryoptimizer_tests_ExecutionGeneratorTest"
          "${CMAKE_CURRENT_SOURCE_DIR}/Select.test"
@@ -150,6 +155,7 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Drop)
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Index)
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Insert)
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Join)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Partition)
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Select)
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/StringPatternMatching)
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/TableGenerator)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/tests/execution_generator/Create.test
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/execution_generator/Create.test b/query_optimizer/tests/execution_generator/Create.test
index 5bd0e76..4ffa665 100644
--- a/query_optimizer/tests/execution_generator/Create.test
+++ b/query_optimizer/tests/execution_generator/Create.test
@@ -40,3 +40,12 @@ CREATE TABLE foo2 (col1 INT, col2 VARCHAR(80))
   WITH BLOCKPROPERTIES (TYPE columnstore, SORT col2);
 --
 ERROR: BLOCKPROPERTIES is invalid.
+==
+
+CREATE TABLE foo3 (attr INT) PARTITION BY HASH(attr) PARTITIONS 4;
+SELECT * FROM foo3;
+--
++-----------+
+|attr       |
++-----------+
++-----------+

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/tests/execution_generator/Partition.test
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/execution_generator/Partition.test b/query_optimizer/tests/execution_generator/Partition.test
new file mode 100644
index 0000000..ab05391
--- /dev/null
+++ b/query_optimizer/tests/execution_generator/Partition.test
@@ -0,0 +1,54 @@
+# 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.
+
+CREATE TABLE foo (id INT NULL,
+                  name CHAR(20))
+PARTITION BY HASH(id) PARTITIONS 4;
+
+INSERT INTO foo
+SELECT int_col, char_col
+FROM test
+WHERE int_col > 0 OR int_col < 0;
+
+SELECT * FROM foo;
+--
++-----------+--------------------+
+|id         |name                |
++-----------+--------------------+
+|          4|          4 2.000000|
+|          8|          8 2.828427|
+|         12|         12 3.464102|
+|         16|         16 4.000000|
+|         24|         24 4.898979|
+|         -3|         -3 1.732051|
+|         -7|         -7 2.645751|
+|        -11|        -11 3.316625|
+|        -15|        -15 3.872983|
+|        -19|        -19 4.358899|
+|        -23|        -23 4.795832|
+|          2|          2 1.414214|
+|          6|          6 2.449490|
+|         14|         14 3.741657|
+|         18|         18 4.242641|
+|         22|         22 4.690416|
+|         -1|         -1 1.000000|
+|         -5|         -5 2.236068|
+|         -9|         -9 3.000000|
+|        -13|        -13 3.605551|
+|        -17|        -17 4.123106|
+|        -21|        -21 4.582576|
++-----------+--------------------+

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/tests/logical_generator/Create.test
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/logical_generator/Create.test b/query_optimizer/tests/logical_generator/Create.test
index aeff9ec..04134f9 100644
--- a/query_optimizer/tests/logical_generator/Create.test
+++ b/query_optimizer/tests/logical_generator/Create.test
@@ -46,3 +46,13 @@ TopLevelPlan
 +-output_attributes=
   +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
   +-AttributeReference[id=1,name=attr2,relation=foo,type=Int]
+==
+
+CREATE TABLE foo (attr INT) PARTITION BY HASH(attr) PARTITIONS 4;
+--
+TopLevelPlan
++-plan=CreateTable[relation=foo]
+| +-attributes=
+|   +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
++-output_attributes=
+  +-AttributeReference[id=0,name=attr,relation=foo,type=Int]

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/tests/physical_generator/Create.test
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/physical_generator/Create.test b/query_optimizer/tests/physical_generator/Create.test
index 54af3fa..c555371 100644
--- a/query_optimizer/tests/physical_generator/Create.test
+++ b/query_optimizer/tests/physical_generator/Create.test
@@ -115,3 +115,21 @@ TopLevelPlan
 |   +-AttributeReference[id=0,name=col1,relation=foo,type=Int]
 +-output_attributes=
   +-AttributeReference[id=0,name=col1,relation=foo,type=Int]
+==
+
+CREATE TABLE foo (attr INT) PARTITION BY HASH(attr) PARTITIONS 4;
+--
+[Optimized Logical Plan]
+TopLevelPlan
++-plan=CreateTable[relation=foo]
+| +-attributes=
+|   +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
++-output_attributes=
+  +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
+[Physical Plan]
+TopLevelPlan
++-plan=CreateTable[relation=foo]
+| +-attributes=
+|   +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
++-output_attributes=
+  +-AttributeReference[id=0,name=attr,relation=foo,type=Int]

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/33680b92/query_optimizer/tests/resolver/Create.test
----------------------------------------------------------------------
diff --git a/query_optimizer/tests/resolver/Create.test b/query_optimizer/tests/resolver/Create.test
index b04d785..28bd4f5 100644
--- a/query_optimizer/tests/resolver/Create.test
+++ b/query_optimizer/tests/resolver/Create.test
@@ -229,3 +229,13 @@ CREATE TABLE foo (attr INT) WITH BLOCKPROPERTIES
 ERROR: The BLOCKSIZEMB property must be between 2MB and 1024MB. (2 : 23)
 (TYPE split_rowstore, BLOCKSIZEMB 2000);
                       ^
+==
+
+CREATE TABLE foo (attr INT) PARTITION BY HASH(attr) PARTITIONS 4;
+--
+TopLevelPlan
++-plan=CreateTable[relation=foo]
+| +-attributes=
+|   +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
++-output_attributes=
+  +-AttributeReference[id=0,name=attr,relation=foo,type=Int]