mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Default host, port and user parameters for source(clickhouse(...))
This commit is contained in:
parent
7fb53b205c
commit
1dce20e5da
@ -17,6 +17,14 @@
|
|||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
inline static UInt16 getPortFromContext(const Context & context, bool secure)
|
||||||
|
{
|
||||||
|
return secure ? context.getTCPPortSecure().value_or(0) : context.getTCPPort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace ErrorCodes
|
namespace ErrorCodes
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -59,10 +67,10 @@ ClickHouseDictionarySource::ClickHouseDictionarySource(
|
|||||||
const std::string & default_database)
|
const std::string & default_database)
|
||||||
: update_time{std::chrono::system_clock::from_time_t(0)}
|
: update_time{std::chrono::system_clock::from_time_t(0)}
|
||||||
, dict_struct{dict_struct_}
|
, dict_struct{dict_struct_}
|
||||||
, host{config.getString(config_prefix + ".host")}
|
|
||||||
, port(config.getInt(config_prefix + ".port"))
|
|
||||||
, secure(config.getBool(config_prefix + ".secure", false))
|
, secure(config.getBool(config_prefix + ".secure", false))
|
||||||
, user{config.getString(config_prefix + ".user", "")}
|
, host{config.getString(config_prefix + ".host", "localhost")}
|
||||||
|
, port(config.getInt(config_prefix + ".port", getPortFromContext(context_, secure)))
|
||||||
|
, user{config.getString(config_prefix + ".user", "default")}
|
||||||
, password{config.getString(config_prefix + ".password", "")}
|
, password{config.getString(config_prefix + ".password", "")}
|
||||||
, db{config.getString(config_prefix + ".db", default_database)}
|
, db{config.getString(config_prefix + ".db", default_database)}
|
||||||
, table{config.getString(config_prefix + ".table")}
|
, table{config.getString(config_prefix + ".table")}
|
||||||
@ -72,7 +80,7 @@ ClickHouseDictionarySource::ClickHouseDictionarySource(
|
|||||||
, query_builder{dict_struct, db, "", table, where, IdentifierQuotingStyle::Backticks}
|
, query_builder{dict_struct, db, "", table, where, IdentifierQuotingStyle::Backticks}
|
||||||
, sample_block{sample_block_}
|
, sample_block{sample_block_}
|
||||||
, context(context_)
|
, context(context_)
|
||||||
, is_local{isLocalAddress({host, port}, secure ? context.getTCPPortSecure().value_or(0) : context.getTCPPort())}
|
, is_local{isLocalAddress({host, port}, getPortFromContext(context_, secure))}
|
||||||
, pool{is_local ? nullptr : createPool(host, port, secure, db, user, password)}
|
, pool{is_local ? nullptr : createPool(host, port, secure, db, user, password)}
|
||||||
, load_all_query{query_builder.composeLoadAllQuery()}
|
, load_all_query{query_builder.composeLoadAllQuery()}
|
||||||
{
|
{
|
||||||
@ -92,9 +100,9 @@ ClickHouseDictionarySource::ClickHouseDictionarySource(
|
|||||||
ClickHouseDictionarySource::ClickHouseDictionarySource(const ClickHouseDictionarySource & other)
|
ClickHouseDictionarySource::ClickHouseDictionarySource(const ClickHouseDictionarySource & other)
|
||||||
: update_time{other.update_time}
|
: update_time{other.update_time}
|
||||||
, dict_struct{other.dict_struct}
|
, dict_struct{other.dict_struct}
|
||||||
|
, secure{other.secure}
|
||||||
, host{other.host}
|
, host{other.host}
|
||||||
, port{other.port}
|
, port{other.port}
|
||||||
, secure{other.secure}
|
|
||||||
, user{other.user}
|
, user{other.user}
|
||||||
, password{other.password}
|
, password{other.password}
|
||||||
, db{other.db}
|
, db{other.db}
|
||||||
|
@ -61,9 +61,9 @@ private:
|
|||||||
|
|
||||||
std::chrono::time_point<std::chrono::system_clock> update_time;
|
std::chrono::time_point<std::chrono::system_clock> update_time;
|
||||||
const DictionaryStructure dict_struct;
|
const DictionaryStructure dict_struct;
|
||||||
|
const bool secure;
|
||||||
const std::string host;
|
const std::string host;
|
||||||
const UInt16 port;
|
const UInt16 port;
|
||||||
const bool secure;
|
|
||||||
const std::string user;
|
const std::string user;
|
||||||
const std::string password;
|
const std::string password;
|
||||||
const std::string db;
|
const std::string db;
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
17
|
17
|
||||||
11
|
11
|
||||||
11
|
11
|
||||||
|
17
|
||||||
|
11
|
||||||
7
|
7
|
||||||
11
|
11
|
||||||
6
|
6
|
||||||
|
@ -51,6 +51,27 @@ DROP DICTIONARY database_for_dict.dict1;
|
|||||||
|
|
||||||
SELECT dictGetUInt8('database_for_dict.dict1', 'second_column', toUInt64(11)); -- {serverError 36}
|
SELECT dictGetUInt8('database_for_dict.dict1', 'second_column', toUInt64(11)); -- {serverError 36}
|
||||||
|
|
||||||
|
-- SOURCE(CLICKHOUSE(...)) uses default params if not specified
|
||||||
|
DROP DICTIONARY IF EXISTS database_for_dict.dict1;
|
||||||
|
|
||||||
|
CREATE DICTIONARY database_for_dict.dict1
|
||||||
|
(
|
||||||
|
key_column UInt64 DEFAULT 0,
|
||||||
|
second_column UInt8 DEFAULT 1,
|
||||||
|
third_column String DEFAULT 'qqq',
|
||||||
|
fourth_column Float64 DEFAULT 42.0
|
||||||
|
)
|
||||||
|
PRIMARY KEY key_column
|
||||||
|
SOURCE(CLICKHOUSE(TABLE 'table_for_dict' PASSWORD '' DB 'database_for_dict'))
|
||||||
|
LIFETIME(MIN 1 MAX 10)
|
||||||
|
LAYOUT(FLAT());
|
||||||
|
|
||||||
|
SELECT dictGetUInt8('database_for_dict.dict1', 'second_column', toUInt64(11));
|
||||||
|
|
||||||
|
SELECT count(distinct(dictGetUInt8('database_for_dict.dict1', 'second_column', toUInt64(number)))) from numbers(100);
|
||||||
|
|
||||||
|
DROP DICTIONARY database_for_dict.dict1;
|
||||||
|
|
||||||
CREATE DICTIONARY database_for_dict.dict1
|
CREATE DICTIONARY database_for_dict.dict1
|
||||||
(
|
(
|
||||||
key_column UInt64 DEFAULT 0,
|
key_column UInt64 DEFAULT 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user