Added "system.licenses" table

This commit is contained in:
Alexey Milovidov 2020-05-11 05:39:01 +03:00
parent f1be26c541
commit da583760c4
7 changed files with 104 additions and 3 deletions

View File

@ -11,13 +11,30 @@ configure_file (StorageSystemBuildOptions.generated.cpp.in ${CONFIG_BUILD})
include(${ClickHouse_SOURCE_DIR}/cmake/dbms_glob_sources.cmake)
add_headers_and_sources(storages_system .)
list (APPEND storages_system_sources ${CONFIG_BUILD})
add_library(clickhouse_storages_system ${storages_system_headers} ${storages_system_sources})
target_link_libraries(clickhouse_storages_system PRIVATE dbms common string_utils clickhouse_common_zookeeper clickhouse_parsers)
add_custom_target(generate-contributors ./StorageSystemContributors.sh SOURCES StorageSystemContributors.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
add_custom_target(generate-contributors
./StorageSystemContributors.sh
SOURCES StorageSystemContributors.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# BYPRODUCTS StorageSystemContributors.generated.cpp
)
if(NOT TARGET generate-source)
add_custom_target(generate-source)
endif()
add_dependencies(generate-source generate-contributors)
set(GENERATED_LICENSES_SRC ${CMAKE_CURRENT_BINARY_DIR}/StorageSystemLicenses.generated.cpp)
add_custom_command(
OUTPUT StorageSystemLicenses.generated.cpp
COMMAND ./StorageSystemLicenses.sh > ${GENERATED_LICENSES_SRC}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
list (APPEND storages_system_sources ${GENERATED_LICENSES_SRC})
# Overlength strings
set_source_files_properties(${GENERATED_LICENSES_SRC} PROPERTIES COMPILE_FLAGS -w)
add_library(clickhouse_storages_system ${storages_system_headers} ${storages_system_sources})
target_link_libraries(clickhouse_storages_system PRIVATE dbms common string_utils clickhouse_common_zookeeper clickhouse_parsers)

View File

@ -0,0 +1,31 @@
#include "StorageSystemLicenses.h"
#include <algorithm>
#include <DataTypes/DataTypeString.h>
extern const char * library_licenses[];
namespace DB
{
NamesAndTypesList StorageSystemLicenses::getNamesAndTypes()
{
return {
{"library_name", std::make_shared<DataTypeString>()},
{"license_type", std::make_shared<DataTypeString>()},
{"license_path", std::make_shared<DataTypeString>()},
{"license_text", std::make_shared<DataTypeString>()},
};
}
void StorageSystemLicenses::fillData(MutableColumns & res_columns, const Context &, const SelectQueryInfo &) const
{
for (const auto * it = library_licenses; *it; it += 4)
{
res_columns[0]->insert(String(it[0]));
res_columns[1]->insert(String(it[1]));
res_columns[2]->insert(String(it[2]));
res_columns[3]->insert(String(it[3]));
}
}
}

View File

@ -0,0 +1,32 @@
#pragma once
#include <Storages/System/IStorageSystemOneBlock.h>
#include <ext/shared_ptr_helper.h>
namespace DB
{
class Context;
/** System table "licenses" with list of licenses of 3rd party libraries
*/
class StorageSystemLicenses final :
public ext::shared_ptr_helper<StorageSystemLicenses>,
public IStorageSystemOneBlock<StorageSystemLicenses>
{
friend struct ext::shared_ptr_helper<StorageSystemLicenses>;
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 "SystemLicenses";
}
static NamesAndTypesList getNamesAndTypes();
};
}

View File

@ -0,0 +1,15 @@
#!/bin/bash
ROOT_PATH="$(git rev-parse --show-toplevel)"
IFS=$'\t'
echo "// autogenerated by $0"
echo "const char * library_licenses[] = {"
${ROOT_PATH}/utils/list-licenses/list-licenses.sh | while read row; do
arr=($row)
echo "\"${arr[0]}\", \"${arr[1]}\", \"${arr[2]}\", R\"heredoc($(cat "${ROOT_PATH}/${arr[2]}"))heredoc\","
echo
done
echo "nullptr"
echo "};"

View File

@ -37,6 +37,7 @@
#include <Storages/System/StorageSystemTables.h>
#include <Storages/System/StorageSystemZooKeeper.h>
#include <Storages/System/StorageSystemContributors.h>
#include <Storages/System/StorageSystemLicenses.h>
#include <Storages/System/StorageSystemDisks.h>
#include <Storages/System/StorageSystemStoragePolicies.h>
#include <Storages/System/StorageSystemZeros.h>
@ -75,6 +76,7 @@ void attachSystemTablesLocal(IDatabase & system_database)
system_database.attachTable("collations", StorageSystemCollations::create("collations"));
system_database.attachTable("table_engines", StorageSystemTableEngines::create("table_engines"));
system_database.attachTable("contributors", StorageSystemContributors::create("contributors"));
system_database.attachTable("licenses", StorageSystemLicenses::create("licenses"));
#ifdef OS_LINUX
system_database.attachTable("stack_trace", StorageSystemStackTrace::create("stack_trace"));
#endif

View File

@ -0,0 +1,2 @@
1
zstd BSD /contrib/zstd/LICENSE

View File

@ -0,0 +1,2 @@
SELECT count() > 10 FROM system.licenses;
SELECT library_name, license_type, license_path FROM system.licenses WHERE library_name LIKE '%zstd%';