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/06/15 01:41:01 UTC

incubator-quickstep git commit: Added PartitionSchemeHeader in Physical Plan node.

Repository: incubator-quickstep
Updated Branches:
  refs/heads/master e6ac59d5a -> 13c16b9cb


Added PartitionSchemeHeader in Physical Plan node.


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

Branch: refs/heads/master
Commit: 13c16b9cbee8a380ad1ab98ef307475376e9e661
Parents: e6ac59d
Author: Zuyu Zhang <zu...@apache.org>
Authored: Wed Jun 14 20:34:57 2017 -0500
Committer: Zuyu Zhang <zu...@apache.org>
Committed: Wed Jun 14 20:34:57 2017 -0500

----------------------------------------------------------------------
 query_optimizer/physical/CMakeLists.txt         |   6 +
 .../physical/PartitionSchemeHeader.cpp          | 113 ++++++++++++++++
 .../physical/PartitionSchemeHeader.hpp          | 132 +++++++++++++++++++
 3 files changed, 251 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/13c16b9c/query_optimizer/physical/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/CMakeLists.txt b/query_optimizer/physical/CMakeLists.txt
index 2751c6e..1e777b1 100644
--- a/query_optimizer/physical/CMakeLists.txt
+++ b/query_optimizer/physical/CMakeLists.txt
@@ -33,6 +33,7 @@ add_library(quickstep_queryoptimizer_physical_InsertTuple InsertTuple.cpp Insert
 add_library(quickstep_queryoptimizer_physical_Join ../../empty_src.cpp Join.hpp)
 add_library(quickstep_queryoptimizer_physical_LIPFilterConfiguration ../../empty_src.cpp LIPFilterConfiguration.hpp)
 add_library(quickstep_queryoptimizer_physical_NestedLoopsJoin NestedLoopsJoin.cpp NestedLoopsJoin.hpp)
+add_library(quickstep_queryoptimizer_physical_PartitionSchemeHeader PartitionSchemeHeader.cpp PartitionSchemeHeader.hpp)
 add_library(quickstep_queryoptimizer_physical_PatternMatcher ../../empty_src.cpp PatternMatcher.hpp)
 add_library(quickstep_queryoptimizer_physical_Physical ../../empty_src.cpp Physical.hpp)
 add_library(quickstep_queryoptimizer_physical_PhysicalType ../../empty_src.cpp PhysicalType.hpp)
@@ -194,6 +195,10 @@ target_link_libraries(quickstep_queryoptimizer_physical_NestedLoopsJoin
                       quickstep_queryoptimizer_physical_Physical
                       quickstep_queryoptimizer_physical_PhysicalType
                       quickstep_utility_Macros)
+target_link_libraries(quickstep_queryoptimizer_physical_PartitionSchemeHeader
+                      glog
+                      quickstep_queryoptimizer_expressions_ExprId
+                      quickstep_utility_Macros)
 target_link_libraries(quickstep_queryoptimizer_physical_PatternMatcher
                       quickstep_queryoptimizer_physical_PhysicalType)
 target_link_libraries(quickstep_queryoptimizer_physical_Physical
@@ -325,6 +330,7 @@ target_link_libraries(quickstep_queryoptimizer_physical
                       quickstep_queryoptimizer_physical_Join
                       quickstep_queryoptimizer_physical_LIPFilterConfiguration
                       quickstep_queryoptimizer_physical_NestedLoopsJoin
+                      quickstep_queryoptimizer_physical_PartitionSchemeHeader
                       quickstep_queryoptimizer_physical_PatternMatcher
                       quickstep_queryoptimizer_physical_Physical
                       quickstep_queryoptimizer_physical_PhysicalType

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/13c16b9c/query_optimizer/physical/PartitionSchemeHeader.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/PartitionSchemeHeader.cpp b/query_optimizer/physical/PartitionSchemeHeader.cpp
new file mode 100644
index 0000000..829b52b
--- /dev/null
+++ b/query_optimizer/physical/PartitionSchemeHeader.cpp
@@ -0,0 +1,113 @@
+/**
+ * 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 "query_optimizer/physical/PartitionSchemeHeader.hpp"
+
+#include <set>
+#include <string>
+#include <unordered_set>
+
+#include "query_optimizer/expressions/ExprId.hpp"
+
+#include "glog/logging.h"
+
+using std::string;
+
+namespace quickstep {
+namespace optimizer {
+namespace physical {
+
+namespace E = expressions;
+
+bool PartitionSchemeHeader::reusablePartitionScheme(const std::unordered_set<E::ExprId> &output_expr_ids) const {
+  DCHECK(!output_expr_ids.empty());
+
+  if (partition_expr_ids.empty()) {
+    return false;
+  }
+
+  for (const EquivalentPartitionExprIds &expr_ids : partition_expr_ids) {
+    bool has_matched_expr = false;
+    for (const E::ExprId expr_id : expr_ids) {
+      if (output_expr_ids.find(expr_id) != output_expr_ids.end()) {
+        has_matched_expr = true;
+        break;
+      }
+    }
+
+    if (!has_matched_expr) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
+namespace {
+
+void PrintEquivalentPartitionExprIds(const PartitionSchemeHeader::EquivalentPartitionExprIds &equivalent_ids,
+                                     string *serialized_header) {
+  *serialized_header += "{ ";
+
+  auto cit = equivalent_ids.cbegin();
+  *serialized_header += std::to_string(*cit);
+  for (++cit; cit != equivalent_ids.cend(); ++cit) {
+    *serialized_header += ", ";
+    *serialized_header += std::to_string(*cit);
+  }
+
+  *serialized_header += " }";
+}
+
+}  // namespace
+
+string PartitionSchemeHeader::toString() const {
+  string serialized_header("PARTITION BY ");
+  switch (partition_type) {
+    case PartitionType::kHash:
+      serialized_header += "HASH";
+      break;
+    case PartitionType::kRandom:
+      serialized_header += "RANDOM";
+      break;
+    case PartitionType::kRange:
+      serialized_header += "RANGE";
+      break;
+    default:
+      break;
+  }
+
+  serialized_header += " ( ";
+  if (!partition_expr_ids.empty()) {
+    auto cit = partition_expr_ids.cbegin();
+    PrintEquivalentPartitionExprIds(*cit, &serialized_header);
+    for (++cit; cit != partition_expr_ids.cend(); ++cit) {
+      serialized_header += ", ";
+      PrintEquivalentPartitionExprIds(*cit, &serialized_header);
+    }
+  }
+  serialized_header += " ) PARTITIONS ";
+  serialized_header += std::to_string(num_partitions);
+
+  return serialized_header;
+}
+
+}  // namespace physical
+}  // namespace optimizer
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/13c16b9c/query_optimizer/physical/PartitionSchemeHeader.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/physical/PartitionSchemeHeader.hpp b/query_optimizer/physical/PartitionSchemeHeader.hpp
new file mode 100644
index 0000000..58d5b15
--- /dev/null
+++ b/query_optimizer/physical/PartitionSchemeHeader.hpp
@@ -0,0 +1,132 @@
+/**
+ * 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_QUERY_OPTIMIZER_PHYSICAL_PARTITION_SCHEME_HEADER_HPP_
+#define QUICKSTEP_QUERY_OPTIMIZER_PHYSICAL_PARTITION_SCHEME_HEADER_HPP_
+
+#include <cstddef>
+#include <set>
+#include <string>
+#include <unordered_set>
+#include <utility>
+#include <vector>
+
+#include "query_optimizer/expressions/ExprId.hpp"
+#include "utility/Macros.hpp"
+
+namespace quickstep {
+namespace optimizer {
+namespace physical {
+
+/** \addtogroup OptimizerPhysical
+ *  @{
+ */
+
+/**
+ * @brief Store the partitioning info for a physical plan node.
+ */
+struct PartitionSchemeHeader {
+  // Each id produces the same partition effect.
+  typedef std::set<expressions::ExprId> EquivalentPartitionExprIds;
+  typedef std::vector<EquivalentPartitionExprIds> PartitionExprIds;
+
+  enum class PartitionType {
+    kHash = 0,
+    kRandom,
+    kRange
+  };
+
+  /**
+   * @brief Constructor.
+   *
+   * @param type The type of partitioning.
+   * @param num_partitions_in The number of partitions to be created.
+   * @param expr_ids The attributes on which the partitioning happens.
+   **/
+  PartitionSchemeHeader(const PartitionType type,
+                        const std::size_t num_partitions_in,
+                        PartitionExprIds &&expr_ids)  // NOLINT(whitespace/operators)
+      : partition_type(type),
+        num_partitions(num_partitions_in),
+        partition_expr_ids(std::move(expr_ids)) {
+  }
+
+  /**
+   * @brief Copy constructor.
+   *
+   * @param other The copy-from instance.
+   **/
+  PartitionSchemeHeader(const PartitionSchemeHeader &other)
+      : partition_type(other.partition_type),
+        num_partitions(other.num_partitions),
+        partition_expr_ids(other.partition_expr_ids) {
+  }
+
+  /**
+   * @brief Check whether the partition scheme header is hash-based.
+   *
+   * @return True if this is a hash partition scheme header. Otherwise, false.
+   **/
+  bool isHashPartition() const {
+    return partition_type == PartitionType::kHash;
+  }
+
+  /**
+   * @brief Check whether the partition scheme header is euqal.
+   *
+   * @param other The instance to compare.
+   *
+   * @return True if both are the same partition scheme header. Otherwise, false.
+   **/
+  bool equal(const PartitionSchemeHeader &other) const {
+    return partition_type == other.partition_type &&
+           num_partitions == other.num_partitions &&
+           partition_expr_ids == other.partition_expr_ids;
+  }
+
+  /**
+   * @brief Check whether the partition scheme header is reusable given 'output_expr_ids'.
+   *
+   * @param output_expr_ids The expressions used to check against PartitionExprIds.
+   *
+   * @return True if this is reusable. Otherwise, false.
+   **/
+  bool reusablePartitionScheme(const std::unordered_set<expressions::ExprId> &output_expr_ids) const;
+
+  /**
+   * @brief Display the partition scheme header as a string.
+   *
+   * @return the string serialized partition scheme header.
+   **/
+  std::string toString() const;
+
+  const PartitionType partition_type;
+  const std::size_t num_partitions;
+  const PartitionExprIds partition_expr_ids;
+
+  // Copyable.
+};
+
+/** @} */
+
+}  // namespace physical
+}  // namespace optimizer
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_QUERY_OPTIMIZER_PHYSICAL_PARTITION_SCHEME_HEADER_HPP_