quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shix...@apache.org
Subject incubator-quickstep git commit: fixed cpplint issue
Date Thu, 23 Jun 2016 21:03:14 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/SQL-window-aggregation 5aa705835 -> 0210099e0


fixed cpplint issue


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

Branch: refs/heads/SQL-window-aggregation
Commit: 0210099e0655813311a973581f70cb69886320d9
Parents: 5aa7058
Author: shixuan-fan <shixuan@apache.org>
Authored: Thu Jun 23 21:03:02 2016 +0000
Committer: shixuan-fan <shixuan@apache.org>
Committed: Thu Jun 23 21:03:02 2016 +0000

----------------------------------------------------------------------
 query_optimizer/expressions/CMakeLists.txt      |  2 +-
 query_optimizer/expressions/PatternMatcher.hpp  |  3 ++
 .../expressions/WindowAggregateFunction.cpp     |  4 +-
 .../expressions/WindowAggregateFunction.hpp     |  4 +-
 query_optimizer/logical/PatternMatcher.hpp      |  2 +
 query_optimizer/logical/WindowAggregate.cpp     |  1 -
 query_optimizer/resolver/Resolver.cpp           | 51 ++++++++++----------
 7 files changed, 36 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0210099e/query_optimizer/expressions/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/query_optimizer/expressions/CMakeLists.txt b/query_optimizer/expressions/CMakeLists.txt
index cde56b2..08d7df5 100644
--- a/query_optimizer/expressions/CMakeLists.txt
+++ b/query_optimizer/expressions/CMakeLists.txt
@@ -345,4 +345,4 @@ target_link_libraries(quickstep_queryoptimizer_expressions
                       quickstep_queryoptimizer_expressions_SimpleCase
                       quickstep_queryoptimizer_expressions_SubqueryExpression
                       quickstep_queryoptimizer_expressions_UnaryExpression
-                      quickstep_queryoptimizer_expressions_WindowAggregate)
+                      quickstep_queryoptimizer_expressions_WindowAggregateFunction)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0210099e/query_optimizer/expressions/PatternMatcher.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/expressions/PatternMatcher.hpp b/query_optimizer/expressions/PatternMatcher.hpp
index 87bc52a..2cc91d6 100644
--- a/query_optimizer/expressions/PatternMatcher.hpp
+++ b/query_optimizer/expressions/PatternMatcher.hpp
@@ -52,6 +52,7 @@ class Scalar;
 class ScalarLiteral;
 class Sum;
 class UnaryExpression;
+class WindowAggregateFunction;
 
 /** \addtogroup OptimizerExpressions
  *  @{
@@ -155,6 +156,8 @@ using SomeScalar = SomeExpressionNode<Scalar,
                                       ExpressionType::kUnaryExpression>;
 using SomeScalarLiteral = SomeExpressionNode<ScalarLiteral, ExpressionType::kScalarLiteral>;
 using SomeUnaryExpression = SomeExpressionNode<UnaryExpression, ExpressionType::kUnaryExpression>;
+using SomeWindowAggregateFunction = SomeExpressionNode<WindowAggregateFunction,
+                                                       ExpressionType::kWindowAggregateFunction>;
 
 using SomeAggregateFunction = SomeExpressionNode<AggregateFunction,
                                                  ExpressionType::kAggregateFunction>;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0210099e/query_optimizer/expressions/WindowAggregateFunction.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/expressions/WindowAggregateFunction.cpp b/query_optimizer/expressions/WindowAggregateFunction.cpp
index 39b5abf..5cab5d6 100644
--- a/query_optimizer/expressions/WindowAggregateFunction.cpp
+++ b/query_optimizer/expressions/WindowAggregateFunction.cpp
@@ -111,7 +111,7 @@ std::vector<AttributeReferencePtr> WindowAggregateFunction::getReferencedAttribu
   referenced_attributes.insert(referenced_attributes.end(),
                                window_info_.order_by_attributes.begin(),
                                window_info_.order_by_attributes.end());
-  
+
   return referenced_attributes;
 }
 
@@ -171,7 +171,7 @@ void WindowAggregateFunction::getFieldStringItems(
 
   if (window_info_.frame_info != nullptr) {
     const WindowFrameInfo *frame_info = window_info_.frame_info;
-    
+
     inline_field_names->push_back("frame_mode");
     inline_field_values->push_back(frame_info->is_row ? "row" : "range");
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0210099e/query_optimizer/expressions/WindowAggregateFunction.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/expressions/WindowAggregateFunction.hpp b/query_optimizer/expressions/WindowAggregateFunction.hpp
index 977f0b4..319dccd 100644
--- a/query_optimizer/expressions/WindowAggregateFunction.hpp
+++ b/query_optimizer/expressions/WindowAggregateFunction.hpp
@@ -60,7 +60,7 @@ struct WindowFrameInfo {
       : is_row(is_row_in),
         num_preceding(num_preceding_in),
         num_following(num_following_in) {}
- 
+
   const bool is_row;
   const int num_preceding;
   const int num_following;
@@ -87,7 +87,7 @@ struct WindowInfo {
         order_by_directions(order_by_directions_in),
         nulls_first(nulls_first_in),
         frame_info(frame_info_in) {}
-  
+
   const std::vector<AttributeReferencePtr> partition_by_attributes;
   const std::vector<AttributeReferencePtr> order_by_attributes;
   const std::vector<bool> order_by_directions;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0210099e/query_optimizer/logical/PatternMatcher.hpp
----------------------------------------------------------------------
diff --git a/query_optimizer/logical/PatternMatcher.hpp b/query_optimizer/logical/PatternMatcher.hpp
index ff8f3d0..de8609e 100644
--- a/query_optimizer/logical/PatternMatcher.hpp
+++ b/query_optimizer/logical/PatternMatcher.hpp
@@ -45,6 +45,7 @@ class Sort;
 class TableReference;
 class TopLevelPlan;
 class UpdateTable;
+class WindowAggregate;
 
 /** \addtogroup OptimizerLogical
  *  @{
@@ -130,6 +131,7 @@ using SomeSort = SomeLogicalNode<Sort, LogicalType::kSort>;
 using SomeTableReference = SomeLogicalNode<TableReference, LogicalType::kTableReference>;
 using SomeTopLevelPlan = SomeLogicalNode<TopLevelPlan, LogicalType::kTopLevelPlan>;
 using SomeUpdateTable = SomeLogicalNode<UpdateTable, LogicalType::kUpdateTable>;
+using SomeWindowAggregate = SomeLogicalNode<WindowAggregate, LogicalType::kWindowAggregate>;
 
 /** @} */
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0210099e/query_optimizer/logical/WindowAggregate.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/logical/WindowAggregate.cpp b/query_optimizer/logical/WindowAggregate.cpp
index 0eb634d..4dc787b 100644
--- a/query_optimizer/logical/WindowAggregate.cpp
+++ b/query_optimizer/logical/WindowAggregate.cpp
@@ -47,7 +47,6 @@ LogicalPtr WindowAggregate::copyWithNewChildren(
 std::vector<E::AttributeReferencePtr> WindowAggregate::getOutputAttributes() const
{
   std::vector<E::AttributeReferencePtr> output_attributes(input_->getOutputAttributes());
   output_attributes.push_back(E::ToRef(window_aggregate_expression_));
-  
   return output_attributes;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0210099e/query_optimizer/resolver/Resolver.cpp
----------------------------------------------------------------------
diff --git a/query_optimizer/resolver/Resolver.cpp b/query_optimizer/resolver/Resolver.cpp
index bad818f..bcd0357 100644
--- a/query_optimizer/resolver/Resolver.cpp
+++ b/query_optimizer/resolver/Resolver.cpp
@@ -208,7 +208,7 @@ struct Resolver::ExpressionResolutionInfo {
 
   // Alias expressions that wraps window aggregate functions.
   WindowAggregationInfo *window_aggregation_info = nullptr;
-  
+
   // Can be NULL if alias references to SELECT-list expressions are not allowed.
   SelectListInfo *select_list_info = nullptr;
   // The first aggregate in the expression.
@@ -1027,21 +1027,21 @@ L::LogicalPtr Resolver::resolveSelect(
         THROW_SQL_ERROR_AT(window.name())
             << "Duplicate definition of window " << window.name()->value();
       }
-      
+
       E::WindowInfo resolved_window = resolveWindow(window, *name_resolver);
       L::LogicalPtr sorted_logical_plan = resolveSortInWindow(logical_plan,
                                                               resolved_window);
 
       WindowPlan window_plan(resolved_window, sorted_logical_plan);
-      
+
       sorted_window_map.emplace(window.name()->value(), window_plan);
     }
   }
 
   QueryAggregationInfo query_aggregation_info(
       (select_query.group_by() != nullptr));
-  WindowAggregationInfo window_aggregation_info(sorted_window_map);    
-  
+  WindowAggregationInfo window_aggregation_info(sorted_window_map);
+
   // Resolve SELECT-list clause.
   std::vector<E::NamedExpressionPtr> select_list_expressions;
   std::vector<bool> has_aggregate_per_expression;
@@ -1061,16 +1061,19 @@ L::LogicalPtr Resolver::resolveSelect(
 
   // Create window aggregate node if needed
   for (E::AliasPtr alias : window_aggregation_info.window_aggregate_expressions) {
-    E::WindowAggregateFunctionPtr window_aggregate_function
-        = std::static_pointer_cast<const E::WindowAggregateFunction>(alias->expression());
+    E::WindowAggregateFunctionPtr window_aggregate_function;
+    if (!E::SomeWindowAggregateFunction::MatchesWithConditionalCast(alias->expression(),
+                                                                    &window_aggregate_function))
{
+      THROW_SQL_ERROR()
+          << "Unexpected expression in window aggregation function";
+    }
     L::LogicalPtr sorted_logical_plan;
 
     // Get the sorted logical plan
     const std::string window_name = window_aggregate_function->window_name();
     if (window_name != "") {
       sorted_logical_plan = sorted_window_map.at(window_name).logical_plan;
-    }
-    else {
+    } else {
       sorted_logical_plan = resolveSortInWindow(logical_plan,
                                                 window_aggregate_function->window_info());
     }
@@ -1664,7 +1667,7 @@ E::WindowInfo Resolver::resolveWindow(const ParseWindow &parse_window,
           *order_by_item.ordering_expression(),
           nullptr,  // No Type hint.
           &expr_resolution_info);
-          
+
       if (order_by_scalar->isConstant()) {
         THROW_SQL_ERROR_AT(&order_by_item)
             << "Constant expression not allowed in ORDER BY";
@@ -1862,19 +1865,19 @@ L::LogicalPtr Resolver::resolveSortInWindow(
   sort_attributes.insert(sort_attributes.end(),
                          window_info.order_by_attributes.begin(),
                          window_info.order_by_attributes.end());
-                  
+
   std::vector<bool> sort_directions(
       window_info.partition_by_attributes.size(), true);
   sort_directions.insert(sort_directions.end(),
                          window_info.order_by_directions.begin(),
                          window_info.order_by_directions.end());
-                      
+
   std::vector<bool> sort_nulls_first(
       window_info.partition_by_attributes.size(), false);
   sort_nulls_first.insert(sort_nulls_first.end(),
                           window_info.nulls_first.begin(),
                           window_info.nulls_first.end());
-                          
+
   L::LogicalPtr sorted_logical_plan =
       L::Sort::Create(logical_plan,
                       sort_attributes,
@@ -1884,7 +1887,6 @@ L::LogicalPtr Resolver::resolveSortInWindow(
 
   return sorted_logical_plan;
 }
-    
 
 void Resolver::resolveSelectClause(
     const ParseSelectionClause &parse_selection,
@@ -2684,9 +2686,9 @@ E::ScalarPtr Resolver::resolveWindowAggregateFunction(
     THROW_SQL_ERROR_AT(&parse_function_call)
        << "Currently we only support single window aggregate in the query";
   }
-      
+
   std::string function_name = ToLower(parse_function_call.name()->value());
-  
+
   // First check for the special case COUNT(*).
   bool count_star = false;
   if (parse_function_call.star() != nullptr) {
@@ -2711,9 +2713,9 @@ E::ScalarPtr Resolver::resolveWindowAggregateFunction(
           resolveExpression(unresolved_argument,
                             nullptr,  // No Type hint.
                             &expr_resolution_info));
-                            
+
       // We don't allow aggregate or window aggregate nested in a window
-      // aggregate function
+      // aggregate function.
       if (expr_resolution_info.hasAggregate() &&
           first_aggregate_function == nullptr) {
         first_aggregate_function =
@@ -2787,23 +2789,22 @@ E::ScalarPtr Resolver::resolveWindowAggregateFunction(
     std::string window_name = parse_function_call.window_name()->value();
     std::unordered_map<std::string, WindowPlan>::const_iterator map_it
         = window_map.find(window_name);
-        
+
     if (map_it == window_map.end()) {
       THROW_SQL_ERROR_AT(parse_function_call.window_name())
         << "Undefined window " << window_name;
     }
-    
+
     window_aggregate_function =
         E::WindowAggregateFunction::Create(*window_aggregate,
                                            resolved_arguments,
                                            map_it->second.window_info,
                                            parse_function_call.window_name()->value(),
                                            parse_function_call.is_distinct());
-  }
-  else {
+  } else {
     E::WindowInfo resolved_window = resolveWindow(*parse_function_call.window(),
                                                   expression_resolution_info->name_resolver);
-                                                  
+
     window_aggregate_function =
         E::WindowAggregateFunction::Create(*window_aggregate,
                                            resolved_arguments,
@@ -2819,13 +2820,13 @@ E::ScalarPtr Resolver::resolveWindowAggregateFunction(
                                                        "" /* attribute_name */,
                                                        internal_alias,
                                                        "$window_aggregate" /* relation_name
*/);
-                                                       
+
   expression_resolution_info->window_aggregation_info
       ->window_aggregate_expressions.emplace_back(aggregate_alias);
   expression_resolution_info->parse_window_aggregate_expression = &parse_function_call;
   return E::ToRef(aggregate_alias);
 }
-    
+
 std::vector<E::PredicatePtr> Resolver::resolvePredicates(
     const PtrList<ParsePredicate> &parse_predicates,
     ExpressionResolutionInfo *expression_resolution_info) {


Mime
View raw message