CLICKHOUSE-4085 system.contributors (#3452)

* CLICKHOUSE-4085 system.contributors

* fi

* Fix random
This commit is contained in:
proller 2018-10-26 20:43:50 +03:00 committed by alexey-milovidov
parent e4e38f71e1
commit c35c979285
13 changed files with 118 additions and 14 deletions

3
.gitignore vendored
View File

@ -9,7 +9,10 @@
# auto generated files
*.logrt
dbms/src/Storages/System/StorageSystemContributors.generated.cpp
/build
/build_*
/docs/build
/docs/edit
/docs/tools/venv/

View File

@ -6,18 +6,12 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/find_vectorclass.cmake)
set (CONFIG_VERSION ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config_version.h)
set (CONFIG_COMMON ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config.h)
set (CONFIG_BUILD ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config_build.cpp)
include (cmake/version.cmake)
message (STATUS "Will build ${VERSION_FULL}")
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config.h.in ${CONFIG_COMMON})
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config_version.h.in ${CONFIG_VERSION})
get_property (BUILD_COMPILE_DEFINITIONS DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
get_property (BUILD_INCLUDE_DIRECTORIES DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
string (TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config_build.cpp.in ${CONFIG_BUILD})
if (NOT MSVC)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif ()

View File

@ -1,4 +0,0 @@
#pragma once
#include <vector>
extern const char * auto_config_build[];

View File

@ -1,5 +1,16 @@
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/StorageSystemContributors.generated.cpp)
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/StorageSystemContributors.sh)
endif()
set (CONFIG_BUILD ${CMAKE_CURRENT_BINARY_DIR}/StorageSystemBuildOptions.generated.cpp)
get_property (BUILD_COMPILE_DEFINITIONS DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
get_property (BUILD_INCLUDE_DIRECTORIES DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
string (TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC)
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 ${LINK_MODE} ${storages_system_headers} ${storages_system_sources})
target_link_libraries(clickhouse_storages_system dbms)
target_include_directories(clickhouse_storages_system PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1,7 +1,9 @@
#include <Common/config_build.h>
#include "StorageSystemBuildOptions.h"
#include <DataTypes/DataTypeString.h>
#include <Interpreters/Settings.h>
#include <Storages/System/StorageSystemBuildOptions.h>
extern const char * auto_config_build[];
namespace DB
{

View File

@ -1,7 +1,5 @@
// .cpp autogenerated by cmake
#include <Common/config_build.h>
const char * auto_config_build[]
{
"VERSION_FULL", "@VERSION_FULL@",

View File

@ -0,0 +1,36 @@
#if __has_include("StorageSystemContributors.generated.cpp")
#include "StorageSystemContributors.h"
#include <algorithm>
#include <pcg_random.hpp>
#include <DataTypes/DataTypeString.h>
#include <Common/randomSeed.h>
extern const char * auto_contributors[];
namespace DB
{
NamesAndTypesList StorageSystemContributors::getNamesAndTypes()
{
return {
{"name", std::make_shared<DataTypeString>()},
};
}
void StorageSystemContributors::fillData(MutableColumns & res_columns, const Context &, const SelectQueryInfo &) const
{
std::vector<const char *> contributors;
for (auto it = auto_contributors; *it; ++it)
contributors.emplace_back(*it);
pcg64 rng(randomSeed());
std::shuffle(contributors.begin(), contributors.end(), rng);
for (auto & it : contributors)
res_columns[0]->insert(String(it));
}
}
#endif

View File

@ -0,0 +1,34 @@
#pragma once
#if __has_include("StorageSystemContributors.generated.cpp")
#include <Storages/System/IStorageSystemOneBlock.h>
#include <ext/shared_ptr_helper.h>
namespace DB
{
class Context;
/** System table "contributors" with list of clickhouse contributors
*/
class StorageSystemContributors : public ext::shared_ptr_helper<StorageSystemContributors>,
public IStorageSystemOneBlock<StorageSystemContributors>
{
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 "SystemContributors";
}
static NamesAndTypesList getNamesAndTypes();
};
}
#endif

View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
CONTRIBUTORS_FILE=${CONTRIBUTORS_FILE=$CUR_DIR/StorageSystemContributors.generated.cpp}
git shortlog --summary | perl -lnE 's/^\s+\d+\s+(.+)/"$1",/; next unless $1; say $_' > $CONTRIBUTORS_FILE.tmp
# If git history not available - dont make target file
if [ ! -s $CONTRIBUTORS_FILE.tmp ]; then
exit
fi
echo "// autogenerated by $0" > $CONTRIBUTORS_FILE
echo "const char * auto_contributors[] {" >> $CONTRIBUTORS_FILE
cat $CONTRIBUTORS_FILE.tmp >> $CONTRIBUTORS_FILE
echo "nullptr };" >> $CONTRIBUTORS_FILE
rm $CONTRIBUTORS_FILE.tmp

View File

@ -32,6 +32,9 @@
#include <Storages/System/StorageSystemTableFunctions.h>
#include <Storages/System/StorageSystemTables.h>
#include <Storages/System/StorageSystemZooKeeper.h>
#if __has_include("StorageSystemContributors.generated.cpp")
# include <Storages/System/StorageSystemContributors.h>
#endif
namespace DB
@ -56,6 +59,9 @@ void attachSystemTablesLocal(IDatabase & system_database)
system_database.attachTable("data_type_families", StorageSystemDataTypeFamilies::create("data_type_families"));
system_database.attachTable("collations", StorageSystemCollations::create("collations"));
system_database.attachTable("table_engines", StorageSystemTableEngines::create("table_engines"));
#if __has_include("StorageSystemContributors.generated.cpp")
system_database.attachTable("contributors", StorageSystemContributors::create("contributors"));
#endif
}
void attachSystemTablesServer(IDatabase & system_database, bool has_zookeeper)

View File

@ -0,0 +1 @@
ok

View File

@ -0,0 +1,2 @@
-- Normally table should contain 250+ contributors. But when fast git clone used (--depth=X) (Travis build) table will contain only <=X contributors
SELECT if ((SELECT count(*) FROM system.contributors) > 1, 'ok', 'fail');

View File

@ -107,6 +107,8 @@ echo -e "\nCurrent version is $VERSION_STRING"
gen_changelog "$VERSION_STRING" "" "$AUTHOR" ""
$CURDIR/dbms/src/Storages/System/StorageSystemContributors.sh
if [ -z "$USE_PBUILDER" ] ; then
DEB_CC=${DEB_CC:=`which gcc-7 gcc-8 gcc | head -n1`}
DEB_CXX=${DEB_CXX:=`which g++-7 g++-8 g++ | head -n1`}