You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by zu...@apache.org on 2016/07/16 22:51:55 UTC
incubator-quickstep git commit: Added Comparisons for the Date Type.
[Forced Update!]
Repository: incubator-quickstep
Updated Branches:
refs/heads/date-cmp 491466f0f -> cf81b5e62 (forced update)
Added Comparisons for the Date Type.
Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/cf81b5e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/cf81b5e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/cf81b5e6
Branch: refs/heads/date-cmp
Commit: cf81b5e62ddf7e96f3fcdb1bcc97ee0768a6997a
Parents: 9a398d3
Author: Zuyu Zhang <zu...@twitter.com>
Authored: Fri Jul 15 16:56:14 2016 -0700
Committer: Zuyu Zhang <zu...@twitter.com>
Committed: Sat Jul 16 15:51:21 2016 -0700
----------------------------------------------------------------------
.../operations/comparisons/BasicComparison.cpp | 6 ++-
.../operations/comparisons/BasicComparison.hpp | 29 ++++++++++--
types/operations/comparisons/CMakeLists.txt | 2 -
types/operations/comparisons/ComparisonUtil.hpp | 34 +++++++++++++++
.../comparisons/LiteralComparators.hpp | 24 +++++-----
.../comparisons/tests/Comparison_unittest.cpp | 46 +++++++++++++++++---
6 files changed, 115 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cf81b5e6/types/operations/comparisons/BasicComparison.cpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/BasicComparison.cpp b/types/operations/comparisons/BasicComparison.cpp
index 21b92ca..ed0ce62 100644
--- a/types/operations/comparisons/BasicComparison.cpp
+++ b/types/operations/comparisons/BasicComparison.cpp
@@ -23,7 +23,6 @@
#include "types/Type.hpp"
#include "types/TypeID.hpp"
#include "utility/EqualsAnyConstant.hpp"
-#include "utility/Macros.hpp"
#include "glog/logging.h"
@@ -49,6 +48,9 @@ bool BasicComparison::canCompareTypes(const Type &left, const Type &right) const
return false;
}
}
+ case kDate: {
+ return right.getTypeID() == kDate;
+ }
case kDatetime: {
return right.getTypeID() == kDatetime;
}
@@ -89,7 +91,7 @@ bool BasicComparison::canComparePartialTypes(const Type *left_type,
const Type *known_type = (left_type != nullptr) ? left_type : right_type;
return QUICKSTEP_EQUALS_ANY_CONSTANT(known_type->getTypeID(),
kInt, kLong, kFloat, kDouble,
- kDatetime, kDatetimeInterval, kYearMonthInterval,
+ kDate, kDatetime, kDatetimeInterval, kYearMonthInterval,
kChar, kVarChar);
}
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cf81b5e6/types/operations/comparisons/BasicComparison.hpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/BasicComparison.hpp b/types/operations/comparisons/BasicComparison.hpp
index 9741c32..c95f774 100644
--- a/types/operations/comparisons/BasicComparison.hpp
+++ b/types/operations/comparisons/BasicComparison.hpp
@@ -22,8 +22,6 @@
#include <cstdint>
#include <string>
-#include "types/DatetimeLit.hpp"
-#include "types/IntervalLit.hpp"
#include "types/Type.hpp"
#include "types/TypeErrors.hpp"
#include "types/TypeFactory.hpp"
@@ -37,6 +35,11 @@
namespace quickstep {
+struct DateLit;
+struct DatetimeIntervalLit;
+struct DatetimeLit;
+struct YearMonthIntervalLit;
+
/** \addtogroup Types
* @{
*/
@@ -161,6 +164,18 @@ bool BasicComparison::compareTypedValuesCheckedHelper(const TypedValue &left,
}
break;
}
+ case kDate: {
+ if (right.getTypeID() == kDate) {
+ if (left.isNull() || right.isNull()) {
+ return false;
+ }
+
+ ComparisonFunctor<DateLit> comparison_functor;
+ return comparison_functor(left.getLiteral<DateLit>(), right.getLiteral<DateLit>());
+ }
+ LOG(FATAL) << "Comparison " << getName() << " can not be applied to types "
+ << left_type.getName() << " and " << right_type.getName();
+ }
case kDatetime: {
if (right.getTypeID() == kDatetime) {
if (left.isNull() || right.isNull()) {
@@ -269,7 +284,8 @@ UncheckedComparator* BasicComparison::makeUncheckedComparatorForTypesHelper(cons
const Type &right) const {
if (left.getSuperTypeID() == Type::kNumeric && right.getSuperTypeID() == Type::kNumeric) {
return makeNumericComparatorOuterHelper<LiteralComparator>(left, right);
- } else if ((left.getTypeID() == kDatetime && right.getTypeID() == kDatetime) ||
+ } else if ((left.getTypeID() == kDate && right.getTypeID() == kDate) ||
+ (left.getTypeID() == kDatetime && right.getTypeID() == kDatetime) ||
(left.getTypeID() == kDatetimeInterval && right.getTypeID() == kDatetimeInterval) ||
(left.getTypeID() == kYearMonthInterval && right.getTypeID() == kYearMonthInterval)) {
return makeDateComparatorOuterHelper<LiteralComparator>(left, right);
@@ -358,6 +374,12 @@ UncheckedComparator* BasicComparison::makeDateComparatorOuterHelper(
const Type &left,
const Type &right) const {
switch (left.getTypeID()) {
+ case kDate:
+ if (left.isNullable()) {
+ return makeDateComparatorInnerHelper<ComparatorType, DateLit, true>(left, right);
+ } else {
+ return makeDateComparatorInnerHelper<ComparatorType, DateLit, false>(left, right);
+ }
case kDatetime:
if (left.isNullable()) {
return makeDateComparatorInnerHelper<ComparatorType, DatetimeLit, true>(left, right);
@@ -389,6 +411,7 @@ UncheckedComparator* BasicComparison::makeDateComparatorInnerHelper(
const Type &left,
const Type &right) const {
switch (right.getTypeID()) {
+ case kDate:
case kDatetime:
case kDatetimeInterval:
case kYearMonthInterval:
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cf81b5e6/types/operations/comparisons/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/CMakeLists.txt b/types/operations/comparisons/CMakeLists.txt
index d2dfecf..d48cdc2 100644
--- a/types/operations/comparisons/CMakeLists.txt
+++ b/types/operations/comparisons/CMakeLists.txt
@@ -64,8 +64,6 @@ target_link_libraries(quickstep_types_operations_comparisons_AsciiStringComparat
quickstep_utility_Macros)
target_link_libraries(quickstep_types_operations_comparisons_BasicComparison
glog
- quickstep_types_DatetimeLit
- quickstep_types_IntervalLit
quickstep_types_Type
quickstep_types_TypeErrors
quickstep_types_TypeFactory
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cf81b5e6/types/operations/comparisons/ComparisonUtil.hpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/ComparisonUtil.hpp b/types/operations/comparisons/ComparisonUtil.hpp
index d7da3fd..d589192 100644
--- a/types/operations/comparisons/ComparisonUtil.hpp
+++ b/types/operations/comparisons/ComparisonUtil.hpp
@@ -163,6 +163,11 @@ auto InvokeOnLessComparatorForTypeIgnoreNullability(const Type &type,
comp(0, 0);
return functor(comp);
}
+ case kDate: {
+ LessLiteralUncheckedComparator<DateLit, false,
+ DateLit, false> comp;
+ return functor(comp);
+ }
case kDatetime: {
LessLiteralUncheckedComparator<DatetimeLit, false,
DatetimeLit, false> comp;
@@ -429,6 +434,18 @@ auto InvokeOnLessComparatorForDifferentTypesIgnoreNullability(
left_type, right_type, functor);
}
}
+ case kDate: {
+ switch (right_type.getTypeID()) {
+ case kDate: {
+ LessLiteralUncheckedComparator<DateLit, false,
+ DateLit, false> comp;
+ return functor(comp);
+ }
+ default:
+ return comparison_util_detail::InvokeOnLessComparatorForDifferentTypesFallback(
+ left_type, right_type, functor);
+ }
+ }
case kDatetime: {
switch (right_type.getTypeID()) {
case kDatetime: {
@@ -766,6 +783,18 @@ auto InvokeOnBothLessComparatorsForDifferentTypesIgnoreNullability(
left_type, right_type, functor);
}
}
+ case kDate: {
+ switch (right_type.getTypeID()) {
+ case kDate: {
+ LessLiteralUncheckedComparator<DateLit, false,
+ DateLit, false> comp;
+ return functor(comp, comp);
+ }
+ default:
+ return comparison_util_detail::InvokeOnBothLessComparatorsForDifferentTypesFallback(
+ left_type, right_type, functor);
+ }
+ }
case kDatetime: {
switch (right_type.getTypeID()) {
case kDatetime: {
@@ -963,6 +992,8 @@ inline bool CheckUntypedValuesEqual(const Type &type, const void *left, const vo
return STLCharEqual(static_cast<const AsciiStringSuperType&>(type).getStringLength())(left, right);
case kVarChar:
return STLVarCharEqual()(left, right);
+ case kDate:
+ return STLLiteralEqual<DateLit>()(left, right);
case kDatetime:
return STLLiteralEqual<DatetimeLit>()(left, right);
case kDatetimeInterval:
@@ -1220,6 +1251,9 @@ inline TypedValue GetLastValueForType(const Type &type) {
return TypedValue(kChar, kLastString, 2);
case kVarChar:
return TypedValue(kVarChar, kLastString, 2);
+ case kDate: {
+ return TypedValue(DateLit::Create(99999, 12, 31));
+ }
case kDatetime: {
DatetimeLit lit;
lit.ticks = std::numeric_limits<std::int64_t>::max();
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cf81b5e6/types/operations/comparisons/LiteralComparators.hpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/LiteralComparators.hpp b/types/operations/comparisons/LiteralComparators.hpp
index 3bf6b00..406ae40 100644
--- a/types/operations/comparisons/LiteralComparators.hpp
+++ b/types/operations/comparisons/LiteralComparators.hpp
@@ -257,8 +257,8 @@ class LiteralUncheckedComparator : public UncheckedComparator {
};
/**
- * @brief The equal UncheckedComparator for seven literals
- * (int, std::int64_t, float, double, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
+ * @brief The equal UncheckedComparator for the following literals
+ * (int, std::int64_t, float, double, DateLit, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
**/
template <typename LeftCppType, bool left_nullable,
typename RightCppType, bool right_nullable>
@@ -267,8 +267,8 @@ using EqualLiteralUncheckedComparator = LiteralUncheckedComparator<EqualFunctor,
RightCppType, right_nullable>;
/**
- * @brief The not-equal UncheckedComparator for seven literals
- * (int, std::int64_t, float, double, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
+ * @brief The not-equal UncheckedComparator for the following literals
+ * (int, std::int64_t, float, double, DateLit, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
**/
template <typename LeftCppType, bool left_nullable,
typename RightCppType, bool right_nullable>
@@ -277,8 +277,8 @@ using NotEqualLiteralUncheckedComparator = LiteralUncheckedComparator<NotEqualFu
RightCppType, right_nullable>;
/**
- * @brief The less-than UncheckedComparator for seven literals
- * (int, std::int64_t, float, double, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
+ * @brief The less-than UncheckedComparator for the following literals
+ * (int, std::int64_t, float, double, DateLit, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
**/
template <typename LeftCppType, bool left_nullable,
typename RightCppType, bool right_nullable>
@@ -287,8 +287,8 @@ using LessLiteralUncheckedComparator = LiteralUncheckedComparator<LessFunctor,
RightCppType, right_nullable>;
/**
- * @brief The less-than-or-equal UncheckedComparator for seven literals
- * (int, std::int64_t, float, double, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
+ * @brief The less-than-or-equal UncheckedComparator for the following literals
+ * (int, std::int64_t, float, double, DateLit, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
**/
template <typename LeftCppType, bool left_nullable,
typename RightCppType, bool right_nullable>
@@ -297,8 +297,8 @@ using LessOrEqualLiteralUncheckedComparator = LiteralUncheckedComparator<LessOrE
RightCppType, right_nullable>;
/**
- * @brief The greater-than UncheckedComparator for seven literals
- * (int, std::int64_t, float, double, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
+ * @brief The greater-than UncheckedComparator for the following literals
+ * (int, std::int64_t, float, double, DateLit, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
**/
template <typename LeftCppType, bool left_nullable,
typename RightCppType, bool right_nullable>
@@ -307,8 +307,8 @@ using GreaterLiteralUncheckedComparator = LiteralUncheckedComparator<GreaterFunc
RightCppType, right_nullable>;
/**
- * @brief The greater-than-or-equal UncheckedComparator for seven literals
- * (int, std::int64_t, float, double, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
+ * @brief The greater-than-or-equal UncheckedComparator for the following literals
+ * (int, std::int64_t, float, double, DateLit, DatetimeLit, DatetimeIntervalLit, and YearMonthIntervalLit).
**/
template <typename LeftCppType, bool left_nullable,
typename RightCppType, bool right_nullable>
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/cf81b5e6/types/operations/comparisons/tests/Comparison_unittest.cpp
----------------------------------------------------------------------
diff --git a/types/operations/comparisons/tests/Comparison_unittest.cpp b/types/operations/comparisons/tests/Comparison_unittest.cpp
index 0d5e387..d09aab7 100644
--- a/types/operations/comparisons/tests/Comparison_unittest.cpp
+++ b/types/operations/comparisons/tests/Comparison_unittest.cpp
@@ -25,8 +25,6 @@
#include <utility>
#include <vector>
-#include "gtest/gtest.h"
-
#include "types/DatetimeLit.hpp"
#include "types/IntervalLit.hpp"
#include "types/Type.hpp"
@@ -40,6 +38,8 @@
#include "utility/Macros.hpp"
#include "utility/ScopedBuffer.hpp"
+#include "gtest/gtest.h"
+
using std::int64_t;
using std::min;
using std::numeric_limits;
@@ -147,6 +147,23 @@ class ComparisonTest : public ::testing::Test {
numeric_typed_values_.emplace_back(double_min_.get(),
&TypeFactory::GetType(kDouble, false));
+ date_null_.reset(new TypedValue(kDate));
+ date_positive_.reset(new TypedValue(DateLit::Create(2016, 7, 15)));
+ date_negative_.reset(new TypedValue(DateLit::Create(-18017, 4, 13)));
+ date_max_.reset(new TypedValue(DateLit::Create(99999, 12, 31)));
+ date_min_.reset(new TypedValue(DateLit::Create(-99999, 1, 1)));
+
+ date_typed_values_.emplace_back(date_null_.get(),
+ &TypeFactory::GetType(kDate, true));
+ date_typed_values_.emplace_back(date_positive_.get(),
+ &TypeFactory::GetType(kDate, false));
+ date_typed_values_.emplace_back(date_negative_.get(),
+ &TypeFactory::GetType(kDate, false));
+ date_typed_values_.emplace_back(date_max_.get(),
+ &TypeFactory::GetType(kDate, false));
+ date_typed_values_.emplace_back(date_min_.get(),
+ &TypeFactory::GetType(kDate, false));
+
datetime_null_.reset(new TypedValue(kDatetime));
DatetimeLit datetime;
datetime.ticks = 0;
@@ -347,6 +364,7 @@ class ComparisonTest : public ::testing::Test {
void checkComparison(const Comparison &comparison) {
checkNumericComparison(comparison);
checkStringComparison(comparison);
+ checkDateComparison(comparison);
checkDatetimeComparison(comparison);
checkDatetimeIntervalComparison(comparison);
checkYearMonthIntervalComparison(comparison);
@@ -524,6 +542,19 @@ class ComparisonTest : public ::testing::Test {
}
}
+ void checkDateComparison(const Comparison &comparison) {
+ for (const std::pair<const TypedValue*, const Type*> &left_item : date_typed_values_) {
+ for (const std::pair<const TypedValue*, const Type*> &right_item : date_typed_values_) {
+ checkDateComparisonChecked<DateLit>(comparison,
+ *left_item.first, *left_item.second,
+ *right_item.first, *right_item.second);
+ checkDateComparisonUnchecked<DateLit>(comparison,
+ *left_item.first, *left_item.second,
+ *right_item.first, *right_item.second);
+ }
+ }
+ }
+
void checkDatetimeComparison(const Comparison &comparison) {
for (const std::pair<const TypedValue*, const Type*> &left_item : datetime_typed_values_) {
for (const std::pair<const TypedValue*, const Type*> &right_item : datetime_typed_values_) {
@@ -719,6 +750,7 @@ class ComparisonTest : public ::testing::Test {
char_ref_extended_short_, char_lit_extended_short_,
char_ref_extended_long_, char_lit_extended_long_,
varchar_null_, varchar_ref_short_, varchar_lit_short_, varchar_ref_long_, varchar_lit_long_,
+ date_null_, date_positive_, date_negative_, date_max_, date_min_,
datetime_null_, datetime_zero_, datetime_positive_, datetime_negative_, datetime_max_, datetime_min_,
datetime_interval_null_, datetime_interval_zero_, datetime_interval_positive_, datetime_interval_negative_,
year_month_interval_null_, year_month_interval_zero_,
@@ -727,7 +759,7 @@ class ComparisonTest : public ::testing::Test {
unique_ptr<ScopedBuffer> extended_short_char_buffer_, extended_long_char_buffer_;
vector<pair<const TypedValue*, const Type*>>
- numeric_typed_values_, datetime_typed_values_, datetime_interval_typed_values_,
+ numeric_typed_values_, date_typed_values_, datetime_typed_values_, datetime_interval_typed_values_,
year_month_interval_typed_values_, string_typed_values_;
};
@@ -803,7 +835,7 @@ void CheckBasicComparisonApplicableToPartialTypes(const Comparison &comparison)
// If only one argument is known, any orderable Type is OK.
for (const TypeID type_id
- : {kInt, kLong, kFloat, kDouble, kDatetime, kDatetimeInterval, kYearMonthInterval}) {
+ : {kInt, kLong, kFloat, kDouble, kDate, kDatetime, kDatetimeInterval, kYearMonthInterval}) {
EXPECT_TRUE(comparison.canComparePartialTypes(
&TypeFactory::GetType(type_id, false), nullptr));
EXPECT_TRUE(comparison.canComparePartialTypes(
@@ -827,12 +859,12 @@ void CheckBasicComparisonApplicableToPartialTypes(const Comparison &comparison)
// If both types are known, expect the same thing as canCompareTypes().
for (const TypeID first_type_id
- : {kInt, kLong, kFloat, kDouble, kDatetime, kDatetimeInterval, kYearMonthInterval}) {
+ : {kInt, kLong, kFloat, kDouble, kDate, kDatetime, kDatetimeInterval, kYearMonthInterval}) {
const Type &first_type = TypeFactory::GetType(first_type_id, false);
const Type &first_type_nullable = TypeFactory::GetType(first_type_id, true);
for (const TypeID second_type_id
- : {kInt, kLong, kFloat, kDouble, kDatetime, kDatetimeInterval, kYearMonthInterval}) {
+ : {kInt, kLong, kFloat, kDouble, kDate, kDatetime, kDatetimeInterval, kYearMonthInterval}) {
const Type &second_type = TypeFactory::GetType(second_type_id, false);
const Type &second_type_nullable = TypeFactory::GetType(second_type_id, true);
EXPECT_EQ(comparison.canCompareTypes(first_type, second_type),
@@ -864,7 +896,7 @@ void CheckBasicComparisonApplicableToPartialTypes(const Comparison &comparison)
const Type &first_type_nullable = TypeFactory::GetType(first_type_id, 10, true);
for (const TypeID second_type_id
- : {kInt, kLong, kFloat, kDouble, kDatetime, kDatetimeInterval, kYearMonthInterval}) {
+ : {kInt, kLong, kFloat, kDouble, kDate, kDatetime, kDatetimeInterval, kYearMonthInterval}) {
const Type &second_type = TypeFactory::GetType(second_type_id, false);
const Type &second_type_nullable = TypeFactory::GetType(second_type_id, true);
EXPECT_EQ(comparison.canCompareTypes(first_type, second_type),