quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianq...@apache.org
Subject [2/6] incubator-quickstep git commit: Initial commit
Date Mon, 21 Nov 2016 05:18:03 GMT
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/viz/CMakeLists.txt b/viz/CMakeLists.txt
new file mode 100644
index 0000000..3521560
--- /dev/null
+++ b/viz/CMakeLists.txt
@@ -0,0 +1,66 @@
+# 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.
+
+add_subdirectory(configs)
+add_subdirectory(rules)
+
+# Declare micro-libs:
+add_library(quickstep_viz_VizAnalyzer VizAnalyzer.cpp VizAnalyzer.hpp)
+add_library(quickstep_viz_VizContext VizContext.cpp VizContext.hpp)
+add_library(quickstep_viz_VizEngine VizEngine.cpp VizEngine.hpp)
+add_library(quickstep_viz_VizHelper VizHelper.cpp VizHelper.hpp)
+add_library(quickstep_viz_VizObject VizObject.cpp VizObject.hpp)
+
+# Link dependencies:
+target_link_libraries(quickstep_viz_VizAnalyzer
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_queryexecution_QueryExecutionTypedefs
+                      quickstep_queryoptimizer_expressions_AttributeReference
+                      quickstep_queryoptimizer_expressions_ExpressionUtil
+                      quickstep_queryoptimizer_physical_Aggregate
+                      quickstep_queryoptimizer_physical_Physical
+                      quickstep_queryoptimizer_physical_PhysicalType
+                      quickstep_utility_Macros
+                      quickstep_viz_VizObject)
+target_link_libraries(quickstep_viz_VizContext
+                      quickstep_utility_Macros
+                      quickstep_viz_VizObject)
+target_link_libraries(quickstep_viz_VizEngine
+                      quickstep_utility_ExecutionDAGVisualizer
+                      quickstep_utility_Macros
+                      quickstep_utility_PlanVisualizer
+                      quickstep_viz_VizAnalyzer
+                      quickstep_viz_VizContext
+                      quickstep_viz_configs_DumpRelation
+                      quickstep_viz_configs_VizConfig
+                      quickstep_viz_rules_VizRule
+                      quickstep_viz_rules_Grouping)
+target_link_libraries(quickstep_viz_VizHelper
+                      quickstep_queryexecution_QueryExecutionTypedefs
+                      quickstep_queryoptimizer_LogicalGenerator
+                      quickstep_queryoptimizer_OptimizerContext
+                      quickstep_queryoptimizer_PhysicalGenerator
+                      quickstep_queryoptimizer_physical_Physical
+                      quickstep_viz_VizAnalyzer
+                      quickstep_viz_VizContext
+                      quickstep_viz_VizEngine
+                      quickstep_utility_Macros)
+target_link_libraries(quickstep_viz_VizObject
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_utility_Macros
+                      quickstep_utility_StringUtil
+                      quickstep_utility_TreeStringSerializable)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizAnalyzer.cpp
----------------------------------------------------------------------
diff --git a/viz/VizAnalyzer.cpp b/viz/VizAnalyzer.cpp
new file mode 100644
index 0000000..b070bab
--- /dev/null
+++ b/viz/VizAnalyzer.cpp
@@ -0,0 +1,97 @@
+/**
+ * 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 "viz/VizAnalyzer.hpp"
+
+#include <cstddef>
+#include <unordered_map>
+#include <vector>
+
+#include "query_optimizer/expressions/AttributeReference.hpp"
+#include "query_optimizer/expressions/ExpressionUtil.hpp"
+#include "query_optimizer/physical/Aggregate.hpp"
+#include "query_optimizer/physical/Physical.hpp"
+#include "query_optimizer/physical/PhysicalType.hpp"
+
+#include "glog/logging.h"
+
+namespace quickstep {
+namespace viz {
+
+namespace E = ::quickstep::optimizer::expressions;
+namespace P = ::quickstep::optimizer::physical;
+
+bool VizAnalyzer::findGroupByAttributes(
+    std::vector<attribute_id> *group_by_attribute_ids) const {
+  std::vector<E::AttributeReferencePtr> group_by_attributes;
+  if (findGroupByAttributesInternal(physical_plan_, &group_by_attributes)) {
+    CHECK(!group_by_attributes.empty());
+
+    std::unordered_map<E::ExprId, attribute_id> attr_id_map;
+    const std::vector<E::AttributeReferencePtr> query_result_attributes =
+        physical_plan_->getOutputAttributes();
+    for (std::size_t i = 0; i < query_result_attributes.size(); ++i) {
+      attr_id_map.emplace(query_result_attributes[i]->id(), i);
+    }
+
+    for (const auto &attr : group_by_attributes) {
+      const auto attr_it = attr_id_map.find(attr->id());
+      CHECK(attr_it != attr_id_map.end());
+      group_by_attribute_ids->emplace_back(attr_it->second);
+    }
+    return true;
+  }
+  return false;
+}
+
+bool VizAnalyzer::findGroupByAttributesInternal(
+    const P::PhysicalPtr &physical_plan,
+    std::vector<E::AttributeReferencePtr> *group_by_attributes) const {
+  switch (physical_plan->getPhysicalType()) {
+    case P::PhysicalType::kTopLevelPlan:  // Fall through
+    case P::PhysicalType::kSort:
+    case P::PhysicalType::kSelection: {
+      if (!findGroupByAttributesInternal(physical_plan->children().at(0),
+                                         group_by_attributes)) {
+        return false;
+      }
+      if (!E::SubsetOfExpressions(*group_by_attributes,
+                                  physical_plan->getOutputAttributes())) {
+        return false;
+      }
+      return true;
+    }
+    case P::PhysicalType::kAggregate: {
+      const P::AggregatePtr &aggregate =
+          std::static_pointer_cast<const P::Aggregate>(physical_plan);
+      if (aggregate->grouping_expressions().empty()) {
+        return false;
+      }
+      *group_by_attributes = E::ToRefVector(aggregate->grouping_expressions());
+      return true;
+    }
+    default:
+      return false;
+  }
+}
+
+
+
+}  // namespace viz
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizAnalyzer.hpp
----------------------------------------------------------------------
diff --git a/viz/VizAnalyzer.hpp b/viz/VizAnalyzer.hpp
new file mode 100644
index 0000000..5bcf24c
--- /dev/null
+++ b/viz/VizAnalyzer.hpp
@@ -0,0 +1,116 @@
+/**
+ * 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_VIZ_VIZ_ANALYZER_HPP_
+#define QUICKSTEP_VIZ_VIZ_ANALYZER_HPP_
+
+#include <cstddef>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "catalog/CatalogTypedefs.hpp"
+#include "query_execution/QueryExecutionTypedefs.hpp"
+#include "query_optimizer/expressions/AttributeReference.hpp"
+#include "query_optimizer/physical/Physical.hpp"
+#include "utility/Macros.hpp"
+#include "viz/VizObject.hpp"
+
+#include "glog/logging.h"
+
+namespace quickstep {
+
+class CatalogDatabase;
+class CatalogRelation;
+class QueryPlan;
+class StorageManager;
+
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class VizAnalyzer : public VizObject {
+ public:
+  VizAnalyzer(const optimizer::physical::PhysicalPtr &physical_plan,
+              const QueryPlan *execution_plan,
+              const std::vector<WorkOrderTimeEntry> *profiling_stats,
+              const CatalogRelation *query_result_relation,
+              const CatalogDatabase *catalog_database,
+              StorageManager *storage_manager)
+      : physical_plan_(physical_plan),
+        execution_plan_(execution_plan),
+        profiling_stats_(profiling_stats),
+        query_result_relation_(query_result_relation),
+        catalog_database_(catalog_database),
+        storage_manager_(storage_manager) {}
+
+  std::string getName() const override {
+    return "VizAnalyzer";
+  }
+
+  inline const optimizer::physical::PhysicalPtr& getQueryPlan() const {
+    return physical_plan_;
+  }
+
+  const QueryPlan* getExecutionPlan() const {
+    return execution_plan_;
+  }
+
+  const std::vector<WorkOrderTimeEntry>* getProfilingStats() const {
+    return profiling_stats_;
+  }
+
+  const CatalogRelation *getRelation() const {
+    return query_result_relation_;
+  }
+
+  const CatalogDatabase *getDatabase() const {
+    return catalog_database_;
+  }
+
+  StorageManager *getStorageManager() const  {
+    return storage_manager_;
+  }
+
+  bool findGroupByAttributes(
+      std::vector<attribute_id> *group_by_attribute_ids) const;
+
+ private:
+  bool findGroupByAttributesInternal(
+      const optimizer::physical::PhysicalPtr &physical_plan,
+      std::vector<optimizer::expressions::AttributeReferencePtr> *group_by_attributes) const;
+
+  const optimizer::physical::PhysicalPtr physical_plan_;
+  const QueryPlan *execution_plan_;
+  const std::vector<WorkOrderTimeEntry> *profiling_stats_;
+  const CatalogRelation *query_result_relation_;
+  const CatalogDatabase *catalog_database_;
+  StorageManager *storage_manager_;
+
+  DISALLOW_COPY_AND_ASSIGN(VizAnalyzer);
+};
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_VIZ_ANALYZER_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizContext.cpp
----------------------------------------------------------------------
diff --git a/viz/VizContext.cpp b/viz/VizContext.cpp
new file mode 100644
index 0000000..243622c
--- /dev/null
+++ b/viz/VizContext.cpp
@@ -0,0 +1,51 @@
+/**
+ * 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 "viz/VizContext.hpp"
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "viz/VizObject.hpp"
+
+namespace quickstep {
+namespace viz {
+
+void VizContext::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<const VizObject *> *non_container_child_fields,
+    std::vector<std::string> *container_child_field_names,
+    std::vector<std::vector<const VizObject *>> *container_child_fields) const {
+  inline_field_names->emplace_back("depth");
+  inline_field_values->emplace_back(std::to_string(depth_));
+  for (const auto &pair : objects_) {
+    non_container_child_field_names->emplace_back(pair.first);
+    non_container_child_fields->emplace_back(pair.second.get());
+  }
+  if (parent_ != nullptr) {
+    non_container_child_field_names->emplace_back("parent");
+    non_container_child_fields->emplace_back(parent_.get());
+  }
+}
+
+}  // namespace viz
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizContext.hpp
----------------------------------------------------------------------
diff --git a/viz/VizContext.hpp b/viz/VizContext.hpp
new file mode 100644
index 0000000..6a29c30
--- /dev/null
+++ b/viz/VizContext.hpp
@@ -0,0 +1,133 @@
+/**
+ * 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_VIZ_VIZ_CONTEXT_HPP_
+#define QUICKSTEP_VIZ_VIZ_CONTEXT_HPP_
+
+#include <cstddef>
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "utility/Macros.hpp"
+#include "viz/VizObject.hpp"
+
+#include "glog/logging.h"
+
+namespace quickstep {
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class VizContext;
+typedef std::shared_ptr<const VizContext> VizContextPtr;
+
+class VizContext : public VizObject {
+ public:
+  VizContext()
+      : parent_(nullptr),
+        depth_(0) {}
+
+  explicit VizContext(const VizContextPtr &parent)
+      : parent_(parent),
+        depth_(parent->depth_+1) {}
+
+  std::string getName() const override {
+    return "VizContext";
+  }
+
+  inline bool hasLocal(const std::string &key) const {
+    return objects_.find(key) != objects_.end();
+  }
+
+  bool has(const std::string &key) const {
+    return hasLocal(key) || (parent_ != nullptr && parent_->has(key));
+  }
+
+  inline void set(const std::string &key,
+                  VizObject *object) {
+    objects_[key].reset(object);
+  }
+
+  template <typename VizObjectT>
+  inline VizObjectT *getLocal(const std::string &key) {
+    CHECK(hasLocal(key));
+    VizObjectT *object = dynamic_cast<VizObjectT *>(objects_.at(key).get());
+
+    CHECK(object != nullptr);
+    return object;
+  }
+
+  template <typename VizObjectT>
+  inline const VizObjectT *getLocal(const std::string &key) const {
+    CHECK(hasLocal(key));
+    const VizObjectT *object =
+        dynamic_cast<const VizObjectT *>(objects_.at(key).get());
+
+    CHECK(object != nullptr);
+    return object;
+  }
+
+  template <typename VizObjectT>
+  const VizObjectT *get(const std::string &key) const {
+    if (hasLocal(key)) {
+      return getLocal<VizObjectT>(key);
+    } else {
+      CHECK(parent_ != nullptr);
+      return parent_->get<VizObjectT>(key);
+    }
+  }
+
+  template <typename VizObjectT, typename FunctorT>
+  void forEach(const std::string &key, FunctorT &functor) const {
+    if (parent_ != nullptr) {
+      parent_->forEach<VizObjectT, FunctorT>(key, functor);
+    }
+    if (hasLocal(key)) {
+      functor(getLocal<VizObjectT>(key));
+    }
+  }
+
+ 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<const VizObject *> *non_container_child_fields,
+      std::vector<std::string> *container_child_field_names,
+      std::vector<std::vector<const VizObject *>> *container_child_fields) const override;
+
+ private:
+  const VizContextPtr parent_;
+  const std::size_t depth_;
+
+  std::map<std::string, std::unique_ptr<VizObject>> objects_;
+
+  DISALLOW_COPY_AND_ASSIGN(VizContext);
+};
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_VIZ_CONTEXT_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizEngine.cpp
----------------------------------------------------------------------
diff --git a/viz/VizEngine.cpp b/viz/VizEngine.cpp
new file mode 100644
index 0000000..263da9e
--- /dev/null
+++ b/viz/VizEngine.cpp
@@ -0,0 +1,74 @@
+/**
+ * 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 "viz/VizEngine.hpp"
+
+#include "utility/PlanVisualizer.hpp"
+#include "utility/ExecutionDAGVisualizer.hpp"
+#include "viz/VizAnalyzer.hpp"
+#include "viz/configs/DumpRelation.hpp"
+#include "viz/rules/Grouping.hpp"
+#include "viz/rules/VizRule.hpp"
+
+#include "json.hpp"
+
+namespace quickstep {
+namespace viz {
+
+using nlohmann::json;
+
+void VizEngine::execute() {
+  rules_.emplace_back(new Grouping(context_base_));
+
+  while (!rules_.empty()) {
+    std::unique_ptr<VizRule> rule(rules_.front().release());
+    rules_.pop_front();
+
+    rule->execute();
+
+    for (auto &derived_rule : rule->derived_rules_) {
+      rules_.emplace_back(derived_rule.release());
+    }
+    for (auto &result_conf : rule->result_confs_) {
+      confs_.emplace_back(result_conf.release());
+    }
+  }
+
+  json viz = json::array();
+  for (auto &conf : confs_) {
+    viz.push_back(conf->toJSON());
+  }
+
+  const VizAnalyzer *analyzer = context_base_->get<VizAnalyzer>("VizAnalyzer");
+  PlanVisualizer plan_visualizer;
+  ExecutionDAGVisualizer dag_visualizer(*analyzer->getExecutionPlan());
+  if (analyzer->getProfilingStats() != nullptr) {
+    dag_visualizer.bindProfilingStats(*analyzer->getProfilingStats());
+  }
+
+  json output = json::object();
+  output["plan"] = plan_visualizer.visualize(analyzer->getQueryPlan());
+  output["dag"] = dag_visualizer.toDOT();
+  output["results"] = DumpRelation(context_base_).toJSON();
+  output["viz"] = viz;
+  std::cerr << output.dump(2) << "\n";
+}
+
+}  // namespace viz
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizEngine.hpp
----------------------------------------------------------------------
diff --git a/viz/VizEngine.hpp b/viz/VizEngine.hpp
new file mode 100644
index 0000000..bf4dcc3
--- /dev/null
+++ b/viz/VizEngine.hpp
@@ -0,0 +1,60 @@
+/**
+ * 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_VIZ_VIZ_ENGINE_HPP_
+#define QUICKSTEP_VIZ_VIZ_ENGINE_HPP_
+
+#include <deque>
+#include <memory>
+#include <vector>
+
+#include "utility/Macros.hpp"
+#include "viz/VizContext.hpp"
+#include "viz/configs/VizConfig.hpp"
+#include "viz/rules/VizRule.hpp"
+
+namespace quickstep {
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class VizEngine {
+ public:
+  explicit VizEngine(const VizContextPtr &context_base)
+      : context_base_(context_base) {}
+
+  void execute();
+
+ private:
+  const VizContextPtr context_base_;
+
+  std::deque<std::unique_ptr<VizRule>> rules_;
+  std::vector<std::unique_ptr<VizConfig>> confs_;
+
+  DISALLOW_COPY_AND_ASSIGN(VizEngine);
+ };
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_VIZ_ENGINE_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizHelper.cpp
----------------------------------------------------------------------
diff --git a/viz/VizHelper.cpp b/viz/VizHelper.cpp
new file mode 100644
index 0000000..4abb632
--- /dev/null
+++ b/viz/VizHelper.cpp
@@ -0,0 +1,76 @@
+/**
+ * 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 "viz/VizHelper.hpp"
+
+#include <memory>
+#include <vector>
+
+#include "query_execution/QueryExecutionTypedefs.hpp"
+#include "query_optimizer/LogicalGenerator.hpp"
+#include "query_optimizer/OptimizerContext.hpp"
+#include "query_optimizer/PhysicalGenerator.hpp"
+#include "query_optimizer/physical/Physical.hpp"
+#include "viz/VizAnalyzer.hpp"
+#include "viz/VizContext.hpp"
+#include "viz/VizEngine.hpp"
+
+#include "glog/logging.h"
+
+namespace quickstep {
+namespace viz {
+
+namespace O = ::quickstep::optimizer;
+namespace P = ::quickstep::optimizer::physical;
+
+void VizHelper::Visualize(const ParseStatement &parse_statement,
+                          const QueryPlan *execution_plan,
+                          const std::vector<WorkOrderTimeEntry> *profiling_stats,
+                          const CatalogRelation *query_result_relation,
+                          const CatalogDatabase *catalog_database,
+                          StorageManager *storage_manager) {
+  // TODO(jianqiao): give some output for empty relation.
+  if (query_result_relation == nullptr) {
+    return;
+  }
+
+  O::OptimizerContext optimizer_context;
+  O::LogicalGenerator logical_generator(&optimizer_context);
+  O::PhysicalGenerator physical_generator;
+
+  const P::PhysicalPtr physical_plan =
+      physical_generator.generatePlan(
+          logical_generator.generatePlan(*catalog_database, parse_statement));
+
+  std::unique_ptr<VizContext> context_base(new VizContext());
+  context_base->set("VizAnalyzer",
+                    new VizAnalyzer(physical_plan,
+                                    execution_plan,
+                                    profiling_stats,
+                                    query_result_relation,
+                                    catalog_database,
+                                    storage_manager));
+
+  VizEngine viz_engine(VizContextPtr(context_base.release()));
+  viz_engine.execute();
+}
+
+
+}  // namespace viz
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizHelper.hpp
----------------------------------------------------------------------
diff --git a/viz/VizHelper.hpp b/viz/VizHelper.hpp
new file mode 100644
index 0000000..3d38698
--- /dev/null
+++ b/viz/VizHelper.hpp
@@ -0,0 +1,62 @@
+/**
+ * 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_VIZ_VIZ_HELPER_HPP_
+#define QUICKSTEP_VIZ_VIZ_HELPER_HPP_
+
+#include <vector>
+
+#include "query_execution/QueryExecutionTypedefs.hpp"
+#include "utility/Macros.hpp"
+
+namespace quickstep {
+
+class CatalogDatabase;
+class CatalogRelation;
+class ParseStatement;
+class QueryPlan;
+class StorageManager;
+
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class VizHelper {
+ public:
+  static void Visualize(const ParseStatement &parse_statement,
+                        const QueryPlan *execution_plan,
+                        const std::vector<WorkOrderTimeEntry> *profiling_stats,
+                        const CatalogRelation *query_result_relation,
+                        const CatalogDatabase *catalog_database,
+                        StorageManager *storage_manager);
+
+ private:
+  VizHelper() {}
+
+  DISALLOW_COPY_AND_ASSIGN(VizHelper);
+};
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_VIZ_HELPER_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizObject.cpp
----------------------------------------------------------------------
diff --git a/viz/VizObject.cpp b/viz/VizObject.cpp
new file mode 100644
index 0000000..0bf2b55
--- /dev/null
+++ b/viz/VizObject.cpp
@@ -0,0 +1,64 @@
+/**
+ * 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 "viz/VizObject.hpp"
+
+#include <memory>
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "utility/StringUtil.hpp"
+
+namespace quickstep {
+namespace viz {
+
+void VizObject::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<const VizObject *> *non_container_child_fields,
+    std::vector<std::string> *container_child_field_names,
+    std::vector<std::vector<const VizObject *>> *container_child_fields) const {
+}
+
+void AttributeIdVector::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<const VizObject *> *non_container_child_fields,
+    std::vector<std::string> *container_child_field_names,
+    std::vector<std::vector<const VizObject *>> *container_child_fields) const {
+  inline_field_names->emplace_back("attribute_ids");
+  inline_field_values->emplace_back(JoinToString(attribute_ids_, ","));
+}
+
+void StringValue::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<const VizObject *> *non_container_child_fields,
+    std::vector<std::string> *container_child_field_names,
+    std::vector<std::vector<const VizObject *>> *container_child_fields) const {
+  inline_field_names->emplace_back("value");
+  inline_field_values->emplace_back(value_);
+}
+
+}  // namespace viz
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/VizObject.hpp
----------------------------------------------------------------------
diff --git a/viz/VizObject.hpp b/viz/VizObject.hpp
new file mode 100644
index 0000000..3c86294
--- /dev/null
+++ b/viz/VizObject.hpp
@@ -0,0 +1,120 @@
+/**
+ * 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_VIZ_VIZ_OBJECT_HPP_
+#define QUICKSTEP_VIZ_VIZ_OBJECT_HPP_
+
+#include <string>
+#include <vector>
+
+#include "catalog/CatalogTypedefs.hpp"
+#include "utility/Macros.hpp"
+#include "utility/TreeStringSerializable.hpp"
+
+namespace quickstep {
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class VizObject : public TreeStringSerializable<const VizObject *> {
+ public:
+  virtual ~VizObject() {}
+
+ protected:
+  VizObject() {}
+
+  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<const VizObject *> *non_container_child_fields,
+      std::vector<std::string> *container_child_field_names,
+      std::vector<std::vector<const VizObject *>> *container_child_fields) const override;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(VizObject);
+};
+
+// ----------------------------------------------------------------------------
+// Light-weight VizObject subclasses.
+
+class AttributeIdVector : public VizObject {
+ public:
+  AttributeIdVector(const std::vector<attribute_id> &attribute_ids)
+      : attribute_ids_(attribute_ids) {}
+
+  std::string getName() const override {
+    return "AttributeIdVector";
+  }
+
+  inline const std::vector<attribute_id>& getAttributeIds() const {
+    return attribute_ids_;
+  }
+
+ 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<const VizObject *> *non_container_child_fields,
+      std::vector<std::string> *container_child_field_names,
+      std::vector<std::vector<const VizObject *>> *container_child_fields) const override;
+
+ private:
+  const std::vector<attribute_id> attribute_ids_;
+
+  DISALLOW_COPY_AND_ASSIGN(AttributeIdVector);
+};
+
+class StringValue : public VizObject {
+ public:
+  StringValue(const std::string &value)
+      : value_(value) {}
+
+  std::string getName() const override {
+    return "StringValue";
+  }
+
+  inline const std::string& value() const {
+    return value_;
+  }
+
+ 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<const VizObject *> *non_container_child_fields,
+      std::vector<std::string> *container_child_field_names,
+      std::vector<std::vector<const VizObject *>> *container_child_fields) const override;
+
+ private:
+  const std::string value_;
+
+  DISALLOW_COPY_AND_ASSIGN(StringValue);
+};
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_VIZ_OBJECT_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/configs/BarChart.hpp
----------------------------------------------------------------------
diff --git a/viz/configs/BarChart.hpp b/viz/configs/BarChart.hpp
new file mode 100644
index 0000000..f000513
--- /dev/null
+++ b/viz/configs/BarChart.hpp
@@ -0,0 +1,78 @@
+/**
+ * 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_VIZ_CONFIGS_BAR_CHART_HPP_
+#define QUICKSTEP_VIZ_CONFIGS_BAR_CHART_HPP_
+
+#include "catalog/CatalogTypedefs.hpp"
+#include "utility/Macros.hpp"
+#include "viz/configs/VizConfig.hpp"
+#include "viz/VizContext.hpp"
+
+#include "json.hpp"
+
+namespace quickstep {
+
+class CatalogRelation;
+class StorageManager;
+
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class BarChart : public VizConfig {
+ public:
+  BarChart(const attribute_id dimension_attr_id,
+           const attribute_id measure_attr_id,
+           const VizContextPtr &context)
+      : VizConfig(context),
+        dimension_attr_id_(dimension_attr_id),
+        measure_attr_id_(measure_attr_id) {}
+
+  ~BarChart() override {}
+
+  nlohmann::json toJSON() override {
+    nlohmann::json data = nlohmann::json::array();
+    data.push_back(copyColumn(dimension_attr_id_));
+    data.push_back(copyColumn(measure_attr_id_));
+
+    nlohmann::json ret;
+    ret["type"] = "BarChart";
+    ret["trace"] = copyTrace();
+    ret["schema"] = copySchema({dimension_attr_id_, measure_attr_id_});
+    ret["data"] = data;
+
+    return ret;
+  }
+
+ private:
+  const attribute_id dimension_attr_id_;
+  const attribute_id measure_attr_id_;
+
+  DISALLOW_COPY_AND_ASSIGN(BarChart);
+ };
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_CONFIGS_BAR_CHART_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/configs/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/viz/configs/CMakeLists.txt b/viz/configs/CMakeLists.txt
new file mode 100644
index 0000000..a33bf78
--- /dev/null
+++ b/viz/configs/CMakeLists.txt
@@ -0,0 +1,48 @@
+# 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.
+
+# Declare micro-libs:
+add_library(quickstep_viz_configs_BarChart ../../empty_src.cpp BarChart.hpp)
+add_library(quickstep_viz_configs_DumpRelation ../../empty_src.cpp DumpRelation.hpp)
+add_library(quickstep_viz_configs_VizConfig VizConfig.cpp VizConfig.hpp)
+
+# Link dependencies:
+target_link_libraries(quickstep_viz_configs_BarChart
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_utility_Macros
+                      quickstep_viz_VizContext
+                      quickstep_viz_configs_VizConfig)
+target_link_libraries(quickstep_viz_configs_DumpRelation
+                      quickstep_catalog_CatalogAttribute
+                      quickstep_catalog_CatalogRelation
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_utility_Macros
+                      quickstep_viz_VizAnalyzer
+                      quickstep_viz_VizContext
+                      quickstep_viz_configs_VizConfig)
+target_link_libraries(quickstep_viz_configs_VizConfig
+                      quickstep_catalog_CatalogAttribute
+                      quickstep_catalog_CatalogRelation
+                      quickstep_catalog_CatalogRelationSchema
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_storage_StorageManager
+                      quickstep_storage_ValueAccessor
+                      quickstep_storage_ValueAccessorUtil
+                      quickstep_utility_Macros
+                      quickstep_viz_VizAnalyzer
+                      quickstep_viz_VizContext
+                      quickstep_viz_VizObject)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/configs/DumpRelation.hpp
----------------------------------------------------------------------
diff --git a/viz/configs/DumpRelation.hpp b/viz/configs/DumpRelation.hpp
new file mode 100644
index 0000000..efcff2f
--- /dev/null
+++ b/viz/configs/DumpRelation.hpp
@@ -0,0 +1,79 @@
+/**
+ * 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_VIZ_CONFIGS_DUMP_RELATION_HPP_
+#define QUICKSTEP_VIZ_CONFIGS_DUMP_RELATION_HPP_
+
+#include "catalog/CatalogAttribute.hpp"
+#include "catalog/CatalogRelation.hpp"
+#include "catalog/CatalogTypedefs.hpp"
+#include "utility/Macros.hpp"
+#include "viz/configs/VizConfig.hpp"
+#include "viz/VizAnalyzer.hpp"
+#include "viz/VizContext.hpp"
+
+#include "json.hpp"
+
+namespace quickstep {
+
+class CatalogRelation;
+class StorageManager;
+
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class DumpRelation : public VizConfig {
+ public:
+  DumpRelation(const VizContextPtr &context)
+      : VizConfig(context) {}
+
+  ~DumpRelation() override {}
+
+  nlohmann::json toJSON() override {
+    const CatalogRelation *relation =
+        context_->get<VizAnalyzer>("VizAnalyzer")->getRelation();
+    std::vector<attribute_id> attr_ids;
+
+    nlohmann::json data = nlohmann::json::array();
+    for (const CatalogAttribute &attr : *relation) {
+      data.push_back(copyColumn(attr.getID()));
+      attr_ids.emplace_back(attr.getID());
+    }
+
+    nlohmann::json ret;
+    ret["type"] = "DumpRelation";
+    ret["schema"] = copySchema(attr_ids);
+    ret["data"] = data;
+
+    return ret;
+  }
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(DumpRelation);
+ };
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_CONFIGS_DUMP_RELATION_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/configs/VizConfig.cpp
----------------------------------------------------------------------
diff --git a/viz/configs/VizConfig.cpp b/viz/configs/VizConfig.cpp
new file mode 100644
index 0000000..3a15931
--- /dev/null
+++ b/viz/configs/VizConfig.cpp
@@ -0,0 +1,91 @@
+/**
+ * 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 "viz/configs/VizConfig.hpp"
+
+#include <memory>
+
+#include "catalog/CatalogAttribute.hpp"
+#include "catalog/CatalogRelation.hpp"
+#include "catalog/CatalogRelationSchema.hpp"
+#include "catalog/CatalogTypedefs.hpp"
+#include "storage/StorageManager.hpp"
+#include "storage/ValueAccessor.hpp"
+#include "storage/ValueAccessorUtil.hpp"
+#include "viz/VizAnalyzer.hpp"
+#include "viz/VizContext.hpp"
+#include "viz/VizObject.hpp"
+
+#include "json.hpp"
+
+namespace quickstep {
+namespace viz {
+
+using nlohmann::json;
+
+VizConfig::VizConfig(const VizContextPtr &context)
+    : context_(context) {
+  const VizAnalyzer *analyzer =
+      context_->get<VizAnalyzer>("VizAnalyzer");
+  relation_ = analyzer->getRelation();
+  storage_manager_ = analyzer->getStorageManager();
+}
+
+json VizConfig::copyColumn(const attribute_id column_id) {
+  json values = json::array();
+  for (const block_id bid : relation_->getBlocksSnapshot()) {
+    BlockReference block = storage_manager_->getBlock(bid, *relation_);
+    std::unique_ptr<ValueAccessor> accessor(
+        block->getTupleStorageSubBlock().createValueAccessor());
+    const Type &type = relation_->getAttributeById(column_id)->getType();
+    InvokeOnValueAccessorNotAdapter(
+        accessor.get(),
+        [&](auto *accessor) -> void {  // NOLINT(build/c++11)
+      while (accessor->next()) {
+        values.push_back(
+            type.printValueToString(accessor->getTypedValue(column_id)));
+      }
+    });
+  }
+  return values;
+}
+
+json VizConfig::copySchema(const std::vector<attribute_id> &attr_ids) {
+  json schema = json::array();
+  for (const attribute_id attr_id : attr_ids) {
+    const CatalogAttribute *attr = relation_->getAttributeById(attr_id);
+    json attr_info;
+    attr_info["name"] = attr->getDisplayName();
+    attr_info["type"] = attr->getType().getName();
+    schema.push_back(attr_info);
+  }
+  return schema;
+}
+
+json VizConfig::copyTrace() {
+  json trace = json::array();
+  auto copy_trace_functor = [&trace](const StringValue *str_value) -> void {
+    trace.push_back(str_value->value());
+  };
+  context_->forEach<StringValue>("trace", copy_trace_functor);
+  return trace;
+}
+
+}  // namespace viz
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/configs/VizConfig.hpp
----------------------------------------------------------------------
diff --git a/viz/configs/VizConfig.hpp b/viz/configs/VizConfig.hpp
new file mode 100644
index 0000000..65f7efe
--- /dev/null
+++ b/viz/configs/VizConfig.hpp
@@ -0,0 +1,68 @@
+/**
+ * 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_VIZ_CONFIGS_VIZ_CONFIG_HPP_
+#define QUICKSTEP_VIZ_CONFIGS_VIZ_CONFIG_HPP_
+
+#include "catalog/CatalogTypedefs.hpp"
+#include "utility/Macros.hpp"
+#include "viz/VizContext.hpp"
+
+#include "json.hpp"
+
+namespace quickstep {
+
+class CatalogRelation;
+class CatalogRelationSchema;
+class StorageManager;
+
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class VizConfig {
+ public:
+  virtual ~VizConfig() {}
+
+  virtual nlohmann::json toJSON() = 0;
+
+ protected:
+  explicit VizConfig(const VizContextPtr &context);
+
+
+  nlohmann::json copyColumn(const attribute_id column_id);
+  nlohmann::json copySchema(const std::vector<attribute_id> &attr_ids);
+  nlohmann::json copyTrace();
+
+  const VizContextPtr context_;
+  const CatalogRelation *relation_;
+  StorageManager *storage_manager_;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(VizConfig);
+ };
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_CONFIGS_VIZ_CONFIG_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/rules/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/viz/rules/CMakeLists.txt b/viz/rules/CMakeLists.txt
new file mode 100644
index 0000000..640a678
--- /dev/null
+++ b/viz/rules/CMakeLists.txt
@@ -0,0 +1,43 @@
+# 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.
+
+# Declare micro-libs:
+add_library(quickstep_viz_rules_Grouping ../../empty_src.cpp Grouping.hpp)
+add_library(quickstep_viz_rules_OneDimensionOneMeasure
+            ../../empty_src.cpp
+            OneDimensionOneMeasure.hpp)
+add_library(quickstep_viz_rules_VizRule ../../empty_src.cpp VizRule.hpp)
+
+# Link dependencies:
+target_link_libraries(quickstep_viz_rules_Grouping
+                      quickstep_catalog_CatalogAttribute
+                      quickstep_catalog_CatalogRelation
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_utility_Macros
+                      quickstep_viz_VizAnalyzer
+                      quickstep_viz_rules_OneDimensionOneMeasure)
+target_link_libraries(quickstep_viz_rules_OneDimensionOneMeasure
+                      quickstep_catalog_CatalogTypedefs
+                      quickstep_utility_Macros
+                      quickstep_viz_VizAnalyzer
+                      quickstep_viz_VizContext
+                      quickstep_viz_VizObject
+                      quickstep_viz_configs_BarChart)
+target_link_libraries(quickstep_viz_rules_VizRule
+                      quickstep_utility_Macros
+                      quickstep_viz_VizContext
+                      quickstep_viz_configs_VizConfig)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/rules/Grouping.hpp
----------------------------------------------------------------------
diff --git a/viz/rules/Grouping.hpp b/viz/rules/Grouping.hpp
new file mode 100644
index 0000000..c20cef1
--- /dev/null
+++ b/viz/rules/Grouping.hpp
@@ -0,0 +1,100 @@
+/**
+ * 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_VIZ_RULES_GROUPING_HPP_
+#define QUICKSTEP_VIZ_RULES_GROUPING_HPP_
+
+#include <memory>
+#include <unordered_set>
+#include <vector>
+
+#include "catalog/CatalogAttribute.hpp"
+#include "catalog/CatalogRelation.hpp"
+#include "catalog/CatalogTypedefs.hpp"
+#include "utility/Macros.hpp"
+#include "viz/VizAnalyzer.hpp"
+#include "viz/rules/OneDimensionOneMeasure.hpp"
+
+namespace quickstep {
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class Grouping : public VizRule {
+ public:
+  Grouping(const VizContextPtr &context)
+      : VizRule(context) {}
+
+  ~Grouping() override {}
+
+  void execute() override {
+    const VizAnalyzer *analyzer =
+        context_->get<VizAnalyzer>("VizAnalyzer");
+
+    std::vector<attribute_id> group_by_attribute_ids;
+    if (analyzer->findGroupByAttributes(&group_by_attribute_ids)) {
+      std::unordered_set<attribute_id> group_by_attr_id_set(
+          group_by_attribute_ids.begin(),
+          group_by_attribute_ids.end());
+      std::vector<attribute_id> residual_attribute_ids;
+      for (const CatalogAttribute &attr : *analyzer->getRelation()) {
+        if (group_by_attr_id_set.find(attr.getID()) == group_by_attr_id_set.end()) {
+          residual_attribute_ids.emplace_back(attr.getID());
+        }
+      }
+
+      std::unique_ptr<VizContext> new_context(new VizContext(context_));
+      new_context->set("trace", new StringValue("Grouping"));
+      new_context->set("Dimensions",
+                       new AttributeIdVector(group_by_attribute_ids));
+      new_context->set("Measures",
+                       new AttributeIdVector(residual_attribute_ids));
+
+      dispatchWithGrouping(analyzer,
+                           VizContextPtr(new_context.release()),
+                           group_by_attribute_ids.size(),
+                           residual_attribute_ids.size());
+    } else {
+      // TODO
+    }
+  }
+
+ private:
+  void dispatchWithGrouping(const VizAnalyzer *analyzer,
+                            const VizContextPtr new_context,
+                            const std::size_t num_dimension_attrs,
+                            const std::size_t num_measure_attrs) {
+    if (num_dimension_attrs == 1) {
+      if (num_measure_attrs == 1) {
+        derive(new OneDimensionOneMeasure(new_context));
+      }
+    }
+  }
+
+  DISALLOW_COPY_AND_ASSIGN(Grouping);
+ };
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_RULES_GROUPING_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/rules/OneDimensionOneMeasure.hpp
----------------------------------------------------------------------
diff --git a/viz/rules/OneDimensionOneMeasure.hpp b/viz/rules/OneDimensionOneMeasure.hpp
new file mode 100644
index 0000000..565ec1b
--- /dev/null
+++ b/viz/rules/OneDimensionOneMeasure.hpp
@@ -0,0 +1,73 @@
+/**
+ * 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_VIZ_RULES_ONE_DIMENSION_ONE_MEASURE_HPP_
+#define QUICKSTEP_VIZ_RULES_ONE_DIMENSION_ONE_MEASURE_HPP_
+
+#include "catalog/CatalogTypedefs.hpp"
+#include "utility/Macros.hpp"
+#include "viz/VizAnalyzer.hpp"
+#include "viz/VizContext.hpp"
+#include "viz/VizObject.hpp"
+#include "viz/configs/BarChart.hpp"
+
+namespace quickstep {
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class OneDimensionOneMeasure : public VizRule {
+ public:
+  OneDimensionOneMeasure(const VizContextPtr &context)
+      : VizRule(context) {}
+
+  ~OneDimensionOneMeasure() override {}
+
+  void execute() override {
+    const AttributeIdVector *dimensions =
+        context_->get<AttributeIdVector>("Dimensions");
+    CHECK_EQ(1uL, dimensions->getAttributeIds().size());
+
+    const AttributeIdVector *measures =
+        context_->get<AttributeIdVector>("Measures");
+    CHECK_EQ(1uL, measures->getAttributeIds().size());
+
+    std::unique_ptr<VizContext> new_context(new VizContext(context_));
+    new_context->set("trace", new StringValue("OneDimensionOneMeasure"));
+
+    const VizContextPtr new_context_ptr(new_context.release());
+
+    // Barchart or Linechart
+    yield(new BarChart(dimensions->getAttributeIds().front(),
+                       measures->getAttributeIds().front(),
+                       new_context_ptr));
+  }
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(OneDimensionOneMeasure);
+ };
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_RULES_ONE_DIMENSION_ONE_MEASURE_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b060eb24/viz/rules/VizRule.hpp
----------------------------------------------------------------------
diff --git a/viz/rules/VizRule.hpp b/viz/rules/VizRule.hpp
new file mode 100644
index 0000000..f034e9e
--- /dev/null
+++ b/viz/rules/VizRule.hpp
@@ -0,0 +1,68 @@
+/**
+ * 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_VIZ_RULES_VIZ_RULE_HPP_
+#define QUICKSTEP_VIZ_RULES_VIZ_RULE_HPP_
+
+#include "utility/Macros.hpp"
+#include "viz/VizContext.hpp"
+#include "viz/configs/VizConfig.hpp"
+
+namespace quickstep {
+namespace viz {
+
+/** \addtogroup Viz
+ *  @{
+ */
+
+class VizRule {
+ public:
+  virtual ~VizRule() {}
+
+  virtual void execute() = 0;
+
+  inline void derive(VizRule *rule) {
+    derived_rules_.emplace_back(rule);
+  }
+
+  inline void yield(VizConfig *conf) {
+    result_confs_.emplace_back(conf);
+  }
+
+ protected:
+  explicit VizRule(const VizContextPtr &context)
+      : context_(context) {}
+
+  const VizContextPtr context_;
+
+ private:
+  friend class VizEngine;
+
+  std::vector<std::unique_ptr<VizRule>> derived_rules_;
+  std::vector<std::unique_ptr<VizConfig>> result_confs_;
+
+  DISALLOW_COPY_AND_ASSIGN(VizRule);
+ };
+
+/** @} */
+
+}  // namespace viz
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_VIZ_RULES_VIZ_RULE_HPP_


Mime
View raw message