You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by aj...@apache.org on 2019/01/16 10:20:05 UTC

[impala] branch master updated: IMPALA-8043: Fix BE test failures related to SystemV timezones.

This is an automated email from the ASF dual-hosted git repository.

ajeges pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


The following commit(s) were added to refs/heads/master by this push:
     new 3338bae  IMPALA-8043: Fix BE test failures related to SystemV timezones.
3338bae is described below

commit 3338bae608b565f471ad1c9bd31f4fd3d88e431c
Author: Attila Jeges <at...@cloudera.com>
AuthorDate: Tue Jan 8 08:12:04 2019 -0800

    IMPALA-8043: Fix BE test failures related to SystemV timezones.
    
    This is a fix for the following issue:
    
    1. Some BE tests (e.g. ExprTest.TimestampFunctions) use the system's
       local timezone but run against a test timezone db (instead of the
       system's timezone db).
    2. On some Linux installations /usr/share/zoneinfo contains symlinks
       to files in the /usr/share/zoneifo/SystemV directory
       (e.g /usr/share/zoneinfo/America/Los_Angeles is a symlink to
       ../SystemV/PST8PDT).
    3. The 'SystemV' directory is not part of the test timezone db, since
       it is obsolete and excluded by default.
    
    Consequently, if the system's local timezone is set to
    America/Los_Angeles, BE tests won't find the corresponding timezone
    file in the test timezone db. BE tests will default to UTC, which will
    break some of them.
    
    This change sets local timezone explicitly for failing BE tests, so
    they don't depend on the system's local timezone.
    It also adds 'SystemV' directory to the test timezone db to avoid
    similar issues in the future.
    
    Change-Id: I9288cd24c8af0c059e55d47c86bd92eaf0075681
    Reviewed-on: http://gerrit.cloudera.org:8080/12199
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/exprs/expr-test.cc              |  56 +++++++++++++++++++--------------
 testdata/data/timezoneverification.csv |  19 +++++++++++
 testdata/tzdb/2017c.zip                | Bin 486180 -> 450152 bytes
 3 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/be/src/exprs/expr-test.cc b/be/src/exprs/expr-test.cc
index 0e0125c..d78d6b2 100644
--- a/be/src/exprs/expr-test.cc
+++ b/be/src/exprs/expr-test.cc
@@ -86,6 +86,10 @@ using namespace Apache::Hadoop::Hive;
 using namespace impala;
 
 namespace impala {
+// America/Anguilla timezone does not observe DST.
+// Use this timezone in tests where DST changes may cause problems.
+const char* TEST_TZ_WITHOUT_DST = "America/Anguilla";
+
 ImpaladQueryExecutor* executor_;
 scoped_ptr<MetricGroup> statestore_metrics(new MetricGroup("statestore_metrics"));
 Statestore* statestore;
@@ -6266,6 +6270,7 @@ TEST_F(ExprTest, TimestampFunctions) {
 
   // Test Unix epoch conversions again but now converting into local timestamp values.
   {
+    ScopedTimeZoneOverride time_zone("PST8PDT");
     ScopedLocalUnixTimestampConversionOverride use_local;
     // Determine what the local time would have been when it was 1970-01-01 GMT
     ptime local_time_at_epoch = c_local_adjustor<ptime>::utc_to_local(from_time_t(0));
@@ -6559,33 +6564,36 @@ TEST_F(ExprTest, TimestampFunctions) {
   TestValidTimestampValue("current_timestamp()");
   TestValidTimestampValue("cast(unix_timestamp() as timestamp)");
 
-  // Test that the epoch is reasonable. The default behavior of UNIX_TIMESTAMP()
-  // is incorrect but wasn't changed for compatibility reasons. The function returns
-  // a value as though the current timezone is UTC. Or in other words, 1970-01-01
-  // in the current timezone is the effective epoch. A flag was introduced to enable
-  // the correct behavior. The first test below checks the default/incorrect behavior.
-  time_t unix_start_time =
-      (posix_time::microsec_clock::local_time() - from_time_t(0)).total_seconds();
-  int64_t unix_timestamp_result = ConvertValue<int64_t>(GetValue("unix_timestamp()",
-      TYPE_BIGINT));
-  EXPECT_BETWEEN(unix_start_time, unix_timestamp_result, static_cast<int64_t>(
-      (posix_time::microsec_clock::local_time() - from_time_t(0)).total_seconds()));
-
-  // Check again with the flag enabled.
   {
-    ScopedLocalUnixTimestampConversionOverride use_local;
-    tm before = to_tm(posix_time::microsec_clock::local_time());
-    unix_start_time = mktime(&before);
-    unix_timestamp_result = ConvertValue<int64_t>(GetValue("unix_timestamp()",
+    // Test that the epoch is reasonable. The default behavior of UNIX_TIMESTAMP()
+    // is incorrect but wasn't changed for compatibility reasons. The function returns
+    // a value as though the current timezone is UTC. Or in other words, 1970-01-01
+    // in the current timezone is the effective epoch. A flag was introduced to enable
+    // the correct behavior. The first test below checks the default/incorrect behavior.
+    ScopedTimeZoneOverride time_zone(TEST_TZ_WITHOUT_DST);
+    time_t unix_start_time =
+        (posix_time::microsec_clock::local_time() - from_time_t(0)).total_seconds();
+    int64_t unix_timestamp_result = ConvertValue<int64_t>(GetValue("unix_timestamp()",
         TYPE_BIGINT));
-    tm after = to_tm(posix_time::microsec_clock::local_time());
-    EXPECT_BETWEEN(unix_start_time, unix_timestamp_result,
-        static_cast<int64_t>(mktime(&after)));
+    EXPECT_BETWEEN(unix_start_time, unix_timestamp_result, static_cast<int64_t>(
+        (posix_time::microsec_clock::local_time() - from_time_t(0)).total_seconds()));
+
+    // Check again with the flag enabled.
+    {
+      ScopedLocalUnixTimestampConversionOverride use_local;
+      tm before = to_tm(posix_time::microsec_clock::local_time());
+      unix_start_time = mktime(&before);
+      unix_timestamp_result = ConvertValue<int64_t>(GetValue("unix_timestamp()",
+          TYPE_BIGINT));
+      tm after = to_tm(posix_time::microsec_clock::local_time());
+      EXPECT_BETWEEN(unix_start_time, unix_timestamp_result,
+          static_cast<int64_t>(mktime(&after)));
+    }
   }
 
   // Test that now() and current_timestamp() are reasonable.
   {
-    ScopedTimeZoneOverride time_zone("PST8PDT");
+    ScopedTimeZoneOverride time_zone(TEST_TZ_WITHOUT_DST);
     ScopedLocalUnixTimestampConversionOverride use_local;
     const Timezone& local_tz = time_zone.GetTimezone();
 
@@ -6611,15 +6619,15 @@ TEST_F(ExprTest, TimestampFunctions) {
 
   // Test cast(unix_timestamp() as timestamp).
   {
-    ScopedTimeZoneOverride time_zone("PST8PDT");
+    ScopedTimeZoneOverride time_zone(TEST_TZ_WITHOUT_DST);
     ScopedLocalUnixTimestampConversionOverride use_local;
     const Timezone& local_tz = time_zone.GetTimezone();
 
     // UNIX_TIMESTAMP() has second precision so the comparison start time is shifted back
     // a second to ensure an earlier value.
-    unix_start_time =
+    time_t unix_start_time =
         (posix_time::microsec_clock::local_time() - from_time_t(0)).total_seconds();
-    timestamp_result = ConvertValue<TimestampValue>(GetValue(
+    TimestampValue timestamp_result = ConvertValue<TimestampValue>(GetValue(
         "cast(unix_timestamp() as timestamp)", TYPE_TIMESTAMP));
     EXPECT_BETWEEN(TimestampValue::FromUnixTime(unix_start_time - 1, local_tz),
         timestamp_result,
diff --git a/testdata/data/timezoneverification.csv b/testdata/data/timezoneverification.csv
index 5fa3b27..565d789 100644
--- a/testdata/data/timezoneverification.csv
+++ b/testdata/data/timezoneverification.csv
@@ -803,6 +803,25 @@ Portugal,2014-12-20 15:00:00,2014-12-20 15:00:00
 ROK,2015-06-20 15:00:00,2015-06-21 00:00:00
 SST,2015-06-20 15:00:00,2015-06-21 02:00:00
 Singapore,2015-06-20 15:00:00,2015-06-20 23:00:00
+SystemV/AST4,2015-06-20 15:00:00,2015-06-20 11:00:00
+SystemV/AST4ADT,2015-06-20 15:00:00,2015-06-20 12:00:00
+SystemV/AST4ADT,2014-12-20 15:00:00,2014-12-20 11:00:00
+SystemV/CST6,2015-06-20 15:00:00,2015-06-20 09:00:00
+SystemV/CST6CDT,2015-06-20 15:00:00,2015-06-20 10:00:00
+SystemV/CST6CDT,2014-12-20 15:00:00,2014-12-20 09:00:00
+SystemV/EST5,2015-06-20 15:00:00,2015-06-20 10:00:00
+SystemV/EST5EDT,2015-06-20 15:00:00,2015-06-20 11:00:00
+SystemV/EST5EDT,2014-12-20 15:00:00,2014-12-20 10:00:00
+SystemV/HST10,2015-06-20 15:00:00,2015-06-20 05:00:00
+SystemV/MST7,2015-06-20 15:00:00,2015-06-20 08:00:00
+SystemV/MST7MDT,2015-06-20 15:00:00,2015-06-20 09:00:00
+SystemV/MST7MDT,2014-12-20 15:00:00,2014-12-20 08:00:00
+SystemV/PST8,2015-06-20 15:00:00,2015-06-20 07:00:00
+SystemV/PST8PDT,2015-06-20 15:00:00,2015-06-20 08:00:00
+SystemV/PST8PDT,2014-12-20 15:00:00,2014-12-20 07:00:00
+SystemV/YST9,2015-06-20 15:00:00,2015-06-20 06:00:00
+SystemV/YST9YDT,2015-06-20 15:00:00,2015-06-20 07:00:00
+SystemV/YST9YDT,2014-12-20 15:00:00,2014-12-20 06:00:00
 Turkey,2015-06-20 15:00:00,2015-06-20 18:00:00
 Turkey,2014-12-20 15:00:00,2014-12-20 17:00:00
 UCT,2015-06-20 15:00:00,2015-06-20 15:00:00
diff --git a/testdata/tzdb/2017c.zip b/testdata/tzdb/2017c.zip
index 2d2af2d..4a95bdb 100644
Binary files a/testdata/tzdb/2017c.zip and b/testdata/tzdb/2017c.zip differ