quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zu...@apache.org
Subject incubator-quickstep git commit: Minor refactored CommandExecutor.
Date Mon, 27 Feb 2017 07:17:45 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/refactor-cmd [created] ab7be7424


Minor refactored CommandExecutor.


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

Branch: refs/heads/refactor-cmd
Commit: ab7be742427004fb3df0cf6350ece017546858a3
Parents: b24349c
Author: Zuyu Zhang <zuyuz@apache.org>
Authored: Sun Feb 26 23:17:26 2017 -0800
Committer: Zuyu Zhang <zuyuz@apache.org>
Committed: Sun Feb 26 23:17:26 2017 -0800

----------------------------------------------------------------------
 catalog/CatalogDatabase.hpp | 10 +++++++
 cli/CMakeLists.txt          |  3 +++
 cli/CommandExecutor.cpp     | 58 ++++++++++++++++++++--------------------
 cli/CommandExecutor.hpp     |  9 -------
 cli/Constants.hpp           | 44 ++++++++++++++++++++++++++++++
 5 files changed, 86 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ab7be742/catalog/CatalogDatabase.hpp
----------------------------------------------------------------------
diff --git a/catalog/CatalogDatabase.hpp b/catalog/CatalogDatabase.hpp
index a0804a2..b071d09 100644
--- a/catalog/CatalogDatabase.hpp
+++ b/catalog/CatalogDatabase.hpp
@@ -343,6 +343,16 @@ class CatalogDatabase : public CatalogDatabaseLite {
   serialization::CatalogDatabase getProto() const;
 
   /**
+   * @brief Check whether this CatalogDatabase is empty.
+   *
+   * @return true if empty, false otherwise.
+   **/
+  bool empty() const {
+    SpinSharedMutexSharedLock<false> lock(relations_mutex_);
+    return rel_map_.empty();
+  }
+
+  /**
    * @brief Get the number of child relations.
    *
    * @return The number of child relations.

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ab7be742/cli/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index c5f3915..71ab620 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -44,6 +44,7 @@ configure_file (
   "${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_DropRelation DropRelation.cpp DropRelation.hpp)
@@ -86,6 +87,7 @@ target_link_libraries(quickstep_cli_CommandExecutor
                       quickstep_catalog_CatalogRelation
                       quickstep_catalog_CatalogRelationSchema
                       quickstep_catalog_CatalogRelationStatistics
+                      quickstep_cli_Constants
                       quickstep_cli_DropRelation
                       quickstep_cli_PrintToScreen
                       quickstep_expressions_aggregation_AggregateFunctionMax
@@ -148,6 +150,7 @@ add_library(quickstep_cli ../empty_src.cpp CliModule.hpp)
 
 target_link_libraries(quickstep_cli
                       quickstep_cli_CommandExecutor
+                      quickstep_cli_Constants
                       quickstep_cli_DefaultsConfigurator
                       quickstep_cli_DropRelation
                       quickstep_cli_Flags

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ab7be742/cli/CommandExecutor.cpp
----------------------------------------------------------------------
diff --git a/cli/CommandExecutor.cpp b/cli/CommandExecutor.cpp
index 78bff98..3380362 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/Constants.hpp"
 #include "cli/DropRelation.hpp"
 #include "cli/PrintToScreen.hpp"
 #include "expressions/aggregation/AggregateFunctionMax.hpp"
@@ -70,8 +71,6 @@ namespace quickstep {
 namespace cli {
 namespace {
 
-namespace C = ::quickstep::cli;
-
 void ExecuteDescribeDatabase(
     const PtrVector<ParseString> *arguments,
     const CatalogDatabase &catalog_database,
@@ -79,10 +78,10 @@ void ExecuteDescribeDatabase(
     FILE *out) {
   // Column width initialized to 6 to take into account the header name
   // and the column value table
-  int max_column_width = C::kInitMaxColumnWidth;
+  int max_column_width = kInitMaxColumnWidth;
   vector<std::size_t> num_blocks;
   const CatalogRelation *relation = nullptr;
-  if (arguments->size() == 0) {
+  if (arguments->empty()) {
     for (const CatalogRelation &rel : catalog_database) {
       max_column_width =
           std::max(static_cast<int>(rel.getName().length()), max_column_width);
@@ -101,32 +100,32 @@ void ExecuteDescribeDatabase(
     num_blocks.push_back(relation->size_blocks());
   }
   // Only if we have relations work on the printing logic.
-  if (catalog_database.size() > 0) {
+  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),
-                                      C::kInitMaxColumnWidth+2);
+                                      kInitMaxColumnWidth + 2);
     vector<int> column_widths;
-    column_widths.push_back(max_column_width +1);
-    column_widths.push_back(C::kInitMaxColumnWidth + 1);
+    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 |", C::kInitMaxColumnWidth, " Type");
+    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->size() == 0) {
+    if (arguments->empty()) {
       for (const CatalogRelation &rel : catalog_database) {
         fprintf(out, " %-*s |", max_column_width, rel.getName().c_str());
-        fprintf(out, " %-*s |", C::kInitMaxColumnWidth - 1, "table");
+        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 |", C::kInitMaxColumnWidth -1, "table");
+      fprintf(out, " %-*s |", kInitMaxColumnWidth - 1, "table");
       fprintf(out, " %-*lu\n", max_num_blocks_digits - 1, *num_blocks_it);
       ++num_blocks_it;
     }
@@ -145,8 +144,8 @@ void ExecuteDescribeTable(
     THROW_SQL_ERROR_AT(&(arguments->front())) << " Unrecognized relation " 
<< table_name_val;
   }
   vector<int> column_widths;
-  int max_attr_column_width = C::kInitMaxColumnWidth;
-  int max_type_column_width = C::kInitMaxColumnWidth;
+  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:
@@ -160,12 +159,12 @@ void ExecuteDescribeTable(
             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);
+  column_widths.push_back(max_attr_column_width + 1);
+  column_widths.push_back(max_type_column_width + 1);
 
-  fprintf(out, "%*s \"%s\"\n", C::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");
+  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,
@@ -175,7 +174,7 @@ void ExecuteDescribeTable(
   }
   // TODO(rogers): Add handlers for partitioning information.
   if (relation->hasIndexScheme()) {
-    fprintf(out, "%*s\n", C::kInitMaxColumnWidth+2, " Indexes");
+    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) {
@@ -213,7 +212,7 @@ inline std::vector<TypedValue> ExecuteQueryForSingleRow(
   parser_wrapper->feedNextBuffer(new std::string(query_string));
 
   ParseResult result = parser_wrapper->getNextStatement();
-  DCHECK(result.condition == ParseResult::kSuccess);
+  DCHECK_EQ(ParseResult::kSuccess, result.condition);
 
   const ParseStatement &statement = *result.parsed_statement;
   const CatalogRelation *query_result_relation = nullptr;
@@ -318,7 +317,7 @@ void ExecuteAnalyze(const PtrVector<ParseString> *arguments,
 
   std::unique_ptr<SqlParserWrapper> parser_wrapper(new SqlParserWrapper());
   std::vector<std::reference_wrapper<const CatalogRelation>> relations;
-  if (arguments->size() == 0) {
+  if (arguments->empty()) {
     relations.insert(relations.begin(), database.begin(), database.end());
   } else {
     for (const auto &rel_name : *arguments) {
@@ -382,7 +381,7 @@ void ExecuteAnalyze(const PtrVector<ParseString> *arguments,
                                    parser_wrapper.get());
 
       auto results_it = results.begin();
-      DCHECK(results_it->getTypeID() == TypeID::kLong);
+      DCHECK_EQ(TypeID::kLong, results_it->getTypeID());
 
       const attribute_id attr_id = attribute.getID();
       mutable_stat->setNumDistinctValues(attr_id,
@@ -411,7 +410,7 @@ void ExecuteAnalyze(const PtrVector<ParseString> *arguments,
                                     query_processor,
                                     parser_wrapper.get());
 
-    DCHECK(num_tuples.getTypeID() == TypeID::kLong);
+    DCHECK_EQ(TypeID::kLong, num_tuples.getTypeID());
     mutable_stat->setNumTuples(num_tuples.getLiteral<std::int64_t>());
 
     mutable_stat->setExactness(true);
@@ -436,15 +435,15 @@ void executeCommand(const ParseStatement &statement,
   const ParseCommand &command = static_cast<const ParseCommand &>(statement);
   const PtrVector<ParseString> *arguments = command.arguments();
   const std::string &command_str = command.command()->value();
-  if (command_str == C::kDescribeDatabaseCommand) {
+  if (command_str == kDescribeDatabaseCommand) {
     ExecuteDescribeDatabase(arguments, catalog_database, storage_manager, out);
-  } else if (command_str == C::kDescribeTableCommand) {
-    if (arguments->size() == 0) {
+  } else if (command_str == kDescribeTableCommand) {
+    if (arguments->empty()) {
       ExecuteDescribeDatabase(arguments, catalog_database, storage_manager, out);
     } else {
       ExecuteDescribeTable(arguments, catalog_database, out);
     }
-  } else if (command_str == C::kAnalyzeCommand) {
+  } else if (command_str == kAnalyzeCommand) {
     ExecuteAnalyze(arguments,
                    main_thread_client_id,
                    foreman_client_id,
@@ -455,5 +454,6 @@ void executeCommand(const ParseStatement &statement,
     THROW_SQL_ERROR_AT(command.command()) << "Invalid Command";
   }
 }
+
 }  // namespace cli
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ab7be742/cli/CommandExecutor.hpp
----------------------------------------------------------------------
diff --git a/cli/CommandExecutor.hpp b/cli/CommandExecutor.hpp
index a1d9af9..b214884 100644
--- a/cli/CommandExecutor.hpp
+++ b/cli/CommandExecutor.hpp
@@ -39,15 +39,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";
-
 /**
   * @brief Executes the command by calling the command handler.
   *

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ab7be742/cli/Constants.hpp
----------------------------------------------------------------------
diff --git a/cli/Constants.hpp b/cli/Constants.hpp
new file mode 100644
index 0000000..1aaa5be
--- /dev/null
+++ b/cli/Constants.hpp
@@ -0,0 +1,44 @@
+/**
+ * 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_CONSTANTS_HPP_
+#define QUICKSTEP_CLI_CONSTANTS_HPP_
+
+namespace quickstep {
+namespace cli {
+
+/** \addtogroup 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";
+
+/** @} */
+
+}  // namespace cli
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_CLI_CONSTANTS_HPP_


Mime
View raw message