You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2020/09/18 23:25:58 UTC
[impala] 02/02: IMPALA-10171: Create query options for local time
related flags
This is an automated email from the ASF dual-hosted git repository.
tarmstrong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 5dccf8024b17148e3736473d03426588f434af48
Author: Csaba Ringhofer <cs...@cloudera.com>
AuthorDate: Thu Sep 17 13:43:14 2020 +0200
IMPALA-10171: Create query options for local time related flags
convert_legacy_hive_parquet_utc_timestamps and
use_local_tz_for_unix_timestamp_conversions were controllable only by
flags until now. After this change the old flags are only used on the
Coordinator to set the defaults for the query options.
If default_query_options also sets these query options, it will
take precedence over the old flags.
Possible follow up work:
- the old flags could be deprecated, as default_query_options
can be used to set this on a server level
- testing these functionalities no longer needs custom cluster
tests - rewriting the existing tests could speed up test
execution
Testing:
- expr-test was rewritten to use the query option instead of the flag
- extended the custom cluster tests for the old flags to also use the
query options
- ran related tests
Change-Id: I5c4252d1c8f8e224c1d0e8234f09374bcc0c6f68
Reviewed-on: http://gerrit.cloudera.org:8080/16469
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
be/src/exec/parquet/hdfs-parquet-scanner.cc | 3 +-
be/src/exec/parquet/parquet-column-readers.cc | 6 --
be/src/exprs/expr-test.cc | 35 ++++-----
be/src/exprs/timestamp-functions.h | 6 +-
be/src/runtime/runtime-state.cc | 12 ++--
be/src/runtime/runtime-state.h | 8 +++
be/src/service/impala-server.cc | 19 +++++
be/src/service/query-options.cc | 8 +++
be/src/service/query-options.h | 6 +-
common/thrift/ImpalaInternalService.thrift | 6 ++
common/thrift/ImpalaService.thrift | 9 +++
.../queries/QueryTest/utc-timestamp-functions.test | 84 ++++++++++++++++++++++
.../test_hive_parquet_timestamp_conversion.py | 16 ++++-
tests/custom_cluster/test_local_tz_conversion.py | 2 +
14 files changed, 183 insertions(+), 37 deletions(-)
diff --git a/be/src/exec/parquet/hdfs-parquet-scanner.cc b/be/src/exec/parquet/hdfs-parquet-scanner.cc
index dd81e8c..c93fc31 100644
--- a/be/src/exec/parquet/hdfs-parquet-scanner.cc
+++ b/be/src/exec/parquet/hdfs-parquet-scanner.cc
@@ -1824,9 +1824,8 @@ ColumnStatsReader HdfsParquetScanner::CreateColumnStatsReader(
ParquetTimestampDecoder HdfsParquetScanner::CreateTimestampDecoder(
const parquet::SchemaElement& element) {
bool timestamp_conversion_needed_for_int96_timestamps =
- FLAGS_convert_legacy_hive_parquet_utc_timestamps &&
file_version_.application == "parquet-mr" &&
- state_->local_time_zone() != UTCPTR;
+ state_->time_zone_for_legacy_parquet_time_conversions() != UTCPTR;
return ParquetTimestampDecoder(element, state_->local_time_zone(),
timestamp_conversion_needed_for_int96_timestamps);
diff --git a/be/src/exec/parquet/parquet-column-readers.cc b/be/src/exec/parquet/parquet-column-readers.cc
index 58cc12f..b00ba51 100644
--- a/be/src/exec/parquet/parquet-column-readers.cc
+++ b/be/src/exec/parquet/parquet-column-readers.cc
@@ -36,11 +36,6 @@
#include "common/names.h"
-// Provide a workaround for IMPALA-1658.
-DEFINE_bool(convert_legacy_hive_parquet_utc_timestamps, false,
- "When true, TIMESTAMPs read from files written by Parquet-MR (used by Hive) will "
- "be converted from UTC to local time. Writes are unaffected.");
-
using namespace impala::io;
using parquet::Encoding;
@@ -920,7 +915,6 @@ template <>
bool ScalarColumnReader<TimestampValue, parquet::Type::INT96, true>::ConvertSlot(
const TimestampValue* src, void* slot) {
// Conversion should only happen when this flag is enabled.
- DCHECK(FLAGS_convert_legacy_hive_parquet_utc_timestamps);
DCHECK(timestamp_decoder_.NeedsConversion());
TimestampValue* dst_ts = reinterpret_cast<TimestampValue*>(slot);
*dst_ts = *src;
diff --git a/be/src/exprs/expr-test.cc b/be/src/exprs/expr-test.cc
index 779aaeb..27fdee8 100644
--- a/be/src/exprs/expr-test.cc
+++ b/be/src/exprs/expr-test.cc
@@ -77,8 +77,6 @@
DECLARE_bool(abort_on_config_error);
DECLARE_bool(disable_optimization_passes);
-DECLARE_bool(use_local_tz_for_unix_timestamp_conversions);
-DECLARE_bool(use_utc_for_unix_timestamp_conversions);
DECLARE_string(hdfs_zone_info_zip);
namespace posix_time = boost::posix_time;
@@ -178,17 +176,16 @@ class ScopedTimeZoneOverride {
const Timezone* new_tz_;
};
-// Enable FLAGS_use_local_tz_for_unix_timestamp_conversions for the duration of the scope.
-class ScopedLocalUnixTimestampConversionOverride {
- bool original_;
+class ScopedExecOption {
+ ImpaladQueryExecutor* executor_;
public:
- ScopedLocalUnixTimestampConversionOverride() {
- original_ = FLAGS_use_local_tz_for_unix_timestamp_conversions;
- FLAGS_use_local_tz_for_unix_timestamp_conversions = true;
+ ScopedExecOption(ImpaladQueryExecutor* executor, string option_string)
+ : executor_(executor) {
+ executor->PushExecOption(option_string);
}
- ~ScopedLocalUnixTimestampConversionOverride() {
- FLAGS_use_local_tz_for_unix_timestamp_conversions = original_;
+ ~ScopedExecOption() {
+ executor_->PopExecOption();
}
};
@@ -6735,7 +6732,8 @@ TEST_P(ExprTest, TimestampFunctions) {
// Test Unix epoch conversions again but now converting into local timestamp values.
{
ScopedTimeZoneOverride time_zone("PST8PDT");
- ScopedLocalUnixTimestampConversionOverride use_local;
+ ScopedExecOption use_local(executor_,
+ "USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS=1");
// 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));
// ... and as an Impala compatible string.
@@ -6954,7 +6952,8 @@ TEST_P(ExprTest, TimestampFunctions) {
// Tests from Hive. When casting from timestamp to numeric, timestamps are considered
// to be local values.
{
- ScopedLocalUnixTimestampConversionOverride use_local;
+ ScopedExecOption use_local(executor_,
+ "USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS=1");
ScopedTimeZoneOverride time_zone("PST8PDT");
TestValue("cast(cast('2011-01-01 01:01:01' as timestamp) as boolean)", TYPE_BOOLEAN,
true);
@@ -7027,7 +7026,8 @@ TEST_P(ExprTest, TimestampFunctions) {
// Check again with the flag enabled.
{
- ScopedLocalUnixTimestampConversionOverride use_local;
+ ScopedExecOption use_local(executor_,
+ "USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS=1");
tm before = to_tm(posix_time::microsec_clock::local_time());
unix_start_time = mktime(&before);
unix_timestamp_result = ConvertValue<int64_t>(GetValue("unix_timestamp()",
@@ -7041,7 +7041,8 @@ TEST_P(ExprTest, TimestampFunctions) {
// Test that now() and current_timestamp() are reasonable.
{
ScopedTimeZoneOverride time_zone(TEST_TZ_WITHOUT_DST);
- ScopedLocalUnixTimestampConversionOverride use_local;
+ ScopedExecOption use_local(executor_,
+ "USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS=1");
const Timezone& local_tz = time_zone.GetTimezone();
const TimestampValue start_time =
@@ -7067,7 +7068,8 @@ TEST_P(ExprTest, TimestampFunctions) {
// Test cast(unix_timestamp() as timestamp).
{
ScopedTimeZoneOverride time_zone(TEST_TZ_WITHOUT_DST);
- ScopedLocalUnixTimestampConversionOverride use_local;
+ ScopedExecOption use_local(executor_,
+ "USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS=1");
const Timezone& local_tz = time_zone.GetTimezone();
// UNIX_TIMESTAMP() has second precision so the comparison start time is shifted back
@@ -8219,7 +8221,8 @@ TEST_P(ExprTest, DateFunctions) {
// Test that current_date() is reasonable.
{
ScopedTimeZoneOverride time_zone(TEST_TZ_WITHOUT_DST);
- ScopedLocalUnixTimestampConversionOverride use_local;
+ ScopedExecOption use_local(executor_,
+ "USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS=1");
const Timezone& local_tz = time_zone.GetTimezone();
const boost::gregorian::date start_date =
diff --git a/be/src/exprs/timestamp-functions.h b/be/src/exprs/timestamp-functions.h
index 602eeda..47a2d86 100644
--- a/be/src/exprs/timestamp-functions.h
+++ b/be/src/exprs/timestamp-functions.h
@@ -109,20 +109,20 @@ class TimestampFunctions {
/// Parses 'string_val' based on the format 'fmt'.
/// The time zone interpretation of the parsed timestamp is determined by
- /// FLAGS_use_local_tz_for_unix_timestamp_conversions. If the flag is true, the
+ /// query option use_local_tz_for_unix_timestamp_conversions. If it is true, the
/// instance is interpreted as a local value. If the flag is false, UTC is assumed.
static BigIntVal Unix(FunctionContext* context, const StringVal& string_val,
const StringVal& fmt);
/// Converts 'tv_val' to a unix time_t.
/// The time zone interpretation of the specified timestamp is determined by
- /// FLAGS_use_local_tz_for_unix_timestamp_conversions. If the flag is true, the
+ /// query option use_local_tz_for_unix_timestamp_conversions. If it is true, the
/// instance is interpreted as a local value. If the flag is false, UTC is assumed.
static BigIntVal Unix(FunctionContext* context, const TimestampVal& tv_val);
/// Returns the current time.
/// The time zone interpretation of the current time is determined by
- /// FLAGS_use_local_tz_for_unix_timestamp_conversions. If the flag is true, the
+ /// query option use_local_tz_for_unix_timestamp_conversions. If it is true, the
/// instance is interpreted as a local value. If the flag is false, UTC is assumed.
static BigIntVal Unix(FunctionContext* context);
diff --git a/be/src/runtime/runtime-state.cc b/be/src/runtime/runtime-state.cc
index 54f46fe..8a994b3 100644
--- a/be/src/runtime/runtime-state.cc
+++ b/be/src/runtime/runtime-state.cc
@@ -61,11 +61,6 @@ using strings::Substitute;
DECLARE_int32(max_errors);
-DEFINE_bool(use_local_tz_for_unix_timestamp_conversions, false,
- "When true, TIMESTAMPs are interpreted in the local time zone when converting to "
- "and from Unix times. When false, TIMESTAMPs are interpreted in the UTC time zone. "
- "Set to true for Hive compatibility.");
-
namespace impala {
const char* RuntimeState::LLVM_CLASS_NAME = "class.impala::RuntimeState";
@@ -85,6 +80,7 @@ RuntimeState::RuntimeState(QueryState* query_state, const TPlanFragment& fragmen
query_state->query_ctx().utc_timestamp_string))),
local_time_zone_(UTCPTR),
time_zone_for_unix_time_conversions_(UTCPTR),
+ time_zone_for_legacy_parquet_time_conversions_(UTCPTR),
profile_(RuntimeProfile::Create(
obj_pool(), "Fragment " + PrintId(instance_ctx.fragment_instance_id))),
instance_buffer_reservation_(obj_pool()->Add(new ReservationTracker)) {
@@ -111,6 +107,7 @@ RuntimeState::RuntimeState(
qctx.utc_timestamp_string))),
local_time_zone_(UTCPTR),
time_zone_for_unix_time_conversions_(UTCPTR),
+ time_zone_for_legacy_parquet_time_conversions_(UTCPTR),
profile_(RuntimeProfile::Create(obj_pool(), "<unnamed>")),
instance_buffer_reservation_(nullptr) {
// We may use execution resources while evaluating exprs, etc. Decremented in
@@ -173,9 +170,12 @@ void RuntimeState::Init() {
LogError(ErrorMsg(TErrorCode::GENERAL, msg));
local_time_zone_ = UTCPTR;
}
- if (FLAGS_use_local_tz_for_unix_timestamp_conversions) {
+ if (query_options().use_local_tz_for_unix_timestamp_conversions) {
time_zone_for_unix_time_conversions_ = local_time_zone_;
}
+ if (query_options().convert_legacy_hive_parquet_utc_timestamps) {
+ time_zone_for_legacy_parquet_time_conversions_ = local_time_zone_;
+ }
}
}
diff --git a/be/src/runtime/runtime-state.h b/be/src/runtime/runtime-state.h
index 57f3806..fce5a95 100644
--- a/be/src/runtime/runtime-state.h
+++ b/be/src/runtime/runtime-state.h
@@ -120,6 +120,9 @@ class RuntimeState {
const Timezone* time_zone_for_unix_time_conversions() const {
return time_zone_for_unix_time_conversions_;
}
+ const Timezone* time_zone_for_legacy_parquet_time_conversions() const {
+ return time_zone_for_legacy_parquet_time_conversions_;
+ }
const TUniqueId& query_id() const { return query_ctx().query_id; }
const TUniqueId& fragment_instance_id() const {
return instance_ctx_ != nullptr
@@ -340,6 +343,11 @@ class RuntimeState {
/// instead.
const Timezone* time_zone_for_unix_time_conversions_;
+ /// Query-global timezone used to read INT96 timestamps written by Hive. UTC by default,
+ /// but if convert_legacy_hive_parquet_utc_timestamps=1, then the local_time_zone_ is
+ /// used instead.
+ const Timezone* time_zone_for_legacy_parquet_time_conversions_;
+
/// Thread resource management object for this fragment's execution. The runtime
/// state is responsible for returning this pool to the thread mgr.
std::unique_ptr<ThreadResourcePool> resource_pool_;
diff --git a/be/src/service/impala-server.cc b/be/src/service/impala-server.cc
index c4f3b1dd..c168246 100644
--- a/be/src/service/impala-server.cc
+++ b/be/src/service/impala-server.cc
@@ -309,6 +309,18 @@ DEFINE_int32(query_event_hook_nthreads, 1, "Number of threads to use for "
DECLARE_bool(compact_catalog_topic);
+DEFINE_bool(use_local_tz_for_unix_timestamp_conversions, false,
+ "When true, TIMESTAMPs are interpreted in the local time zone when converting to "
+ "and from Unix times. When false, TIMESTAMPs are interpreted in the UTC time zone. "
+ "Set to true for Hive compatibility. "
+ "Can be overriden with the query option with the same name.");
+
+// Provide a workaround for IMPALA-1658.
+DEFINE_bool(convert_legacy_hive_parquet_utc_timestamps, false,
+ "When true, TIMESTAMPs read from files written by Parquet-MR (used by Hive) will "
+ "be converted from UTC to local time. Writes are unaffected. "
+ "Can be overriden with the query option with the same name.");
+
namespace {
using namespace impala;
@@ -1580,6 +1592,13 @@ void ImpalaServer::InitializeConfigVariables() {
// Set idle_session_timeout here to let the SET command return the value of
// the command line option FLAGS_idle_session_timeout
default_query_options_.__set_idle_session_timeout(FLAGS_idle_session_timeout);
+ // The next query options used to be set with flags. Setting them in
+ // default_query_options_ here in order to make default_query_options
+ // take precedence over the legacy flags.
+ default_query_options_.__set_use_local_tz_for_unix_timestamp_conversions(
+ FLAGS_use_local_tz_for_unix_timestamp_conversions);
+ default_query_options_.__set_convert_legacy_hive_parquet_utc_timestamps(
+ FLAGS_convert_legacy_hive_parquet_utc_timestamps);
QueryOptionsMask set_query_options; // unused
Status status = ParseQueryOptions(FLAGS_default_query_options,
&default_query_options_, &set_query_options);
diff --git a/be/src/service/query-options.cc b/be/src/service/query-options.cc
index 73c05ac..f3be764 100644
--- a/be/src/service/query-options.cc
+++ b/be/src/service/query-options.cc
@@ -953,6 +953,14 @@ Status impala::SetQueryOption(const string& key, const string& value,
query_options->__set_runtime_filter_error_rate(val);
break;
}
+ case TImpalaQueryOptions::USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS: {
+ query_options->__set_use_local_tz_for_unix_timestamp_conversions(IsTrue(value));
+ break;
+ }
+ case TImpalaQueryOptions::CONVERT_LEGACY_HIVE_PARQUET_UTC_TIMESTAMPS: {
+ query_options->__set_convert_legacy_hive_parquet_utc_timestamps(IsTrue(value));
+ break;
+ }
default:
if (IsRemovedQueryOption(key)) {
LOG(WARNING) << "Ignoring attempt to set removed query option '" << key << "'";
diff --git a/be/src/service/query-options.h b/be/src/service/query-options.h
index 06fd32f..cb28aa0 100644
--- a/be/src/service/query-options.h
+++ b/be/src/service/query-options.h
@@ -47,7 +47,7 @@ typedef std::unordered_map<string, beeswax::TQueryOptionLevel::type>
// time we add or remove a query option to/from the enum TImpalaQueryOptions.
#define QUERY_OPTS_TABLE\
DCHECK_EQ(_TImpalaQueryOptions_VALUES_TO_NAMES.size(),\
- TImpalaQueryOptions::RUNTIME_FILTER_ERROR_RATE + 1);\
+ TImpalaQueryOptions::CONVERT_LEGACY_HIVE_PARQUET_UTC_TIMESTAMPS + 1);\
REMOVED_QUERY_OPT_FN(abort_on_default_limit_exceeded, ABORT_ON_DEFAULT_LIMIT_EXCEEDED)\
QUERY_OPT_FN(abort_on_error, ABORT_ON_ERROR, TQueryOptionLevel::REGULAR)\
REMOVED_QUERY_OPT_FN(allow_unsupported_formats, ALLOW_UNSUPPORTED_FORMATS)\
@@ -213,6 +213,10 @@ typedef std::unordered_map<string, beeswax::TQueryOptionLevel::type>
TQueryOptionLevel::ADVANCED)\
QUERY_OPT_FN(runtime_filter_error_rate, RUNTIME_FILTER_ERROR_RATE,\
TQueryOptionLevel::ADVANCED)\
+ QUERY_OPT_FN(use_local_tz_for_unix_timestamp_conversions,\
+ USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS, TQueryOptionLevel::ADVANCED)\
+ QUERY_OPT_FN(convert_legacy_hive_parquet_utc_timestamps,\
+ CONVERT_LEGACY_HIVE_PARQUET_UTC_TIMESTAMPS, TQueryOptionLevel::ADVANCED)\
;
/// Enforce practical limits on some query options to avoid undesired query state.
diff --git a/common/thrift/ImpalaInternalService.thrift b/common/thrift/ImpalaInternalService.thrift
index 3a9eefd..76bbfd1 100644
--- a/common/thrift/ImpalaInternalService.thrift
+++ b/common/thrift/ImpalaInternalService.thrift
@@ -447,6 +447,12 @@ struct TQueryOptions {
// See comment in ImpalaService.thrift
111: optional double runtime_filter_error_rate;
+
+ // See comment in ImpalaService.thrift
+ 112: optional bool use_local_tz_for_unix_timestamp_conversions = false;
+
+ // See comment in ImpalaService.thrift
+ 113: optional bool convert_legacy_hive_parquet_utc_timestamps = false;
}
// Impala currently has two types of sessions: Beeswax and HiveServer2
diff --git a/common/thrift/ImpalaService.thrift b/common/thrift/ImpalaService.thrift
index 05a7711..849909c 100644
--- a/common/thrift/ImpalaService.thrift
+++ b/common/thrift/ImpalaService.thrift
@@ -571,6 +571,15 @@ enum TImpalaQueryOptions {
// A value (0.0, 1.0) that is the target false positive probability for runtime bloom
// filters. If not set, falls back to max_filter_error_rate.
RUNTIME_FILTER_ERROR_RATE = 110
+
+ // When true, TIMESTAMPs are interpreted in the local time zone (set in query option
+ // TIMEZONE) when converting to and from Unix times.
+ // When false, TIMESTAMPs are interpreted in the UTC time zone.
+ USE_LOCAL_TZ_FOR_UNIX_TIMESTAMP_CONVERSIONS = 111
+
+ // When true, TIMESTAMPs read from files written by Parquet-MR (used by Hive) will
+ // be converted from UTC to local time. Writes are unaffected.
+ CONVERT_LEGACY_HIVE_PARQUET_UTC_TIMESTAMPS = 112
}
// The summary of a DML statement.
diff --git a/testdata/workloads/functional-query/queries/QueryTest/utc-timestamp-functions.test b/testdata/workloads/functional-query/queries/QueryTest/utc-timestamp-functions.test
index 5bb13bc..a74ef68 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/utc-timestamp-functions.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/utc-timestamp-functions.test
@@ -16,3 +16,87 @@ TIMESTAMP,TIMESTAMP,TIMESTAMP,TIMESTAMP,TIMESTAMP,TIMESTAMP,TIMESTAMP
---- RESULTS
NULL,1970-01-01 00:00:00,1970-01-01 00:00:00.000001000,1400-01-01 00:00:00,9999-12-31 23:59:59,9999-12-31 23:59:59.000001000,NULL
====
+---- QUERY
+# This following test is copied from local-timestamp-functions.test as from IMPALA-10171
+# flag use_local_tz_for_unix_timestamp_conversions can be overriden with a query option.
+# TODO: remove/reduce this test duplication
+SET timezone=CET;
+SET use_local_tz_for_unix_timestamp_conversions=1;
+SELECT
+from_unixtime(0),
+from_unixtime((40 * 365) * 24 * 60 * 60),
+from_unixtime((180 + 40 * 365) * 24 * 60 * 60);
+---- TYPES
+STRING,STRING,STRING
+---- RESULTS
+'1970-01-01 01:00:00','2009-12-22 01:00:00','2010-06-20 02:00:00'
+====
+---- QUERY
+# This following test is copied from local-timestamp-functions.test as from IMPALA-10171
+# flag use_local_tz_for_unix_timestamp_conversions can be overriden with a query option.
+# TODO: remove/reduce this test duplication
+set timezone="America/Los_Angeles";
+SET use_local_tz_for_unix_timestamp_conversions=1;
+SELECT
+from_unixtime(0),
+from_unixtime((40 * 365) * 24 * 60 * 60),
+from_unixtime((180 + 40 * 365) * 24 * 60 * 60);
+---- TYPES
+STRING,STRING,STRING
+---- RESULTS
+'1969-12-31 16:00:00','2009-12-21 16:00:00','2010-06-19 17:00:00'
+====
+---- QUERY
+# This following test is copied from local-timestamp-functions.test as from IMPALA-10171
+# flag use_local_tz_for_unix_timestamp_conversions can be overriden with a query option.
+# TODO: remove/reduce this test duplication
+SET timezone=CET;
+SET use_local_tz_for_unix_timestamp_conversions=1;
+SELECT
+unix_timestamp('1970-01-01 01:00:00'),
+unix_timestamp('2009-12-22 01:00:00'),
+unix_timestamp('2010-06-20 02:00:00');
+---- TYPES
+BIGINT,BIGINT,BIGINT
+---- RESULTS
+0,1261440000,1276992000
+====
+---- QUERY
+# This following test is copied from local-timestamp-functions.test as from IMPALA-10171
+# flag use_local_tz_for_unix_timestamp_conversions can be overriden with a query option.
+# TODO: remove/reduce this test duplication
+set timezone="America/Los_Angeles";
+SET use_local_tz_for_unix_timestamp_conversions=1;
+SELECT
+unix_timestamp('1969-12-31 16:00:00'),
+unix_timestamp('2009-12-21 16:00:00'),
+unix_timestamp('2010-06-19 17:00:00');
+---- TYPES
+BIGINT,BIGINT,BIGINT
+---- RESULTS
+0,1261440000,1276992000
+====
+---- QUERY
+# This following test is copied from local-timestamp-functions.test as from IMPALA-10171
+# flag use_local_tz_for_unix_timestamp_conversions can be overriden with a query option.
+# TODO: remove/reduce this test duplication
+SET timezone=CET;
+SET use_local_tz_for_unix_timestamp_conversions=1;
+select cast(0 as timestamp);
+---- TYPES
+TIMESTAMP
+---- RESULTS
+1970-01-01 01:00:00
+====
+---- QUERY
+# This following test is copied from local-timestamp-functions.test as from IMPALA-10171
+# flag use_local_tz_for_unix_timestamp_conversions can be overriden with a query option.
+# TODO: remove/reduce this test duplication
+SET timezone="America/Los_Angeles";
+SET use_local_tz_for_unix_timestamp_conversions=1;
+select cast(0 as timestamp);
+---- TYPES
+TIMESTAMP
+---- RESULTS
+1969-12-31 16:00:00
+====
diff --git a/tests/custom_cluster/test_hive_parquet_timestamp_conversion.py b/tests/custom_cluster/test_hive_parquet_timestamp_conversion.py
index 75c9c74..c93a0d0 100644
--- a/tests/custom_cluster/test_hive_parquet_timestamp_conversion.py
+++ b/tests/custom_cluster/test_hive_parquet_timestamp_conversion.py
@@ -72,6 +72,11 @@ class TestHiveParquetTimestampConversion(CustomClusterTestSuite):
def test_conversion(self, vector, unique_database):
self.check_sanity(True)
self._test_conversion_with_validation(vector, unique_database)
+ # Override query option convert_legacy_hive_parquet_utc_timestamps.
+ query_options = {"timezone": "PST8PDT",
+ "convert_legacy_hive_parquet_utc_timestamps": "0"}
+ self._test_no_conversion(vector, query_options, "PST8PDT")
+
# Test with UTC too to check the optimizations added in IMPALA-9385.
for tz_name in ["PST8PDT", "UTC"]:
# The value read from the Hive table should be the same as reading a UTC converted
@@ -106,15 +111,20 @@ class TestHiveParquetTimestampConversion(CustomClusterTestSuite):
"-hdfs_zone_info_zip=%s" % get_fs_path("/test-warehouse/tzdb/2017c.zip"))
def test_no_conversion(self, vector):
self.check_sanity(False)
+ # Do not override query option convert_legacy_hive_parquet_utc_timestamps.
+ query_options = {"timezone": "PST8PDT"}
+ self._test_no_conversion(vector, query_options, "PST8PDT")
+
+ def _test_no_conversion(self, vector, query_options, tz_name):
# Without conversion all the values will be different.
- tz_name = "PST8PDT"
+
data = self.execute_query_expect_success(self.client, """
SELECT h.id, h.day, h.timestamp_col, i.timestamp_col
FROM functional_parquet.alltypesagg_hive_13_1 h
JOIN functional_parquet.alltypesagg
i ON i.id = h.id AND i.day = h.day -- serves as a unique key
WHERE h.timestamp_col != FROM_UTC_TIMESTAMP(i.timestamp_col, '%s')
- """ % tz_name, query_options={"timezone": tz_name})\
+ """ % tz_name, query_options=query_options)\
.get_data()
assert len(data.split('\n')) == 10000
# A value should either stay null or stay not null.
@@ -126,7 +136,7 @@ class TestHiveParquetTimestampConversion(CustomClusterTestSuite):
WHERE
(h.timestamp_col IS NULL AND i.timestamp_col IS NOT NULL)
OR (h.timestamp_col IS NOT NULL AND i.timestamp_col IS NULL)
- """, query_options={"timezone": tz_name})\
+ """, query_options=query_options)\
.get_data()
assert len(data) == 0
diff --git a/tests/custom_cluster/test_local_tz_conversion.py b/tests/custom_cluster/test_local_tz_conversion.py
index 2ea7323..0bddd02 100644
--- a/tests/custom_cluster/test_local_tz_conversion.py
+++ b/tests/custom_cluster/test_local_tz_conversion.py
@@ -54,6 +54,8 @@ class TestLocalTzConversion(CustomClusterTestSuite):
@CustomClusterTestSuite.with_args("--use_local_tz_for_unix_timestamp_conversions=true")
def test_timestamp_functions(self, vector):
"""Tests timestamp functions with --use_local_tz_for_unix_timestamp_conversions=true
+ TODO: this test can be probably removed as a query option is created for
+ use_local_tz_for_unix_timestamp_conversions in IMPALA-10171
"""
vector.get_value('exec_option')['enable_expr_rewrites'] = \
vector.get_value('enable_expr_rewrites')