You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by hb...@apache.org on 2016/08/31 18:39:05 UTC

incubator-quickstep git commit: Tests fixed.

Repository: incubator-quickstep
Updated Branches:
  refs/heads/datetype-fix 483901f4f -> ed883564d


Tests fixed.


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

Branch: refs/heads/datetype-fix
Commit: ed883564d6e5f396b5b40cb3f7535e8a2b7f3875
Parents: 483901f
Author: Harshad Deshmukh <hb...@apache.org>
Authored: Wed Aug 31 13:38:34 2016 -0500
Committer: Harshad Deshmukh <hb...@apache.org>
Committed: Wed Aug 31 13:38:34 2016 -0500

----------------------------------------------------------------------
 .../operations/unary_operations/CMakeLists.txt  |  1 +
 .../unary_operations/DateExtractOperation.cpp   |  1 +
 .../tests/DateExtractOperation_unittest.cpp     | 71 +++++++++++++++-----
 3 files changed, 58 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ed883564/types/operations/unary_operations/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/CMakeLists.txt b/types/operations/unary_operations/CMakeLists.txt
index 8aee499..4a7af91 100644
--- a/types/operations/unary_operations/CMakeLists.txt
+++ b/types/operations/unary_operations/CMakeLists.txt
@@ -165,5 +165,6 @@ target_link_libraries(UnaryOperation_tests
                       quickstep_types_operations_unaryoperations_UnaryOperation
                       quickstep_types_operations_unaryoperations_UnaryOperationFactory
                       quickstep_types_operations_unaryoperations_UnaryOperationID
+                      quickstep_utility_EqualsAnyConstant
                       quickstep_utility_Macros)
 add_test(UnaryOperation_tests UnaryOperation_tests)

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ed883564/types/operations/unary_operations/DateExtractOperation.cpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/DateExtractOperation.cpp b/types/operations/unary_operations/DateExtractOperation.cpp
index 325adb0..285f554 100644
--- a/types/operations/unary_operations/DateExtractOperation.cpp
+++ b/types/operations/unary_operations/DateExtractOperation.cpp
@@ -391,6 +391,7 @@ const Type* DateExtractOperation::pushDownTypeHint(const Type *type_hint) const
         // have Datetime or Date as the underlying date implementation.
         return nullptr;
       case DateExtractUnit::kDay:  // Fall through.
+      case DateExtractUnit::kHour:
       case DateExtractUnit::kMinute:
       case DateExtractUnit::kSecond:
         return &TypeFactory::GetType(kDatetime, type_hint->isNullable());

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/ed883564/types/operations/unary_operations/tests/DateExtractOperation_unittest.cpp
----------------------------------------------------------------------
diff --git a/types/operations/unary_operations/tests/DateExtractOperation_unittest.cpp b/types/operations/unary_operations/tests/DateExtractOperation_unittest.cpp
index 6cff66c..6daf6b3 100644
--- a/types/operations/unary_operations/tests/DateExtractOperation_unittest.cpp
+++ b/types/operations/unary_operations/tests/DateExtractOperation_unittest.cpp
@@ -31,6 +31,7 @@
 #include "types/operations/unary_operations/DateExtractOperation.hpp"
 #include "types/operations/unary_operations/UnaryOperation.hpp"
 #include "types/operations/unary_operations/UnaryOperationFactory.hpp"
+#include "utility/EqualsAnyConstant.hpp"
 
 #include "gtest/gtest.h"
 
@@ -44,10 +45,13 @@ namespace quickstep {
 class DateExtractOperationTest : public ::testing::Test {
  protected:
   virtual void SetUp() {
-    dt_literal_.ticks = 1431359664 * DatetimeLit::kTicksPerSecond;  // Mon, 11 May 2015 15:54:24 GMT.
-    datetime_.reset(new TypedValue(dt_literal_));
-
+    datetime_literal_.ticks = 1431359664 * DatetimeLit::kTicksPerSecond;  // Mon, 11 May 2015 15:54:24 GMT.
+    datetime_.reset(new TypedValue(datetime_literal_));
     datetime_null_.reset(new TypedValue(kDatetime));
+
+    date_literal_ = DateLit::Create(2015, 05, 11); // 11 May 2015.
+    date_.reset(new TypedValue(date_literal_));
+    date_null_.reset(new TypedValue(kDate));
   }
 
   void checkDateExtractOperationSerialization(const DateExtractOperation &operation) {
@@ -57,7 +61,7 @@ class DateExtractOperationTest : public ::testing::Test {
     EXPECT_TRUE(operation.equals(UnaryOperationFactory::ReconstructFromProto(proto)));
   }
 
-  void checkDateExtract(int64_t expected, const DateExtractUnit unit) {
+  void checkDatetimeExtract(int64_t expected, const DateExtractUnit unit) {
     const DateExtractOperation &operation = DateExtractOperation::Instance(unit);
     checkDateExtractOperationSerialization(operation);
 
@@ -74,6 +78,23 @@ class DateExtractOperationTest : public ::testing::Test {
     EXPECT_TRUE(unchecked_operator_->applyToTypedValue(*datetime_null_).isNull());
   }
 
+  void checkDateExtract(int32_t expected, const DateExtractUnit unit) {
+    const DateExtractOperation &operation = DateExtractOperation::Instance(unit);
+    checkDateExtractOperationSerialization(operation);
+
+    EXPECT_EQ(expected,
+              operation.applyToChecked(*date_,
+                                       TypeFactory::GetType(kDate, true)).getLiteral<int32_t>());
+    EXPECT_TRUE(operation.applyToChecked(*date_null_,
+                                         TypeFactory::GetType(kDate, true)).isNull());
+
+    unchecked_operator_.reset(
+        operation.makeUncheckedUnaryOperatorForType(TypeFactory::GetType(kDate, true)));
+    EXPECT_EQ(expected, unchecked_operator_->applyToTypedValue(*date_).getLiteral<int32_t>());
+
+    EXPECT_TRUE(unchecked_operator_->applyToTypedValue(*date_null_).isNull());
+  }
+
   static void CheckFixedNullableResultTypeForField(const DateExtractUnit field) {
     const Type *fixed_result_type
         = DateExtractOperation::Instance(field).fixedNullableResultType();
@@ -112,21 +133,34 @@ class DateExtractOperationTest : public ::testing::Test {
   static void CheckPushDownTypeHintForField(const DateExtractUnit field) {
     const UnaryOperation &op = DateExtractOperation::Instance(field);
 
+    // For nullable types.
     const Type *argument_hint
         = op.pushDownTypeHint(&TypeFactory::GetType(kLong, true));
     if ((field == DateExtractUnit::kMonth) || (field == DateExtractUnit::kYear)) {
       // If field is either Year or Month, the argument is NULL.
       ASSERT_EQ(argument_hint, nullptr);
-    } else {
+    } else if (QUICKSTEP_EQUALS_ANY_CONSTANT(field,
+                                             DateExtractUnit::kDay,
+                                             DateExtractUnit::kHour,
+                                             DateExtractUnit::kMinute,
+                                             DateExtractUnit::kSecond)) {
       // Otherwise, if hint is Long, then the argument is a Datetime with the
       // same nullability.
       ASSERT_NE(argument_hint, nullptr);
       EXPECT_TRUE(TypeFactory::GetType(kDatetime, true).equals(*argument_hint));
     }
 
+    // For non-nullable types.
     argument_hint = op.pushDownTypeHint(&TypeFactory::GetType(kLong, false));
-    ASSERT_NE(argument_hint, nullptr);
-    EXPECT_TRUE(TypeFactory::GetType(kDatetime, false).equals(*argument_hint));
+    if ((field == DateExtractUnit::kMonth) || (field == DateExtractUnit::kYear)) {
+      // If field is either Year or Month, the argument is NULL.
+      ASSERT_EQ(argument_hint, nullptr);
+    } else {
+      // Otherwise, if hint is Long, then the argument is a Datetime with the
+      // same nullability.
+      ASSERT_NE(argument_hint, nullptr);
+      EXPECT_TRUE(TypeFactory::GetType(kDatetime, false).equals(*argument_hint));
+    }
 
     // Anything else can't be returned, so there is no hint for argument type.
     EXPECT_EQ(nullptr, op.pushDownTypeHint(nullptr));
@@ -143,19 +177,26 @@ class DateExtractOperationTest : public ::testing::Test {
     EXPECT_EQ(nullptr, op.pushDownTypeHint(&TypeFactory::GetType(kVarChar, 10, true)));
   }
 
-  DatetimeLit dt_literal_;
+  DatetimeLit datetime_literal_;
+  DateLit date_literal_;
   unique_ptr<TypedValue> datetime_, datetime_null_;
+  unique_ptr<TypedValue> date_, date_null_;
 
   unique_ptr<UncheckedUnaryOperator> unchecked_operator_;
 };
 
-TEST_F(DateExtractOperationTest, DateExtratUnaryOperationTest) {
-  checkDateExtract(dt_literal_.yearField(), DateExtractUnit::kYear);
-  checkDateExtract(dt_literal_.monthField(), DateExtractUnit::kMonth);
-  checkDateExtract(dt_literal_.dayField(), DateExtractUnit::kDay);
-  checkDateExtract(dt_literal_.hourField(), DateExtractUnit::kHour);
-  checkDateExtract(dt_literal_.minuteField(), DateExtractUnit::kMinute);
-  checkDateExtract(dt_literal_.secondField(), DateExtractUnit::kSecond);
+TEST_F(DateExtractOperationTest, DateTimeExtractUnaryOperationTest) {
+  checkDatetimeExtract(datetime_literal_.yearField(), DateExtractUnit::kYear);
+  checkDatetimeExtract(datetime_literal_.monthField(), DateExtractUnit::kMonth);
+  checkDatetimeExtract(datetime_literal_.dayField(), DateExtractUnit::kDay);
+  checkDatetimeExtract(datetime_literal_.hourField(), DateExtractUnit::kHour);
+  checkDatetimeExtract(datetime_literal_.minuteField(), DateExtractUnit::kMinute);
+  checkDatetimeExtract(datetime_literal_.secondField(), DateExtractUnit::kSecond);
+}
+
+TEST_F(DateExtractOperationTest, DateExtractUnaryOperationTest) {
+  checkDateExtract(date_literal_.yearField(), DateExtractUnit::kYear);
+  checkDateExtract(date_literal_.monthField(), DateExtractUnit::kMonth);
 }
 
 TEST_F(DateExtractOperationTest, FixedNullableResultTypeTest) {