quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zu...@apache.org
Subject [15/24] incubator-quickstep git commit: Moved Describe command to an util file.
Date Wed, 01 Mar 2017 22:43:27 GMT
Moved Describe command to an util file.


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

Branch: refs/heads/dist-patch
Commit: 5f5073f34f3fd8b06907d65e7d503c77067d336e
Parents: 132fed6
Author: Zuyu Zhang <zuyuz@apache.org>
Authored: Tue Feb 28 01:34:10 2017 -0800
Committer: Zuyu Zhang <zuyuz@apache.org>
Committed: Tue Feb 28 14:22:37 2017 -0800

----------------------------------------------------------------------
 cli/CMakeLists.txt                        |  56 +++++---
 cli/CommandExecutor.cpp                   | 136 +------------------
 cli/CommandExecutorUtil.cpp               | 180 +++++++++++++++++++++++++
 cli/CommandExecutorUtil.hpp               |  63 +++++++++
 cli/Constants.hpp                         |   5 -
 cli/PrintToScreen.cpp                     |  29 ++--
 cli/PrintToScreen.hpp                     |   4 +-
 cli/tests/command_executor/CMakeLists.txt |   1 -
 8 files changed, 307 insertions(+), 167 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/5f5073f3/cli/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index 7b4319a..ffeed2f 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -43,18 +43,15 @@ configure_file (
   "${CMAKE_CURRENT_SOURCE_DIR}/CliConfig.h.in"
   "${CMAKE_CURRENT_BINARY_DIR}/CliConfig.h"
 )
-add_library(quickstep_cli_CommandExecutor CommandExecutor.cpp CommandExecutor.hpp)
-add_library(quickstep_cli_Constants ../empty_src.cpp Constants.hpp)
 
 # Declare micro-libs and link dependencies:
+add_library(quickstep_cli_CommandExecutor CommandExecutor.cpp CommandExecutor.hpp)
+add_library(quickstep_cli_CommandExecutorUtil CommandExecutorUtil.cpp CommandExecutorUtil.hpp)
+add_library(quickstep_cli_Constants ../empty_src.cpp Constants.hpp)
+add_library(quickstep_cli_DefaultsConfigurator DefaultsConfigurator.cpp DefaultsConfigurator.hpp)
 add_library(quickstep_cli_DropRelation DropRelation.cpp DropRelation.hpp)
-target_link_libraries(quickstep_cli_DropRelation
-                      quickstep_catalog_CatalogDatabase
-                      quickstep_catalog_CatalogRelation
-                      quickstep_storage_StorageBlockInfo
-                      quickstep_storage_StorageManager
-                      quickstep_utility_Macros)
 add_library(quickstep_cli_Flags Flags.cpp Flags.hpp)
+add_library(quickstep_cli_InputParserUtil InputParserUtil.cpp InputParserUtil.hpp)
 
 if(USE_LINENOISE)
   add_library(quickstep_cli_LineReader
@@ -62,21 +59,14 @@ if(USE_LINENOISE)
               LineReaderLineNoise.cpp
               LineReader.hpp
               LineReaderLineNoise.hpp)
-  target_link_libraries(quickstep_cli_LineReader
-                        linenoise
-                        quickstep_utility_Macros)
 else()
   add_library(quickstep_cli_LineReader
               LineReader.cpp
               LineReaderDumb.cpp
               LineReader.hpp
               LineReaderDumb.hpp)
-  target_link_libraries(quickstep_cli_LineReader
-                        quickstep_utility_Macros)
 endif()
 
-add_library(quickstep_cli_DefaultsConfigurator DefaultsConfigurator.cpp DefaultsConfigurator.hpp)
-add_library(quickstep_cli_InputParserUtil InputParserUtil.cpp InputParserUtil.hpp)
 add_library(quickstep_cli_PrintToScreen PrintToScreen.cpp PrintToScreen.hpp)
 
 # Link dependencies:
@@ -87,6 +77,7 @@ target_link_libraries(quickstep_cli_CommandExecutor
                       quickstep_catalog_CatalogRelation
                       quickstep_catalog_CatalogRelationSchema
                       quickstep_catalog_CatalogRelationStatistics
+                      quickstep_cli_CommandExecutorUtil
                       quickstep_cli_Constants
                       quickstep_cli_DropRelation
                       quickstep_cli_PrintToScreen
@@ -108,8 +99,22 @@ target_link_libraries(quickstep_cli_CommandExecutor
                       quickstep_types_TypedValue
                       quickstep_utility_PtrVector
                       quickstep_utility_SqlError
+                      quickstep_utility_StringUtil
+                      tmb)
+target_link_libraries(quickstep_cli_CommandExecutorUtil
+                      quickstep_catalog_CatalogAttribute
+                      quickstep_catalog_CatalogDatabase
+                      quickstep_catalog_CatalogRelation
+                      quickstep_catalog_IndexScheme
+                      quickstep_cli_PrintToScreen
+                      quickstep_parser_ParseString
+                      quickstep_storage_StorageBlockLayout_proto
+                      quickstep_types_Type
+                      quickstep_types_TypeID
+                      quickstep_types_TypedValue
+                      quickstep_utility_PtrVector
+                      quickstep_utility_SqlError
                       quickstep_utility_StringUtil)
-
 target_link_libraries(quickstep_cli_DefaultsConfigurator
                       glog
                       quickstep_catalog_Catalog
@@ -120,6 +125,12 @@ if(QUICKSTEP_HAVE_LIBNUMA)
   target_link_libraries(quickstep_cli_DefaultsConfigurator
                         ${LIBNUMA_LIBRARY})
 endif()
+target_link_libraries(quickstep_cli_DropRelation
+                      quickstep_catalog_CatalogDatabase
+                      quickstep_catalog_CatalogRelation
+                      quickstep_storage_StorageBlockInfo
+                      quickstep_storage_StorageManager
+                      quickstep_utility_Macros)
 target_link_libraries(quickstep_cli_Flags
                       quickstep_cli_DefaultsConfigurator
                       quickstep_storage_StorageConstants
@@ -129,8 +140,16 @@ target_link_libraries(quickstep_cli_InputParserUtil
                       quickstep_utility_Macros
                       quickstep_utility_StringUtil)
 if(QUICKSTEP_HAVE_LIBNUMA)
-target_link_libraries(quickstep_cli_InputParserUtil
-                      ${LIBNUMA_LIBRARY})
+  target_link_libraries(quickstep_cli_InputParserUtil
+                        ${LIBNUMA_LIBRARY})
+endif()
+if(USE_LINENOISE)
+  target_link_libraries(quickstep_cli_LineReader
+                        linenoise
+                        quickstep_utility_Macros)
+else()
+  target_link_libraries(quickstep_cli_LineReader
+                        quickstep_utility_Macros)
 endif()
 target_link_libraries(quickstep_cli_PrintToScreen
                       ${GFLAGS_LIB_NAME}
@@ -151,6 +170,7 @@ add_library(quickstep_cli ../empty_src.cpp CliModule.hpp)
 
 target_link_libraries(quickstep_cli
                       quickstep_cli_CommandExecutor
+                      quickstep_cli_CommandExecutorUtil
                       quickstep_cli_Constants
                       quickstep_cli_DefaultsConfigurator
                       quickstep_cli_DropRelation

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/5f5073f3/cli/CommandExecutor.cpp
----------------------------------------------------------------------
diff --git a/cli/CommandExecutor.cpp b/cli/CommandExecutor.cpp
index 7f63469..6a84672 100644
--- a/cli/CommandExecutor.cpp
+++ b/cli/CommandExecutor.cpp
@@ -32,6 +32,7 @@
 #include "catalog/CatalogRelation.hpp"
 #include "catalog/CatalogRelationSchema.hpp"
 #include "catalog/CatalogRelationStatistics.hpp"
+#include "cli/CommandExecutorUtil.hpp"
 #include "cli/Constants.hpp"
 #include "cli/DropRelation.hpp"
 #include "cli/PrintToScreen.hpp"
@@ -72,132 +73,6 @@ namespace quickstep {
 namespace cli {
 namespace {
 
-void ExecuteDescribeDatabase(
-    const PtrVector<ParseString> &arguments,
-    const CatalogDatabase &catalog_database,
-    FILE *out) {
-  // Column width initialized to 6 to take into account the header name
-  // and the column value table
-  int max_column_width = kInitMaxColumnWidth;
-  vector<std::size_t> num_blocks;
-  const CatalogRelation *relation = nullptr;
-  if (arguments.empty()) {
-    for (const CatalogRelation &rel : catalog_database) {
-      max_column_width =
-          std::max(static_cast<int>(rel.getName().length()), max_column_width);
-      num_blocks.push_back(rel.size_blocks());
-    }
-  } else {
-    const ParseString &table_name = arguments.front();
-    const std::string &table_name_val = table_name.value();
-    relation = catalog_database.getRelationByName(table_name_val);
-
-    if (relation == nullptr) {
-      THROW_SQL_ERROR_AT(&(arguments.front())) << " Unrecognized relation " <<
table_name_val;
-    }
-    max_column_width = std::max(static_cast<int>(relation->getName().length()),
-                                    max_column_width);
-    num_blocks.push_back(relation->size_blocks());
-  }
-  // Only if we have relations work on the printing logic.
-  if (!catalog_database.empty()) {
-    const std::size_t max_num_blocks = *std::max_element(num_blocks.begin(), num_blocks.end());
-    const int max_num_blocks_digits = std::max(PrintToScreen::GetNumberOfDigits(max_num_blocks),
-                                      kInitMaxColumnWidth + 2);
-    vector<int> column_widths;
-    column_widths.push_back(max_column_width + 1);
-    column_widths.push_back(kInitMaxColumnWidth + 1);
-    column_widths.push_back(max_num_blocks_digits + 1);
-    fputs("       List of relations\n\n", out);
-    fprintf(out, "%-*s |", max_column_width + 1, " Name");
-    fprintf(out, "%-*s |", kInitMaxColumnWidth, " Type");
-    fprintf(out, "%-*s\n", max_num_blocks_digits, " Blocks");
-    PrintToScreen::printHBar(column_widths, out);
-    //  If there are no argument print the entire list of tables
-    //  else print the particular table only.
-    vector<std::size_t>::const_iterator num_blocks_it = num_blocks.begin();
-    if (arguments.empty()) {
-      for (const CatalogRelation &rel : catalog_database) {
-        fprintf(out, " %-*s |", max_column_width, rel.getName().c_str());
-        fprintf(out, " %-*s |", kInitMaxColumnWidth - 1, "table");
-        fprintf(out, " %-*lu\n", max_num_blocks_digits - 1, *num_blocks_it);
-        ++num_blocks_it;
-      }
-    } else {
-      fprintf(out, " %-*s |", max_column_width, relation->getName().c_str());
-      fprintf(out, " %-*s |", kInitMaxColumnWidth - 1, "table");
-      fprintf(out, " %-*lu\n", max_num_blocks_digits - 1, *num_blocks_it);
-      ++num_blocks_it;
-    }
-    fputc('\n', out);
-  }
-}
-
-void ExecuteDescribeTable(
-    const PtrVector<ParseString> &arguments,
-    const CatalogDatabase &catalog_database, FILE *out) {
-  const ParseString &table_name = arguments.front();
-  const std::string &table_name_val = table_name.value();
-  const CatalogRelation *relation =
-      catalog_database.getRelationByName(table_name_val);
-  if (relation == nullptr) {
-    THROW_SQL_ERROR_AT(&(arguments.front())) << " Unrecognized relation "  <<
table_name_val;
-  }
-  vector<int> column_widths;
-  int max_attr_column_width = kInitMaxColumnWidth;
-  int max_type_column_width = kInitMaxColumnWidth;
-
-  for (const CatalogAttribute &attr : *relation) {
-    // Printed column needs to be wide enough to print:
-    //   1. The attribute name (in the printed "header").
-    //   2. Any value of the attribute's Type.
-    max_attr_column_width =
-        std::max(max_attr_column_width,
-            static_cast<int>(attr.getDisplayName().length()));
-    max_type_column_width =
-        std::max(max_type_column_width,
-            static_cast<int>(attr.getType().getName().length()));
-  }
-  // Add room for one extra character to allow spacing between the column ending and the
vertical bar
-  column_widths.push_back(max_attr_column_width + 1);
-  column_widths.push_back(max_type_column_width + 1);
-
-  fprintf(out, "%*s \"%s\"\n", kInitMaxColumnWidth, "Table", table_name_val.c_str());
-  fprintf(out, "%-*s |", max_attr_column_width + 1, " Column");
-  fprintf(out, "%-*s\n", max_type_column_width + 1, " Type");
-  PrintToScreen::printHBar(column_widths, out);
-  for (const CatalogAttribute &attr : *relation) {
-    fprintf(out, " %-*s |", max_attr_column_width,
-            attr.getDisplayName().c_str());
-    fprintf(out, " %-*s\n", max_type_column_width,
-            attr.getType().getName().c_str());
-  }
-  // TODO(rogers): Add handlers for partitioning information.
-  if (relation->hasIndexScheme()) {
-    fprintf(out, "%*s\n", kInitMaxColumnWidth + 2, " Indexes");
-    const quickstep::IndexScheme &index_scheme = relation->getIndexScheme();
-    for (auto index_it = index_scheme.begin(); index_it != index_scheme.end();
-         ++index_it) {
-      fprintf(out, "  \"%-*s\" %s", static_cast<int>(index_it->first.length()),
-              index_it->first.c_str(),
-              index_it->second.IndexSubBlockType_Name(
-                  index_it->second.sub_block_type()).c_str());
-      fputc(' ', out);
-      fputc('(', out);
-      fprintf(out, "%s", relation->getAttributeById(index_it->second.indexed_attribute_ids(0))
-                             ->getDisplayName().c_str());
-      for (std::size_t i = 1; i < static_cast<std::size_t>(index_it->second.indexed_attribute_ids_size());
++i) {
-        const char *attribute_display_name = relation->getAttributeById(
-                                                 index_it->second.indexed_attribute_ids(i))
-                                                     ->getDisplayName().c_str();
-        fprintf(out, ", %s", attribute_display_name);
-      }
-      fputc(')', out);
-      fputc('\n', out);
-    }
-  }
-}
-
 /**
  * @brief A helper function that executes a SQL query to obtain a row of results.
  */
@@ -422,12 +297,15 @@ void executeCommand(const ParseStatement &statement,
   const PtrVector<ParseString> &arguments = *(command.arguments());
   const std::string &command_str = command.command()->value();
   if (command_str == kDescribeDatabaseCommand) {
-    ExecuteDescribeDatabase(arguments, catalog_database, out);
+    const string database_description = ExecuteDescribeDatabase(arguments, catalog_database);
+    fprintf(out, "%s", database_description.c_str());
   } else if (command_str == kDescribeTableCommand) {
     if (arguments.empty()) {
-      ExecuteDescribeDatabase(arguments, catalog_database, out);
+      const string database_description = ExecuteDescribeDatabase(arguments, catalog_database);
+      fprintf(out, "%s", database_description.c_str());
     } else {
-      ExecuteDescribeTable(arguments, catalog_database, out);
+      const string table_description = ExecuteDescribeTable(arguments, catalog_database);
+      fprintf(out, "%s", table_description.c_str());
     }
   } else if (command_str == kAnalyzeCommand) {
     ExecuteAnalyze(arguments,

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/5f5073f3/cli/CommandExecutorUtil.cpp
----------------------------------------------------------------------
diff --git a/cli/CommandExecutorUtil.cpp b/cli/CommandExecutorUtil.cpp
new file mode 100644
index 0000000..d17617f
--- /dev/null
+++ b/cli/CommandExecutorUtil.cpp
@@ -0,0 +1,180 @@
+/**
+ * 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 "cli/CommandExecutorUtil.hpp"
+
+#include <algorithm>
+#include <cstddef>
+#include <iomanip>
+#include <string>
+#include <vector>
+
+#include "catalog/CatalogAttribute.hpp"
+#include "catalog/CatalogDatabase.hpp"
+#include "catalog/CatalogRelation.hpp"
+#include "catalog/IndexScheme.hpp"
+#include "cli/PrintToScreen.hpp"
+#include "parser/ParseString.hpp"
+#include "storage/StorageBlockLayout.pb.h"
+#include "types/Type.hpp"
+#include "types/TypeID.hpp"
+#include "types/TypedValue.hpp"
+#include "utility/PtrVector.hpp"
+#include "utility/SqlError.hpp"
+#include "utility/StringUtil.hpp"
+
+using std::ostringstream;
+using std::setw;
+using std::size_t;
+using std::string;
+using std::vector;
+
+namespace quickstep {
+namespace cli {
+
+namespace {
+
+// Adding the max column width as 6 as the default initializer
+// as the length of the word Column is 6 characters.
+// This is used while describing the table.
+
+constexpr int kInitMaxColumnWidth = 6;
+
+}  // namespace
+
+string ExecuteDescribeDatabase(
+    const PtrVector<ParseString> &arguments,
+    const CatalogDatabase &catalog_database) {
+  // Column width initialized to 6 to take into account the header name
+  // and the column value table
+  int max_column_width = kInitMaxColumnWidth;
+  vector<std::size_t> num_blocks;
+  const CatalogRelation *relation = nullptr;
+  if (arguments.empty()) {
+    for (const CatalogRelation &rel : catalog_database) {
+      max_column_width =
+          std::max(static_cast<int>(rel.getName().length()), max_column_width);
+      num_blocks.push_back(rel.size_blocks());
+    }
+  } else {
+    const ParseString &table_name = arguments.front();
+    const std::string &table_name_val = table_name.value();
+    relation = catalog_database.getRelationByName(table_name_val);
+
+    if (relation == nullptr) {
+      THROW_SQL_ERROR_AT(&(arguments.front())) << " Unrecognized relation " <<
table_name_val;
+    }
+    max_column_width = std::max(static_cast<int>(relation->getName().length()),
+                                    max_column_width);
+    num_blocks.push_back(relation->size_blocks());
+  }
+
+  ostringstream oss;
+  // Only if we have relations work on the printing logic.
+  if (!catalog_database.empty()) {
+    const std::size_t max_num_blocks = *std::max_element(num_blocks.begin(), num_blocks.end());
+    const int max_num_blocks_digits = std::max(PrintToScreen::GetNumberOfDigits(max_num_blocks),
+                                               kInitMaxColumnWidth + 2);
+
+    oss << "       List of relations\n\n"
+        << std::left << setw(max_column_width + 1) << " Name" <<
" |"
+        << setw(kInitMaxColumnWidth) << " Type" << " |"
+        << setw(max_num_blocks_digits) << " Blocks" << '\n'
+        << PrintToScreen::GenerateHBar({ max_column_width + 1, kInitMaxColumnWidth
+ 1, max_num_blocks_digits + 1 });
+
+    //  If there are no argument print the entire list of tables
+    //  else print the particular table only.
+    vector<std::size_t>::const_iterator num_blocks_it = num_blocks.begin();
+    if (arguments.empty()) {
+      for (const CatalogRelation &rel : catalog_database) {
+        oss << ' ' << setw(max_column_width) << rel.getName() <<
" |"
+            << setw(kInitMaxColumnWidth) << " table" << " | "
+            << setw(max_num_blocks_digits - 1) << *num_blocks_it << '\n';
+        ++num_blocks_it;
+      }
+    } else {
+      oss << ' ' << setw(max_column_width) << relation->getName() <<
" |"
+          << setw(kInitMaxColumnWidth) << " table" << " | "
+          << setw(max_num_blocks_digits - 1) << *num_blocks_it << '\n';
+      ++num_blocks_it;
+    }
+    oss << '\n';
+  }
+
+  return oss.str();
+}
+
+string ExecuteDescribeTable(
+    const PtrVector<ParseString> &arguments,
+    const CatalogDatabase &catalog_database) {
+  const ParseString &table_name = arguments.front();
+  const std::string &table_name_val = table_name.value();
+  const CatalogRelation *relation =
+      catalog_database.getRelationByName(table_name_val);
+  if (relation == nullptr) {
+    THROW_SQL_ERROR_AT(&(arguments.front())) << " Unrecognized relation "  <<
table_name_val;
+  }
+
+  int max_attr_column_width = kInitMaxColumnWidth;
+  int max_type_column_width = kInitMaxColumnWidth;
+  for (const CatalogAttribute &attr : *relation) {
+    // Printed column needs to be wide enough to print:
+    //   1. The attribute name (in the printed "header").
+    //   2. Any value of the attribute's Type.
+    max_attr_column_width =
+        std::max(max_attr_column_width,
+            static_cast<int>(attr.getDisplayName().length()));
+    max_type_column_width =
+        std::max(max_type_column_width,
+            static_cast<int>(attr.getType().getName().length()));
+  }
+
+  ostringstream oss;
+  oss << setw(kInitMaxColumnWidth) << "Table" << " \"" << table_name_val
<< "\"\n";
+  oss << std::left << setw(max_attr_column_width + 1) << " Column" <<
" |";
+  oss << setw(max_type_column_width + 1) << " Type" << '\n';
+
+  // Add room for one extra character to allow spacing between the column ending and the
vertical bar
+  oss << PrintToScreen::GenerateHBar({ max_attr_column_width + 1, max_type_column_width
+ 1 });
+
+  for (const CatalogAttribute &attr : *relation) {
+    oss << ' ' << setw(max_attr_column_width) << attr.getDisplayName()
<< " | "
+        << setw(max_type_column_width) << attr.getType().getName() << '\n';
+  }
+  // TODO(rogers): Add handlers for partitioning information.
+  if (relation->hasIndexScheme()) {
+    oss << setw(kInitMaxColumnWidth + 2) << " Indexes" << '\n';
+    for (const auto &index : relation->getIndexScheme()) {
+      const IndexSubBlockDescription &index_description = index.second;
+      oss << "  \"" << index.first << "\" "
+          << index_description.IndexSubBlockType_Name(index_description.sub_block_type())
+          << " ("
+          << relation->getAttributeById(index_description.indexed_attribute_ids(0))->getDisplayName();
+      for (int i = 1; i < index_description.indexed_attribute_ids_size(); ++i) {
+        oss << ", " << relation->getAttributeById(index_description.indexed_attribute_ids(i))->getDisplayName();
+      }
+      oss << ")\n";
+    }
+  }
+
+  return oss.str();
+}
+
+}  // namespace cli
+}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/5f5073f3/cli/CommandExecutorUtil.hpp
----------------------------------------------------------------------
diff --git a/cli/CommandExecutorUtil.hpp b/cli/CommandExecutorUtil.hpp
new file mode 100644
index 0000000..7f8c4df
--- /dev/null
+++ b/cli/CommandExecutorUtil.hpp
@@ -0,0 +1,63 @@
+/**
+ * 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_CLI_COMMAND_COMMAND_EXECUTOR_UTIL_HPP_
+#define QUICKSTEP_CLI_COMMAND_COMMAND_EXECUTOR_UTIL_HPP_
+
+#include <string>
+
+#include "utility/PtrVector.hpp"
+
+namespace quickstep {
+
+class CatalogDatabase;
+class ParseString;
+
+namespace cli {
+
+/** \addtogroup CLI
+ *  @{
+ */
+
+/**
+  * @brief Executes the command by calling the command handler.
+  *
+  * @param statement The parsed statement from the cli.
+  * @param catalog_database The catalog information about the current database.
+  * @param main_thread_client_id The TMB client ID of the main thread.
+  * @param foreman_client_id The TMB client ID of the Foreman thread.
+  * @param bus A pointer to the TMB.
+  * @param query_processor The query processor to generate plans for SQL queries.
+  * @param foreman The foreman to execute query plans.
+  * @param out The stream where the output of the command has to be redirected to.
+*/
+extern std::string ExecuteDescribeDatabase(
+    const PtrVector<ParseString> &arguments,
+    const CatalogDatabase &catalog_database);
+
+extern std::string ExecuteDescribeTable(
+    const PtrVector<ParseString> &arguments,
+    const CatalogDatabase &catalog_database);
+
+/** @} */
+
+}  // namespace cli
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_CLI_COMMAND_COMMAND_EXECUTOR_UTIL_HPP_

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/5f5073f3/cli/Constants.hpp
----------------------------------------------------------------------
diff --git a/cli/Constants.hpp b/cli/Constants.hpp
index 1aaa5be..0b4a37b 100644
--- a/cli/Constants.hpp
+++ b/cli/Constants.hpp
@@ -27,11 +27,6 @@ namespace cli {
  *  @{
  */
 
-// Adding the max column width as 6 as the default initializer
-// as the length of the word Column is 6 characters.
-// This is used while describing the table.
-constexpr int kInitMaxColumnWidth = 6;
-
 constexpr char kDescribeDatabaseCommand[] = "\\dt";
 constexpr char kDescribeTableCommand[] = "\\d";
 constexpr char kAnalyzeCommand[] = "\\analyze";

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/5f5073f3/cli/PrintToScreen.cpp
----------------------------------------------------------------------
diff --git a/cli/PrintToScreen.cpp b/cli/PrintToScreen.cpp
index 7d06474..bb64c93 100644
--- a/cli/PrintToScreen.cpp
+++ b/cli/PrintToScreen.cpp
@@ -19,10 +19,13 @@
 
 #include "cli/PrintToScreen.hpp"
 
+#include <cmath>
 #include <cstddef>
 #include <cstdio>
-#include <cmath>
+#include <iomanip>
 #include <memory>
+#include <sstream>
+#include <string>
 #include <vector>
 
 #include "catalog/CatalogAttribute.hpp"
@@ -42,6 +45,7 @@
 using std::fprintf;
 using std::fputc;
 using std::size_t;
+using std::string;
 using std::vector;
 
 namespace quickstep {
@@ -88,7 +92,8 @@ void PrintToScreen::PrintRelation(const CatalogRelation &relation,
     column_widths.push_back(column_width);
   }
 
-  printHBar(column_widths, out);
+  const string hbar = GenerateHBar(column_widths);
+  fprintf(out, "%s", hbar.c_str());
 
   fputc('|', out);
   vector<int>::const_iterator width_it = column_widths.begin();
@@ -101,7 +106,7 @@ void PrintToScreen::PrintRelation(const CatalogRelation &relation,
   }
   fputc('\n', out);
 
-  printHBar(column_widths, out);
+  fprintf(out, "%s", hbar.c_str());
 
   std::vector<block_id> blocks = relation.getBlocksSnapshot();
   for (const block_id current_block_id : blocks) {
@@ -120,19 +125,19 @@ void PrintToScreen::PrintRelation(const CatalogRelation &relation,
     }
   }
 
-  printHBar(column_widths, out);
+  fprintf(out, "%s", hbar.c_str());
 }
 
-void PrintToScreen::printHBar(const vector<int> &column_widths,
-                              FILE *out) {
-  fputc('+', out);
+string PrintToScreen::GenerateHBar(const vector<int> &column_widths) {
+  string hbar("+");
+
   for (const int width : column_widths) {
-    for (int i = 0; i < width; ++i) {
-      fputc('-', out);
-    }
-    fputc('+', out);
+    hbar.append(width, '-');
+    hbar.push_back('+');
   }
-  fputc('\n', out);
+  hbar.push_back('\n');
+
+  return hbar;
 }
 
 void PrintToScreen::printTuple(const TupleStorageSubBlock &tuple_store,

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/5f5073f3/cli/PrintToScreen.hpp
----------------------------------------------------------------------
diff --git a/cli/PrintToScreen.hpp b/cli/PrintToScreen.hpp
index 2b5fd7e..f444857 100644
--- a/cli/PrintToScreen.hpp
+++ b/cli/PrintToScreen.hpp
@@ -21,6 +21,7 @@
 #define QUICKSTEP_CLI_PRINT_TO_SCREEN_HPP_
 
 #include <cstdio>
+#include <string>
 #include <vector>
 
 #include "storage/StorageBlockInfo.hpp"
@@ -46,8 +47,7 @@ class PrintToScreen {
                             StorageManager *storage_manager,
                             FILE *out);
 
-  static void printHBar(const std::vector<int> &column_widths,
-                        FILE *out);
+  static std::string GenerateHBar(const std::vector<int> &column_widths);
 
   /**
    * @brief Get the total number of tuples in the given relation.

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/5f5073f3/cli/tests/command_executor/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cli/tests/command_executor/CMakeLists.txt b/cli/tests/command_executor/CMakeLists.txt
index 0bdf865..2cbf1bf 100644
--- a/cli/tests/command_executor/CMakeLists.txt
+++ b/cli/tests/command_executor/CMakeLists.txt
@@ -30,4 +30,3 @@ add_test(quickstep_cli_tests_commandexecutor_dt
 # duration of their test.
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/D)
 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Dt)
-


Mime
View raw message