You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by sp...@apache.org on 2016/12/11 17:46:00 UTC

[37/51] [abbrv] [partial] incubator-quickstep git commit: remove c++ files

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/expressions/aggregation/tests/AggregationHandleMin_unittest.cpp
----------------------------------------------------------------------
diff --git a/expressions/aggregation/tests/AggregationHandleMin_unittest.cpp b/expressions/aggregation/tests/AggregationHandleMin_unittest.cpp
deleted file mode 100644
index 6e6d188..0000000
--- a/expressions/aggregation/tests/AggregationHandleMin_unittest.cpp
+++ /dev/null
@@ -1,822 +0,0 @@
-/**
- * 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 <cstddef>
-#include <cstdint>
-#include <cstring>
-#include <memory>
-#include <sstream>
-#include <string>
-#include <vector>
-
-#include "catalog/CatalogTypedefs.hpp"
-#include "expressions/aggregation/AggregateFunction.hpp"
-#include "expressions/aggregation/AggregateFunctionFactory.hpp"
-#include "expressions/aggregation/AggregationHandle.hpp"
-#include "expressions/aggregation/AggregationHandleMin.hpp"
-#include "expressions/aggregation/AggregationID.hpp"
-#include "storage/AggregationOperationState.hpp"
-#include "storage/FastHashTableFactory.hpp"
-#include "storage/StorageManager.hpp"
-#include "types/CharType.hpp"
-#include "types/DatetimeIntervalType.hpp"
-#include "types/DatetimeLit.hpp"
-#include "types/DatetimeType.hpp"
-#include "types/DoubleType.hpp"
-#include "types/FloatType.hpp"
-#include "types/IntType.hpp"
-#include "types/IntervalLit.hpp"
-#include "types/LongType.hpp"
-#include "types/Type.hpp"
-#include "types/TypeFactory.hpp"
-#include "types/TypeID.hpp"
-#include "types/TypedValue.hpp"
-#include "types/VarCharType.hpp"
-#include "types/YearMonthIntervalType.hpp"
-#include "types/containers/ColumnVector.hpp"
-
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-#include "types/containers/ColumnVectorsValueAccessor.hpp"
-#endif
-
-#include "types/operations/comparisons/Comparison.hpp"
-#include "types/operations/comparisons/ComparisonFactory.hpp"
-#include "types/operations/comparisons/ComparisonID.hpp"
-
-#include "gtest/gtest.h"
-
-namespace quickstep {
-
-class AggregationHandleMinTest : public ::testing::Test {
- protected:
-  static const int kNumSamples = 200;
-  static const int kIterations = 5;
-
-  // Helper method that calls AggregationHandleMin::iterateUnaryInl() to
-  // aggregate 'value' into '*state'.
-  void iterateHandle(AggregationState *state, const TypedValue &value) {
-    static_cast<const AggregationHandleMin &>(*aggregation_handle_min_)
-        .iterateUnaryInl(static_cast<AggregationStateMin *>(state), value);
-  }
-
-  void initializeHandle(const Type &type) {
-    aggregation_handle_min_.reset(
-        AggregateFunctionFactory::Get(AggregationID::kMin)
-            .createHandle(std::vector<const Type *>(1, &type)));
-    aggregation_handle_min_state_.reset(
-        aggregation_handle_min_->createInitialState());
-  }
-
-  static bool ApplyToTypesTest(TypeID typeID) {
-    const Type &type =
-        (typeID == kChar || typeID == kVarChar)
-            ? TypeFactory::GetType(typeID, static_cast<std::size_t>(10))
-            : TypeFactory::GetType(typeID);
-
-    return AggregateFunctionFactory::Get(AggregationID::kMin)
-        .canApplyToTypes(std::vector<const Type *>(1, &type));
-  }
-
-  static bool ResultTypeForArgumentTypeTest(TypeID input_type_id,
-                                            TypeID output_type_id) {
-    const Type *result_type =
-        AggregateFunctionFactory::Get(AggregationID::kMin)
-            .resultTypeForArgumentTypes(std::vector<const Type *>(
-                1, &TypeFactory::GetType(input_type_id)));
-    return (result_type->getTypeID() == output_type_id);
-  }
-
-  template <typename CppType>
-  static void CheckMinValue(CppType expected,
-                            const AggregationHandle &handle,
-                            const AggregationState &state) {
-    EXPECT_EQ(expected, handle.finalize(state).getLiteral<CppType>());
-  }
-
-  template <typename CppType>
-  static void CheckMinValue(CppType expected, const TypedValue &value) {
-    EXPECT_EQ(expected, value.getLiteral<CppType>());
-  }
-
-  static void CheckMinString(const std::string &expected,
-                             const AggregationHandle &handle,
-                             const AggregationState &state) {
-    TypedValue value = handle.finalize(state);
-
-    ASSERT_EQ(expected.length(), value.getAsciiStringLength());
-    EXPECT_EQ(0,
-              std::strncmp(expected.c_str(),
-                           static_cast<const char *>(value.getDataPtr()),
-                           value.getAsciiStringLength()));
-  }
-
-  // Static templated method to initialize data types.
-  template <typename CppType>
-  void SetDataType(int value, CppType *data) {
-    *data = value;
-  }
-
-  template <typename GenericType>
-  void checkAggregationMinGeneric() {
-    const GenericType &type = GenericType::Instance(true);
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_min_->finalize(*aggregation_handle_min_state_)
-            .isNull());
-
-    typename GenericType::cpptype val;
-    typename GenericType::cpptype min;
-    SetDataType(1000, &min);
-
-    iterateHandle(aggregation_handle_min_state_.get(), type.makeNullValue());
-    for (int i = 0; i < kIterations; ++i) {
-      for (int j = kNumSamples - 1; j >= 0; --j) {
-        if (type.getTypeID() == kInt || type.getTypeID() == kLong) {
-          SetDataType(i * kNumSamples + j - 10, &val);
-        } else {
-          SetDataType(static_cast<float>(i * kNumSamples + j - 10) / 10, &val);
-        }
-        iterateHandle(aggregation_handle_min_state_.get(),
-                      type.makeValue(&val));
-        if (min > val) {
-          min = val;
-        }
-      }
-    }
-    iterateHandle(aggregation_handle_min_state_.get(), type.makeNullValue());
-    CheckMinValue<typename GenericType::cpptype>(
-        min, *aggregation_handle_min_, *aggregation_handle_min_state_);
-
-    // Test mergeStates().
-    std::unique_ptr<AggregationState> merge_state(
-        aggregation_handle_min_->createInitialState());
-    aggregation_handle_min_->mergeStates(*merge_state,
-                                         aggregation_handle_min_state_.get());
-
-    iterateHandle(merge_state.get(), type.makeNullValue());
-    for (int i = 0; i < kIterations; ++i) {
-      for (int j = kNumSamples - 1; j >= 0; --j) {
-        if (type.getTypeID() == kInt || type.getTypeID() == kLong) {
-          SetDataType(i * kNumSamples + j - 20, &val);
-        } else {
-          SetDataType(static_cast<float>(i * kNumSamples + j - 20) / 10, &val);
-        }
-        iterateHandle(merge_state.get(), type.makeValue(&val));
-        if (min > val) {
-          min = val;
-        }
-      }
-    }
-    aggregation_handle_min_->mergeStates(*merge_state,
-                                         aggregation_handle_min_state_.get());
-    CheckMinValue<typename GenericType::cpptype>(
-        min, *aggregation_handle_min_, *aggregation_handle_min_state_);
-  }
-
-  template <typename GenericType>
-  ColumnVector* createColumnVectorGeneric(const Type &type,
-                                          typename GenericType::cpptype *min) {
-    NativeColumnVector *column =
-        new NativeColumnVector(type, kIterations * kNumSamples + 3);
-
-    typename GenericType::cpptype val;
-    SetDataType(1000, min);
-
-    column->appendTypedValue(type.makeNullValue());
-    for (int i = 0; i < kIterations; ++i) {
-      for (int j = kNumSamples - 1; j >= 0; --j) {
-        if (type.getTypeID() == kInt || type.getTypeID() == kLong) {
-          SetDataType(i * kNumSamples + j - 10, &val);
-        } else {
-          SetDataType(static_cast<float>(i * kNumSamples + j - 10) / 10, &val);
-        }
-        column->appendTypedValue(type.makeValue(&val));
-        if (*min > val) {
-          *min = val;
-        }
-      }
-      // One NULL in the middle.
-      if (i == kIterations / 2) {
-        column->appendTypedValue(type.makeNullValue());
-      }
-    }
-    column->appendTypedValue(type.makeNullValue());
-
-    return column;
-  }
-
-  template <typename GenericType>
-  void checkAggregationMinGenericColumnVector() {
-    const GenericType &type = GenericType::Instance(true);
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_min_->finalize(*aggregation_handle_min_state_)
-            .isNull());
-
-    typename GenericType::cpptype min;
-    std::vector<std::unique_ptr<ColumnVector>> column_vectors;
-    column_vectors.emplace_back(
-        createColumnVectorGeneric<GenericType>(type, &min));
-
-    std::unique_ptr<AggregationState> cv_state(
-        aggregation_handle_min_->accumulateColumnVectors(column_vectors));
-
-    // Test the state generated directly by accumulateColumnVectors(), and also
-    // test after merging back.
-    CheckMinValue<typename GenericType::cpptype>(
-        min, *aggregation_handle_min_, *cv_state);
-
-    aggregation_handle_min_->mergeStates(*cv_state,
-                                         aggregation_handle_min_state_.get());
-    CheckMinValue<typename GenericType::cpptype>(
-        min, *aggregation_handle_min_, *aggregation_handle_min_state_);
-  }
-
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-  template <typename GenericType>
-  void checkAggregationMinGenericValueAccessor() {
-    const GenericType &type = GenericType::Instance(true);
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_min_->finalize(*aggregation_handle_min_state_)
-            .isNull());
-
-    std::unique_ptr<ColumnVectorsValueAccessor> accessor(
-        new ColumnVectorsValueAccessor());
-
-    typename GenericType::cpptype min;
-    accessor->addColumn(createColumnVectorGeneric<GenericType>(type, &min));
-
-    std::unique_ptr<AggregationState> va_state(
-        aggregation_handle_min_->accumulateValueAccessor(
-            accessor.get(), std::vector<attribute_id>(1, 0)));
-
-    // Test the state generated directly by accumulateValueAccessor(), and also
-    // test after merging back.
-    CheckMinValue<typename GenericType::cpptype>(
-        min, *aggregation_handle_min_, *va_state);
-
-    aggregation_handle_min_->mergeStates(*va_state,
-                                         aggregation_handle_min_state_.get());
-    CheckMinValue<typename GenericType::cpptype>(
-        min, *aggregation_handle_min_, *aggregation_handle_min_state_);
-  }
-#endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-
-  template <typename StringType>
-  void checkAggregationMinString() {
-    const StringType &type = StringType::Instance(10, true);
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_min_->finalize(*aggregation_handle_min_state_)
-            .isNull());
-
-    std::unique_ptr<UncheckedComparator> fast_comparator_;
-    fast_comparator_.reset(ComparisonFactory::GetComparison(ComparisonID::kLess)
-                               .makeUncheckedComparatorForTypes(type, type));
-    std::string string_literal;
-    std::string min = "z";
-    int val;
-    iterateHandle(aggregation_handle_min_state_.get(), type.makeNullValue());
-    for (int i = 0; i < kIterations; ++i) {
-      for (int j = kNumSamples - 1; j >= 0; --j) {
-        val = i * kNumSamples + j;
-        std::ostringstream oss;
-        oss << "test" << val;
-        string_literal = oss.str();
-
-        iterateHandle(
-            aggregation_handle_min_state_.get(),
-            type.makeValue(string_literal.c_str(), string_literal.length() + 1)
-                .ensureNotReference());
-        if (fast_comparator_->compareDataPtrs(string_literal.c_str(),
-                                              min.c_str())) {
-          min = string_literal;
-        }
-      }
-    }
-    iterateHandle(aggregation_handle_min_state_.get(), type.makeNullValue());
-    CheckMinString(
-        min, *aggregation_handle_min_, *aggregation_handle_min_state_);
-
-    // Test mergeStates().
-    std::unique_ptr<AggregationState> merge_state(
-        aggregation_handle_min_->createInitialState());
-    aggregation_handle_min_->mergeStates(*merge_state,
-                                         aggregation_handle_min_state_.get());
-
-    iterateHandle(merge_state.get(), type.makeNullValue());
-    for (int i = 0; i < kIterations; ++i) {
-      for (int j = kNumSamples - 1; j >= 0; --j) {
-        val = i * kNumSamples + j;
-        std::ostringstream oss;
-        oss << "min" << val;
-        string_literal = oss.str();
-
-        iterateHandle(
-            merge_state.get(),
-            type.makeValue(string_literal.c_str(), string_literal.length() + 1)
-                .ensureNotReference());
-        if (fast_comparator_->compareDataPtrs(string_literal.c_str(),
-                                              min.c_str())) {
-          min = string_literal;
-        }
-      }
-    }
-    aggregation_handle_min_->mergeStates(*merge_state,
-                                         aggregation_handle_min_state_.get());
-    CheckMinString(
-        min, *aggregation_handle_min_, *aggregation_handle_min_state_);
-  }
-
-  template <typename ColumnVectorType>
-  ColumnVector* createColumnVectorString(const Type &type, std::string *min) {
-    ColumnVectorType *column =
-        new ColumnVectorType(type, kIterations * kNumSamples + 3);
-    std::unique_ptr<UncheckedComparator> fast_comparator_;
-    fast_comparator_.reset(ComparisonFactory::GetComparison(ComparisonID::kLess)
-                               .makeUncheckedComparatorForTypes(type, type));
-    std::string string_literal;
-    *min = "z";
-    int val;
-    column->appendTypedValue(type.makeNullValue());
-    for (int i = 0; i < kIterations; ++i) {
-      for (int j = kNumSamples - 1; j >= 0; --j) {
-        val = i * kNumSamples + j;
-        std::ostringstream oss;
-        oss << "test" << val;
-        string_literal = oss.str();
-
-        column->appendTypedValue(
-            type.makeValue(string_literal.c_str(), string_literal.length() + 1)
-                .ensureNotReference());
-        if (fast_comparator_->compareDataPtrs(string_literal.c_str(),
-                                              min->c_str())) {
-          *min = string_literal;
-        }
-      }
-      // One NULL in the middle.
-      if (i == kIterations / 2) {
-        column->appendTypedValue(type.makeNullValue());
-      }
-    }
-    column->appendTypedValue(type.makeNullValue());
-
-    return column;
-  }
-
-  template <typename StringType, typename ColumnVectorType>
-  void checkAggregationMinStringColumnVector() {
-    const StringType &type = StringType::Instance(10, true);
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_min_->finalize(*aggregation_handle_min_state_)
-            .isNull());
-
-    std::string min;
-    std::vector<std::unique_ptr<ColumnVector>> column_vectors;
-    column_vectors.emplace_back(
-        createColumnVectorString<ColumnVectorType>(type, &min));
-
-    std::unique_ptr<AggregationState> cv_state(
-        aggregation_handle_min_->accumulateColumnVectors(column_vectors));
-
-    // Test the state generated directly by accumulateColumnVectors(), and also
-    // test after merging back.
-    CheckMinString(min, *aggregation_handle_min_, *cv_state);
-
-    aggregation_handle_min_->mergeStates(*cv_state,
-                                         aggregation_handle_min_state_.get());
-    CheckMinString(
-        min, *aggregation_handle_min_, *aggregation_handle_min_state_);
-  }
-
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-  template <typename StringType, typename ColumnVectorType>
-  void checkAggregationMinStringValueAccessor() {
-    const StringType &type = StringType::Instance(10, true);
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_min_->finalize(*aggregation_handle_min_state_)
-            .isNull());
-
-    std::string min;
-    std::unique_ptr<ColumnVectorsValueAccessor> accessor(
-        new ColumnVectorsValueAccessor());
-    accessor->addColumn(createColumnVectorString<ColumnVectorType>(type, &min));
-
-    std::unique_ptr<AggregationState> va_state(
-        aggregation_handle_min_->accumulateValueAccessor(
-            accessor.get(), std::vector<attribute_id>(1, 0)));
-
-    // Test the state generated directly by accumulateValueAccessor(), and also
-    // test after merging back.
-    CheckMinString(min, *aggregation_handle_min_, *va_state);
-
-    aggregation_handle_min_->mergeStates(*va_state,
-                                         aggregation_handle_min_state_.get());
-    CheckMinString(
-        min, *aggregation_handle_min_, *aggregation_handle_min_state_);
-  }
-#endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-
-  std::unique_ptr<AggregationHandle> aggregation_handle_min_;
-  std::unique_ptr<AggregationState> aggregation_handle_min_state_;
-  std::unique_ptr<StorageManager> storage_manager_;
-};
-
-template <>
-void AggregationHandleMinTest::CheckMinValue<float>(
-    float val, const AggregationHandle &handle, const AggregationState &state) {
-  EXPECT_FLOAT_EQ(val, handle.finalize(state).getLiteral<float>());
-}
-
-template <>
-void AggregationHandleMinTest::CheckMinValue<double>(
-    double val,
-    const AggregationHandle &handle,
-    const AggregationState &state) {
-  EXPECT_DOUBLE_EQ(val, handle.finalize(state).getLiteral<double>());
-}
-
-template <>
-void AggregationHandleMinTest::SetDataType<DatetimeLit>(int value,
-                                                        DatetimeLit *data) {
-  data->ticks = value;
-}
-
-template <>
-void AggregationHandleMinTest::SetDataType<DatetimeIntervalLit>(
-    int value, DatetimeIntervalLit *data) {
-  data->interval_ticks = value;
-}
-
-template <>
-void AggregationHandleMinTest::SetDataType<YearMonthIntervalLit>(
-    int value, YearMonthIntervalLit *data) {
-  data->months = value;
-}
-
-typedef AggregationHandleMinTest AggregationHandleMinDeathTest;
-
-TEST_F(AggregationHandleMinTest, IntTypeTest) {
-  checkAggregationMinGeneric<IntType>();
-}
-
-TEST_F(AggregationHandleMinTest, LongTypeTest) {
-  checkAggregationMinGeneric<LongType>();
-}
-
-TEST_F(AggregationHandleMinTest, FloatTypeTest) {
-  checkAggregationMinGeneric<FloatType>();
-}
-
-TEST_F(AggregationHandleMinTest, DoubleTypeTest) {
-  checkAggregationMinGeneric<DoubleType>();
-}
-
-TEST_F(AggregationHandleMinTest, DatetimeType) {
-  checkAggregationMinGeneric<DatetimeType>();
-}
-
-TEST_F(AggregationHandleMinTest, DatetimeIntervalType) {
-  checkAggregationMinGeneric<DatetimeIntervalType>();
-}
-
-TEST_F(AggregationHandleMinTest, YearMonthIntervalType) {
-  checkAggregationMinGeneric<YearMonthIntervalType>();
-}
-
-TEST_F(AggregationHandleMinTest, CharTypeTest) {
-  checkAggregationMinString<CharType>();
-}
-
-TEST_F(AggregationHandleMinTest, VarCharTypeTest) {
-  checkAggregationMinString<VarCharType>();
-}
-
-TEST_F(AggregationHandleMinTest, IntTypeColumnVectorTest) {
-  checkAggregationMinGenericColumnVector<IntType>();
-}
-
-TEST_F(AggregationHandleMinTest, LongTypeColumnVectorTest) {
-  checkAggregationMinGenericColumnVector<LongType>();
-}
-
-TEST_F(AggregationHandleMinTest, FloatTypeColumnVectorTest) {
-  checkAggregationMinGenericColumnVector<FloatType>();
-}
-
-TEST_F(AggregationHandleMinTest, DoubleTypeColumnVectorTest) {
-  checkAggregationMinGenericColumnVector<DoubleType>();
-}
-
-TEST_F(AggregationHandleMinTest, DatetimeTypeColumnVectorTest) {
-  checkAggregationMinGenericColumnVector<DatetimeType>();
-}
-
-TEST_F(AggregationHandleMinTest, DatetimeIntervalTypeColumnVectorTest) {
-  checkAggregationMinGenericColumnVector<DatetimeIntervalType>();
-}
-
-TEST_F(AggregationHandleMinTest, YearMonthIntervalTypeColumnVectorTest) {
-  checkAggregationMinGenericColumnVector<YearMonthIntervalType>();
-}
-
-TEST_F(AggregationHandleMinTest, CharTypeColumnVectorTest) {
-  checkAggregationMinStringColumnVector<CharType, NativeColumnVector>();
-}
-
-TEST_F(AggregationHandleMinTest, VarCharTypeColumnVectorTest) {
-  checkAggregationMinStringColumnVector<VarCharType, IndirectColumnVector>();
-}
-
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-TEST_F(AggregationHandleMinTest, IntTypeValueAccessorTest) {
-  checkAggregationMinGenericValueAccessor<IntType>();
-}
-
-TEST_F(AggregationHandleMinTest, LongTypeValueAccessorTest) {
-  checkAggregationMinGenericValueAccessor<LongType>();
-}
-
-TEST_F(AggregationHandleMinTest, FloatTypeValueAccessorTest) {
-  checkAggregationMinGenericValueAccessor<FloatType>();
-}
-
-TEST_F(AggregationHandleMinTest, DoubleTypeValueAccessorTest) {
-  checkAggregationMinGenericValueAccessor<DoubleType>();
-}
-
-TEST_F(AggregationHandleMinTest, DatetimeTypeValueAccessorTest) {
-  checkAggregationMinGenericValueAccessor<DatetimeType>();
-}
-
-TEST_F(AggregationHandleMinTest, DatetimeIntervalTypeValueAccessorTest) {
-  checkAggregationMinGenericValueAccessor<DatetimeIntervalType>();
-}
-
-TEST_F(AggregationHandleMinTest, YearMonthIntervalTypeValueAccessorTest) {
-  checkAggregationMinGenericValueAccessor<YearMonthIntervalType>();
-}
-
-TEST_F(AggregationHandleMinTest, CharTypeValueAccessorTest) {
-  checkAggregationMinStringValueAccessor<CharType, NativeColumnVector>();
-}
-
-TEST_F(AggregationHandleMinTest, VarCharTypeValueAccessorTest) {
-  checkAggregationMinStringValueAccessor<VarCharType, IndirectColumnVector>();
-}
-#endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-
-#ifdef QUICKSTEP_DEBUG
-TEST_F(AggregationHandleMinDeathTest, WrongTypeTest) {
-  const Type &int_non_null_type = IntType::Instance(false);
-  const Type &long_type = LongType::Instance(true);
-  const Type &double_type = DoubleType::Instance(true);
-  const Type &float_type = FloatType::Instance(true);
-  const Type &char_type = CharType::Instance(true, 10);
-  const Type &varchar_type = VarCharType::Instance(true, 10);
-
-  initializeHandle(IntType::Instance(true));
-  int int_val = 0;
-  std::int64_t long_val = 0;
-  double double_val = 0;
-  float float_val = 0;
-
-  iterateHandle(aggregation_handle_min_state_.get(),
-                int_non_null_type.makeValue(&int_val));
-
-  EXPECT_DEATH(iterateHandle(aggregation_handle_min_state_.get(),
-                             long_type.makeValue(&long_val)),
-               "");
-  EXPECT_DEATH(iterateHandle(aggregation_handle_min_state_.get(),
-                             double_type.makeValue(&double_val)),
-               "");
-  EXPECT_DEATH(iterateHandle(aggregation_handle_min_state_.get(),
-                             float_type.makeValue(&float_val)),
-               "");
-  EXPECT_DEATH(iterateHandle(aggregation_handle_min_state_.get(),
-                             char_type.makeValue("asdf", 5)),
-               "");
-  EXPECT_DEATH(iterateHandle(aggregation_handle_min_state_.get(),
-                             varchar_type.makeValue("asdf", 5)),
-               "");
-
-  // Test mergeStates() with incorrectly typed handles.
-  std::unique_ptr<AggregationHandle> aggregation_handle_min_long(
-      AggregateFunctionFactory::Get(AggregationID::kMin)
-          .createHandle(std::vector<const Type *>(1, &long_type)));
-  std::unique_ptr<AggregationState> aggregation_state_min_merge_long(
-      aggregation_handle_min_long->createInitialState());
-  static_cast<const AggregationHandleMin &>(*aggregation_handle_min_long)
-      .iterateUnaryInl(static_cast<AggregationStateMin *>(
-                           aggregation_state_min_merge_long.get()),
-                       long_type.makeValue(&long_val));
-  EXPECT_DEATH(
-      aggregation_handle_min_->mergeStates(*aggregation_state_min_merge_long,
-                                           aggregation_handle_min_state_.get()),
-      "");
-
-  std::unique_ptr<AggregationHandle> aggregation_handle_min_double(
-      AggregateFunctionFactory::Get(AggregationID::kMin)
-          .createHandle(std::vector<const Type *>(1, &double_type)));
-  std::unique_ptr<AggregationState> aggregation_state_min_merge_double(
-      aggregation_handle_min_double->createInitialState());
-  static_cast<const AggregationHandleMin &>(*aggregation_handle_min_double)
-      .iterateUnaryInl(static_cast<AggregationStateMin *>(
-                           aggregation_state_min_merge_double.get()),
-                       double_type.makeValue(&double_val));
-  EXPECT_DEATH(
-      aggregation_handle_min_->mergeStates(*aggregation_state_min_merge_double,
-                                           aggregation_handle_min_state_.get()),
-      "");
-
-  std::unique_ptr<AggregationHandle> aggregation_handle_min_float(
-      AggregateFunctionFactory::Get(AggregationID::kMin)
-          .createHandle(std::vector<const Type *>(1, &float_type)));
-  std::unique_ptr<AggregationState> aggregation_state_min_merge_float(
-      aggregation_handle_min_float->createInitialState());
-  static_cast<const AggregationHandleMin &>(*aggregation_handle_min_float)
-      .iterateUnaryInl(static_cast<AggregationStateMin *>(
-                           aggregation_state_min_merge_float.get()),
-                       float_type.makeValue(&float_val));
-  EXPECT_DEATH(
-      aggregation_handle_min_->mergeStates(*aggregation_state_min_merge_float,
-                                           aggregation_handle_min_state_.get()),
-      "");
-}
-#endif
-
-TEST_F(AggregationHandleMinTest, canApplyToTypeTest) {
-  EXPECT_TRUE(ApplyToTypesTest(kInt));
-  EXPECT_TRUE(ApplyToTypesTest(kLong));
-  EXPECT_TRUE(ApplyToTypesTest(kFloat));
-  EXPECT_TRUE(ApplyToTypesTest(kDouble));
-  EXPECT_TRUE(ApplyToTypesTest(kChar));
-  EXPECT_TRUE(ApplyToTypesTest(kVarChar));
-}
-
-TEST_F(AggregationHandleMinTest, ResultTypeForArgumentTypeTest) {
-  EXPECT_TRUE(ResultTypeForArgumentTypeTest(kInt, kInt));
-  EXPECT_TRUE(ResultTypeForArgumentTypeTest(kLong, kLong));
-  EXPECT_TRUE(ResultTypeForArgumentTypeTest(kFloat, kFloat));
-  EXPECT_TRUE(ResultTypeForArgumentTypeTest(kDouble, kDouble));
-}
-
-TEST_F(AggregationHandleMinTest, GroupByTableMergeTest) {
-  const Type &int_non_null_type = IntType::Instance(false);
-  initializeHandle(int_non_null_type);
-  storage_manager_.reset(new StorageManager("./test_min_data"));
-  std::unique_ptr<AggregationStateHashTableBase> source_hash_table(
-      AggregationStateFastHashTableFactory::CreateResizable(
-          HashTableImplType::kSeparateChaining,
-          std::vector<const Type *>(1, &int_non_null_type),
-          10,
-          {aggregation_handle_min_.get()->getPayloadSize()},
-          {aggregation_handle_min_.get()},
-          storage_manager_.get()));
-  std::unique_ptr<AggregationStateHashTableBase> destination_hash_table(
-      AggregationStateFastHashTableFactory::CreateResizable(
-          HashTableImplType::kSeparateChaining,
-          std::vector<const Type *>(1, &int_non_null_type),
-          10,
-          {aggregation_handle_min_.get()->getPayloadSize()},
-          {aggregation_handle_min_.get()},
-          storage_manager_.get()));
-
-  AggregationStateFastHashTable *destination_hash_table_derived =
-      static_cast<AggregationStateFastHashTable *>(
-          destination_hash_table.get());
-
-  AggregationStateFastHashTable *source_hash_table_derived =
-      static_cast<AggregationStateFastHashTable *>(source_hash_table.get());
-
-  AggregationHandleMin *aggregation_handle_min_derived =
-      static_cast<AggregationHandleMin *>(aggregation_handle_min_.get());
-  // We create three keys: first is present in both the hash tables, second key
-  // is present only in the source hash table while the third key is present
-  // the destination hash table only.
-  std::vector<TypedValue> common_key;
-  common_key.emplace_back(0);
-  std::vector<TypedValue> exclusive_source_key, exclusive_destination_key;
-  exclusive_source_key.emplace_back(1);
-  exclusive_destination_key.emplace_back(2);
-
-  const int common_key_source_min = 3000;
-  TypedValue common_key_source_min_val(common_key_source_min);
-
-  const int common_key_destination_min = 4000;
-  TypedValue common_key_destination_min_val(common_key_destination_min);
-
-  const int exclusive_key_source_min = 100;
-  TypedValue exclusive_key_source_min_val(exclusive_key_source_min);
-
-  const int exclusive_key_destination_min = 200;
-  TypedValue exclusive_key_destination_min_val(exclusive_key_destination_min);
-
-  std::unique_ptr<AggregationStateMin> common_key_source_state(
-      static_cast<AggregationStateMin *>(
-          aggregation_handle_min_->createInitialState()));
-  std::unique_ptr<AggregationStateMin> common_key_destination_state(
-      static_cast<AggregationStateMin *>(
-          aggregation_handle_min_->createInitialState()));
-  std::unique_ptr<AggregationStateMin> exclusive_key_source_state(
-      static_cast<AggregationStateMin *>(
-          aggregation_handle_min_->createInitialState()));
-  std::unique_ptr<AggregationStateMin> exclusive_key_destination_state(
-      static_cast<AggregationStateMin *>(
-          aggregation_handle_min_->createInitialState()));
-
-  // Create min value states for keys.
-  aggregation_handle_min_derived->iterateUnaryInl(common_key_source_state.get(),
-                                                  common_key_source_min_val);
-  int actual_val = aggregation_handle_min_->finalize(*common_key_source_state)
-                       .getLiteral<int>();
-  EXPECT_EQ(common_key_source_min_val.getLiteral<int>(), actual_val);
-
-  aggregation_handle_min_derived->iterateUnaryInl(
-      common_key_destination_state.get(), common_key_destination_min_val);
-  actual_val = aggregation_handle_min_->finalize(*common_key_destination_state)
-                   .getLiteral<int>();
-  EXPECT_EQ(common_key_destination_min_val.getLiteral<int>(), actual_val);
-
-  aggregation_handle_min_derived->iterateUnaryInl(
-      exclusive_key_destination_state.get(), exclusive_key_destination_min_val);
-  actual_val =
-      aggregation_handle_min_->finalize(*exclusive_key_destination_state)
-          .getLiteral<int>();
-  EXPECT_EQ(exclusive_key_destination_min_val.getLiteral<int>(), actual_val);
-
-  aggregation_handle_min_derived->iterateUnaryInl(
-      exclusive_key_source_state.get(), exclusive_key_source_min_val);
-  actual_val = aggregation_handle_min_->finalize(*exclusive_key_source_state)
-                   .getLiteral<int>();
-  EXPECT_EQ(exclusive_key_source_min_val.getLiteral<int>(), actual_val);
-
-  // Add the key-state pairs to the hash tables.
-  unsigned char buffer[100];
-  buffer[0] = '\0';
-  memcpy(buffer + 1,
-         common_key_source_state.get()->getPayloadAddress(),
-         aggregation_handle_min_.get()->getPayloadSize());
-  source_hash_table_derived->putCompositeKey(common_key, buffer);
-
-  memcpy(buffer + 1,
-         common_key_destination_state.get()->getPayloadAddress(),
-         aggregation_handle_min_.get()->getPayloadSize());
-  destination_hash_table_derived->putCompositeKey(common_key, buffer);
-
-  memcpy(buffer + 1,
-         exclusive_key_source_state.get()->getPayloadAddress(),
-         aggregation_handle_min_.get()->getPayloadSize());
-  source_hash_table_derived->putCompositeKey(exclusive_source_key, buffer);
-
-  memcpy(buffer + 1,
-         exclusive_key_destination_state.get()->getPayloadAddress(),
-         aggregation_handle_min_.get()->getPayloadSize());
-  destination_hash_table_derived->putCompositeKey(exclusive_destination_key,
-                                                      buffer);
-
-  EXPECT_EQ(2u, destination_hash_table_derived->numEntries());
-  EXPECT_EQ(2u, source_hash_table_derived->numEntries());
-
-  AggregationOperationState::mergeGroupByHashTables(
-      source_hash_table.get(), destination_hash_table.get());
-
-  EXPECT_EQ(3u, destination_hash_table_derived->numEntries());
-
-  CheckMinValue<int>(
-      common_key_source_min_val.getLiteral<int>(),
-      aggregation_handle_min_derived->finalizeHashTableEntryFast(
-          destination_hash_table_derived->getSingleCompositeKey(common_key) +
-          1));
-  CheckMinValue<int>(exclusive_key_destination_min_val.getLiteral<int>(),
-                     aggregation_handle_min_derived->finalizeHashTableEntryFast(
-                         destination_hash_table_derived->getSingleCompositeKey(
-                             exclusive_destination_key) +
-                         1));
-  CheckMinValue<int>(exclusive_key_source_min_val.getLiteral<int>(),
-                     aggregation_handle_min_derived->finalizeHashTableEntryFast(
-                         source_hash_table_derived->getSingleCompositeKey(
-                             exclusive_source_key) +
-                         1));
-}
-
-}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/expressions/aggregation/tests/AggregationHandleSum_unittest.cpp
----------------------------------------------------------------------
diff --git a/expressions/aggregation/tests/AggregationHandleSum_unittest.cpp b/expressions/aggregation/tests/AggregationHandleSum_unittest.cpp
deleted file mode 100644
index 1d1c084..0000000
--- a/expressions/aggregation/tests/AggregationHandleSum_unittest.cpp
+++ /dev/null
@@ -1,611 +0,0 @@
-/**
- * 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 <cstddef>
-#include <cstdint>
-#include <memory>
-#include <vector>
-
-#include "catalog/CatalogTypedefs.hpp"
-#include "expressions/aggregation/AggregateFunction.hpp"
-#include "expressions/aggregation/AggregateFunctionFactory.hpp"
-#include "expressions/aggregation/AggregationHandle.hpp"
-#include "expressions/aggregation/AggregationHandleSum.hpp"
-#include "expressions/aggregation/AggregationID.hpp"
-#include "storage/AggregationOperationState.hpp"
-#include "storage/FastHashTableFactory.hpp"
-#include "storage/StorageManager.hpp"
-#include "types/CharType.hpp"
-#include "types/DatetimeIntervalType.hpp"
-#include "types/DoubleType.hpp"
-#include "types/FloatType.hpp"
-#include "types/IntType.hpp"
-#include "types/IntervalLit.hpp"
-#include "types/LongType.hpp"
-#include "types/Type.hpp"
-#include "types/TypeFactory.hpp"
-#include "types/TypeID.hpp"
-#include "types/TypedValue.hpp"
-#include "types/VarCharType.hpp"
-#include "types/YearMonthIntervalType.hpp"
-#include "types/containers/ColumnVector.hpp"
-
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-#include "types/containers/ColumnVectorsValueAccessor.hpp"
-#endif
-
-#include "gtest/gtest.h"
-
-namespace quickstep {
-
-class AggregationHandleSumTest : public ::testing::Test {
- protected:
-  static const int kNumSamples = 1000;
-
-  // Helper method that calls AggregationHandleSum::iterateUnaryInl() to
-  // aggregate 'value' into '*state'.
-  void iterateHandle(AggregationState *state, const TypedValue &value) {
-    static_cast<const AggregationHandleSum &>(*aggregation_handle_sum_)
-        .iterateUnaryInl(static_cast<AggregationStateSum *>(state), value);
-  }
-
-  void initializeHandle(const Type &type) {
-    aggregation_handle_sum_.reset(
-        AggregateFunctionFactory::Get(AggregationID::kSum)
-            .createHandle(std::vector<const Type *>(1, &type)));
-    aggregation_handle_sum_state_.reset(
-        aggregation_handle_sum_->createInitialState());
-  }
-
-  static bool ApplyToTypesTest(TypeID typeID) {
-    const Type &type =
-        (typeID == kChar || typeID == kVarChar)
-            ? TypeFactory::GetType(typeID, static_cast<std::size_t>(10))
-            : TypeFactory::GetType(typeID);
-
-    return AggregateFunctionFactory::Get(AggregationID::kSum)
-        .canApplyToTypes(std::vector<const Type *>(1, &type));
-  }
-
-  static bool ResultTypeForArgumentTypeTest(TypeID input_type_id,
-                                            TypeID output_type_id) {
-    const Type *result_type =
-        AggregateFunctionFactory::Get(AggregationID::kSum)
-            .resultTypeForArgumentTypes(std::vector<const Type *>(
-                1, &TypeFactory::GetType(input_type_id)));
-    return (result_type->getTypeID() == output_type_id);
-  }
-
-  template <typename CppType>
-  static void CheckSumValue(CppType expected,
-                            const AggregationHandle &target,
-                            const AggregationState &state) {
-    EXPECT_EQ(expected, target.finalize(state).getLiteral<CppType>());
-  }
-
-  template <typename CppType>
-  static void CheckSumValue(CppType expected, const TypedValue &value) {
-    EXPECT_EQ(expected, value.getLiteral<CppType>());
-  }
-
-  // Static templated method to set a meaningful to data types.
-  template <typename CppType>
-  static void SetDataType(int value, CppType *data) {
-    *data = value;
-  }
-
-  template <typename GenericType, typename PrecisionType>
-  void checkAggregationSumGeneric() {
-    const GenericType &type = GenericType::Instance(true);
-
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_sum_->finalize(*aggregation_handle_sum_state_)
-            .isNull());
-
-    typename GenericType::cpptype val;
-    typename PrecisionType::cpptype sum;
-    SetDataType(0, &sum);
-
-    iterateHandle(aggregation_handle_sum_state_.get(), type.makeNullValue());
-    for (int i = 0; i < kNumSamples; ++i) {
-      if (type.getTypeID() == kInt || type.getTypeID() == kLong) {
-        SetDataType(i - 10, &val);
-      } else {
-        SetDataType(static_cast<float>(i - 10) / 10, &val);
-      }
-      iterateHandle(aggregation_handle_sum_state_.get(), type.makeValue(&val));
-      sum += val;
-    }
-    iterateHandle(aggregation_handle_sum_state_.get(), type.makeNullValue());
-    CheckSumValue<typename PrecisionType::cpptype>(
-        sum, *aggregation_handle_sum_, *aggregation_handle_sum_state_);
-
-    // Test mergeStates().
-    std::unique_ptr<AggregationState> merge_state(
-        aggregation_handle_sum_->createInitialState());
-    aggregation_handle_sum_->mergeStates(*merge_state,
-                                         aggregation_handle_sum_state_.get());
-
-    iterateHandle(merge_state.get(), type.makeNullValue());
-    for (int i = 0; i < kNumSamples; ++i) {
-      if (type.getTypeID() == kInt || type.getTypeID() == kLong) {
-        SetDataType(i - 10, &val);
-      } else {
-        SetDataType(static_cast<float>(i - 10) / 10, &val);
-      }
-      iterateHandle(merge_state.get(), type.makeValue(&val));
-      sum += val;
-    }
-    aggregation_handle_sum_->mergeStates(*merge_state,
-                                         aggregation_handle_sum_state_.get());
-    CheckSumValue<typename PrecisionType::cpptype>(
-        sum, *aggregation_handle_sum_, *aggregation_handle_sum_state_);
-  }
-
-  template <typename GenericType, typename Output>
-  ColumnVector* createColumnVectorGeneric(const Type &type, Output *sum) {
-    NativeColumnVector *column = new NativeColumnVector(type, kNumSamples + 3);
-
-    typename GenericType::cpptype val;
-    SetDataType(0, sum);
-
-    column->appendTypedValue(type.makeNullValue());
-    for (int i = 0; i < kNumSamples; ++i) {
-      if (type.getTypeID() == kInt || type.getTypeID() == kLong) {
-        SetDataType(i - 10, &val);
-      } else {
-        SetDataType(static_cast<float>(i - 10) / 10, &val);
-      }
-      column->appendTypedValue(type.makeValue(&val));
-      *sum += val;
-      // One NULL in the middle.
-      if (i == kNumSamples / 2) {
-        column->appendTypedValue(type.makeNullValue());
-      }
-    }
-    column->appendTypedValue(type.makeNullValue());
-
-    return column;
-  }
-
-  template <typename GenericType, typename PrecisionType>
-  void checkAggregationSumGenericColumnVector() {
-    const GenericType &type = GenericType::Instance(true);
-
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_sum_->finalize(*aggregation_handle_sum_state_)
-            .isNull());
-
-    typename PrecisionType::cpptype sum;
-    std::vector<std::unique_ptr<ColumnVector>> column_vectors;
-    column_vectors.emplace_back(
-        createColumnVectorGeneric<GenericType, typename PrecisionType::cpptype>(
-            type, &sum));
-
-    std::unique_ptr<AggregationState> cv_state(
-        aggregation_handle_sum_->accumulateColumnVectors(column_vectors));
-
-    // Test the state generated directly by accumulateColumnVectors(), and also
-    // test after merging back.
-    CheckSumValue<typename PrecisionType::cpptype>(
-        sum, *aggregation_handle_sum_, *cv_state);
-
-    aggregation_handle_sum_->mergeStates(*cv_state,
-                                         aggregation_handle_sum_state_.get());
-    CheckSumValue<typename PrecisionType::cpptype>(
-        sum, *aggregation_handle_sum_, *aggregation_handle_sum_state_);
-  }
-
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-  template <typename GenericType, typename PrecisionType>
-  void checkAggregationSumGenericValueAccessor() {
-    const GenericType &type = GenericType::Instance(true);
-
-    initializeHandle(type);
-    EXPECT_TRUE(
-        aggregation_handle_sum_->finalize(*aggregation_handle_sum_state_)
-            .isNull());
-
-    typename PrecisionType::cpptype sum;
-    std::unique_ptr<ColumnVectorsValueAccessor> accessor(
-        new ColumnVectorsValueAccessor());
-    accessor->addColumn(
-        createColumnVectorGeneric<GenericType, typename PrecisionType::cpptype>(
-            type, &sum));
-
-    std::unique_ptr<AggregationState> va_state(
-        aggregation_handle_sum_->accumulateValueAccessor(
-            accessor.get(), std::vector<attribute_id>(1, 0)));
-
-    // Test the state generated directly by accumulateValueAccessor(), and also
-    // test after merging back.
-    CheckSumValue<typename PrecisionType::cpptype>(
-        sum, *aggregation_handle_sum_, *va_state);
-
-    aggregation_handle_sum_->mergeStates(*va_state,
-                                         aggregation_handle_sum_state_.get());
-    CheckSumValue<typename PrecisionType::cpptype>(
-        sum, *aggregation_handle_sum_, *aggregation_handle_sum_state_);
-  }
-#endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-
-  std::unique_ptr<AggregationHandle> aggregation_handle_sum_;
-  std::unique_ptr<AggregationState> aggregation_handle_sum_state_;
-  std::unique_ptr<StorageManager> storage_manager_;
-};
-
-const int AggregationHandleSumTest::kNumSamples;
-
-template <>
-void AggregationHandleSumTest::CheckSumValue<float>(
-    float val, const AggregationHandle &handle, const AggregationState &state) {
-  EXPECT_FLOAT_EQ(val, handle.finalize(state).getLiteral<float>());
-}
-
-template <>
-void AggregationHandleSumTest::CheckSumValue<double>(
-    double val,
-    const AggregationHandle &handle,
-    const AggregationState &state) {
-  EXPECT_DOUBLE_EQ(val, handle.finalize(state).getLiteral<double>());
-}
-
-template <>
-void AggregationHandleSumTest::SetDataType<DatetimeIntervalLit>(
-    int value, DatetimeIntervalLit *data) {
-  data->interval_ticks = value;
-}
-
-template <>
-void AggregationHandleSumTest::SetDataType<YearMonthIntervalLit>(
-    int value, YearMonthIntervalLit *data) {
-  data->months = value;
-}
-
-typedef AggregationHandleSumTest AggregationHandleSumDeathTest;
-
-TEST_F(AggregationHandleSumTest, IntTypeTest) {
-  checkAggregationSumGeneric<IntType, LongType>();
-}
-
-TEST_F(AggregationHandleSumTest, LongTypeTest) {
-  checkAggregationSumGeneric<LongType, LongType>();
-}
-
-TEST_F(AggregationHandleSumTest, FloatTypeTest) {
-  checkAggregationSumGeneric<FloatType, DoubleType>();
-}
-
-TEST_F(AggregationHandleSumTest, DoubleTypeTest) {
-  checkAggregationSumGeneric<DoubleType, DoubleType>();
-}
-
-TEST_F(AggregationHandleSumTest, DatetimeIntervalTypeTest) {
-  checkAggregationSumGeneric<DatetimeIntervalType, DatetimeIntervalType>();
-}
-
-TEST_F(AggregationHandleSumTest, YearMonthIntervalTypeTest) {
-  checkAggregationSumGeneric<YearMonthIntervalType, YearMonthIntervalType>();
-}
-
-TEST_F(AggregationHandleSumTest, IntTypeColumnVectorTest) {
-  checkAggregationSumGenericColumnVector<IntType, LongType>();
-}
-
-TEST_F(AggregationHandleSumTest, LongTypeColumnVectorTest) {
-  checkAggregationSumGenericColumnVector<LongType, LongType>();
-}
-
-TEST_F(AggregationHandleSumTest, FloatTypeColumnVectorTest) {
-  checkAggregationSumGenericColumnVector<FloatType, DoubleType>();
-}
-
-TEST_F(AggregationHandleSumTest, DoubleTypeColumnVectorTest) {
-  checkAggregationSumGenericColumnVector<DoubleType, DoubleType>();
-}
-
-TEST_F(AggregationHandleSumTest, DatetimeIntervalTypeColumnVectorTest) {
-  checkAggregationSumGenericColumnVector<DatetimeIntervalType,
-                                         DatetimeIntervalType>();
-}
-
-TEST_F(AggregationHandleSumTest, YearMonthIntervalTypeColumnVectorTest) {
-  checkAggregationSumGenericColumnVector<YearMonthIntervalType,
-                                         YearMonthIntervalType>();
-}
-
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-TEST_F(AggregationHandleSumTest, IntTypeValueAccessorTest) {
-  checkAggregationSumGenericValueAccessor<IntType, LongType>();
-}
-
-TEST_F(AggregationHandleSumTest, LongTypeValueAccessorTest) {
-  checkAggregationSumGenericValueAccessor<LongType, LongType>();
-}
-
-TEST_F(AggregationHandleSumTest, FloatTypeValueAccessorTest) {
-  checkAggregationSumGenericValueAccessor<FloatType, DoubleType>();
-}
-
-TEST_F(AggregationHandleSumTest, DoubleTypeValueAccessorTest) {
-  checkAggregationSumGenericValueAccessor<DoubleType, DoubleType>();
-}
-
-TEST_F(AggregationHandleSumTest, DatetimeIntervalTypeValueAccessorTest) {
-  checkAggregationSumGenericValueAccessor<DatetimeIntervalType,
-                                          DatetimeIntervalType>();
-}
-
-TEST_F(AggregationHandleSumTest, YearMonthIntervalTypeValueAccessorTest) {
-  checkAggregationSumGenericValueAccessor<YearMonthIntervalType,
-                                          YearMonthIntervalType>();
-}
-#endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-
-#ifdef QUICKSTEP_DEBUG
-TEST_F(AggregationHandleSumDeathTest, CharTypeTest) {
-  const Type &type = CharType::Instance(true, 10);
-  EXPECT_DEATH(initializeHandle(type), "");
-}
-
-TEST_F(AggregationHandleSumDeathTest, VarTypeTest) {
-  const Type &type = VarCharType::Instance(true, 10);
-  EXPECT_DEATH(initializeHandle(type), "");
-}
-
-TEST_F(AggregationHandleSumDeathTest, WrongTypeTest) {
-  const Type &int_non_null_type = IntType::Instance(false);
-  const Type &long_type = LongType::Instance(true);
-  const Type &double_type = DoubleType::Instance(true);
-  const Type &float_type = FloatType::Instance(true);
-  const Type &char_type = CharType::Instance(true, 10);
-  const Type &varchar_type = VarCharType::Instance(true, 10);
-
-  initializeHandle(IntType::Instance(true));
-  int int_val = 0;
-  std::int64_t long_val = 0;
-  double double_val = 0;
-  float float_val = 0;
-
-  // Passes.
-  iterateHandle(aggregation_handle_sum_state_.get(),
-                int_non_null_type.makeValue(&int_val));
-
-  EXPECT_DEATH(iterateHandle(aggregation_handle_sum_state_.get(),
-                             long_type.makeValue(&long_val)),
-               "");
-  EXPECT_DEATH(iterateHandle(aggregation_handle_sum_state_.get(),
-                             double_type.makeValue(&double_val)),
-               "");
-  EXPECT_DEATH(iterateHandle(aggregation_handle_sum_state_.get(),
-                             float_type.makeValue(&float_val)),
-               "");
-  EXPECT_DEATH(iterateHandle(aggregation_handle_sum_state_.get(),
-                             char_type.makeValue("asdf", 5)),
-               "");
-  EXPECT_DEATH(iterateHandle(aggregation_handle_sum_state_.get(),
-                             varchar_type.makeValue("asdf", 5)),
-               "");
-
-  // Test mergeStates() with incorrectly typed handles.
-  std::unique_ptr<AggregationHandle> aggregation_handle_sum_double(
-      AggregateFunctionFactory::Get(AggregationID::kSum)
-          .createHandle(std::vector<const Type *>(1, &double_type)));
-  std::unique_ptr<AggregationState> aggregation_state_sum_merge_double(
-      aggregation_handle_sum_double->createInitialState());
-  static_cast<const AggregationHandleSum &>(*aggregation_handle_sum_double)
-      .iterateUnaryInl(static_cast<AggregationStateSum *>(
-                           aggregation_state_sum_merge_double.get()),
-                       double_type.makeValue(&double_val));
-  EXPECT_DEATH(
-      aggregation_handle_sum_->mergeStates(*aggregation_state_sum_merge_double,
-                                           aggregation_handle_sum_state_.get()),
-      "");
-
-  std::unique_ptr<AggregationHandle> aggregation_handle_sum_float(
-      AggregateFunctionFactory::Get(AggregationID::kSum)
-          .createHandle(std::vector<const Type *>(1, &float_type)));
-  std::unique_ptr<AggregationState> aggregation_state_sum_merge_float(
-      aggregation_handle_sum_float->createInitialState());
-  static_cast<const AggregationHandleSum &>(*aggregation_handle_sum_float)
-      .iterateUnaryInl(static_cast<AggregationStateSum *>(
-                           aggregation_state_sum_merge_float.get()),
-                       float_type.makeValue(&float_val));
-  EXPECT_DEATH(
-      aggregation_handle_sum_->mergeStates(*aggregation_state_sum_merge_float,
-                                           aggregation_handle_sum_state_.get()),
-      "");
-}
-#endif
-
-TEST_F(AggregationHandleSumTest, canApplyToTypeTest) {
-  EXPECT_TRUE(ApplyToTypesTest(kInt));
-  EXPECT_TRUE(ApplyToTypesTest(kLong));
-  EXPECT_TRUE(ApplyToTypesTest(kFloat));
-  EXPECT_TRUE(ApplyToTypesTest(kDouble));
-  EXPECT_FALSE(ApplyToTypesTest(kChar));
-  EXPECT_FALSE(ApplyToTypesTest(kVarChar));
-  EXPECT_FALSE(ApplyToTypesTest(kDatetime));
-  EXPECT_TRUE(ApplyToTypesTest(kDatetimeInterval));
-  EXPECT_TRUE(ApplyToTypesTest(kYearMonthInterval));
-}
-
-TEST_F(AggregationHandleSumTest, ResultTypeForArgumentTypeTest) {
-  EXPECT_TRUE(ResultTypeForArgumentTypeTest(kInt, kLong));
-  EXPECT_TRUE(ResultTypeForArgumentTypeTest(kLong, kLong));
-  EXPECT_TRUE(ResultTypeForArgumentTypeTest(kFloat, kDouble));
-  EXPECT_TRUE(ResultTypeForArgumentTypeTest(kDouble, kDouble));
-  EXPECT_TRUE(
-      ResultTypeForArgumentTypeTest(kDatetimeInterval, kDatetimeInterval));
-  EXPECT_TRUE(
-      ResultTypeForArgumentTypeTest(kYearMonthInterval, kYearMonthInterval));
-}
-
-TEST_F(AggregationHandleSumTest, GroupByTableMergeTest) {
-  const Type &long_non_null_type = LongType::Instance(false);
-  initializeHandle(long_non_null_type);
-  storage_manager_.reset(new StorageManager("./test_sum_data"));
-  std::unique_ptr<AggregationStateHashTableBase> source_hash_table(
-      AggregationStateFastHashTableFactory::CreateResizable(
-          HashTableImplType::kSeparateChaining,
-          std::vector<const Type *>(1, &long_non_null_type),
-          10,
-          {aggregation_handle_sum_.get()->getPayloadSize()},
-          {aggregation_handle_sum_.get()},
-          storage_manager_.get()));
-  std::unique_ptr<AggregationStateHashTableBase> destination_hash_table(
-      AggregationStateFastHashTableFactory::CreateResizable(
-          HashTableImplType::kSeparateChaining,
-          std::vector<const Type *>(1, &long_non_null_type),
-          10,
-          {aggregation_handle_sum_.get()->getPayloadSize()},
-          {aggregation_handle_sum_.get()},
-          storage_manager_.get()));
-
-  AggregationStateFastHashTable *destination_hash_table_derived =
-      static_cast<AggregationStateFastHashTable *>(
-          destination_hash_table.get());
-
-  AggregationStateFastHashTable *source_hash_table_derived =
-      static_cast<AggregationStateFastHashTable *>(source_hash_table.get());
-
-  AggregationHandleSum *aggregation_handle_sum_derived =
-      static_cast<AggregationHandleSum *>(aggregation_handle_sum_.get());
-  // We create three keys: first is present in both the hash tables, second key
-  // is present only in the source hash table while the third key is present
-  // the destination hash table only.
-  std::vector<TypedValue> common_key;
-  common_key.emplace_back(static_cast<std::int64_t>(0));
-  std::vector<TypedValue> exclusive_source_key, exclusive_destination_key;
-  exclusive_source_key.emplace_back(static_cast<std::int64_t>(1));
-  exclusive_destination_key.emplace_back(static_cast<std::int64_t>(2));
-
-  const std::int64_t common_key_source_sum = 3000;
-  TypedValue common_key_source_sum_val(common_key_source_sum);
-
-  const std::int64_t common_key_destination_sum = 4000;
-  TypedValue common_key_destination_sum_val(common_key_destination_sum);
-
-  const std::int64_t merged_common_key =
-      common_key_source_sum + common_key_destination_sum;
-  TypedValue common_key_merged_val(merged_common_key);
-
-  const std::int64_t exclusive_key_source_sum = 100;
-  TypedValue exclusive_key_source_sum_val(exclusive_key_source_sum);
-
-  const std::int64_t exclusive_key_destination_sum = 200;
-  TypedValue exclusive_key_destination_sum_val(exclusive_key_destination_sum);
-
-  std::unique_ptr<AggregationStateSum> common_key_source_state(
-      static_cast<AggregationStateSum *>(
-          aggregation_handle_sum_->createInitialState()));
-  std::unique_ptr<AggregationStateSum> common_key_destination_state(
-      static_cast<AggregationStateSum *>(
-          aggregation_handle_sum_->createInitialState()));
-  std::unique_ptr<AggregationStateSum> exclusive_key_source_state(
-      static_cast<AggregationStateSum *>(
-          aggregation_handle_sum_->createInitialState()));
-  std::unique_ptr<AggregationStateSum> exclusive_key_destination_state(
-      static_cast<AggregationStateSum *>(
-          aggregation_handle_sum_->createInitialState()));
-
-  // Create sum value states for keys.
-  aggregation_handle_sum_derived->iterateUnaryInl(common_key_source_state.get(),
-                                                  common_key_source_sum_val);
-  std::int64_t actual_val =
-      aggregation_handle_sum_->finalize(*common_key_source_state)
-          .getLiteral<std::int64_t>();
-  EXPECT_EQ(common_key_source_sum_val.getLiteral<std::int64_t>(), actual_val);
-
-  aggregation_handle_sum_derived->iterateUnaryInl(
-      common_key_destination_state.get(), common_key_destination_sum_val);
-  actual_val = aggregation_handle_sum_->finalize(*common_key_destination_state)
-                   .getLiteral<std::int64_t>();
-  EXPECT_EQ(common_key_destination_sum_val.getLiteral<std::int64_t>(),
-            actual_val);
-
-  aggregation_handle_sum_derived->iterateUnaryInl(
-      exclusive_key_destination_state.get(), exclusive_key_destination_sum_val);
-  actual_val =
-      aggregation_handle_sum_->finalize(*exclusive_key_destination_state)
-          .getLiteral<std::int64_t>();
-  EXPECT_EQ(exclusive_key_destination_sum_val.getLiteral<std::int64_t>(),
-            actual_val);
-
-  aggregation_handle_sum_derived->iterateUnaryInl(
-      exclusive_key_source_state.get(), exclusive_key_source_sum_val);
-  actual_val = aggregation_handle_sum_->finalize(*exclusive_key_source_state)
-                   .getLiteral<std::int64_t>();
-  EXPECT_EQ(exclusive_key_source_sum_val.getLiteral<std::int64_t>(),
-            actual_val);
-
-  // Add the key-state pairs to the hash tables.
-  unsigned char buffer[100];
-  buffer[0] = '\0';
-  memcpy(buffer + 1,
-         common_key_source_state.get()->getPayloadAddress(),
-         aggregation_handle_sum_.get()->getPayloadSize());
-  source_hash_table_derived->putCompositeKey(common_key, buffer);
-
-  memcpy(buffer + 1,
-         common_key_destination_state.get()->getPayloadAddress(),
-         aggregation_handle_sum_.get()->getPayloadSize());
-  destination_hash_table_derived->putCompositeKey(common_key, buffer);
-
-  memcpy(buffer + 1,
-         exclusive_key_source_state.get()->getPayloadAddress(),
-         aggregation_handle_sum_.get()->getPayloadSize());
-  source_hash_table_derived->putCompositeKey(exclusive_source_key, buffer);
-
-  memcpy(buffer + 1,
-         exclusive_key_destination_state.get()->getPayloadAddress(),
-         aggregation_handle_sum_.get()->getPayloadSize());
-  destination_hash_table_derived->putCompositeKey(exclusive_destination_key,
-                                                      buffer);
-
-  EXPECT_EQ(2u, destination_hash_table_derived->numEntries());
-  EXPECT_EQ(2u, source_hash_table_derived->numEntries());
-
-  AggregationOperationState::mergeGroupByHashTables(
-      source_hash_table.get(), destination_hash_table.get());
-
-  EXPECT_EQ(3u, destination_hash_table_derived->numEntries());
-
-  CheckSumValue<std::int64_t>(
-      common_key_merged_val.getLiteral<std::int64_t>(),
-      aggregation_handle_sum_derived->finalizeHashTableEntryFast(
-          destination_hash_table_derived->getSingleCompositeKey(common_key) +
-          1));
-  CheckSumValue<std::int64_t>(
-      exclusive_key_destination_sum_val.getLiteral<std::int64_t>(),
-      aggregation_handle_sum_derived->finalizeHashTableEntryFast(
-          destination_hash_table_derived->getSingleCompositeKey(
-              exclusive_destination_key) +
-          1));
-  CheckSumValue<std::int64_t>(
-      exclusive_key_source_sum_val.getLiteral<std::int64_t>(),
-      aggregation_handle_sum_derived->finalizeHashTableEntryFast(
-          source_hash_table_derived->getSingleCompositeKey(
-              exclusive_source_key) +
-          1));
-}
-
-}  // namespace quickstep

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/expressions/predicate/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/expressions/predicate/CMakeLists.txt b/expressions/predicate/CMakeLists.txt
deleted file mode 100644
index b90562c..0000000
--- a/expressions/predicate/CMakeLists.txt
+++ /dev/null
@@ -1,159 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# Declare micro-libs:
-add_library(quickstep_expressions_predicate_ComparisonPredicate
-            ComparisonPredicate.cpp
-            ComparisonPredicate.hpp)
-add_library(quickstep_expressions_predicate_ConjunctionPredicate
-            ConjunctionPredicate.cpp
-            ConjunctionPredicate.hpp)
-add_library(quickstep_expressions_predicate_DisjunctionPredicate
-            DisjunctionPredicate.cpp
-            DisjunctionPredicate.hpp)
-add_library(quickstep_expressions_predicate_NegationPredicate
-            NegationPredicate.cpp
-            NegationPredicate.hpp)
-add_library(quickstep_expressions_predicate_Predicate
-            Predicate.cpp
-            Predicate.hpp)
-add_library(quickstep_expressions_predicate_PredicateCost
-            ../../empty_src.cpp
-            PredicateCost.hpp)
-add_library(quickstep_expressions_predicate_PredicateWithList
-            ../../empty_src.cpp
-            PredicateWithList.hpp)
-add_library(quickstep_expressions_predicate_TrivialPredicates
-            ../../empty_src.cpp
-            TrivialPredicates.hpp)
-
-# Link dependencies:
-target_link_libraries(quickstep_expressions_predicate_ComparisonPredicate
-                      quickstep_catalog_CatalogAttribute
-                      quickstep_catalog_CatalogTypedefs
-                      quickstep_expressions_Expressions_proto
-                      quickstep_expressions_predicate_Predicate
-                      quickstep_expressions_predicate_PredicateCost
-                      quickstep_expressions_scalar_Scalar
-                      quickstep_expressions_scalar_ScalarAttribute
-                      quickstep_storage_IndexSubBlock
-                      quickstep_storage_StorageBlockInfo
-                      quickstep_storage_SubBlocksReference
-                      quickstep_storage_TupleStorageSubBlock
-                      quickstep_storage_ValueAccessor
-                      quickstep_types_Type
-                      quickstep_types_TypeErrors
-                      quickstep_types_TypedValue
-                      quickstep_types_containers_ColumnVector
-                      quickstep_types_operations_Operation_proto
-                      quickstep_types_operations_comparisons_Comparison
-                      quickstep_utility_Macros
-                      quickstep_utility_PtrVector)
-target_link_libraries(quickstep_expressions_predicate_ConjunctionPredicate
-                      quickstep_catalog_CatalogTypedefs
-                      quickstep_expressions_Expressions_proto
-                      quickstep_expressions_predicate_Predicate
-                      quickstep_expressions_predicate_PredicateWithList
-                      quickstep_storage_StorageBlockInfo
-                      quickstep_storage_TupleIdSequence
-                      quickstep_storage_ValueAccessor
-                      quickstep_utility_Macros
-                      quickstep_utility_PtrList)
-target_link_libraries(quickstep_expressions_predicate_DisjunctionPredicate
-                      quickstep_catalog_CatalogTypedefs
-                      quickstep_expressions_Expressions_proto
-                      quickstep_expressions_predicate_Predicate
-                      quickstep_expressions_predicate_PredicateWithList
-                      quickstep_storage_StorageBlockInfo
-                      quickstep_storage_TupleIdSequence
-                      quickstep_storage_ValueAccessor
-                      quickstep_utility_Macros
-                      quickstep_utility_PtrList)
-target_link_libraries(quickstep_expressions_predicate_NegationPredicate
-                      quickstep_catalog_CatalogTypedefs
-                      quickstep_expressions_Expressions_proto
-                      quickstep_expressions_predicate_Predicate
-                      quickstep_storage_StorageBlockInfo
-                      quickstep_storage_TupleIdSequence
-                      quickstep_utility_Macros)
-target_link_libraries(quickstep_expressions_predicate_Predicate
-                      quickstep_catalog_CatalogTypedefs
-                      quickstep_expressions_Expressions_proto
-                      quickstep_storage_StorageBlockInfo
-                      quickstep_storage_TupleIdSequence
-                      quickstep_storage_ValueAccessor
-                      quickstep_utility_Macros)
-target_link_libraries(quickstep_expressions_predicate_PredicateWithList
-                      quickstep_expressions_predicate_Predicate
-                      quickstep_utility_Macros
-                      quickstep_utility_PtrList)
-target_link_libraries(quickstep_expressions_predicate_TrivialPredicates
-                      quickstep_catalog_CatalogTypedefs
-                      quickstep_expressions_Expressions_proto
-                      quickstep_expressions_predicate_Predicate
-                      quickstep_storage_StorageBlockInfo
-                      quickstep_utility_Macros)
-
-# Submodule all-in-one library:
-add_library(quickstep_expressions_predicate ../../empty_src.cpp)
-target_link_libraries(quickstep_expressions_predicate
-                      quickstep_expressions_predicate_ComparisonPredicate
-                      quickstep_expressions_predicate_ConjunctionPredicate
-                      quickstep_expressions_predicate_DisjunctionPredicate
-                      quickstep_expressions_predicate_NegationPredicate
-                      quickstep_expressions_predicate_Predicate
-                      quickstep_expressions_predicate_PredicateCost
-                      quickstep_expressions_predicate_PredicateWithList
-                      quickstep_expressions_predicate_TrivialPredicates)
-
-# Tests:
-add_executable(Predicate_unittest "${CMAKE_CURRENT_SOURCE_DIR}/tests/Predicate_unittest.cpp")
-target_link_libraries(Predicate_unittest
-                      gtest
-                      gtest_main
-                      quickstep_catalog_CatalogAttribute
-                      quickstep_catalog_CatalogDatabase
-                      quickstep_catalog_CatalogRelation
-                      quickstep_expressions_ExpressionFactories
-                      quickstep_expressions_predicate_ComparisonPredicate
-                      quickstep_expressions_predicate_ConjunctionPredicate
-                      quickstep_expressions_predicate_DisjunctionPredicate
-                      quickstep_expressions_predicate_NegationPredicate
-                      quickstep_expressions_predicate_Predicate
-                      quickstep_expressions_predicate_PredicateWithList
-                      quickstep_expressions_predicate_TrivialPredicates
-                      quickstep_expressions_scalar_Scalar
-                      quickstep_expressions_scalar_ScalarAttribute
-                      quickstep_expressions_scalar_ScalarBinaryExpression
-                      quickstep_expressions_scalar_ScalarLiteral
-                      quickstep_expressions_scalar_ScalarUnaryExpression
-                      quickstep_types_DatetimeLit
-                      quickstep_types_IntervalLit
-                      quickstep_types_Type
-                      quickstep_types_TypeFactory
-                      quickstep_types_TypeID
-                      quickstep_types_TypedValue
-                      quickstep_types_operations_binaryoperations_BinaryOperation
-                      quickstep_types_operations_binaryoperations_BinaryOperationID
-                      quickstep_types_operations_comparisons_Comparison
-                      quickstep_types_operations_comparisons_ComparisonFactory
-                      quickstep_types_operations_comparisons_ComparisonID
-                      quickstep_types_operations_unaryoperations_UnaryOperation
-                      quickstep_types_operations_unaryoperations_UnaryOperationID
-                      quickstep_utility_Macros
-                      quickstep_utility_PtrList)
-add_test(Predicate_unittest Predicate_unittest)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/156290a4/expressions/predicate/ComparisonPredicate.cpp
----------------------------------------------------------------------
diff --git a/expressions/predicate/ComparisonPredicate.cpp b/expressions/predicate/ComparisonPredicate.cpp
deleted file mode 100644
index 5f8612e..0000000
--- a/expressions/predicate/ComparisonPredicate.cpp
+++ /dev/null
@@ -1,376 +0,0 @@
-/**
- * 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 "expressions/predicate/ComparisonPredicate.hpp"
-
-#include <cstddef>
-#include <limits>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "catalog/CatalogAttribute.hpp"
-#include "expressions/Expressions.pb.h"
-#include "expressions/predicate/PredicateCost.hpp"
-#include "expressions/scalar/Scalar.hpp"
-#include "expressions/scalar/ScalarAttribute.hpp"
-#include "storage/IndexSubBlock.hpp"
-#include "storage/SubBlocksReference.hpp"
-#include "storage/TupleStorageSubBlock.hpp"
-#include "storage/ValueAccessor.hpp"
-#include "types/Type.hpp"
-#include "types/TypeErrors.hpp"
-#include "types/TypedValue.hpp"
-#include "types/containers/ColumnVector.hpp"
-#include "types/operations/Operation.pb.h"
-#include "types/operations/comparisons/Comparison.hpp"
-#include "utility/Macros.hpp"
-#include "utility/PtrVector.hpp"
-
-#include "glog/logging.h"
-
-namespace quickstep {
-
-class TupleIdSequence;
-
-ComparisonPredicate::ComparisonPredicate(const Comparison &comparison,
-                                         Scalar *left_operand,
-                                         Scalar *right_operand)
-    : comparison_(comparison),
-      left_operand_(left_operand),
-      right_operand_(right_operand) {
-  initHelper(false);
-}
-
-serialization::Predicate ComparisonPredicate::getProto() const {
-  serialization::Predicate proto;
-  proto.set_predicate_type(serialization::Predicate::COMPARISON);
-  proto.MutableExtension(serialization::ComparisonPredicate::comparison)->CopyFrom(comparison_.getProto());
-  proto.MutableExtension(serialization::ComparisonPredicate::left_operand)->CopyFrom(left_operand_->getProto());
-  proto.MutableExtension(serialization::ComparisonPredicate::right_operand)->CopyFrom(right_operand_->getProto());
-
-  return proto;
-}
-
-Predicate* ComparisonPredicate::clone() const {
-  return new ComparisonPredicate(comparison_,
-                                 left_operand_->clone(),
-                                 right_operand_->clone());
-}
-
-bool ComparisonPredicate::isAttributeLiteralComparisonPredicate() const {
-  return (left_operand_->hasStaticValue() && (right_operand_->getDataSource() == Scalar::kAttribute))
-         || (right_operand_->hasStaticValue() && (left_operand_->getDataSource() == Scalar::kAttribute));
-}
-
-bool ComparisonPredicate::matchesForSingleTuple(const ValueAccessor &accessor,
-                                                const tuple_id tuple) const {
-  if (fast_comparator_.get() == nullptr) {
-    return static_result_;
-  } else {
-    return fast_comparator_->compareTypedValues(left_operand_->getValueForSingleTuple(accessor, tuple),
-                                                right_operand_->getValueForSingleTuple(accessor, tuple));
-  }
-}
-
-bool ComparisonPredicate::matchesForJoinedTuples(
-    const ValueAccessor &left_accessor,
-    const relation_id left_relation_id,
-    const tuple_id left_tuple_id,
-    const ValueAccessor &right_accessor,
-    const relation_id right_relation_id,
-    const tuple_id right_tuple_id) const {
-  if (fast_comparator_.get() == nullptr) {
-    return static_result_;
-  } else {
-    return fast_comparator_->compareTypedValues(
-        left_operand_->getValueForJoinedTuples(left_accessor,
-                                               left_relation_id,
-                                               left_tuple_id,
-                                               right_accessor,
-                                               right_relation_id,
-                                               right_tuple_id),
-        right_operand_->getValueForJoinedTuples(left_accessor,
-                                                left_relation_id,
-                                                left_tuple_id,
-                                                right_accessor,
-                                                right_relation_id,
-                                                right_tuple_id));
-  }
-}
-
-TupleIdSequence* ComparisonPredicate::getAllMatches(
-    ValueAccessor *accessor,
-    const SubBlocksReference *sub_blocks_ref,
-    const TupleIdSequence *filter,
-    const TupleIdSequence *existence_map) const {
-#ifdef QUICKSTEP_ENABLE_VECTOR_PREDICATE_SHORT_CIRCUIT
-  static constexpr bool short_circuit = true;
-#else
-  static constexpr bool short_circuit = false;
-#endif
-
-  if (fast_comparator_.get() == nullptr) {
-    return GenerateSequenceForStaticResult(accessor, filter, existence_map, static_result_);
-  } else if (sub_blocks_ref != nullptr && comparison_.isBasicComparison()) {
-    // NOTE(Jianqiao): sub-block indices only apply to basic comparisons.
-
-    // Try to find a method faster than a simple scan to evaluate this
-    // comparison.
-    std::size_t fastest_subblock = std::numeric_limits<std::size_t>::max();
-    predicate_cost_t lowest_cost
-        = sub_blocks_ref->tuple_store.estimatePredicateEvaluationCost(*this);
-    for (std::size_t index_id = 0; index_id < sub_blocks_ref->indices.size(); ++index_id) {
-      if (sub_blocks_ref->indices_consistent[index_id]) {
-        const predicate_cost_t index_cost
-            = sub_blocks_ref->indices[index_id].estimatePredicateEvaluationCost(*this);
-        if (index_cost < lowest_cost) {
-          fastest_subblock = index_id;
-          lowest_cost = index_cost;
-        }
-      }
-    }
-    if (fastest_subblock != std::numeric_limits<std::size_t>::max()) {
-      return sub_blocks_ref->indices[fastest_subblock].getMatchesForPredicate(*this, filter);
-    } else if (!PredicateCostIsSimpleScan(lowest_cost)) {
-      return sub_blocks_ref->tuple_store.getMatchesForPredicate(*this, filter);
-    }
-  }
-
-  // When short-circuiting is turned on, we should only evaluate the comparison
-  // for tuples that are set in '*filter'. We might need to generate a
-  // ColumnVector of values for the operand on either side of the comparison
-  // with a call to Scalar::getAllValues() before we evaluate the comparison,
-  // but we only actually care about the operand's values for the tuples that
-  // are set in '*filter' (evaluating the Scalar's value for other tuples would
-  // be a waste of memory and computation). Therefore, we set up a
-  // ValueAccessor here that only iterates over the tuples in '*filter', and we
-  // pass it in to Scalar::getAllValues() calls below so that we only generate
-  // those values that we actually need to check. We use '*filter' in place of
-  // the existence bitmap in such cases, because the filter effectively IS the
-  // existence bitmap for '*short_circuit_adapter' (this way, the tuple IDs
-  // don't get screwed up and still correspond to the original "physical" IDs
-  // in the block).
-  std::unique_ptr<ValueAccessor> short_circuit_adapter;
-  if (short_circuit && (filter != nullptr)) {
-    short_circuit_adapter.reset(accessor->createSharedTupleIdSequenceAdapterVirtual(*filter));
-  }
-
-  // NOTE(chasseur): We don't check if both operations have a static value,
-  // because if they did then this comparison would have a static result
-  // which is handled above.
-  if (left_operand_->hasStaticValue()) {
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-    const attribute_id right_operand_attr_id
-        = right_operand_->getAttributeIdForValueAccessor();
-    if (right_operand_attr_id != -1) {
-      return fast_comparator_->compareStaticValueAndValueAccessor(
-          left_operand_->getStaticValue(),
-          accessor,
-          right_operand_attr_id,
-          filter);
-    }
-#endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-
-    if (short_circuit_adapter) {
-      std::unique_ptr<ColumnVector> right_values(right_operand_->getAllValues(
-          short_circuit_adapter.get(),
-          sub_blocks_ref));
-      return fast_comparator_->compareStaticValueAndColumnVector(
-          left_operand_->getStaticValue(),
-          *right_values,
-          nullptr,
-          filter);
-    } else {
-      std::unique_ptr<ColumnVector> right_values(right_operand_->getAllValues(
-          accessor,
-          sub_blocks_ref));
-      return fast_comparator_->compareStaticValueAndColumnVector(
-          left_operand_->getStaticValue(),
-          *right_values,
-          filter,
-          existence_map);
-    }
-  } else if (right_operand_->hasStaticValue()) {
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-    const attribute_id left_operand_attr_id
-        = left_operand_->getAttributeIdForValueAccessor();
-    if (left_operand_attr_id != -1) {
-      return fast_comparator_->compareValueAccessorAndStaticValue(
-          accessor,
-          left_operand_attr_id,
-          right_operand_->getStaticValue(),
-          filter);
-    }
-#endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-
-    if (short_circuit_adapter) {
-      std::unique_ptr<ColumnVector> left_values(left_operand_->getAllValues(
-          short_circuit_adapter.get(),
-          sub_blocks_ref));
-      return fast_comparator_->compareColumnVectorAndStaticValue(
-          *left_values,
-          right_operand_->getStaticValue(),
-          nullptr,
-          filter);
-    } else {
-      std::unique_ptr<ColumnVector> left_values(left_operand_->getAllValues(
-          accessor,
-          sub_blocks_ref));
-      return fast_comparator_->compareColumnVectorAndStaticValue(
-          *left_values,
-          right_operand_->getStaticValue(),
-          filter,
-          existence_map);
-    }
-  } else {
-#ifdef QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-    const attribute_id left_operand_attr_id
-        = left_operand_->getAttributeIdForValueAccessor();
-    const attribute_id right_operand_attr_id
-        = right_operand_->getAttributeIdForValueAccessor();
-
-    if (left_operand_attr_id != -1) {
-      if (right_operand_attr_id != -1) {
-        return fast_comparator_->compareSingleValueAccessor(accessor,
-                                                            left_operand_attr_id,
-                                                            right_operand_attr_id,
-                                                            filter);
-      } else {
-        if (short_circuit_adapter) {
-          std::unique_ptr<ColumnVector> right_values(right_operand_->getAllValues(
-              short_circuit_adapter.get(),
-              sub_blocks_ref));
-          return fast_comparator_->compareValueAccessorAndColumnVector(
-              short_circuit_adapter.get(),
-              left_operand_attr_id,
-              *right_values,
-              nullptr,
-              filter);
-        } else {
-          std::unique_ptr<ColumnVector> right_values(right_operand_->getAllValues(
-              accessor,
-              sub_blocks_ref));
-          return fast_comparator_->compareValueAccessorAndColumnVector(accessor,
-                                                                       left_operand_attr_id,
-                                                                       *right_values,
-                                                                       filter,
-                                                                       existence_map);
-        }
-      }
-    } else if (right_operand_attr_id != -1) {
-      if (short_circuit_adapter) {
-        std::unique_ptr<ColumnVector> left_values(left_operand_->getAllValues(
-            short_circuit_adapter.get(),
-            sub_blocks_ref));
-        return fast_comparator_->compareColumnVectorAndValueAccessor(
-            *left_values,
-            short_circuit_adapter.get(),
-            right_operand_attr_id,
-            nullptr,
-            filter);
-      } else {
-        std::unique_ptr<ColumnVector> left_values(left_operand_->getAllValues(
-            accessor,
-            sub_blocks_ref));
-        return fast_comparator_->compareColumnVectorAndValueAccessor(*left_values,
-                                                                     accessor,
-                                                                     right_operand_attr_id,
-                                                                     filter,
-                                                                     existence_map);
-      }
-    }
-#endif  // QUICKSTEP_ENABLE_VECTOR_COPY_ELISION_SELECTION
-
-    if (short_circuit_adapter) {
-      std::unique_ptr<ColumnVector> left_values(left_operand_->getAllValues(
-          short_circuit_adapter.get(),
-          sub_blocks_ref));
-      std::unique_ptr<ColumnVector> right_values(right_operand_->getAllValues(
-          short_circuit_adapter.get(),
-          sub_blocks_ref));
-      return fast_comparator_->compareColumnVectors(*left_values,
-                                                    *right_values,
-                                                    nullptr,
-                                                    filter);
-    } else {
-      std::unique_ptr<ColumnVector> left_values(left_operand_->getAllValues(
-          accessor,
-          sub_blocks_ref));
-      std::unique_ptr<ColumnVector> right_values(right_operand_->getAllValues(
-          accessor,
-          sub_blocks_ref));
-      return fast_comparator_->compareColumnVectors(*left_values,
-                                                    *right_values,
-                                                    filter,
-                                                    existence_map);
-    }
-  }
-}
-
-bool ComparisonPredicate::getStaticResult() const {
-  if (fast_comparator_.get() == nullptr) {
-    return static_result_;
-  } else {
-    FATAL_ERROR("Called getStaticResult() on a predicate which has no static result");
-  }
-}
-
-std::pair<bool, attribute_id> ComparisonPredicate::getAttributeFromAttributeLiteralComparison() const {
-  DCHECK(isAttributeLiteralComparisonPredicate());
-  if (left_operand_->hasStaticValue()) {
-    DCHECK_EQ(Scalar::kAttribute, right_operand_->getDataSource());
-    return std::pair<bool, attribute_id>(
-        false,
-        static_cast<const ScalarAttribute&>(*right_operand_).getAttribute().getID());
-  } else {
-    DCHECK_EQ(Scalar::kAttribute, left_operand_->getDataSource());
-    return std::pair<bool, attribute_id>(
-        true,
-        static_cast<const ScalarAttribute&>(*left_operand_).getAttribute().getID());
-  }
-}
-
-void ComparisonPredicate::initHelper(bool own_children) {
-  if (comparison_.canCompareTypes(left_operand_->getType(), right_operand_->getType())) {
-    if (left_operand_->hasStaticValue() && right_operand_->hasStaticValue()) {
-      static_result_ = comparison_.compareTypedValuesChecked(left_operand_->getStaticValue(),
-                                                             left_operand_->getType(),
-                                                             right_operand_->getStaticValue(),
-                                                             right_operand_->getType());
-    } else {
-      fast_comparator_.reset(comparison_.makeUncheckedComparatorForTypes(left_operand_->getType(),
-                                                                         right_operand_->getType()));
-    }
-  } else {
-    const Type &left_operand_type = left_operand_->getType();
-    const Type &right_operand_type = right_operand_->getType();
-    if (!own_children) {
-      left_operand_.release();
-      right_operand_.release();
-    }
-    throw OperationInapplicableToType(comparison_.getName(),
-                                      2,
-                                      left_operand_type.getName().c_str(),
-                                      right_operand_type.getName().c_str());
-  }
-}
-
-}  // namespace quickstep