Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C8299200CB6 for ; Thu, 15 Jun 2017 03:41:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C6E8B160BE8; Thu, 15 Jun 2017 01:41:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C0449160BDB for ; Thu, 15 Jun 2017 03:41:05 +0200 (CEST) Received: (qmail 48247 invoked by uid 500); 15 Jun 2017 01:41:04 -0000 Mailing-List: contact commits-help@quickstep.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@quickstep.incubator.apache.org Delivered-To: mailing list commits@quickstep.incubator.apache.org Received: (qmail 48238 invoked by uid 99); 15 Jun 2017 01:41:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Jun 2017 01:41:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 7D9ECCFCE3 for ; Thu, 15 Jun 2017 01:41:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.231 X-Spam-Level: X-Spam-Status: No, score=-4.231 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id FoekozhH7adB for ; Thu, 15 Jun 2017 01:41:03 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 0D3885F5A2 for ; Thu, 15 Jun 2017 01:41:01 +0000 (UTC) Received: (qmail 48158 invoked by uid 99); 15 Jun 2017 01:41:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Jun 2017 01:41:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1B0A1DFAF5; Thu, 15 Jun 2017 01:41:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zuyuz@apache.org To: commits@quickstep.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-quickstep git commit: Added PartitionSchemeHeader in Physical Plan node. Date: Thu, 15 Jun 2017 01:41:01 +0000 (UTC) archived-at: Thu, 15 Jun 2017 01:41:07 -0000 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 Authored: Wed Jun 14 20:34:57 2017 -0500 Committer: Zuyu Zhang 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 +#include +#include + +#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 &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 +#include +#include +#include +#include +#include + +#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 EquivalentPartitionExprIds; + typedef std::vector 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 &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_