Files
impala/tests/custom_cluster/test_shared_tzdb.py
Joe McDonnell 82bd087fb1 IMPALA-11973: Add absolute_import, division to all eligible Python files
This takes steps to make Python 2 behave like Python 3 as
a way to flush out issues with running on Python 3. Specifically,
it handles two main differences:
 1. Python 3 requires absolute imports within packages. This
    can be emulated via "from __future__ import absolute_import"
 2. Python 3 changed division to "true" division that doesn't
    round to an integer. This can be emulated via
    "from __future__ import division"

This changes all Python files to add imports for absolute_import
and division. For completeness, this also includes print_function in the
import.

I scrutinized each old-division location and converted some locations
to use the integer division '//' operator if it needed an integer
result (e.g. for indices, counts of records, etc). Some code was also using
relative imports and needed to be adjusted to handle absolute_import.
This fixes all Pylint warnings about no-absolute-import and old-division,
and these warnings are now banned.

Testing:
 - Ran core tests

Change-Id: Idb0fcbd11f3e8791f5951c4944be44fb580e576b
Reviewed-on: http://gerrit.cloudera.org:8080/19588
Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com>
Tested-by: Joe McDonnell <joemcdonnell@cloudera.com>
2023-03-09 17:17:57 +00:00

121 lines
5.6 KiB
Python

# 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.
#
# Tests for IMPALA-3307
from __future__ import absolute_import, division, print_function
import pytest
from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
from tests.util.filesystem_utils import get_fs_path
class TestSharedTimezoneDatabase(CustomClusterTestSuite):
'''IMPALA-3307 adds two startup flags to impalad:
1. --hdfs_zone_info_zip to specify an HDFS/S3/ADLS path to a zip file that contains
the shared compiled time-zone database to use instead of the default
/usr/share/zoneinfo.
2. --hdfs_zone_alias_conf to specify an HDFS/S3/ADLS path to a shared config file
that contains definitions for non-standard time-zone aliases.
This file tests that the startup flags behave as expected.
'''
@classmethod
def add_test_dimensions(cls):
super(CustomClusterTestSuite, cls).add_test_dimensions()
# Timestamp conversion doesn't depend on file format and compression.
# Cut down on testing time by limiting the file format and compression.
cls.ImpalaTestMatrix.add_constraint(lambda v:
v.get_value('table_format').file_format == 'text' and
v.get_value('table_format').compression_codec == 'none')
@CustomClusterTestSuite.with_args("-hdfs_zone_info_zip=%s" %
get_fs_path("/test-warehouse/tzdb/2017c.zip"))
def test_shared_timezones(self, vector):
result = self.client.execute("select timezone, utctime, localtime, \
from_utc_timestamp(utctime,timezone) as impalaresult from \
functional.alltimezones where localtime != from_utc_timestamp(utctime,timezone)")
assert(len(result.data) == 0)
@CustomClusterTestSuite.with_args("-hdfs_zone_info_zip=%s" %
get_fs_path("/test-warehouse/tzdb/2017c.zip"))
def test_invalid_aliases(self, vector):
""" Test that conversions from/to invalid timezones return the timestamp
without change and issue a warning.
IMPALA-7060/IMPALA-3307 removed many abbreviations, aliases and some timezones,
because these timezone names are not supported by Hive and Spark.
"""
timestamp = '2018-04-19 13:07:48.891829000'
for function in ['from_utc_timestamp', 'to_utc_timestamp']:
for timezone in ['invalid timezone', 'CEST', 'Mideast/Riyadh87']:
result = self.execute_query_expect_success(self.client,
"select {0}('{1}', '{2}');".format(function, timestamp, timezone))
assert "UDF WARNING: Unknown timezone '%s'" % timezone == result.log.strip()
assert timestamp == result.get_data()
@CustomClusterTestSuite.with_args("-hdfs_zone_info_zip=%s -hdfs_zone_alias_conf=%s" %
(get_fs_path("/test-warehouse/tzdb/2017c.zip"),
get_fs_path("/test-warehouse/tzdb/alias.conf")))
def test_shared_timezone_aliases(self, vector):
ts_utc = '2018-04-19 13:07:48.891829000'
ts_utc_plus5400sec = '2018-04-19 14:37:48.891829000'
ts_utc_min5400sec = '2018-04-19 11:37:48.891829000'
# Test tz abbreviations that are not listed in the custom aliases config file.
# Impala should issue a warning and fall back to UTC.
for abbrev in ['PST', 'JST', 'ACT', 'VST']:
result = self.execute_query_expect_success(self.client,
"select from_utc_timestamp('{0}', '{1}');".format(ts_utc, abbrev))
assert "UDF WARNING: Unknown timezone '%s'" % abbrev == result.log.strip()
assert ts_utc == result.get_data()
# Test custom tz aliases defined as aliases for time-zones.
data = self.execute_query_expect_success(self.client, """
select from_utc_timestamp('{0}', 'America/Cancun'),
from_utc_timestamp('{0}', 'Cancun'),
from_utc_timestamp('{0}', 'America/Argentina/Mendoza'),
from_utc_timestamp('{0}', 'Mendoza'),
from_utc_timestamp('{0}', 'Mendoza2'),
from_utc_timestamp('{0}', 'Utc'),
from_utc_timestamp('{0}', 'Etc/GMT+1'),
from_utc_timestamp('{0}', 'GMT-01:00'),
from_utc_timestamp('{0}', 'Asia/Riyadh'),
from_utc_timestamp('{0}', 'Mideast/Riyadh89');
""".format(ts_utc)).get_data()
ts_cancun, ts_cancun_alias,\
ts_mendoza, ts_mendoza_alias, ts_mendoza_alias2,\
ts_utc_alias,\
ts_gmt_plus_1hour, ts_gmt_plus_1hour_alias,\
ts_riyadh, ts_riyadh_alias = data.split('\t')
assert ts_cancun == ts_cancun_alias
assert ts_mendoza == ts_mendoza_alias == ts_mendoza_alias2
assert ts_utc == ts_utc_alias
assert ts_gmt_plus_1hour == ts_gmt_plus_1hour_alias
assert ts_riyadh == ts_riyadh_alias
# Test custom tz reviations defined as UTC offsets.
data = self.execute_query_expect_success(self.client, """
select from_utc_timestamp('{0}', 'Fifty-Four-Hundred'),
from_utc_timestamp('{0}', 'Min-Fifty-Four-Hundred');
""".format(ts_utc)).get_data()
assert [ts_utc_plus5400sec, ts_utc_min5400sec] == data.split('\t')