Printed out the partition info in QueryPlan.
diff --git a/query_optimizer/CMakeLists.txt b/query_optimizer/CMakeLists.txt
index 4ea21b2..5e0db44 100644
--- a/query_optimizer/CMakeLists.txt
+++ b/query_optimizer/CMakeLists.txt
@@ -212,6 +212,7 @@
quickstep_queryoptimizer_expressions_ExprId
quickstep_utility_Macros)
target_link_libraries(quickstep_queryoptimizer_OptimizerTree
+ quickstep_catalog_Catalog_proto
quickstep_storage_StorageBlockLayout_proto
quickstep_utility_Macros
quickstep_utility_TreeStringSerializable)
diff --git a/query_optimizer/OptimizerTree.hpp b/query_optimizer/OptimizerTree.hpp
index 62df66d..c54ce20 100644
--- a/query_optimizer/OptimizerTree.hpp
+++ b/query_optimizer/OptimizerTree.hpp
@@ -25,6 +25,7 @@
#include <string>
#include <vector>
+#include "catalog/Catalog.pb.h"
#include "storage/StorageBlockLayout.pb.h"
#include "utility/Macros.hpp"
#include "utility/TreeStringSerializable.hpp"
@@ -283,6 +284,44 @@
return node.release();
}
+template<class TreeNodeType>
+OptimizerProtoRepresentation<TreeNodeType>* getOptimizerRepresentationForProto(
+ const serialization::PartitionSchemeHeader *partition_header) {
+ if (partition_header == nullptr) {
+ return nullptr;
+ }
+
+ auto node = std::make_unique<OptimizerProtoRepresentation<TreeNodeType>>();
+
+ // Add properties based on the partition type.
+ switch (partition_header->partition_type()) {
+ case serialization::PartitionSchemeHeader::HASH: {
+ node->addProperty("partition_type", "hash");
+ break;
+ }
+ case serialization::PartitionSchemeHeader::RANDOM: {
+ node->addProperty("partition_type", "random");
+ break;
+ }
+ case serialization::PartitionSchemeHeader::RANGE: {
+ node->addProperty("partition_type", "range");
+ // TODO(quickstep-team): display the range boundaries.
+ node->addProperty("range_boundaries", "TODO");
+ break;
+ }
+ default:
+ LOG(FATAL) << "Unrecognized partition type in protobuf message.";
+ }
+ // Every case will specify a partition number and a partition attributes.
+ node->addProperty("num_partitions", partition_header->num_partitions());
+
+ for (int i = 0; i < partition_header->partition_attribute_ids_size(); ++i) {
+ node->addProperty("partition_attr_id", partition_header->partition_attribute_ids(i));
+ }
+
+ return node.release();
+}
+
/** @} */
} // namespace optimizer
diff --git a/query_optimizer/logical/CreateTable.cpp b/query_optimizer/logical/CreateTable.cpp
index 111d04b..9977a0f 100644
--- a/query_optimizer/logical/CreateTable.cpp
+++ b/query_optimizer/logical/CreateTable.cpp
@@ -49,6 +49,11 @@
non_container_child_field_names->push_back("block_properties");
non_container_child_fields->push_back(block_properties_representation_);
}
+
+ if (partition_scheme_header_proto_representation_) {
+ non_container_child_field_names->push_back("partition_scheme_header");
+ non_container_child_fields->push_back(partition_scheme_header_proto_representation_);
+ }
}
} // namespace logical
diff --git a/query_optimizer/logical/CreateTable.hpp b/query_optimizer/logical/CreateTable.hpp
index da4325d..b380ac9 100644
--- a/query_optimizer/logical/CreateTable.hpp
+++ b/query_optimizer/logical/CreateTable.hpp
@@ -48,7 +48,7 @@
/**
* @brief Represents an operation that creates a new table.
*/
-class CreateTable : public Logical {
+class CreateTable final : public Logical {
public:
LogicalType getLogicalType() const override { return LogicalType::kCreateTable; }
@@ -138,13 +138,17 @@
block_properties_(block_properties),
block_properties_representation_(
getOptimizerRepresentationForProto<OptimizerTreeBaseNodePtr>(block_properties_.get())),
- partition_scheme_header_proto_(partition_scheme_header_proto) {}
+ partition_scheme_header_proto_(partition_scheme_header_proto),
+ partition_scheme_header_proto_representation_(
+ getOptimizerRepresentationForProto<OptimizerTreeBaseNodePtr>(partition_scheme_header_proto_.get())) {}
- std::string relation_name_;
- std::vector<expressions::AttributeReferencePtr> attributes_;
- std::shared_ptr<const StorageBlockLayoutDescription> block_properties_;
- std::shared_ptr<const OptimizerProtoRepresentation<OptimizerTreeBaseNodePtr> > block_properties_representation_;
- std::shared_ptr<const serialization::PartitionSchemeHeader> partition_scheme_header_proto_;
+ const std::string relation_name_;
+ const std::vector<expressions::AttributeReferencePtr> attributes_;
+ const std::shared_ptr<const StorageBlockLayoutDescription> block_properties_;
+ const std::shared_ptr<const OptimizerProtoRepresentation<OptimizerTreeBaseNodePtr>> block_properties_representation_;
+ const std::shared_ptr<const serialization::PartitionSchemeHeader> partition_scheme_header_proto_;
+ const std::shared_ptr<const OptimizerProtoRepresentation<OptimizerTreeBaseNodePtr>>
+ partition_scheme_header_proto_representation_;
DISALLOW_COPY_AND_ASSIGN(CreateTable);
};
diff --git a/query_optimizer/physical/CreateTable.cpp b/query_optimizer/physical/CreateTable.cpp
index d42eac3..95e6a9d 100644
--- a/query_optimizer/physical/CreateTable.cpp
+++ b/query_optimizer/physical/CreateTable.cpp
@@ -49,6 +49,11 @@
non_container_child_field_names->push_back("block_properties");
non_container_child_fields->push_back(block_properties_representation_);
}
+
+ if (partition_scheme_header_proto_representation_) {
+ non_container_child_field_names->push_back("partition_scheme_header");
+ non_container_child_fields->push_back(partition_scheme_header_proto_representation_);
+ }
}
} // namespace physical
diff --git a/query_optimizer/physical/CreateTable.hpp b/query_optimizer/physical/CreateTable.hpp
index 05eab0d..6ebdfa2 100644
--- a/query_optimizer/physical/CreateTable.hpp
+++ b/query_optimizer/physical/CreateTable.hpp
@@ -49,7 +49,7 @@
/**
* @brief Creates a table.
*/
-class CreateTable : public Physical {
+class CreateTable final : public Physical {
public:
PhysicalType getPhysicalType() const override {
return PhysicalType::kCreateTable;
@@ -145,13 +145,17 @@
block_properties_(block_properties),
block_properties_representation_(
getOptimizerRepresentationForProto<OptimizerTreeBaseNodePtr>(block_properties_.get())),
- partition_scheme_header_proto_(partition_scheme_header_proto) {}
+ partition_scheme_header_proto_(partition_scheme_header_proto),
+ partition_scheme_header_proto_representation_(
+ getOptimizerRepresentationForProto<OptimizerTreeBaseNodePtr>(partition_scheme_header_proto_.get())) {}
- std::string relation_name_;
- std::vector<expressions::AttributeReferencePtr> attributes_;
- std::shared_ptr<const StorageBlockLayoutDescription> block_properties_;
- std::shared_ptr<const OptimizerProtoRepresentation<OptimizerTreeBaseNodePtr> > block_properties_representation_;
- std::shared_ptr<const serialization::PartitionSchemeHeader> partition_scheme_header_proto_;
+ const std::string relation_name_;
+ const std::vector<expressions::AttributeReferencePtr> attributes_;
+ const std::shared_ptr<const StorageBlockLayoutDescription> block_properties_;
+ const std::shared_ptr<const OptimizerProtoRepresentation<OptimizerTreeBaseNodePtr>> block_properties_representation_;
+ const std::shared_ptr<const serialization::PartitionSchemeHeader> partition_scheme_header_proto_;
+ const std::shared_ptr<const OptimizerProtoRepresentation<OptimizerTreeBaseNodePtr>>
+ partition_scheme_header_proto_representation_;
DISALLOW_COPY_AND_ASSIGN(CreateTable);
};
diff --git a/query_optimizer/tests/logical_generator/Create.test b/query_optimizer/tests/logical_generator/Create.test
index aac49fb..89b4a99 100644
--- a/query_optimizer/tests/logical_generator/Create.test
+++ b/query_optimizer/tests/logical_generator/Create.test
@@ -52,6 +52,10 @@
--
TopLevelPlan
+-plan=CreateTable[relation=foo]
+| +-partition_scheme_header=ProtoDescription
+| | +-Property=ProtoProperty[Property=partition_type,Value=hash]
+| | +-Property=ProtoProperty[Property=num_partitions,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=0]
| +-attributes=
| +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
+-output_attributes=
@@ -59,10 +63,19 @@
==
CREATE TABLE foo (attr1 INT, attr2 LONG, attr3 FLOAT, attr4 DOUBLE, attr5 CHAR(5), attr6 VARCHAR(4))
-PARTITION BY HASH(attr1, attr2, attr3, attr4, attr5, attr6) PARTITIONS 4;
+PARTITION BY HASH(attr2, attr1, attr3, attr4, attr5, attr6) PARTITIONS 4;
--
TopLevelPlan
+-plan=CreateTable[relation=foo]
+| +-partition_scheme_header=ProtoDescription
+| | +-Property=ProtoProperty[Property=partition_type,Value=hash]
+| | +-Property=ProtoProperty[Property=num_partitions,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=1]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=0]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=2]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=3]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=5]
| +-attributes=
| +-AttributeReference[id=0,name=attr1,relation=foo,type=Int]
| +-AttributeReference[id=1,name=attr2,relation=foo,type=Long]
diff --git a/query_optimizer/tests/physical_generator/Create.test b/query_optimizer/tests/physical_generator/Create.test
index 161cc00..a2dd5c0 100644
--- a/query_optimizer/tests/physical_generator/Create.test
+++ b/query_optimizer/tests/physical_generator/Create.test
@@ -122,6 +122,10 @@
[Optimized Logical Plan]
TopLevelPlan
+-plan=CreateTable[relation=foo]
+| +-partition_scheme_header=ProtoDescription
+| | +-Property=ProtoProperty[Property=partition_type,Value=hash]
+| | +-Property=ProtoProperty[Property=num_partitions,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=0]
| +-attributes=
| +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
+-output_attributes=
@@ -129,6 +133,10 @@
[Physical Plan]
TopLevelPlan
+-plan=CreateTable[relation=foo]
+| +-partition_scheme_header=ProtoDescription
+| | +-Property=ProtoProperty[Property=partition_type,Value=hash]
+| | +-Property=ProtoProperty[Property=num_partitions,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=0]
| +-attributes=
| +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
+-output_attributes=
@@ -141,6 +149,15 @@
[Optimized Logical Plan]
TopLevelPlan
+-plan=CreateTable[relation=foo]
+| +-partition_scheme_header=ProtoDescription
+| | +-Property=ProtoProperty[Property=partition_type,Value=hash]
+| | +-Property=ProtoProperty[Property=num_partitions,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=0]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=1]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=2]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=3]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=5]
| +-attributes=
| +-AttributeReference[id=0,name=attr1,relation=foo,type=Int]
| +-AttributeReference[id=1,name=attr2,relation=foo,type=Long]
@@ -158,6 +175,15 @@
[Physical Plan]
TopLevelPlan
+-plan=CreateTable[relation=foo]
+| +-partition_scheme_header=ProtoDescription
+| | +-Property=ProtoProperty[Property=partition_type,Value=hash]
+| | +-Property=ProtoProperty[Property=num_partitions,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=0]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=1]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=2]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=3]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=5]
| +-attributes=
| +-AttributeReference[id=0,name=attr1,relation=foo,type=Int]
| +-AttributeReference[id=1,name=attr2,relation=foo,type=Long]
diff --git a/query_optimizer/tests/resolver/Create.test b/query_optimizer/tests/resolver/Create.test
index 1372cf4..c216c85 100644
--- a/query_optimizer/tests/resolver/Create.test
+++ b/query_optimizer/tests/resolver/Create.test
@@ -181,9 +181,7 @@
CREATE TABLE foo (attr INT, attr2 INT) WITH
BLOCKPROPERTIES (TYPE compressed_rowstore, COMPRESS 1);
--
-ERROR: The COMPRESS property must be specified as ALL or a list of attributes. (2 : 1)
-BLOCKPROPERTIES (TYPE compresse...
-^
+[same as above]
==
# All specified COMPRESS columns must exist.
@@ -235,6 +233,10 @@
--
TopLevelPlan
+-plan=CreateTable[relation=foo]
+| +-partition_scheme_header=ProtoDescription
+| | +-Property=ProtoProperty[Property=partition_type,Value=hash]
+| | +-Property=ProtoProperty[Property=num_partitions,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=0]
| +-attributes=
| +-AttributeReference[id=0,name=attr,relation=foo,type=Int]
+-output_attributes=
@@ -246,6 +248,15 @@
--
TopLevelPlan
+-plan=CreateTable[relation=foo]
+| +-partition_scheme_header=ProtoDescription
+| | +-Property=ProtoProperty[Property=partition_type,Value=hash]
+| | +-Property=ProtoProperty[Property=num_partitions,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=0]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=1]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=2]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=3]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=4]
+| | +-Property=ProtoProperty[Property=partition_attr_id,Value=5]
| +-attributes=
| +-AttributeReference[id=0,name=attr1,relation=foo,type=Int]
| +-AttributeReference[id=1,name=attr2,relation=foo,type=Long]