Merge pull request #14030 from ClickHouse/bharatnc-ncb/timezones-table

Merging #13880
This commit is contained in:
alexey-milovidov 2020-08-26 13:15:17 +03:00 committed by GitHub
commit 9341b2acf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 128 additions and 6 deletions

View File

@ -20,12 +20,18 @@ if (NOT USE_INTERNAL_CCTZ_LIBRARY)
)
if (NOT EXTERNAL_CCTZ_LIBRARY_WORKS)
message (${RECONFIGURE_MESSAGE_LEVEL} "External cctz is not working: ${LIBRARY_CCTZ} ${INCLUDE_CCTZ}")
message (${RECONFIGURE_MESSAGE_LEVEL} "External cctz is not working: ${LIBRARY_CCTZ} ${INCLUDE_CCTZ}")
else()
add_library (cctz UNKNOWN IMPORTED)
set_property (TARGET cctz PROPERTY IMPORTED_LOCATION ${LIBRARY_CCTZ})
set_property (TARGET cctz PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INCLUDE_CCTZ})
endif()
set(SYSTEM_STORAGE_TZ_FILE "${CMAKE_BINARY_DIR}/src/Storages/System/StorageSystemTimeZones.generated.cpp")
file(REMOVE ${SYSTEM_STORAGE_TZ_FILE})
file(APPEND ${SYSTEM_STORAGE_TZ_FILE} "// autogenerated by ClickHouse/contrib/cctz-cmake/CMakeLists.txt\n")
file(APPEND ${SYSTEM_STORAGE_TZ_FILE} "const char * auto_time_zones[] {nullptr};\n" )
else()
set (EXTERNAL_CCTZ_LIBRARY_FOUND 0)
message (${RECONFIGURE_MESSAGE_LEVEL} "Can't find system cctz")
@ -57,8 +63,14 @@ if (NOT EXTERNAL_CCTZ_LIBRARY_FOUND OR NOT EXTERNAL_CCTZ_LIBRARY_WORKS)
target_compile_definitions (cctz PRIVATE __USE_BSD linux _XOPEN_SOURCE=600)
endif ()
# Related to time_zones table:
# StorageSystemTimeZones.generated.cpp is autogenerated each time during a build
# data in this file will be used to populate the system.time_zones table, this is specific to OS_LINUX
# as the library that's built using embedded tzdata is also specific to OS_LINUX
set(SYSTEM_STORAGE_TZ_FILE "${CMAKE_BINARY_DIR}/src/Storages/System/StorageSystemTimeZones.generated.cpp")
# remove existing copies so that its generated fresh on each build.
file(REMOVE ${SYSTEM_STORAGE_TZ_FILE})
# Build a libray with embedded tzdata
if (OS_LINUX)
# get the list of timezones from tzdata shipped with cctz
set(TZDIR ${LIBRARY_DIR}/testdata/zoneinfo)
@ -69,9 +81,16 @@ if (NOT EXTERNAL_CCTZ_LIBRARY_FOUND OR NOT EXTERNAL_CCTZ_LIBRARY_WORKS)
set(TZ_OBJS)
# each file/symlink in that dir (except of tab and localtime) store the info about timezone
execute_process(COMMAND bash -c "cd ${TZDIR} && find * -type f,l -and ! -name '*.tab' -and ! -name 'localtime' | sort | paste -sd ';'" OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE TIMEZONES )
execute_process(COMMAND
bash -c "cd ${TZDIR} && find * -type f,l -and ! -name '*.tab' -and ! -name 'localtime' | sort | paste -sd ';'"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE TIMEZONES)
file(APPEND ${SYSTEM_STORAGE_TZ_FILE} "// autogenerated by ClickHouse/contrib/cctz-cmake/CMakeLists.txt\n")
file(APPEND ${SYSTEM_STORAGE_TZ_FILE} "const char * auto_time_zones[] {\n" )
foreach(TIMEZONE ${TIMEZONES})
file(APPEND ${SYSTEM_STORAGE_TZ_FILE} " \"${TIMEZONE}\",\n")
string(REPLACE "/" "_" TIMEZONE_ID ${TIMEZONE})
string(REPLACE "+" "_PLUS_" TIMEZONE_ID ${TIMEZONE_ID})
set(TZ_OBJ ${TIMEZONE_ID}.o)
@ -87,6 +106,8 @@ if (NOT EXTERNAL_CCTZ_LIBRARY_FOUND OR NOT EXTERNAL_CCTZ_LIBRARY_WORKS)
set_source_files_properties(${TZ_OBJ} PROPERTIES EXTERNAL_OBJECT true GENERATED true)
endforeach(TIMEZONE)
file(APPEND ${SYSTEM_STORAGE_TZ_FILE} " nullptr};\n")
add_library(tzdata STATIC ${TZ_OBJS})
set_target_properties(tzdata PROPERTIES LINKER_LANGUAGE C)
# whole-archive prevents symbols from being discarded for unknown reason
@ -95,6 +116,9 @@ if (NOT EXTERNAL_CCTZ_LIBRARY_FOUND OR NOT EXTERNAL_CCTZ_LIBRARY_WORKS)
# library into single string.
add_dependencies(cctz tzdata)
target_link_libraries(cctz INTERFACE "-Wl,${WHOLE_ARCHIVE} $<TARGET_FILE:tzdata> -Wl,${NO_WHOLE_ARCHIVE}")
else ()
file(APPEND ${SYSTEM_STORAGE_TZ_FILE} "// autogenerated by ClickHouse/contrib/cctz-cmake/CMakeLists.txt\n")
file(APPEND ${SYSTEM_STORAGE_TZ_FILE} "const char * auto_time_zones[] {nullptr};\n" )
endif ()
endif ()

View File

@ -0,0 +1,30 @@
# system.time_zones {#system-time_zones}
Contains a list of time zones that are supported by the ClickHouse server. This list of timezones might vary depending on the version of ClickHouse.
Columns:
- `time_zone` (String) — List of supported time zones.
**Example**
``` sql
SELECT * FROM system.time_zones LIMIT 10
```
``` text
┌─time_zone──────────┐
│ Africa/Abidjan │
│ Africa/Accra │
│ Africa/Addis_Ababa │
│ Africa/Algiers │
│ Africa/Asmara │
│ Africa/Asmera │
│ Africa/Bamako │
│ Africa/Bangui │
│ Africa/Banjul │
│ Africa/Bissau │
└────────────────────┘
```
[Original article](https://clickhouse.tech/docs/en/operations/system_tables/time_zones) <!--hide-->

View File

@ -29,6 +29,7 @@ endif()
add_dependencies(generate-source generate-contributors)
set(GENERATED_LICENSES_SRC ${CMAKE_CURRENT_BINARY_DIR}/StorageSystemLicenses.generated.cpp)
set(GENERATED_TIMEZONES_SRC ${CMAKE_CURRENT_BINARY_DIR}/StorageSystemTimeZones.generated.cpp)
add_custom_command(
OUTPUT StorageSystemLicenses.generated.cpp
@ -36,6 +37,8 @@ add_custom_command(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
list (APPEND storages_system_sources ${GENERATED_LICENSES_SRC})
list (APPEND storages_system_sources ${GENERATED_TIMEZONES_SRC})
# Overlength strings
set_source_files_properties(${GENERATED_LICENSES_SRC} PROPERTIES COMPILE_FLAGS -w)

View File

@ -0,0 +1,23 @@
#include "StorageSystemTimeZones.h"
#include <algorithm>
#include <DataTypes/DataTypeString.h>
extern const char * auto_time_zones[];
namespace DB
{
NamesAndTypesList StorageSystemTimeZones::getNamesAndTypes()
{
return {
{"time_zone", std::make_shared<DataTypeString>()},
};
}
void StorageSystemTimeZones::fillData(MutableColumns & res_columns, const Context &, const SelectQueryInfo &) const
{
for (auto * it = auto_time_zones; *it; ++it)
res_columns[0]->insert(String(*it));
}
}

View File

@ -0,0 +1,29 @@
#pragma once
#include <Storages/System/IStorageSystemOneBlock.h>
#include <ext/shared_ptr_helper.h>
namespace DB
{
class Context;
/** System table "time_zones" with list of timezones pulled from /contrib/cctz/testdata/zoneinfo
*/
class StorageSystemTimeZones final : public ext::shared_ptr_helper<StorageSystemTimeZones>,
public IStorageSystemOneBlock<StorageSystemTimeZones>
{
friend struct ext::shared_ptr_helper<StorageSystemTimeZones>;
protected:
void fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo & query_info) const override;
using IStorageSystemOneBlock::IStorageSystemOneBlock;
public:
std::string getName() const override { return "SystemTimeZones"; }
static NamesAndTypesList getNamesAndTypes();
};
}

View File

@ -39,6 +39,7 @@
#include <Storages/System/StorageSystemContributors.h>
#if !defined(ARCADIA_BUILD)
#include <Storages/System/StorageSystemLicenses.h>
#include <Storages/System/StorageSystemTimeZones.h>
#endif
#include <Storages/System/StorageSystemDisks.h>
#include <Storages/System/StorageSystemStoragePolicies.h>
@ -105,9 +106,9 @@ void attachSystemTablesLocal(IDatabase & system_database)
attach<StorageSystemQuotasUsage>(system_database, "quotas_usage");
attach<StorageSystemUserDirectories>(system_database, "user_directories");
attach<StorageSystemPrivileges>(system_database, "privileges");
#if !defined(ARCADIA_BUILD)
attach<StorageSystemLicenses>(system_database, "licenses");
attach<StorageSystemTimeZones>(system_database, "time_zones");
#endif
#ifdef OS_LINUX
attach<StorageSystemStackTrace>(system_database, "stack_trace");

View File

@ -7,7 +7,7 @@ PEERDIR(
)
SRCS(
<? find . -name '*.cpp' | grep -v -F tests | grep -v -P 'Kafka|RabbitMQ|S3|HDFS|Licenses' | sed 's/^\.\// /' | sort ?>
<? find . -name '*.cpp' | grep -v -F tests | grep -v -P 'Kafka|RabbitMQ|S3|HDFS|Licenses|TimeZones' | sed 's/^\.\// /' | sort ?>
)
END()

View File

@ -0,0 +1 @@
ok

View File

@ -0,0 +1,9 @@
-- There are currently 594 timezones which are used from the binary embedded inside the ClickHouse binary
-- Refer: contrib/cctz-cmake/CMakeLists.txt for the complete list. The count may change but we expect there will be at least 500 timezones.
-- SELECT count(*)
-- FROM system.time_zones
--
-- ┌─count()─┐
-- │ 594 │
-- └─────────┘
SELECT if ((SELECT count(*) FROM system.time_zones) > 500, 'ok', 'fail');

View File

@ -135,4 +135,5 @@
01391_join_on_dict_crash
01401_FORMAT_SETTINGS
01411_bayesian_ab_testing
01455_time_zones
01456_ast_optimizations_over_distributed

View File

@ -90,7 +90,8 @@
"01300_client_save_history_when_terminated",
"orc_output",
"01370_client_autocomplete_word_break_characters",
"01193_metadata_loading"
"01193_metadata_loading",
"01455_time_zones"
],
"release-build": [
"avx2"