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: Move window information into handle
Date Tue, 26 Jul 2016 22:01:18 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/SQL-window-aggregation ff513a6dc -> 0a23f1719


Move window information into handle


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

Branch: refs/heads/SQL-window-aggregation
Commit: 0a23f17197d6dfa87831b29aae20fdb913925b32
Parents: ff513a6
Author: shixuan <shixuan@apache.org>
Authored: Tue Jul 26 17:01:01 2016 -0500
Committer: shixuan <shixuan@apache.org>
Committed: Tue Jul 26 17:01:01 2016 -0500

----------------------------------------------------------------------
 expressions/window_aggregation/CMakeLists.txt   |   4 +
 .../WindowAggregateFunction.hpp                 |  19 ++-
 .../WindowAggregateFunctionAvg.cpp              |  16 ++-
 .../WindowAggregateFunctionAvg.hpp              |   7 +-
 .../WindowAggregateFunctionCount.cpp            |   8 +-
 .../WindowAggregateFunctionCount.hpp            |   7 +-
 .../WindowAggregateFunctionMax.cpp              |   7 +-
 .../WindowAggregateFunctionMax.hpp              |   7 +-
 .../WindowAggregateFunctionMin.cpp              |   7 +-
 .../WindowAggregateFunctionMin.hpp              |   7 +-
 .../WindowAggregateFunctionSum.cpp              |   7 +-
 .../WindowAggregateFunctionSum.hpp              |   7 +-
 .../WindowAggregationHandle.cpp                 | 138 ++++++++++++-------
 .../WindowAggregationHandle.hpp                 |  61 ++++----
 .../WindowAggregationHandleAvg.cpp              |  50 +++----
 .../WindowAggregationHandleAvg.hpp              |  25 ++--
 .../WindowAggregationHandleAvg_unittest.cpp     |  88 ++++++------
 storage/WindowAggregationOperationState.cpp     |  37 +----
 storage/WindowAggregationOperationState.hpp     |   8 --
 19 files changed, 276 insertions(+), 234 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/CMakeLists.txt b/expressions/window_aggregation/CMakeLists.txt
index 9e06897..3a79b7e 100644
--- a/expressions/window_aggregation/CMakeLists.txt
+++ b/expressions/window_aggregation/CMakeLists.txt
@@ -130,6 +130,7 @@ target_link_libraries(quickstep_expressions_windowaggregation_WindowAggregationH
                       glog
                       quickstep_catalog_CatalogRelationSchema
                       quickstep_catalog_CatalogTypedefs
+                      quickstep_expressions_scalar_Scalar
                       quickstep_storage_StorageBlockInfo
                       quickstep_types_Type
                       quickstep_types_TypeFactory
@@ -183,7 +184,10 @@ add_executable(WindowAggregationHandle_tests
 target_link_libraries(WindowAggregationHandle_tests
                       gtest
                       gtest_main
+                      quickstep_catalog_CatalogAttribute
                       quickstep_catalog_CatalogTypedefs
+                      quickstep_expressions_scalar_Scalar
+                      quickstep_expressions_scalar_ScalarAttribute
                       quickstep_expressions_windowaggregation_WindowAggregateFunction
                       quickstep_expressions_windowaggregation_WindowAggregateFunctionFactory
                       quickstep_expressions_windowaggregation_WindowAggregationHandle

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunction.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunction.hpp b/expressions/window_aggregation/WindowAggregateFunction.hpp
index d56b4ab..f08974a 100644
--- a/expressions/window_aggregation/WindowAggregateFunction.hpp
+++ b/expressions/window_aggregation/WindowAggregateFunction.hpp
@@ -20,6 +20,7 @@
 #ifndef QUICKSTEP_EXPRESSIONS_WINDOW_AGGREGATION_WINDOW_AGGREGATE_FUNCTION_HPP_
 #define QUICKSTEP_EXPRESSIONS_WINDOW_AGGREGATION_WINDOW_AGGREGATE_FUNCTION_HPP_
 
+#include <memory>
 #include <string>
 #include <vector>
 
@@ -32,6 +33,7 @@
 namespace quickstep {
 
 class CatalogRelationSchema;
+class Scalar;
 class Type;
 class WindowAggregationHandle;
 
@@ -120,10 +122,12 @@ class WindowAggregateFunction {
    *
    * @param argument_types A list of zero or more Types (in order) for
    *        arguments to this WindowAggregateFunction.
-   * @param partition_key_types A list or zero or more Types for partition keys
-   *                            to this WindowAggregateFunction.
-   * @param first_order_key_type A pointer to the first order key type, nullptr
-   *                             if not needed.
+   * @param partition_key_types The Types of the partition key.
+   * @param first_order_key_type The type of the first order key, nullptr if
+   *                             not needed.
+   * @param is_row True if the frame mode is ROWS, false if RANGE.
+   * @param num_preceding The number of rows/range that precedes the current row.
+   * @param num_following The number of rows/range that follows the current row.
    * 
    * @return A new WindowAggregationHandle that can be used to compute this
    *         WindowAggregateFunction over the specified argument_types. Caller
@@ -131,8 +135,11 @@ class WindowAggregateFunction {
    **/
   virtual WindowAggregationHandle* createHandle(
       const std::vector<const Type*> &argument_types,
-      const std::vector<const Type*> &partition_key_types,
-      const Type *first_order_key_type) const = 0;
+      const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+      const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+      const bool is_row,
+      const std::int64_t num_preceding,
+      const std::int64_t num_following) const = 0;
 
  protected:
   explicit WindowAggregateFunction(const WindowAggregationID win_agg_id)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp b/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp
index 6c1b139..beb1c7a 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionAvg.cpp
@@ -73,15 +73,21 @@ const Type* WindowAggregateFunctionAvg::resultTypeForArgumentTypes(
 
 WindowAggregationHandle* WindowAggregateFunctionAvg::createHandle(
     const std::vector<const Type*> &argument_types,
-    const std::vector<const Type*> &partition_key_types,
-    const Type *first_order_key_type) const {
+    const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+    const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+    const bool is_row,
+    const std::int64_t num_preceding,
+    const std::int64_t num_following) const {
   DCHECK(canApplyToTypes(argument_types))
       << "Attempted to create an WindowAggregationHandleAvg for argument Type(s)"
       << " that AVG can not be applied to.";
 
-  return new WindowAggregationHandleAvg(partition_key_types,
-                                        first_order_key_type,
-                                        *argument_types.front());
+  return new WindowAggregationHandleAvg(partition_by_attributes,
+                                        order_by_attributes,
+                                        is_row,
+                                        num_preceding,
+                                        num_following,
+                                        argument_types[0]);
 }
 
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionAvg.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionAvg.hpp b/expressions/window_aggregation/WindowAggregateFunctionAvg.hpp
index b5e91fd..0e50415 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionAvg.hpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionAvg.hpp
@@ -58,8 +58,11 @@ class WindowAggregateFunctionAvg : public WindowAggregateFunction {
 
   WindowAggregationHandle* createHandle(
       const std::vector<const Type*> &argument_types,
-      const std::vector<const Type*> &partition_key_types,
-      const Type *first_order_key_type) const override;
+      const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+      const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+      const bool is_row,
+      const std::int64_t num_preceding,
+      const std::int64_t num_following) const override;
 
  private:
   WindowAggregateFunctionAvg()

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionCount.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionCount.cpp b/expressions/window_aggregation/WindowAggregateFunctionCount.cpp
index 7a24813..ccd81ac 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionCount.cpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionCount.cpp
@@ -47,12 +47,16 @@ const Type* WindowAggregateFunctionCount::resultTypeForArgumentTypes(
 
 WindowAggregationHandle* WindowAggregateFunctionCount::createHandle(
     const std::vector<const Type*> &argument_types,
-    const std::vector<const Type*> &partition_key_types,
-    const Type *first_order_key_type) const {
+    const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+    const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+    const bool is_row,
+    const std::int64_t num_preceding,
+    const std::int64_t num_following) const {
   DCHECK(canApplyToTypes(argument_types))
       << "Attempted to create a WindowAggregationHandleCount for argument Types "
       << "that COUNT can not be applied to (> 1 argument).";
 
+  // TODO(Shixuan): Add handle for Count.
   return nullptr;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionCount.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionCount.hpp b/expressions/window_aggregation/WindowAggregateFunctionCount.hpp
index f34af40..2e5506a 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionCount.hpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionCount.hpp
@@ -58,8 +58,11 @@ class WindowAggregateFunctionCount : public WindowAggregateFunction {
 
   WindowAggregationHandle* createHandle(
       const std::vector<const Type*> &argument_types,
-      const std::vector<const Type*> &partition_key_types,
-      const Type *first_order_key_type) const override;
+      const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+      const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+      const bool is_row,
+      const std::int64_t num_preceding,
+      const std::int64_t num_following) const override;
 
  private:
   WindowAggregateFunctionCount()

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionMax.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionMax.cpp b/expressions/window_aggregation/WindowAggregateFunctionMax.cpp
index ab8a727..acfce82 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionMax.cpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionMax.cpp
@@ -55,8 +55,11 @@ const Type* WindowAggregateFunctionMax::resultTypeForArgumentTypes(
 
 WindowAggregationHandle* WindowAggregateFunctionMax::createHandle(
     const std::vector<const Type*> &argument_types,
-    const std::vector<const Type*> &partition_key_types,
-    const Type *first_order_key_type) const {
+    const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+    const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+    const bool is_row,
+    const std::int64_t num_preceding,
+    const std::int64_t num_following) const {
   DCHECK(canApplyToTypes(argument_types))
       << "Attempted to create a WindowAggregationHandleMax for argument Type(s) "
       << "that MAX can not be applied to.";

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionMax.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionMax.hpp b/expressions/window_aggregation/WindowAggregateFunctionMax.hpp
index f865ec7..a215703 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionMax.hpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionMax.hpp
@@ -58,8 +58,11 @@ class WindowAggregateFunctionMax : public WindowAggregateFunction {
 
   WindowAggregationHandle* createHandle(
       const std::vector<const Type*> &argument_types,
-      const std::vector<const Type*> &partition_key_types,
-      const Type *first_order_key_type) const override;
+      const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+      const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+      const bool is_row,
+      const std::int64_t num_preceding,
+      const std::int64_t num_following) const override;
 
  private:
   WindowAggregateFunctionMax()

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionMin.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionMin.cpp b/expressions/window_aggregation/WindowAggregateFunctionMin.cpp
index 579447f..cd845bd 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionMin.cpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionMin.cpp
@@ -55,8 +55,11 @@ const Type* WindowAggregateFunctionMin::resultTypeForArgumentTypes(
 
 WindowAggregationHandle* WindowAggregateFunctionMin::createHandle(
     const std::vector<const Type*> &argument_types,
-    const std::vector<const Type*> &partition_key_types,
-    const Type *first_order_key_type) const {
+    const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+    const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+    const bool is_row,
+    const std::int64_t num_preceding,
+    const std::int64_t num_following) const {
   DCHECK(canApplyToTypes(argument_types))
       << "Attempted to create a WindowAggregationHandleMin for argument Type(s) "
       << "that MIN can not be applied to.";

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionMin.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionMin.hpp b/expressions/window_aggregation/WindowAggregateFunctionMin.hpp
index 1b02da1..fab88a8 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionMin.hpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionMin.hpp
@@ -58,8 +58,11 @@ class WindowAggregateFunctionMin : public WindowAggregateFunction {
 
   WindowAggregationHandle* createHandle(
       const std::vector<const Type*> &argument_types,
-      const std::vector<const Type*> &partition_key_types,
-      const Type *first_order_key_type) const override;
+      const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+      const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+      const bool is_row,
+      const std::int64_t num_preceding,
+      const std::int64_t num_following) const override;
 
  private:
   WindowAggregateFunctionMin()

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionSum.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionSum.cpp b/expressions/window_aggregation/WindowAggregateFunctionSum.cpp
index d3e089e..e2aeb60 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionSum.cpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionSum.cpp
@@ -71,8 +71,11 @@ const Type* WindowAggregateFunctionSum::resultTypeForArgumentTypes(
 
 WindowAggregationHandle* WindowAggregateFunctionSum::createHandle(
     const std::vector<const Type*> &argument_types,
-    const std::vector<const Type*> &partition_key_types,
-    const Type *first_order_key_type) const {
+    const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+    const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+    const bool is_row,
+    const std::int64_t num_preceding,
+    const std::int64_t num_following) const {
   DCHECK(canApplyToTypes(argument_types))
       << "Attempted to create a WindowAggregationHandleSum for argument Type(s) "
       << "that SUM can not be applied to.";

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregateFunctionSum.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregateFunctionSum.hpp b/expressions/window_aggregation/WindowAggregateFunctionSum.hpp
index 4963040..8d7d61d 100644
--- a/expressions/window_aggregation/WindowAggregateFunctionSum.hpp
+++ b/expressions/window_aggregation/WindowAggregateFunctionSum.hpp
@@ -58,8 +58,11 @@ class WindowAggregateFunctionSum : public WindowAggregateFunction {
 
   WindowAggregationHandle* createHandle(
       const std::vector<const Type*> &argument_types,
-      const std::vector<const Type*> &partition_key_types,
-      const Type *first_order_key_type) const override;
+      const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+      const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+      const bool is_row,
+      const std::int64_t num_preceding,
+      const std::int64_t num_following) const override;
 
  private:
   WindowAggregateFunctionSum()

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregationHandle.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregationHandle.cpp b/expressions/window_aggregation/WindowAggregationHandle.cpp
index 578711f..e0062da 100644
--- a/expressions/window_aggregation/WindowAggregationHandle.cpp
+++ b/expressions/window_aggregation/WindowAggregationHandle.cpp
@@ -24,6 +24,7 @@
 #include <vector>
 
 #include "catalog/CatalogTypedefs.hpp"
+#include "expressions/scalar/Scalar.hpp"
 #include "types/Type.hpp"
 #include "types/TypeFactory.hpp"
 #include "types/TypeID.hpp"
@@ -39,17 +40,44 @@
 namespace quickstep {
 
 WindowAggregationHandle::WindowAggregationHandle(
-    const std::vector<const Type*> &partition_key_types,
-    const Type *first_order_key_type) {
+    const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+    const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+    const bool is_row,
+    const std::int64_t num_preceding,
+    const std::int64_t num_following)
+    : is_row_(is_row),
+      num_preceding_(num_preceding),
+      num_following_(num_following) {
+  // IDs and types of partition keys.
+  std::vector<const Type*> partition_key_types;
+  for (const std::unique_ptr<const Scalar> &partition_by_attribute : partition_by_attributes) {
+    partition_key_ids_.push_back(
+        partition_by_attribute->getAttributeIdForValueAccessor());
+    partition_key_types.push_back(&partition_by_attribute->getType());
+  }
+
   // Comparison operators for checking if two tuples belong to the same partition.
   for (const Type *partition_key_type : partition_key_types) {
-    equal_comparators_.emplace_back(
+    partition_equal_comparators_.emplace_back(
         ComparisonFactory::GetComparison(ComparisonID::kEqual)
             .makeUncheckedComparatorForTypes(*partition_key_type, *partition_key_type));
   }
 
-  // If in RANGE mode, need comparators and operators to check window frame.
-  if (first_order_key_type != nullptr) {
+  // IDs and types of order keys.
+  const Type *first_order_key_type = nullptr;
+  for (const std::unique_ptr<const Scalar> &order_by_attribute : order_by_attributes) {
+    order_key_ids_.push_back(
+        order_by_attribute->getAttributeIdForValueAccessor());
+    if (first_order_key_type == nullptr) {
+      first_order_key_type = &order_by_attribute->getType();
+    }
+  }
+
+  // ID and type of the first order key if in RANGE mode.
+  if (!is_row) {
+    DCHECK(first_order_key_type != nullptr);
+
+    // Comparators and operators to check window frame in RANGE mode.
     const Type &long_type = TypeFactory::GetType(kLong, false);
     range_compare_type_ =
         TypeFactory::GetUnifyingType(*first_order_key_type, long_type);
@@ -65,8 +93,7 @@ WindowAggregationHandle::WindowAggregationHandle(
 
 bool WindowAggregationHandle::samePartition(
     const ColumnVectorsValueAccessor *tuple_accessor,
-    const tuple_id test_tuple_id,
-    const std::vector<attribute_id> &partition_by_ids) const {
+    const tuple_id test_tuple_id) const {
   // If test tuple does not exist.
   if (test_tuple_id < 0 ||
       test_tuple_id >= tuple_accessor->getNumTuples()) {
@@ -75,12 +102,12 @@ bool WindowAggregationHandle::samePartition(
 
   // Check all partition by attributes.
   for (std::size_t partition_by_index = 0;
-       partition_by_index < partition_by_ids.size();
+       partition_by_index < partition_key_ids_.size();
        ++partition_by_index) {
-    if (!equal_comparators_[partition_by_index]->compareTypedValues(
-            tuple_accessor->getTypedValue(partition_by_ids[partition_by_index]),
+    if (!partition_equal_comparators_[partition_by_index]->compareTypedValues(
+            tuple_accessor->getTypedValue(partition_key_ids_[partition_by_index]),
             tuple_accessor->getTypedValueAtAbsolutePosition(
-                partition_by_ids[partition_by_index], test_tuple_id))) {
+                partition_key_ids_[partition_by_index], test_tuple_id))) {
       return false;
     }
   }
@@ -88,58 +115,71 @@ bool WindowAggregationHandle::samePartition(
   return true;
 }
 
-bool WindowAggregationHandle::inRange(
+bool WindowAggregationHandle::inWindow(
     const ColumnVectorsValueAccessor *tuple_accessor,
-    const tuple_id test_tuple_id,
-    const attribute_id first_order_by_id,
-    const std::int64_t num_preceding,
-    const std::int64_t num_following) const {
+    const tuple_id test_tuple_id) const {
   // If test tuple does not exist.
-  if (test_tuple_id < 0 ||
-      test_tuple_id >= tuple_accessor->getNumTuples()) {
+  if (!samePartition(tuple_accessor, test_tuple_id)) {
     return false;
   }
 
-  // If test tuple is the current tuple, then it is in the range.
-  if (test_tuple_id == tuple_accessor->getCurrentPosition()) {
+  tuple_id current_tuple_id = tuple_accessor->getCurrentPosition();
+
+  // If test tuple is the current tuple, then it is in the window.
+  if (test_tuple_id == current_tuple_id) {
     return true;
   }
 
-  // Get the test value.
-  const Type &long_type = TypeFactory::GetType(kLong, false);
-  TypedValue test_value =
-      range_add_operator_->applyToTypedValues(
-          tuple_accessor->getTypedValueAtAbsolutePosition(first_order_by_id, test_tuple_id),
-          long_type.makeZeroValue());
+  // In ROWS mode, check the difference of tuple_id.
+  if (is_row_) {
+    if (num_preceding_ != -1 &&
+        test_tuple_id < current_tuple_id - num_preceding_) {
+      return false;
+    }
 
-  // NULL will be considered not in range.
-  if (test_value.isNull() ||
-      tuple_accessor->getTypedValue(first_order_by_id).isNull()) {
-    return false;
-  }
+    if (num_following_ != -1 &&
+        test_tuple_id > current_tuple_id + num_following_) {
+      return false;
+    }
+  } else {
+    // In RANGE mode, check the difference of first order key value.
+    // Get the test value.
+    const Type &long_type = TypeFactory::GetType(kLong, false);
+    TypedValue test_value =
+        range_add_operator_->applyToTypedValues(
+            tuple_accessor->getTypedValueAtAbsolutePosition(order_key_ids_[0], test_tuple_id),
+            long_type.makeZeroValue());
 
-  // Get the boundary value if it is not UNBOUNDED.
-  bool in_range = true;
+    // NULL will be considered not in range.
+    if (test_value.isNull() ||
+        tuple_accessor->getTypedValue(order_key_ids_[0]).isNull()) {
+      return false;
+    }
 
-  if (num_preceding < 1) {  // num_preceding is negated.
-    TypedValue start_boundary_value =
-        range_add_operator_->applyToTypedValues(
-            tuple_accessor->getTypedValue(first_order_by_id),
-            long_type.makeValue(&num_preceding));
-    in_range &=
-        range_comparator_->compareTypedValues(start_boundary_value, test_value);
-  }
+    // Get the boundary value if it is not UNBOUNDED.
+    if (num_preceding_ > -1) {  // num_preceding is negated.
+      std::int64_t neg_num_preceding = -num_preceding_;
+      TypedValue start_boundary_value =
+          range_add_operator_->applyToTypedValues(
+              tuple_accessor->getTypedValue(order_key_ids_[0]),
+              long_type.makeValue(&neg_num_preceding));
+      if (!range_comparator_->compareTypedValues(start_boundary_value, test_value)) {
+        return false;
+      }
+    }
 
-  if (num_following > -1) {
-    TypedValue end_boundary_value =
-        range_add_operator_->applyToTypedValues(
-            tuple_accessor->getTypedValue(first_order_by_id),
-            long_type.makeValue(&num_following));
-    in_range &=
-        range_comparator_->compareTypedValues(test_value, end_boundary_value);
+    if (num_following_ > -1) {
+      TypedValue end_boundary_value =
+          range_add_operator_->applyToTypedValues(
+              tuple_accessor->getTypedValue(order_key_ids_[0]),
+              long_type.makeValue(&num_following_));
+      if (!range_comparator_->compareTypedValues(test_value, end_boundary_value)) {
+        return false;
+      }
+    }
   }
 
-  return in_range;
+  return true;
 }
 
 }  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregationHandle.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregationHandle.hpp b/expressions/window_aggregation/WindowAggregationHandle.hpp
index 5595e11..b43d8a1 100644
--- a/expressions/window_aggregation/WindowAggregationHandle.hpp
+++ b/expressions/window_aggregation/WindowAggregationHandle.hpp
@@ -43,6 +43,7 @@
 
 namespace quickstep {
 
+class Scalar;
 class Type;
 class ValueAccessor;
 
@@ -78,8 +79,8 @@ class ValueAccessor;
  *           3 FOLLOWING", we have to store all the tuples in the state (at
  *           least two pointers to the start tuple and end tuple), so that
  *           we could know which values should be dropped as the window slides.
- *        For each computed value, generate a TypedValue store in a ColumnVector
- *        for window aggregate values.
+ *        For each computed value, generate a TypedValue and store it into a
+ *        ColumnVector for window aggregate values.
  *     3. Return the result ColumnVector.
  *
  * TODO(Shixuan): Currently we don't support parallelization. The basic idea for
@@ -101,21 +102,11 @@ class WindowAggregationHandle {
    *
    * @param block_accessors A pointer to the value accessor of block attributes.
    * @param arguments The ColumnVectors of arguments
-   * @param partition_by_ids The ids of partition keys.
-   * @param order_by_ids The ids of order keys.
-   * @param is_row True if the frame mode is ROWS, false if it is RANGE.
-   * @param num_preceding The number of rows/range that precedes the current row.
-   * @param num_following The number of rows/range that follows the current row.
    *
    * @return A ColumnVector of the calculated window aggregates.
    **/
   virtual ColumnVector* calculate(ColumnVectorsValueAccessor* block_accessors,
-                                  const std::vector<ColumnVector*> &arguments,
-                                  const std::vector<attribute_id> &partition_by_ids,
-                                  const std::vector<attribute_id> &order_by_ids,
-                                  const bool is_row,
-                                  const std::int64_t num_preceding,
-                                  const std::int64_t num_following) const = 0;
+                                  const std::vector<ColumnVector*> &arguments) const = 0;
 
  protected:
   /**
@@ -124,10 +115,16 @@ class WindowAggregationHandle {
    * @param partition_key_types The Types of the partition key.
    * @param first_order_key_type The type of the first order key, nullptr if
    *                             not needed.
+   * @param is_row True if the frame mode is ROWS, false if RANGE.
+   * @param num_preceding The number of rows/range that precedes the current row.
+   * @param num_following The number of rows/range that follows the current row.
    **/
   WindowAggregationHandle(
-      const std::vector<const Type*> &partition_key_types,
-      const Type *first_order_key_type);
+      const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+      const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+      const bool is_row,
+      const std::int64_t num_preceding,
+      const std::int64_t num_following);
 
   /**
    * @brief Check if test tuple is in the same partition as the current
@@ -135,40 +132,38 @@ class WindowAggregationHandle {
    *
    * @param tuple_accessor The ValueAccessor for tuples.
    * @param test_tuple_id The id of the test tuple.
-   * @param partition_by_ids The id of partition keys.
    *
    * @return True if test tuple is in the same partition as the current tuple in
    *         the accessor, false if not.
    **/
   bool samePartition(const ColumnVectorsValueAccessor *tuple_accessor,
-                     const tuple_id test_tuple_id,
-                     const std::vector<attribute_id> &partition_by_ids) const;
+                     const tuple_id test_tuple_id) const;
 
   /**
    * @brief Check if test tuple is in the defined range.
    *
    * @param tuple_accessor The ValueAccessor for tuples.
    * @param test_tuple_id The id of the test tuple.
-   * @param first_order_by_id The id of first order key.
-   * @param num_preceding The value difference betweem the window start boundary
-   *                      and current value. This value has to be negated.
-   * @param num_following The value difference between the window end boudnary
-   *                      and current value.
    *
-   * @return True if test tuple is in the defined range, false if not.
+   * @return True if test tuple is in the defined window, false if not.
    **/
-  bool inRange(const ColumnVectorsValueAccessor *tuple_accessor,
-               const tuple_id test_tuple_id,
-               const attribute_id first_order_by_id,
-               const std::int64_t num_preceding,
-               const std::int64_t num_following) const;
+  bool inWindow(const ColumnVectorsValueAccessor *tuple_accessor,
+                const tuple_id test_tuple_id) const;
+
+  // Ids and comparators for partition keys.
+  std::vector<attribute_id> partition_key_ids_;
+  std::vector<std::unique_ptr<UncheckedComparator>> partition_equal_comparators_;
 
-  std::vector<std::unique_ptr<UncheckedComparator>> equal_comparators_;
+  // Id, type, Comparator and operator for frame boundary check in RANGE mode.
+  std::vector<attribute_id> order_key_ids_;
   std::unique_ptr<UncheckedBinaryOperator> range_add_operator_;
-  // A "less than or equal to" comparator will be defined.
-  std::unique_ptr<UncheckedComparator> range_comparator_;
+  std::unique_ptr<UncheckedComparator> range_comparator_;  // Less than or Equal
   const Type* range_compare_type_;
-  const Type *first_order_key_type_;
+
+  // Window frame information.
+  const bool is_row_;
+  const std::int64_t num_preceding_;
+  const std::int64_t num_following_;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(WindowAggregationHandle);

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregationHandleAvg.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregationHandleAvg.cpp b/expressions/window_aggregation/WindowAggregationHandleAvg.cpp
index f1e1ada..dae1f33 100644
--- a/expressions/window_aggregation/WindowAggregationHandleAvg.cpp
+++ b/expressions/window_aggregation/WindowAggregationHandleAvg.cpp
@@ -41,15 +41,21 @@
 namespace quickstep {
 
 WindowAggregationHandleAvg::WindowAggregationHandleAvg(
-    const std::vector<const Type*> &partition_key_types,
-    const Type *first_order_by_key_type,
-    const Type &type)
-    : WindowAggregationHandle(partition_key_types, first_order_by_key_type),
-      argument_type_(type) {
+    const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+    const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+    const bool is_row,
+    const std::int64_t num_preceding,
+    const std::int64_t num_following,
+    const Type *argument_type)
+    : WindowAggregationHandle(partition_by_attributes,
+                              order_by_attributes,
+                              is_row,
+                              num_preceding,
+                              num_following) {
   // We sum Int as Long and Float as Double so that we have more headroom when
   // adding many values.
   TypeID type_id;
-  switch (type.getTypeID()) {
+  switch (argument_type->getTypeID()) {
     case kInt:
     case kLong:
       type_id = kLong;
@@ -59,7 +65,7 @@ WindowAggregationHandleAvg::WindowAggregationHandleAvg(
       type_id = kDouble;
       break;
     default:
-      type_id = type.getTypeID();
+      type_id = argument_type->getTypeID();
       break;
   }
 
@@ -76,12 +82,12 @@ WindowAggregationHandleAvg::WindowAggregationHandleAvg(
   // Add operator for summing argument values.
   fast_add_operator_.reset(
       BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kAdd)
-          .makeUncheckedBinaryOperatorForTypes(*sum_type_, argument_type_));
+          .makeUncheckedBinaryOperatorForTypes(*sum_type_, *argument_type));
 
   // Subtract operator for dropping argument values off the window.
   fast_subtract_operator_.reset(
       BinaryOperationFactory::GetBinaryOperation(BinaryOperationID::kSubtract)
-          .makeUncheckedBinaryOperatorForTypes(*sum_type_, argument_type_));
+          .makeUncheckedBinaryOperatorForTypes(*sum_type_, *argument_type));
 
   // Divide operator for dividing sum by count to get final average.
   divide_operator_.reset(
@@ -91,12 +97,7 @@ WindowAggregationHandleAvg::WindowAggregationHandleAvg(
 
 ColumnVector* WindowAggregationHandleAvg::calculate(
     ColumnVectorsValueAccessor *tuple_accessor,
-    const std::vector<ColumnVector*> &arguments,
-    const std::vector<attribute_id> &partition_by_ids,
-    const std::vector<attribute_id> &order_by_ids,
-    const bool is_row,
-    const std::int64_t num_preceding,
-    const std::int64_t num_following) const {
+    const std::vector<ColumnVector*> &arguments) const {
   DCHECK_EQ(1u, arguments.size());
   DCHECK(arguments[0]->isNative());
   DCHECK_EQ(static_cast<std::size_t>(tuple_accessor->getNumTuples()),
@@ -125,7 +126,7 @@ ColumnVector* WindowAggregationHandleAvg::calculate(
 
     // If current tuple is not in the same partition as the previous tuple,
     // reset the window.
-    if (!samePartition(tuple_accessor, current_tuple_id - 1, partition_by_ids)) {
+    if (!samePartition(tuple_accessor, current_tuple_id - 1)) {
       start_tuple_id = current_tuple_id;
       end_tuple_id = current_tuple_id;
       count = 0;
@@ -133,13 +134,7 @@ ColumnVector* WindowAggregationHandleAvg::calculate(
     }
 
     // Drop tuples that will be out of the window from the beginning.
-    while (num_preceding != -1 &&
-           ((is_row && current_tuple_id - start_tuple_id > num_preceding) ||
-            (!is_row && !inRange(tuple_accessor,
-                                 start_tuple_id,
-                                 order_by_ids[0],
-                                 -num_preceding,
-                                 num_following)))) {
+    while (!inWindow(tuple_accessor, start_tuple_id)) {
       TypedValue start_value =
           argument_accessor->getTypedValueAtAbsolutePosition(0, start_tuple_id);
       // Ignore the value if NULL.
@@ -152,14 +147,7 @@ ColumnVector* WindowAggregationHandleAvg::calculate(
     }
 
     // Add tuples that will be included by the window at the end.
-    while (samePartition(tuple_accessor, end_tuple_id, partition_by_ids) &&
-           (num_following == -1 ||
-            (is_row && end_tuple_id - current_tuple_id <= num_following) ||
-            (!is_row && inRange(tuple_accessor,
-                                end_tuple_id,
-                                order_by_ids[0],
-                                -num_preceding,
-                                num_following)))) {
+    while (inWindow(tuple_accessor, end_tuple_id)) {
       TypedValue end_value =
           argument_accessor->getTypedValueAtAbsolutePosition(0, end_tuple_id);
 

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/WindowAggregationHandleAvg.hpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/WindowAggregationHandleAvg.hpp b/expressions/window_aggregation/WindowAggregationHandleAvg.hpp
index 980f25b..b709cf4 100644
--- a/expressions/window_aggregation/WindowAggregationHandleAvg.hpp
+++ b/expressions/window_aggregation/WindowAggregationHandleAvg.hpp
@@ -53,12 +53,7 @@ class WindowAggregationHandleAvg : public WindowAggregationHandle {
   ~WindowAggregationHandleAvg() override {}
 
   ColumnVector* calculate(ColumnVectorsValueAccessor* block_accessors,
-                          const std::vector<ColumnVector*> &arguments,
-                          const std::vector<attribute_id> &partition_by_ids,
-                          const std::vector<attribute_id> &order_by_ids,
-                          const bool is_row,
-                          const std::int64_t num_preceding,
-                          const std::int64_t num_following) const override;
+                          const std::vector<ColumnVector*> &arguments) const override;
 
  private:
   friend class WindowAggregateFunctionAvg;
@@ -67,13 +62,21 @@ class WindowAggregationHandleAvg : public WindowAggregationHandle {
    * @brief Constructor.
    *
    * @param partition_key_types The Types of the partition key.
-   * @param type Type of the avg value.
+   * @param first_order_key_type The type of the first order key, nullptr if
+   *                             not needed.
+   * @param is_row True if the frame mode is ROWS, false if RANGE.
+   * @param num_preceding The number of rows/range that precedes the current row.
+   * @param num_following The number of rows/range that follows the current row.
+   * @param argument_type Type of the argument.
    **/
-  WindowAggregationHandleAvg(const std::vector<const Type*> &partition_key_types,
-                             const Type *first_order_key_type,
-                             const Type &type);
+  WindowAggregationHandleAvg(
+      const std::vector<std::unique_ptr<const Scalar>> &partition_by_attributes,
+      const std::vector<std::unique_ptr<const Scalar>> &order_by_attributes,
+      const bool is_row,
+      const std::int64_t num_preceding,
+      const std::int64_t num_following,
+      const Type *argument_type);
 
-  const Type &argument_type_;
   const Type *sum_type_;
   const Type *result_type_;
   std::unique_ptr<UncheckedBinaryOperator> fast_add_operator_;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/expressions/window_aggregation/tests/WindowAggregationHandleAvg_unittest.cpp
----------------------------------------------------------------------
diff --git a/expressions/window_aggregation/tests/WindowAggregationHandleAvg_unittest.cpp b/expressions/window_aggregation/tests/WindowAggregationHandleAvg_unittest.cpp
index 98c2a78..d2cbbd8 100644
--- a/expressions/window_aggregation/tests/WindowAggregationHandleAvg_unittest.cpp
+++ b/expressions/window_aggregation/tests/WindowAggregationHandleAvg_unittest.cpp
@@ -23,7 +23,10 @@
 #include <memory>
 #include <vector>
 
+#include "catalog/CatalogAttribute.hpp"
 #include "catalog/CatalogTypedefs.hpp"
+#include "expressions/scalar/Scalar.hpp"
+#include "expressions/scalar/ScalarAttribute.hpp"
 #include "expressions/window_aggregation/WindowAggregateFunction.hpp"
 #include "expressions/window_aggregation/WindowAggregateFunctionFactory.hpp"
 #include "expressions/window_aggregation/WindowAggregationHandle.hpp"
@@ -67,13 +70,27 @@ namespace {
 class WindowAggregationHandleAvgTest : public::testing::Test {
  protected:
   // Handle initialization.
-  void initializeHandle(const Type &argument_type) {
+  WindowAggregationHandle* initializeHandle(const Type &argument_type,
+                                            const bool is_row = true,
+                                            const std::int64_t num_preceding = -1,
+                                            const std::int64_t num_following = 0) {
     const WindowAggregateFunction &function =
         WindowAggregateFunctionFactory::Get(WindowAggregationID::kAvg);
+    const Type &int_type = TypeFactory::GetType(kInt, false);
+    std::vector<std::unique_ptr<const Scalar>> partition_by_attributes;
+    std::vector<std::unique_ptr<const Scalar>> order_by_attributes;
+    partition_by_attributes.emplace_back(
+        new ScalarAttribute(CatalogAttribute(nullptr, "partition_key", int_type, kPartitionKeyIndex)));
+    order_by_attributes.emplace_back(
+        new ScalarAttribute(CatalogAttribute(nullptr, "order_key", int_type, kOrderKeyIndex)));
     std::vector<const Type*> partition_key_types(1, &TypeFactory::GetType(kInt, false));
-    handle_avg_.reset(function.createHandle(std::vector<const Type*>(1, &argument_type),
-                                            partition_key_types,
-                                            &(TypeFactory::GetType(kInt, false))));
+
+    return function.createHandle(std::vector<const Type*>(1, &argument_type),
+                                 partition_by_attributes,
+                                 order_by_attributes,
+                                 is_row,
+                                 num_preceding,
+                                 num_following);
   }
 
   // Test canApplyToTypes().
@@ -121,9 +138,6 @@ class WindowAggregationHandleAvgTest : public::testing::Test {
 
   template <typename GenericType, typename OutputType = DoubleType>
   void checkWindowAggregationAvgGeneric() {
-    const GenericType &type = GenericType::Instance(true);
-    initializeHandle(type);
-
     // Create argument, partition key and cpptype vectors.
     std::vector<typename GenericType::cpptype*> argument_cpp_vector;
     argument_cpp_vector.reserve(kNumTuples);
@@ -190,19 +204,15 @@ class WindowAggregationHandleAvgTest : public::testing::Test {
                        const std::vector<typename GenericType::cpptype*> &argument_cpp_vector) {
     std::vector<ColumnVector*> arguments;
     arguments.push_back(argument_type_vector);
-    // The partition key index is 0.
-    std::vector<attribute_id> partition_key(1, kPartitionKeyIndex);
-    std::vector<attribute_id> order_key(1, kOrderKeyIndex);
 
     // Check ROWS mode.
+    WindowAggregationHandle *rows_handle =
+        initializeHandle(GenericType::Instance(true),
+                         true  /* is_row */,
+                         -1  /* num_preceding: UNBOUNDED PRECEDING */,
+                         0  /* num_following: CURRENT ROW */);
     ColumnVector *rows_result =
-        handle_avg_->calculate(tuple_accessor,
-                               arguments,
-                               partition_key,
-                               order_key,
-                               true  /* is_row */,
-                               -1  /* num_preceding: UNBOUNDED PRECEDING */,
-                               0  /* num_following: CURRENT ROW */);
+        rows_handle->calculate(tuple_accessor, arguments);
 
     // Get the cpptype result.
     std::vector<typename OutputType::cpptype*> rows_result_cpp_vector;
@@ -234,14 +244,13 @@ class WindowAggregationHandleAvgTest : public::testing::Test {
     CheckAvgValues(rows_result_cpp_vector, rows_result);
 
     // Check RANGE mode.
+    WindowAggregationHandle *range_handle =
+        initializeHandle(GenericType::Instance(true),
+                         false  /* is_row */,
+                         -1  /* num_preceding: UNBOUNDED PRECEDING */,
+                         0  /* num_following: CURRENT ROW */);
     ColumnVector *range_result =
-        handle_avg_->calculate(tuple_accessor,
-                               arguments,
-                               partition_key,
-                               order_key,
-                               false  /* is_row */,
-                               -1  /* num_preceding: UNBOUNDED PRECEDING */,
-                               0  /* num_following: CURRENT ROW */);
+        range_handle->calculate(tuple_accessor, arguments);
 
     // Get the cpptype result.
     std::vector<typename OutputType::cpptype*> range_result_cpp_vector;
@@ -292,19 +301,15 @@ class WindowAggregationHandleAvgTest : public::testing::Test {
                           const std::vector<typename GenericType::cpptype*> &argument_cpp_vector) {
     std::vector<ColumnVector*> arguments;
     arguments.push_back(argument_type_vector);
-    // The partition key index is 0.
-    std::vector<attribute_id> partition_key(1, kPartitionKeyIndex);
-    std::vector<attribute_id> order_key(1, kOrderKeyIndex);
 
     // Check ROWS mode.
+    WindowAggregationHandle *rows_handle =
+        initializeHandle(GenericType::Instance(true),
+                         true  /* is_row */,
+                         kNumPreceding,
+                         kNumFollowing);
     ColumnVector *rows_result =
-        handle_avg_->calculate(tuple_accessor,
-                               arguments,
-                               partition_key,
-                               order_key,
-                               true  /* is_row */,
-                               kNumPreceding,
-                               kNumFollowing);
+        rows_handle->calculate(tuple_accessor, arguments);
 
     // Get the cpptype result.
     // For each value, calculate all surrounding values in the window.
@@ -359,14 +364,13 @@ class WindowAggregationHandleAvgTest : public::testing::Test {
     CheckAvgValues(rows_result_cpp_vector, rows_result);
 
     // Check RANGE mode.
+    WindowAggregationHandle *range_handle =
+        initializeHandle(GenericType::Instance(true),
+                         false  /* is_row */,
+                         kNumPreceding,
+                         kNumFollowing);
     ColumnVector *range_result =
-        handle_avg_->calculate(tuple_accessor,
-                               arguments,
-                               partition_key,
-                               order_key,
-                               false  /* is_row */,
-                               kNumPreceding,
-                               kNumFollowing);
+        range_handle->calculate(tuple_accessor, arguments);
 
     // Get the cpptype result.
     // For each value, calculate all surrounding values in the window.
@@ -423,8 +427,6 @@ class WindowAggregationHandleAvgTest : public::testing::Test {
 
     CheckAvgValues(range_result_cpp_vector, range_result);
   }
-
-  std::unique_ptr<WindowAggregationHandle> handle_avg_;
 };
 
 template <>

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/storage/WindowAggregationOperationState.cpp
----------------------------------------------------------------------
diff --git a/storage/WindowAggregationOperationState.cpp b/storage/WindowAggregationOperationState.cpp
index 45119ab..49fa44d 100644
--- a/storage/WindowAggregationOperationState.cpp
+++ b/storage/WindowAggregationOperationState.cpp
@@ -63,9 +63,6 @@ WindowAggregationOperationState::WindowAggregationOperationState(
     StorageManager *storage_manager)
     : input_relation_(input_relation),
       arguments_(std::move(arguments)),
-      is_row_(is_row),
-      num_preceding_(num_preceding),
-      num_following_(num_following),
       storage_manager_(storage_manager) {
   // Get the Types of this window aggregate's arguments so that we can create an
   // AggregationHandle.
@@ -77,29 +74,14 @@ WindowAggregationOperationState::WindowAggregationOperationState(
   // Check if window aggregate function could apply to the arguments.
   DCHECK(window_aggregate_function->canApplyToTypes(argument_types));
 
-  // IDs and types of partition keys.
-  std::vector<const Type*> partition_by_types;
-  for (const std::unique_ptr<const Scalar> &partition_by_attribute : partition_by_attributes) {
-    partition_by_ids_.push_back(
-        partition_by_attribute->getAttributeIdForValueAccessor());
-    partition_by_types.push_back(&partition_by_attribute->getType());
-  }
-
-  // IDs of order keys and type of the first order key if in RANGE mode.
-  const Type* first_order_by_type = nullptr;
-  for (const std::unique_ptr<const Scalar> &order_by_attribute : order_by_attributes) {
-    order_by_ids_.push_back(
-        order_by_attribute->getAttributeIdForValueAccessor());
-    if (!is_row && first_order_by_type == nullptr) {
-      first_order_by_type = &order_by_attribute->getType();
-    }
-  }
-
   // Create the handle and initial state.
   window_aggregation_handle_.reset(
-      window_aggregate_function->createHandle(std::move(argument_types),
-                                              std::move(partition_by_types),
-                                              first_order_by_type));
+      window_aggregate_function->createHandle(argument_types,
+                                              partition_by_attributes,
+                                              order_by_attributes,
+                                              is_row,
+                                              num_preceding,
+                                              num_following));
 }
 
 WindowAggregationOperationState* WindowAggregationOperationState::ReconstructFromProto(
@@ -308,12 +290,7 @@ void WindowAggregationOperationState::windowAggregateBlocks(
   // Do actual calculation in handle.
   ColumnVector *window_aggregates =
       window_aggregation_handle_->calculate(all_blocks_accessor,
-                                            argument_vecs,
-                                            partition_by_ids_,
-                                            order_by_ids_,
-                                            is_row_,
-                                            num_preceding_,
-                                            num_following_);
+                                            argument_vecs);
 
   all_blocks_accessor->addColumn(window_aggregates);
   output_destination->bulkInsertTuples(all_blocks_accessor);

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/0a23f171/storage/WindowAggregationOperationState.hpp
----------------------------------------------------------------------
diff --git a/storage/WindowAggregationOperationState.hpp b/storage/WindowAggregationOperationState.hpp
index cb29b92..726b102 100644
--- a/storage/WindowAggregationOperationState.hpp
+++ b/storage/WindowAggregationOperationState.hpp
@@ -122,14 +122,6 @@ class WindowAggregationOperationState {
   const std::vector<block_id> block_ids_;
   std::unique_ptr<WindowAggregationHandle> window_aggregation_handle_;
   std::vector<std::unique_ptr<const Scalar>> arguments_;
-  std::vector<attribute_id> partition_by_ids_;
-  std::vector<attribute_id> order_by_ids_;
-
-  // Frame info.
-  const bool is_row_;
-  const std::int64_t num_preceding_;
-  const std::int64_t num_following_;
-
   StorageManager *storage_manager_;
 
   DISALLOW_COPY_AND_ASSIGN(WindowAggregationOperationState);


Mime
View raw message