http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/OptimizerLogicalModule.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/OptimizerLogicalModule.hpp b/query_optimizer/logical/OptimizerLogicalModule.hpp deleted file mode 100644 index fe05718..0000000 --- a/query_optimizer/logical/OptimizerLogicalModule.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -/** @defgroup OptimizerLogical - * @ingroup QueryOptimizer - * - * Logical operators used in the query optimizer. - **/
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/PatternMatcher.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/PatternMatcher.hpp b/query_optimizer/logical/PatternMatcher.hpp deleted file mode 100644 index b931ace..0000000 --- a/query_optimizer/logical/PatternMatcher.hpp +++ /dev/null @@ -1,144 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_PATTERN_MATCHER_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_PATTERN_MATCHER_HPP_ - -#include <memory> -#include <type_traits> - -#include "query_optimizer/logical/LogicalType.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -class Aggregate; -class BinaryJoin; -class CopyFrom; -class CreateTable; -class DeleteTuples; -class DropTable; -class Filter; -class HashJoin; -class InsertTuple; -class Join; -class MultiwayCartesianJoin; -class NestedLoopsJoin; -class Project; -class SharedSubplanReference; -class Sort; -class TableReference; -class TopLevelPlan; -class UpdateTable; -class WindowAggregate; - -/** \addtogroup OptimizerLogical - * @{ - */ - -/** - * @brief Templated matcher for each Logical node class. - * - * @param LogicalClass The logical class for the logical node to be matched with. - * @param logical_types All the logical types of the logical class. - */ -template <class LogicalClass, LogicalType... logical_types> -class SomeLogicalNode { - public: - /** - * @brief Checks whether the object managed in \p logical is an instance - * of the template argument LogicalClass by checking whether - * it is one of types in the given template arguments logical_types. - * - * @param logical The logical node to be checked. - * @return True for a match; otherwise false. - */ - template <class OtherLogicalClass> - static bool Matches(const std::shared_ptr<const OtherLogicalClass> &logical) { - for (const LogicalType logical_type : kLogicalTypes) { - if (logical->getLogicalType() == logical_type) { - return true; - } - } - return false; - } - - /** - * @brief Checks whether the object managed in \p logical is an instance - * of the template argument LogicalClass by checking whether - * it is one of types in the given template arguments logical_types, - * If true, it additionally casts \p logical to a std::shared_ptr - * \p cast_logical of the template argument LogicalClass. - * - * @param logical The logical node to be checked. - * @param cast_logical The cast logical node. - * @return True if the object managed in \p logical is an instance of LogicalClass. - */ - template <class OtherLogicalClass> - static bool MatchesWithConditionalCast(const std::shared_ptr<const OtherLogicalClass> &logical, - std::shared_ptr<const LogicalClass> *cast_logical) { - bool is_match = Matches(logical); - if (is_match) { - *cast_logical = std::static_pointer_cast<const LogicalClass>(logical); - } - return is_match; - } - - private: - constexpr static LogicalType kLogicalTypes[] = {logical_types...}; -}; - -template <class LogicalClass, LogicalType... logical_types> -constexpr LogicalType SomeLogicalNode<LogicalClass, logical_types...>::kLogicalTypes[]; - -// Specializations for all Logical classes. - -using SomeAggregate = SomeLogicalNode<Aggregate, LogicalType::kAggregate>; -using SomeBinaryJoin = SomeLogicalNode<BinaryJoin, - LogicalType::kHashJoin, - LogicalType::kNestedLoopsJoin>; -using SomeCopyFrom = SomeLogicalNode<CopyFrom, LogicalType::kCopyFrom>; -using SomeCreateTable = SomeLogicalNode<CreateTable, LogicalType::kCreateTable>; -using SomeDeleteTuples = SomeLogicalNode<DeleteTuples, LogicalType::kDeleteTuples>; -using SomeDropTable = SomeLogicalNode<DropTable, LogicalType::kDropTable>; -using SomeFilter = SomeLogicalNode<Filter, LogicalType::kFilter>; -using SomeHashJoin = SomeLogicalNode<HashJoin, LogicalType::kHashJoin>; -using SomeInsertTuple = SomeLogicalNode<InsertTuple, LogicalType::kInsertTuple>; -using SomeJoin = SomeLogicalNode<Join, - LogicalType::kHashJoin, - LogicalType::kMultiwayCartesianJoin, - LogicalType::kNestedLoopsJoin>; -using SomeMultiwayCartesianJoin = SomeLogicalNode<MultiwayCartesianJoin, LogicalType::kMultiwayCartesianJoin>; -using SomeNestedLoopsJoin = SomeLogicalNode<NestedLoopsJoin, LogicalType::kNestedLoopsJoin>; -using SomeProject = SomeLogicalNode<Project, LogicalType::kProject>; -using SomeSharedSubplanReference = SomeLogicalNode<SharedSubplanReference, LogicalType::kSharedSubplanReference>; -using SomeSort = SomeLogicalNode<Sort, LogicalType::kSort>; -using SomeTableReference = SomeLogicalNode<TableReference, LogicalType::kTableReference>; -using SomeTopLevelPlan = SomeLogicalNode<TopLevelPlan, LogicalType::kTopLevelPlan>; -using SomeUpdateTable = SomeLogicalNode<UpdateTable, LogicalType::kUpdateTable>; -using SomeWindowAggregate = SomeLogicalNode<WindowAggregate, LogicalType::kWindowAggregate>; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif /* QUERY_PLANNER_LOGICAL_PATTERN_MATCHER_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/Project.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/Project.cpp b/query_optimizer/logical/Project.cpp deleted file mode 100644 index 18c8fe9..0000000 --- a/query_optimizer/logical/Project.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/logical/Project.hpp" - -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/ExpressionUtil.hpp" -#include "query_optimizer/expressions/NamedExpression.hpp" -#include "query_optimizer/expressions/PatternMatcher.hpp" -#include "utility/Cast.hpp" - -#include "glog/logging.h" - -namespace quickstep { -namespace optimizer { -namespace logical { - -namespace E = ::quickstep::optimizer::expressions; - -LogicalPtr Project::copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const { - DCHECK_EQ(children().size(), new_children.size()); - return Project::Create(new_children[0], project_expressions_); -} - -std::vector<E::AttributeReferencePtr> Project::getOutputAttributes() const { - return ToRefVector(project_expressions_); -} - -std::vector<E::AttributeReferencePtr> Project::getReferencedAttributes() const { - std::vector<E::AttributeReferencePtr> referenced_attributes; - for (const E::NamedExpressionPtr &project_expression : project_expressions_) { - const std::vector<E::AttributeReferencePtr> referenced_attributes_in_expression = - project_expression->getReferencedAttributes(); - referenced_attributes.insert(referenced_attributes.end(), - referenced_attributes_in_expression.begin(), - referenced_attributes_in_expression.end()); - } - return referenced_attributes; -} - -LogicalPtr Project::copyWithNewInputExpressions( - const std::vector<E::ExpressionPtr> &input_expressions) const { - DCHECK_EQ(project_expressions_.size(), input_expressions.size()); - std::vector<E::NamedExpressionPtr> new_project_expressions; - for (const E::ExpressionPtr &input_expression : input_expressions) { - E::NamedExpressionPtr project_expression; - E::SomeNamedExpression::MatchesWithConditionalCast(input_expression, &project_expression); - DCHECK(project_expression != nullptr); - new_project_expressions.emplace_back(project_expression); - } - return Create(input_, new_project_expressions); -} - -void Project::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - non_container_child_field_names->push_back("input"); - non_container_child_fields->push_back(input_); - - container_child_field_names->push_back("project_list"); - container_child_fields->push_back( - CastSharedPtrVector<OptimizerTreeBase>(project_expressions_)); -} - -} // namespace logical -} // namespace optimizer -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/Project.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/Project.hpp b/query_optimizer/logical/Project.hpp deleted file mode 100644 index 83b352c..0000000 --- a/query_optimizer/logical/Project.hpp +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_PROJECT_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_PROJECT_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/Expression.hpp" -#include "query_optimizer/expressions/NamedExpression.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -/** \addtogroup OptimizerLogical - * @{ - */ - -class Project; -typedef std::shared_ptr<const Project> ProjectPtr; - -/** - * @brief Project operator that computes the values of a list of expressions for - * each input tuple and outputs them as a new relation. - */ -class Project : public Logical { - public: - LogicalType getLogicalType() const override { return LogicalType::kProject; } - - std::string getName() const override { return "Project"; } - - /** - * @return The expressions to be evaluated by the Project. - */ - const std::vector<expressions::NamedExpressionPtr>& project_expressions() const { - return project_expressions_; - } - - /** - * @return The input operator. - */ - const LogicalPtr& input() const { return input_; } - - LogicalPtr copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const override; - - LogicalPtr copyWithNewInputExpressions( - const std::vector<expressions::ExpressionPtr> &input_expressions) const override; - - std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override; - - std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override; - - /** - * @brief Creates a Project that computes \p project_expressions on the - * relation produced by \p input. - * - * @param input The input operator to this Project. - * @param project_expressions The project expressions. - * @return An immutable Project. - */ - static ProjectPtr Create( - const LogicalPtr &input, - const std::vector<expressions::NamedExpressionPtr> &project_expressions) { - return ProjectPtr(new Project(input, project_expressions)); - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const override; - - private: - Project( - const LogicalPtr &input, - const std::vector<expressions::NamedExpressionPtr> &project_expressions) - : input_(input), project_expressions_(project_expressions) { - addChild(input); - addInputExpressions(project_expressions_); - } - - LogicalPtr input_; - std::vector<expressions::NamedExpressionPtr> project_expressions_; - - DISALLOW_COPY_AND_ASSIGN(Project); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif /* QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_PROJECT_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/Sample.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/Sample.cpp b/query_optimizer/logical/Sample.cpp deleted file mode 100644 index 577292c..0000000 --- a/query_optimizer/logical/Sample.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/logical/Sample.hpp" - -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/ExpressionUtil.hpp" -#include "query_optimizer/expressions/NamedExpression.hpp" -#include "utility/Cast.hpp" - -#include "glog/logging.h" - -namespace quickstep { -namespace optimizer { -namespace logical { - -namespace E = ::quickstep::optimizer::expressions; - -LogicalPtr Sample::copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const { - DCHECK_EQ(children().size(), new_children.size()); - return Sample::Create(new_children[0], is_block_sample_, percentage_); -} - -void Sample::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - non_container_child_field_names->push_back("input"); - non_container_child_fields->push_back(input_); - - inline_field_names->push_back("percentage"); - inline_field_values->push_back(std::to_string(percentage_)); - - inline_field_names->push_back("is_block_sample"); - inline_field_values->push_back(std::to_string(is_block_sample_)); -} - -} // namespace logical -} // namespace optimizer -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/Sample.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/Sample.hpp b/query_optimizer/logical/Sample.hpp deleted file mode 100644 index e2403c5..0000000 --- a/query_optimizer/logical/Sample.hpp +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SAMPLE_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SAMPLE_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/NamedExpression.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -/** \addtogroup OptimizerLogical - * @{ - */ - -class Sample; -typedef std::shared_ptr<const Sample> SamplePtr; - -/** - * @brief Sample operator that samples the data at a block level or - * at the tuple level and outputs them as a new relation. - */ -class Sample : public Logical { - public: - LogicalType getLogicalType() const override { return LogicalType::kSample; } - - std::string getName() const override { return "SAMPLE"; } - - LogicalPtr copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const override; - - std::vector<expressions::AttributeReferencePtr> - getOutputAttributes() const override { - return input_->getOutputAttributes(); - } - - std::vector<expressions::AttributeReferencePtr> - getReferencedAttributes() const override { - return input_->getReferencedAttributes(); - } - - /** - * @return The percentage of data to be sampled. - */ - int percentage() const { - return percentage_; - } - - /** - * @return Flag indicating the sample type. - */ - bool is_block_sample() const { - return is_block_sample_; - } - - /** - * @return The input operator. - */ - const LogicalPtr& input() const { return input_; } - - /** - * @brief Creates a Sample operator that samples the data from the - * relation produced by \p input. - * @param input The input operator to this Sample. - * @param is_block_sample Flag indicating if the sampling is either a block or - * tuple level sampling - * @param percentage The percentage of tuples/blocks to be sampled - * - * @return An immutable Sample. - */ - static SamplePtr Create(const LogicalPtr &input, const bool is_block_sample, - const int percentage) { - return SamplePtr(new Sample(input, is_block_sample, percentage)); - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> - *container_child_fields) const override; - - private: - Sample(const LogicalPtr &input, - const bool is_block_sample, - const int percentage) - : input_(input), - is_block_sample_(is_block_sample), - percentage_(percentage) { - addChild(input); - } - - LogicalPtr input_; - const bool is_block_sample_; - const int percentage_; - - DISALLOW_COPY_AND_ASSIGN(Sample); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif // QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SAMPLE_HPP_ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/SharedSubplanReference.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/SharedSubplanReference.cpp b/query_optimizer/logical/SharedSubplanReference.cpp deleted file mode 100644 index 3a0fcb3..0000000 --- a/query_optimizer/logical/SharedSubplanReference.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/logical/SharedSubplanReference.hpp" - -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "utility/Cast.hpp" - -#include "glog/logging.h" - -namespace quickstep { -namespace optimizer { -namespace logical { - -void SharedSubplanReference::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - inline_field_names->push_back("subplan_id"); - inline_field_values->push_back(std::to_string(subplan_id_)); - - container_child_field_names->push_back("referenced_attributes"); - container_child_fields->push_back(CastSharedPtrVector<OptimizerTreeBase>(referenced_attributes_)); - - container_child_field_names->push_back("output_attributes"); - container_child_fields->push_back(CastSharedPtrVector<OptimizerTreeBase>(output_attributes_)); -} - -LogicalPtr SharedSubplanReference::copyWithNewChildren(const std::vector<LogicalPtr> &new_children) const { - DCHECK(new_children.empty()); - return Create(subplan_id_, referenced_attributes_, output_attributes_); -} - -} // namespace logical -} // namespace optimizer -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/SharedSubplanReference.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/SharedSubplanReference.hpp b/query_optimizer/logical/SharedSubplanReference.hpp deleted file mode 100644 index 79ef4ad..0000000 --- a/query_optimizer/logical/SharedSubplanReference.hpp +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SHARED_SUBPLAN_REFERENCE_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SHARED_SUBPLAN_REFERENCE_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Macros.hpp" - -#include "glog/logging.h" - -namespace quickstep { -namespace optimizer { -namespace logical { - -/** \addtogroup OptimizerLogical - * @{ - */ - -class SharedSubplanReference; -typedef std::shared_ptr<const SharedSubplanReference> SharedSubplanReferencePtr; - -/** - * @brief A reference to a shared subplan stored in the TopLevelPlan node. - */ -class SharedSubplanReference : public Logical { - public: - LogicalType getLogicalType() const override { - return LogicalType::kSharedSubplanReference; - } - - std::string getName() const override { - return "SharedSubplanReference"; - } - - /** - * @return The ID of the shared subplan. - */ - int subplan_id() const { - return subplan_id_; - } - - /** - * @return The attributes from the referenced shared subplan. - */ - const std::vector<expressions::AttributeReferencePtr>& referenced_attributes() const { - return referenced_attributes_; - } - - /** - * @return The output attributes of this shared subplan reference. - */ - const std::vector<expressions::AttributeReferencePtr>& output_attributes() const { - return output_attributes_; - } - - std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override { - return output_attributes_; - } - - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const override; - - LogicalPtr copyWithNewChildren(const std::vector<LogicalPtr> &new_children) const override; - - std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override { - return referenced_attributes_; - } - - /** - * @brief Creates a SharedSubplanReference. - * - * @param subplan_id The ID of the shared subplan, which is the index of the referenced - * shared subplan in <shared_subplans_> of the TopLevelPlan. - * @param referenced_attributes The attributes from the referenced shared subplan. - * @param output_attributes The output attributes of this shared subplan reference. - * @return An immutable SharedSubplanReference. - */ - static SharedSubplanReferencePtr Create( - int subplan_id, - const std::vector<expressions::AttributeReferencePtr> &referenced_attributes, - const std::vector<expressions::AttributeReferencePtr> &output_attributes) { - return SharedSubplanReferencePtr( - new SharedSubplanReference(subplan_id, referenced_attributes, output_attributes)); - } - - private: - SharedSubplanReference(int subplan_id, - const std::vector<expressions::AttributeReferencePtr> &referenced_attributes, - const std::vector<expressions::AttributeReferencePtr> &output_attributes) - : subplan_id_(subplan_id), - referenced_attributes_(referenced_attributes), - output_attributes_(output_attributes) { - DCHECK_EQ(output_attributes_.size(), referenced_attributes_.size()); - } - - int subplan_id_; - std::vector<expressions::AttributeReferencePtr> referenced_attributes_; - std::vector<expressions::AttributeReferencePtr> output_attributes_; - - DISALLOW_COPY_AND_ASSIGN(SharedSubplanReference); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif /* QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SHARED_SUBPLAN_REFERENCE_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/Sort.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/Sort.cpp b/query_optimizer/logical/Sort.cpp deleted file mode 100644 index 3667f64..0000000 --- a/query_optimizer/logical/Sort.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/logical/Sort.hpp" - -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/ExpressionUtil.hpp" -#include "query_optimizer/expressions/NamedExpression.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "utility/Cast.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -namespace E = ::quickstep::optimizer::expressions; - -LogicalPtr Sort::copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const { - DCHECK_EQ(getNumChildren(), new_children.size()); - return Create(new_children[0], sort_attributes_, sort_ascending_, nulls_first_flags_, limit_); -} - -void Sort::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - non_container_child_field_names->push_back("input"); - non_container_child_fields->push_back(input_); - - inline_field_names->push_back("is_ascending"); - std::string ascending_list("["); - for (bool is_ascending : sort_ascending_) { - if (is_ascending) { - ascending_list.append("true,"); - } else { - ascending_list.append("false,"); - } - } - ascending_list.pop_back(); - ascending_list.append("]"); - inline_field_values->push_back(ascending_list); - - inline_field_names->push_back("nulls_first"); - std::string nulls_first_flags("["); - for (bool nulls_first_flag : nulls_first_flags_) { - if (nulls_first_flag) { - nulls_first_flags.append("true,"); - } else { - nulls_first_flags.append("false,"); - } - } - nulls_first_flags.pop_back(); - nulls_first_flags.append("]"); - inline_field_values->push_back(nulls_first_flags); - - container_child_field_names->push_back("sort_expressions"); - container_child_fields->push_back( - CastSharedPtrVector<OptimizerTreeBase>(sort_attributes_)); -} - -} // namespace logical -} // namespace optimizer -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/Sort.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/Sort.hpp b/query_optimizer/logical/Sort.hpp deleted file mode 100644 index 894970b..0000000 --- a/query_optimizer/logical/Sort.hpp +++ /dev/null @@ -1,184 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SORT_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SORT_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -/** \addtogroup OptimizerLogical - * @{ - */ - -class Sort; -typedef std::shared_ptr<const Sort> SortPtr; - -/** - * @brief Sort operator that sorts the input tuples by a subset of attributes. - */ -class Sort : public Logical { - public: - LogicalType getLogicalType() const override { return LogicalType::kSort; } - - std::string getName() const override { return "Sort"; } - - /** - * @return The input logical node. - */ - const LogicalPtr& input() const { return input_; } - - /** - * @return The sorting attributes. - */ - const std::vector<expressions::AttributeReferencePtr>& sort_attributes() const { - return sort_attributes_; - } - - /** - * @return The sorting directions. - */ - const std::vector<bool>& sort_ascending() const { return sort_ascending_; } - - /** - * @brief The order directions for null values. - */ - const std::vector<bool>& nulls_first_flags() const { - return nulls_first_flags_; - } - - /** - * @return The number of output sorted rows. -1 for a full table sort. - */ - int limit() const { - return limit_; - } - - LogicalPtr copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const override; - - std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override { - return input_->getOutputAttributes(); - } - - std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override { - return sort_attributes_; - } - /** - * @brief Creates a Sort logical node. - * - * @param input The input to the Sort. - * @param sort_attributes The sorting attributes. - * @param sort_ascending The vector of ordering directions. - * @param nulls_first_flags The vector of ordering directions for null values. - * @param limit The number of output rows. -1 for a full table sort. - * - * @return An immutable Sort. - */ - static SortPtr Create( - const LogicalPtr &input, - const std::vector<expressions::AttributeReferencePtr> &sort_attributes, - const std::vector<bool> &sort_ascending, - const std::vector<bool> &nulls_first_flags, - const int limit) { - return SortPtr(new Sort(input, - sort_attributes, - sort_ascending, - nulls_first_flags, - limit)); - } - - static SortPtr Create( - const LogicalPtr &input, - std::vector<expressions::AttributeReferencePtr> &&sort_attributes, - std::vector<bool> &&sort_ascending, - std::vector<bool> &&nulls_first_flags, - const int limit) { - return SortPtr(new Sort(input, - std::move(sort_attributes), - std::move(sort_ascending), - std::move(nulls_first_flags), - limit)); - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> * - container_child_fields) const override; - - private: - Sort(const LogicalPtr &input, - const std::vector<expressions::AttributeReferencePtr> &sort_attributes, - const std::vector<bool> &sort_ascending, - const std::vector<bool> &nulls_first_flags, - const int limit) - : input_(input), - sort_attributes_(sort_attributes), - sort_ascending_(sort_ascending), - nulls_first_flags_(nulls_first_flags), - limit_(limit) { - addChild(input_); - } - - Sort(const LogicalPtr &input, - std::vector<expressions::AttributeReferencePtr> &&sort_attributes, - std::vector<bool> &&sort_ascending, - std::vector<bool> &&nulls_first_flags, - const int limit) - : input_(input), - sort_attributes_(std::move(sort_attributes)), - sort_ascending_(std::move(sort_ascending)), - nulls_first_flags_(std::move(nulls_first_flags)), - limit_(limit) { - addChild(input_); - } - - LogicalPtr input_; - std::vector<expressions::AttributeReferencePtr> sort_attributes_; - // Has 1:1 matching with <sort_expressions_>. - std::vector<bool> sort_ascending_; - std::vector<bool> nulls_first_flags_; - int limit_; - - DISALLOW_COPY_AND_ASSIGN(Sort); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif /* QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_SORT_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/TableGenerator.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/TableGenerator.hpp b/query_optimizer/logical/TableGenerator.hpp deleted file mode 100644 index 15ca985..0000000 --- a/query_optimizer/logical/TableGenerator.hpp +++ /dev/null @@ -1,183 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_TABLE_GENERATOR_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_TABLE_GENERATOR_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "expressions/table_generator/GeneratorFunctionHandle.hpp" -#include "query_optimizer/OptimizerContext.hpp" -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/ExprId.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Cast.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -namespace E = ::quickstep::optimizer::expressions; - -using quickstep::GeneratorFunctionHandle; - -/** \addtogroup OptimizerLogical - * @{ - */ - -class TableGenerator; -typedef std::shared_ptr<const TableGenerator> TableGeneratorPtr; - -/** - * @brief Leaf logical node that represents a table that will be populated - * by a generator function. - * - * @note For how to add a new generator function, see the documentation of - * GeneratorFunction and GeneratorFunctionHandle. - */ -class TableGenerator : public Logical { - public: - LogicalType getLogicalType() const override { return LogicalType::kTableGenerator; } - - std::string getName() const override { return "TableGenerator"; } - - LogicalPtr copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const override { - return TableGeneratorPtr( - new TableGenerator(generator_function_handle_, - table_alias_, - attribute_list_)); - } - - /** - * @return The reference to the generator function handle. - */ - const GeneratorFunctionHandlePtr& generator_function_handle() const { - return generator_function_handle_; - } - - /** - * @return The alias name of this table. - */ - const std::string& table_alias() const { - return table_alias_; - } - - /** - * @return The reference to the output attributes of this table. - */ - const std::vector<expressions::AttributeReferencePtr>& attribute_list() const { - return attribute_list_; - } - - std::vector<E::AttributeReferencePtr> getOutputAttributes() const override { - return attribute_list_; - } - - std::vector<E::AttributeReferencePtr> getReferencedAttributes() const override { - return {}; - } - - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> * - container_child_fields) const override { - inline_field_names->push_back("function_name"); - inline_field_values->push_back(generator_function_handle_->getName()); - - if (table_alias_ != generator_function_handle_->getName()) { - inline_field_names->push_back("table_alias"); - inline_field_values->push_back(table_alias_); - } - - container_child_field_names->push_back(""); - container_child_fields->push_back(CastSharedPtrVector<OptimizerTreeBase>(attribute_list_)); - } - - /** - * @brief Creates a logical TableGenerator node. - * - * @param generator_function_handle The shared_ptr reference to a generator - function handle. - * @param table_alias The alias name of this table. - * @param optimizer_context The OptimizerContext for the query - * @return An immutable TableGenerator. - */ - static TableGeneratorPtr Create( - const GeneratorFunctionHandlePtr &generator_function_handle, - const std::string &table_alias, - OptimizerContext *optimizer_context) { - return TableGeneratorPtr( - new TableGenerator(generator_function_handle, - table_alias, - optimizer_context)); - } - - private: - TableGenerator(const GeneratorFunctionHandlePtr &generator_function_handle, - const std::string &table_alias, - OptimizerContext *optimizer_context) - : generator_function_handle_(generator_function_handle), - table_alias_(table_alias) { - int num_attrs = generator_function_handle->getNumberOfOutputColumns(); - const std::string &table_name = generator_function_handle->getName(); - - for (int i = 0; i < num_attrs; ++i) { - attribute_list_.emplace_back( - E::AttributeReference::Create( - optimizer_context->nextExprId(), - generator_function_handle->getOutputColumnName(i), - table_alias, - table_name, - generator_function_handle->getOutputColumnType(i), - E::AttributeReferenceScope::kLocal)); - } - } - - TableGenerator(const GeneratorFunctionHandlePtr &generator_function_handle, - const std::string &table_alias, - const std::vector<E::AttributeReferencePtr> &attribute_list) - : generator_function_handle_(generator_function_handle), - table_alias_(table_alias), - attribute_list_(attribute_list) { - } - - GeneratorFunctionHandlePtr generator_function_handle_; - std::string table_alias_; - std::vector<E::AttributeReferencePtr> attribute_list_; - - DISALLOW_COPY_AND_ASSIGN(TableGenerator); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif /* QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_TABLE_GENERATOR_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/TableReference.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/TableReference.cpp b/query_optimizer/logical/TableReference.cpp deleted file mode 100644 index 6d94665..0000000 --- a/query_optimizer/logical/TableReference.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/logical/TableReference.hpp" - -#include <string> -#include <vector> - -#include "catalog/CatalogRelation.hpp" -#include "query_optimizer/OptimizerContext.hpp" -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "utility/Cast.hpp" - -#include "glog/logging.h" - -namespace quickstep { -namespace optimizer { -namespace logical { - -namespace E = ::quickstep::optimizer::expressions; - -TableReference::TableReference(const CatalogRelation *catalog_relation, - const std::string &relation_alias, - OptimizerContext *optimizer_context) - : catalog_relation_(catalog_relation), - relation_alias_(relation_alias) { - for (CatalogRelation::const_iterator attribute_it = catalog_relation_->begin(); - attribute_it < catalog_relation_->end(); - ++attribute_it) { - attribute_list_.emplace_back( - E::AttributeReference::Create( - optimizer_context->nextExprId(), - attribute_it->getName(), - attribute_it->getDisplayName(), - relation_alias, - attribute_it->getType(), - E::AttributeReferenceScope::kLocal)); - } -} - -LogicalPtr TableReference::copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const { - DCHECK_EQ(new_children.size(), children().size()); - return TableReferencePtr( - new TableReference(catalog_relation_, relation_alias_, attribute_list_)); -} - -void TableReference::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - inline_field_names->push_back("relation_name"); - inline_field_values->push_back(catalog_relation_->getName()); - - if (relation_alias_ != catalog_relation_->getName()) { - inline_field_names->push_back("relation_alias"); - inline_field_values->push_back(relation_alias_); - } - - container_child_field_names->push_back(""); - container_child_fields->push_back(CastSharedPtrVector<OptimizerTreeBase>(attribute_list_)); -} - -} // namespace logical -} // namespace optimizer -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/TableReference.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/TableReference.hpp b/query_optimizer/logical/TableReference.hpp deleted file mode 100644 index 6788c82..0000000 --- a/query_optimizer/logical/TableReference.hpp +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_EXPRESSIONS_LOGICAL_TABLE_REFERENCE_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_EXPRESSIONS_LOGICAL_TABLE_REFERENCE_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Macros.hpp" - -#include "glog/logging.h" - -namespace quickstep { - -class CatalogRelation; - -namespace optimizer { - -class OptimizerContext; - -namespace logical { - -/** \addtogroup OptimizerLogical - * @{ - */ - -class TableReference; -typedef std::shared_ptr<const TableReference> TableReferencePtr; - -/** - * @brief Leaf logical operator that represents a reference to - * a catalog relation. - */ -class TableReference : public Logical { - public: - LogicalType getLogicalType() const override { return LogicalType::kTableReference; } - - std::string getName() const override { return "TableReference"; } - - /** - * @return The catalog relation which the operator scans. - */ - const CatalogRelation* catalog_relation() const { return catalog_relation_; } - - /** - * @return The relation alias. - */ - const std::string& relation_alias() const { return relation_alias_; } - - /** - * @return The references to the attributes in the relation. - */ - const std::vector<expressions::AttributeReferencePtr>& attribute_list() const { - return attribute_list_; - } - - LogicalPtr copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const override; - - std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override { - return attribute_list_; - } - - std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override { - return getOutputAttributes(); - } - - /** - * @brief Generates a AttributeRerference for each CatalogAttribute in the \p - * catalog_relation and creates a TableReference on it. - * - * @param catalog_relation The catalog relation to be scanned. - * @param relation_alias The relation alias. This is stored here for the printing purpose only. - * @param optimizer_context The OptimizerContext for the query. - * @return An immutable TableReference. - */ - static TableReferencePtr Create(const CatalogRelation *catalog_relation, - const std::string &relation_alias, - OptimizerContext *optimizer_context) { - DCHECK(!relation_alias.empty()); - return TableReferencePtr( - new TableReference(catalog_relation, relation_alias, optimizer_context)); - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const override; - - private: - TableReference(const CatalogRelation *catalog_relation, - const std::string &relation_alias, - OptimizerContext *optimizer_context); - - // Constructor where the attribute list is explicitly given. - TableReference( - const CatalogRelation *catalog_relation, - const std::string &relation_alias, - const std::vector<expressions::AttributeReferencePtr> &attribute_list) - : catalog_relation_(catalog_relation), - relation_alias_(relation_alias), - attribute_list_(attribute_list) {} - - const CatalogRelation *catalog_relation_; - std::string relation_alias_; - std::vector<expressions::AttributeReferencePtr> attribute_list_; - - DISALLOW_COPY_AND_ASSIGN(TableReference); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif /* QUICKSTEP_QUERY_OPTIMIZER_EXPRESSIONS_LOGICAL_TABLE_REFERENCE_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/TopLevelPlan.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/TopLevelPlan.cpp b/query_optimizer/logical/TopLevelPlan.cpp deleted file mode 100644 index 3a6eb44..0000000 --- a/query_optimizer/logical/TopLevelPlan.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/logical/TopLevelPlan.hpp" - -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "utility/Cast.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -namespace E = ::quickstep::optimizer::expressions; - -void TopLevelPlan::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - non_container_child_field_names->push_back("plan"); - non_container_child_fields->push_back(plan_); - - if (!shared_subplans_.empty()) { - container_child_field_names->push_back("shared_subplans"); - container_child_fields->push_back( - CastSharedPtrVector<OptimizerTreeBase>(shared_subplans_)); - } - - container_child_field_names->push_back("output_attributes"); - container_child_fields->push_back( - CastSharedPtrVector<OptimizerTreeBase>(plan_->getOutputAttributes())); -} - -} // namespace logical -} // namespace optimizer -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/TopLevelPlan.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/TopLevelPlan.hpp b/query_optimizer/logical/TopLevelPlan.hpp deleted file mode 100644 index 0b8f1a4..0000000 --- a/query_optimizer/logical/TopLevelPlan.hpp +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_TOP_LEVEL_PLAN_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_TOP_LEVEL_PLAN_HPP_ - -#include <memory> -#include <string> -#include <unordered_map> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/ExprId.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Macros.hpp" - -#include "glog/logging.h" - -namespace quickstep { -namespace optimizer { -namespace logical { - -/** \addtogroup OptimizerLogical - * @{ - */ - -class TopLevelPlan; -typedef std::shared_ptr<const TopLevelPlan> TopLevelPlanPtr; - -/** - * @brief The root of a logical plan tree that contains the entire logical plan - * and shared subplans. - */ -class TopLevelPlan : public Logical { - public: - /** - * @brief Destructor. - */ - ~TopLevelPlan() override {} - - LogicalType getLogicalType() const override { return LogicalType::kTopLevelPlan; } - - std::string getName() const override { return "TopLevelPlan"; } - - /** - * @return The input plan. - */ - const LogicalPtr& plan() const { return plan_; } - - /** - * @return The vector of the shared subplans. - */ - const std::vector<LogicalPtr>& shared_subplans() const { return shared_subplans_; } - - LogicalPtr copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const override { - DCHECK_EQ(getNumChildren(), new_children.size()); - // The first is the main plan, and the remaining - // children are shared subplans referenced in the main plan. - std::vector<LogicalPtr> new_shared_subplans; - if (new_children.size() > 1u) { - new_shared_subplans.insert(new_shared_subplans.end(), - ++new_children.begin(), - new_children.end()); - } - return Create(new_children[0], new_shared_subplans, uncorrelated_subquery_map_); - } - - /** - * @return Map from the expression ID of an attribute reference to the - * uncorrelated subquery that produces the attribute. - */ - const std::unordered_map<expressions::ExprId, int>& uncorrelated_subquery_map() const { - return uncorrelated_subquery_map_; - } - - std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override { - return plan()->getOutputAttributes(); - } - - std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override { - return {}; - } - - /** - * @brief Creates a TopLevelPlan. - * - * @param plan The input plan. - * @param shared_subplans The subplans referenced in the main input plan. - * @param uncorrelated_subquery_map Map from expression IDs to uncorrelated scalar subqueries. - * @return An immutable TopLevelPlan. - */ - static TopLevelPlanPtr Create(const LogicalPtr &plan, - const std::vector<LogicalPtr> &shared_subplans = std::vector<LogicalPtr>(), - const std::unordered_map<expressions::ExprId, int> &uncorrelated_subquery_map = - std::unordered_map<expressions::ExprId, int>()) { - return TopLevelPlanPtr(new TopLevelPlan(plan, shared_subplans, uncorrelated_subquery_map)); - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const override; - - private: - TopLevelPlan(const LogicalPtr &plan, - const std::vector<LogicalPtr> &shared_subplans, - const std::unordered_map<expressions::ExprId, int> &uncorrelated_subquery_map) - : plan_(plan), - shared_subplans_(shared_subplans), - uncorrelated_subquery_map_(uncorrelated_subquery_map) { - addChild(plan); - for (const LogicalPtr &shared_subplan : shared_subplans) { - addChild(shared_subplan); - } - } - - LogicalPtr plan_; - // Stored in the topological ordering based on dependencies. - std::vector<LogicalPtr> shared_subplans_; - - std::unordered_map<expressions::ExprId, int> uncorrelated_subquery_map_; - - DISALLOW_COPY_AND_ASSIGN(TopLevelPlan); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif /* QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_TOP_LEVEL_PLAN_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/UpdateTable.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/UpdateTable.cpp b/query_optimizer/logical/UpdateTable.cpp deleted file mode 100644 index 8f02f5d..0000000 --- a/query_optimizer/logical/UpdateTable.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/logical/UpdateTable.hpp" - -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/Predicate.hpp" -#include "query_optimizer/expressions/Scalar.hpp" -#include "utility/Cast.hpp" - -#include "glog/logging.h" - -namespace quickstep { -namespace optimizer { -namespace logical { - -LogicalPtr UpdateTable::copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const { - DCHECK_EQ(getNumChildren(), new_children.size()); - return Create(new_children[0], assignees_, assignment_expressions_, - predicate_); -} - -std::vector<expressions::AttributeReferencePtr> UpdateTable::getReferencedAttributes() const { - std::vector<expressions::AttributeReferencePtr> referenced_attributes = assignees_; - for (const expressions::ScalarPtr& assignment_expression : assignment_expressions_) { - std::vector<expressions::AttributeReferencePtr> attrs_referenced_in_expression = - assignment_expression->getReferencedAttributes(); - referenced_attributes.insert(referenced_attributes.end(), - attrs_referenced_in_expression.begin(), - attrs_referenced_in_expression.end()); - } - if (predicate_ != nullptr) { - std::vector<expressions::AttributeReferencePtr> attrs_referenced_in_predicate = - predicate_->getReferencedAttributes(); - referenced_attributes.insert(referenced_attributes.end(), - attrs_referenced_in_predicate.begin(), - attrs_referenced_in_predicate.end()); - } - return referenced_attributes; -} - -void UpdateTable::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - non_container_child_field_names->push_back("input"); - non_container_child_fields->push_back(input_); - if (predicate_ != nullptr) { - non_container_child_field_names->push_back("predicate"); - non_container_child_fields->push_back(predicate_); - } - - container_child_field_names->push_back("attributes"); - container_child_fields->push_back(CastSharedPtrVector<OptimizerTreeBase>(assignees_)); - container_child_field_names->push_back("assigned_values"); - container_child_fields->push_back( - CastSharedPtrVector<OptimizerTreeBase>(assignment_expressions_)); -} - -} // namespace logical -} // namespace optimizer -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/UpdateTable.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/UpdateTable.hpp b/query_optimizer/logical/UpdateTable.hpp deleted file mode 100644 index ec0d50f..0000000 --- a/query_optimizer/logical/UpdateTable.hpp +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_UPDATETABLE_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_UPDATETABLE_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/Predicate.hpp" -#include "query_optimizer/expressions/Scalar.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -/** \addtogroup OptimizerLogical - * @{ - */ - -class UpdateTable; -typedef std::shared_ptr<const UpdateTable> UpdateTablePtr; - -/** - * @brief Updates a relation with new assignments to some tuples. - */ -class UpdateTable : public Logical { - public: - LogicalType getLogicalType() const override { return LogicalType::kUpdateTable; } - - std::string getName() const override { return "UpdateTable"; } - - /** - * @return The logical node that creates the table to be updated. - */ - const LogicalPtr& input() const { return input_; } - - /** - * @return The attributes to be assigned values to. - */ - const std::vector<expressions::AttributeReferencePtr>& assignees() const { - return assignees_; - } - - /** - * @return The expressions for which the values are assigned. - */ - const std::vector<expressions::ScalarPtr>& assignment_expressions() const { - return assignment_expressions_; - } - - /** - * @return The predicate to select tuples to be updated. - */ - const expressions::PredicatePtr& predicate() const { return predicate_; } - - LogicalPtr copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const override; - - std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override { - return std::vector<expressions::AttributeReferencePtr>(); - } - - std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override; - - /** - * @brief Creates an UpdateTable logical node that represents an operation to - * update a table with given assignments. - * - * @param input The input gives the table to be updated. - * @param assignees The attribute list to assign values to. - * @param assignment_expressions The expressions that gives the values to be - * assigned. - * @param predicate The predicate to select tuples to be updated. - * @return An immutable UpdateTable node. - */ - static UpdateTablePtr Create( - const LogicalPtr &input, - const std::vector<expressions::AttributeReferencePtr> &assignees, - const std::vector<expressions::ScalarPtr> &assignment_expressions, - const expressions::PredicatePtr &predicate) { - return UpdateTablePtr( - new UpdateTable(input, assignees, assignment_expressions, predicate)); - } - - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const override; - - private: - UpdateTable(const LogicalPtr &input, - const std::vector<expressions::AttributeReferencePtr> &assignees, - const std::vector<expressions::ScalarPtr> &assignment_expressions, - const expressions::PredicatePtr &predicate) - : input_(input), - assignees_(assignees), - assignment_expressions_(assignment_expressions), - predicate_(predicate) { - addChild(input); - } - - LogicalPtr input_; - // The attributes to be assigned values to. - std::vector<expressions::AttributeReferencePtr> assignees_; - // The expressions for which the values are assigned. Has 1:1 matching with - // <assignees_>. - std::vector<expressions::ScalarPtr> assignment_expressions_; - expressions::PredicatePtr predicate_; - - DISALLOW_COPY_AND_ASSIGN(UpdateTable); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif /* QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_UPDATETABLE_HPP_ */ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/WindowAggregate.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/WindowAggregate.cpp b/query_optimizer/logical/WindowAggregate.cpp deleted file mode 100644 index cc09d97..0000000 --- a/query_optimizer/logical/WindowAggregate.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/logical/WindowAggregate.hpp" - -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/Alias.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/ExpressionUtil.hpp" -#include "query_optimizer/expressions/NamedExpression.hpp" -#include "query_optimizer/expressions/PatternMatcher.hpp" -#include "utility/Cast.hpp" - -#include "glog/logging.h" - -namespace quickstep { -namespace optimizer { -namespace logical { - -namespace E = ::quickstep::optimizer::expressions; - -LogicalPtr WindowAggregate::copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const { - DCHECK_EQ(getNumChildren(), new_children.size()); - return Create(new_children[0], window_aggregate_expression_); -} - -std::vector<E::AttributeReferencePtr> WindowAggregate::getOutputAttributes() const { - std::vector<E::AttributeReferencePtr> output_attributes(input_->getOutputAttributes()); - output_attributes.push_back(E::ToRef(window_aggregate_expression_)); - return output_attributes; -} - -std::vector<E::AttributeReferencePtr> WindowAggregate::getReferencedAttributes() const { - return window_aggregate_expression_->getReferencedAttributes(); -} - -LogicalPtr WindowAggregate::copyWithNewInputExpressions( - const std::vector<E::ExpressionPtr> &input_expressions) const { - // Only one expression needed - DCHECK_EQ(1u, input_expressions.size()); - - E::AliasPtr window_aggregate_expression; - E::SomeAlias::MatchesWithConditionalCast(input_expressions[0], - &window_aggregate_expression); - - return Create(input_, window_aggregate_expression); -} - -void WindowAggregate::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - non_container_child_field_names->push_back("input"); - non_container_child_fields->push_back(input_); - - non_container_child_field_names->push_back("window_aggregate_expression"); - non_container_child_fields->push_back(window_aggregate_expression_); -} - -} // namespace logical -} // namespace optimizer -} // namespace quickstep http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/logical/WindowAggregate.hpp ---------------------------------------------------------------------- diff --git a/query_optimizer/logical/WindowAggregate.hpp b/query_optimizer/logical/WindowAggregate.hpp deleted file mode 100644 index b156938..0000000 --- a/query_optimizer/logical/WindowAggregate.hpp +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#ifndef QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_WINDOW_AGGREGATE_HPP_ -#define QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_WINDOW_AGGREGATE_HPP_ - -#include <memory> -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/Alias.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/Expression.hpp" -#include "query_optimizer/expressions/NamedExpression.hpp" -#include "query_optimizer/logical/Logical.hpp" -#include "query_optimizer/logical/LogicalType.hpp" -#include "utility/Macros.hpp" - -namespace quickstep { -namespace optimizer { -namespace logical { - -/** \addtogroup OptimizerLogical - * @{ - */ - -class WindowAggregate; -typedef std::shared_ptr<const WindowAggregate> WindowAggregatePtr; - -/** - * @brief Window aggregate operator that computes window aggregate expressions. - */ -class WindowAggregate : public Logical { - public: - LogicalType getLogicalType() const override { - return LogicalType::kWindowAggregate; - } - - std::string getName() const override { return "WindowAggregate"; } - - /** - * @return The input logical node. - */ - const LogicalPtr& input() const { return input_; } - - /** - * @return PARTITION BY expressions. - */ - const expressions::AliasPtr window_aggregate_expression() const { - return window_aggregate_expression_; - } - - LogicalPtr copyWithNewChildren( - const std::vector<LogicalPtr> &new_children) const override; - - LogicalPtr copyWithNewInputExpressions( - const std::vector<expressions::ExpressionPtr> &input_expressions) const override; - - std::vector<expressions::AttributeReferencePtr> getOutputAttributes() const override; - - std::vector<expressions::AttributeReferencePtr> getReferencedAttributes() const override; - - /** - * @brief Creates an Aggregate logical node. - * - * @param input The input node. - * @param window_aggregate_expression The window aggregate expression. - * @return An immutable WindowAggregate node. - */ - static WindowAggregatePtr Create( - const LogicalPtr &input, - const expressions::AliasPtr &window_aggregate_expression) { - return WindowAggregatePtr(new WindowAggregate(input, window_aggregate_expression)); - } - - protected: - void getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const override; - - private: - WindowAggregate(const LogicalPtr &input, - const expressions::AliasPtr &window_aggregate_expression) - : input_(input), - window_aggregate_expression_(window_aggregate_expression) { - addChild(input_); - addInputExpression(window_aggregate_expression_); - } - - const LogicalPtr input_; - const expressions::AliasPtr window_aggregate_expression_; - - DISALLOW_COPY_AND_ASSIGN(WindowAggregate); -}; - -/** @} */ - -} // namespace logical -} // namespace optimizer -} // namespace quickstep - -#endif // QUICKSTEP_QUERY_OPTIMIZER_LOGICAL_WINDOW_AGGREGATE_HPP_ http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/query_optimizer/physical/Aggregate.cpp ---------------------------------------------------------------------- diff --git a/query_optimizer/physical/Aggregate.cpp b/query_optimizer/physical/Aggregate.cpp deleted file mode 100644 index 35476af..0000000 --- a/query_optimizer/physical/Aggregate.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - **/ - -#include "query_optimizer/physical/Aggregate.hpp" - -#include <string> -#include <vector> - -#include "query_optimizer/OptimizerTree.hpp" -#include "query_optimizer/expressions/AttributeReference.hpp" -#include "query_optimizer/expressions/ExpressionUtil.hpp" -#include "query_optimizer/expressions/NamedExpression.hpp" -#include "query_optimizer/expressions/Predicate.hpp" -#include "utility/Cast.hpp" - -namespace quickstep { -namespace optimizer { -namespace physical { - -namespace E = ::quickstep::optimizer::expressions; - -std::vector<E::AttributeReferencePtr> Aggregate::getOutputAttributes() const { - std::vector<E::AttributeReferencePtr> output_attributes( - E::ToRefVector(grouping_expressions_)); - const std::vector<E::AttributeReferencePtr> aggregate_output_attributes = - E::ToRefVector(aggregate_expressions_); - output_attributes.insert(output_attributes.end(), - aggregate_output_attributes.begin(), - aggregate_output_attributes.end()); - return output_attributes; -} - -std::vector<E::AttributeReferencePtr> Aggregate::getReferencedAttributes() - const { - std::vector<E::AttributeReferencePtr> referenced_attributes; - for (const E::NamedExpressionPtr &grouping_expression : - grouping_expressions_) { - const std::vector<E::AttributeReferencePtr> referenced_attributes_in_expression = - grouping_expression->getReferencedAttributes(); - referenced_attributes.insert(referenced_attributes.end(), - referenced_attributes_in_expression.begin(), - referenced_attributes_in_expression.end()); - } - for (const E::AliasPtr &aggregate_expression : - aggregate_expressions_) { - const std::vector<E::AttributeReferencePtr> referenced_attributes_in_expression = - aggregate_expression->getReferencedAttributes(); - referenced_attributes.insert(referenced_attributes.end(), - referenced_attributes_in_expression.begin(), - referenced_attributes_in_expression.end()); - } - if (filter_predicate_ != nullptr) { - const std::vector<E::AttributeReferencePtr> referenced_attributes_in_predicate = - filter_predicate_->getReferencedAttributes(); - referenced_attributes.insert(referenced_attributes.end(), - referenced_attributes_in_predicate.begin(), - referenced_attributes_in_predicate.end()); - } - - // TODO(jianqiao): This is a quick fix to the COUNT(*) problem that we retain - // at least one column from the child plan to survive the PruneColumns physical - // optimization. The comprehensive approach should also try to optimize the - // child plan with regard to the knowledge that the aggregation actually don't - // care about the values of the child plan's output but needs only the number - // of rows of the output. - if (referenced_attributes.size() == 0) { - DCHECK_GT(input_->getOutputAttributes().size(), static_cast<std::size_t>(0)); - referenced_attributes.emplace_back(input_->getOutputAttributes()[0]); - } - - return referenced_attributes; -} - -void Aggregate::getFieldStringItems( - std::vector<std::string> *inline_field_names, - std::vector<std::string> *inline_field_values, - std::vector<std::string> *non_container_child_field_names, - std::vector<OptimizerTreeBaseNodePtr> *non_container_child_fields, - std::vector<std::string> *container_child_field_names, - std::vector<std::vector<OptimizerTreeBaseNodePtr>> *container_child_fields) const { - non_container_child_field_names->push_back("input"); - non_container_child_fields->push_back(input_); - - container_child_field_names->push_back("grouping_expressions"); - container_child_fields->push_back( - CastSharedPtrVector<OptimizerTreeBase>(grouping_expressions_)); - container_child_field_names->push_back("aggregate_expressions"); - container_child_fields->push_back( - CastSharedPtrVector<OptimizerTreeBase>(aggregate_expressions_)); - - if (filter_predicate_ != nullptr) { - non_container_child_field_names->push_back("filter_predicate"); - non_container_child_fields->push_back(filter_predicate_); - } -} - -} // namespace physical -} // namespace optimizer -} // namespace quickstep