mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-03 13:02:00 +00:00
Implement tcpPort() function literal
This commit is contained in:
parent
bef6463cb4
commit
1787cd89a7
@ -14,6 +14,7 @@
|
||||
#include <Parsers/ASTFunctionWithKeyValueArguments.h>
|
||||
#include <Parsers/ASTDictionaryAttributeDeclaration.h>
|
||||
#include <Dictionaries/DictionaryFactory.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -356,7 +357,8 @@ NamesToTypeNames buildDictionaryAttributesConfiguration(
|
||||
void buildConfigurationFromFunctionWithKeyValueArguments(
|
||||
AutoPtr<Document> doc,
|
||||
AutoPtr<Element> root,
|
||||
const ASTExpressionList * ast_expr_list)
|
||||
const ASTExpressionList * ast_expr_list,
|
||||
const Context & context)
|
||||
{
|
||||
const auto & children = ast_expr_list->children;
|
||||
for (size_t i = 0; i != children.size(); ++i)
|
||||
@ -365,19 +367,30 @@ void buildConfigurationFromFunctionWithKeyValueArguments(
|
||||
AutoPtr<Element> current_xml_element(doc->createElement(pair->first));
|
||||
root->appendChild(current_xml_element);
|
||||
|
||||
if (const auto * identifier = pair->second->as<const ASTIdentifier>(); identifier)
|
||||
if (const auto * identifier = pair->second->as<const ASTIdentifier>())
|
||||
{
|
||||
AutoPtr<Text> value(doc->createTextNode(identifier->name()));
|
||||
current_xml_element->appendChild(value);
|
||||
}
|
||||
else if (const auto * literal = pair->second->as<const ASTLiteral>(); literal)
|
||||
else if (const auto * literal = pair->second->as<const ASTLiteral>())
|
||||
{
|
||||
AutoPtr<Text> value(doc->createTextNode(getFieldAsString(literal->value)));
|
||||
current_xml_element->appendChild(value);
|
||||
}
|
||||
else if (const auto * list = pair->second->as<const ASTExpressionList>(); list)
|
||||
else if (const auto * list = pair->second->as<const ASTExpressionList>())
|
||||
{
|
||||
buildConfigurationFromFunctionWithKeyValueArguments(doc, current_xml_element, list);
|
||||
buildConfigurationFromFunctionWithKeyValueArguments(doc, current_xml_element, list, context);
|
||||
}
|
||||
else if (const auto * func = pair->second->as<ASTFunction>())
|
||||
{
|
||||
auto builder = FunctionFactory::instance().tryGet(func->name, context);
|
||||
auto function = builder->build({});
|
||||
auto result = function->execute({}, {}, 0);
|
||||
|
||||
Field value;
|
||||
result->get(0, value);
|
||||
AutoPtr<Text> text_value(doc->createTextNode(getFieldAsString(value)));
|
||||
current_xml_element->appendChild(text_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -406,13 +419,14 @@ void buildSourceConfiguration(
|
||||
AutoPtr<Document> doc,
|
||||
AutoPtr<Element> root,
|
||||
const ASTFunctionWithKeyValueArguments * source,
|
||||
const ASTDictionarySettings * settings)
|
||||
const ASTDictionarySettings * settings,
|
||||
const Context & context)
|
||||
{
|
||||
AutoPtr<Element> outer_element(doc->createElement("source"));
|
||||
root->appendChild(outer_element);
|
||||
AutoPtr<Element> source_element(doc->createElement(source->name));
|
||||
outer_element->appendChild(source_element);
|
||||
buildConfigurationFromFunctionWithKeyValueArguments(doc, source_element, source->elements->as<const ASTExpressionList>());
|
||||
buildConfigurationFromFunctionWithKeyValueArguments(doc, source_element, source->elements->as<const ASTExpressionList>(), context);
|
||||
|
||||
if (settings != nullptr)
|
||||
{
|
||||
@ -466,7 +480,8 @@ void checkPrimaryKey(const NamesToTypeNames & all_attrs, const Names & key_attrs
|
||||
}
|
||||
|
||||
|
||||
DictionaryConfigurationPtr getDictionaryConfigurationFromAST(const ASTCreateQuery & query, const std::string & database_)
|
||||
DictionaryConfigurationPtr
|
||||
getDictionaryConfigurationFromAST(const ASTCreateQuery & query, const Context & context, const std::string & database_)
|
||||
{
|
||||
checkAST(query);
|
||||
|
||||
@ -510,7 +525,7 @@ DictionaryConfigurationPtr getDictionaryConfigurationFromAST(const ASTCreateQuer
|
||||
buildPrimaryKeyConfiguration(xml_document, structure_element, complex, pk_attrs, query.dictionary_attributes_list);
|
||||
|
||||
buildLayoutConfiguration(xml_document, current_dictionary, dictionary_layout);
|
||||
buildSourceConfiguration(xml_document, current_dictionary, query.dictionary->source, query.dictionary->dict_settings);
|
||||
buildSourceConfiguration(xml_document, current_dictionary, query.dictionary->source, query.dictionary->dict_settings, context);
|
||||
buildLifetimeConfiguration(xml_document, current_dictionary, query.dictionary->lifetime);
|
||||
|
||||
if (query.dictionary->range)
|
||||
|
@ -10,5 +10,6 @@ using DictionaryConfigurationPtr = Poco::AutoPtr<Poco::Util::AbstractConfigurati
|
||||
/// Convert dictionary AST to Poco::AbstractConfiguration
|
||||
/// This function is necessary because all loadable objects configuration are Poco::AbstractConfiguration
|
||||
/// Can throw exception if query is ill-formed
|
||||
DictionaryConfigurationPtr getDictionaryConfigurationFromAST(const ASTCreateQuery & query, const std::string & database_ = "");
|
||||
DictionaryConfigurationPtr
|
||||
getDictionaryConfigurationFromAST(const ASTCreateQuery & query, const Context & context, const std::string & database_ = "");
|
||||
}
|
||||
|
@ -857,7 +857,7 @@ BlockIO InterpreterCreateQuery::createDictionary(ASTCreateQuery & create)
|
||||
|
||||
if (create.attach)
|
||||
{
|
||||
auto config = getDictionaryConfigurationFromAST(create);
|
||||
auto config = getDictionaryConfigurationFromAST(create, context);
|
||||
auto modification_time = database->getObjectMetadataModificationTime(dictionary_name);
|
||||
database->attachDictionary(dictionary_name, DictionaryAttachInfo{query_ptr, config, modification_time});
|
||||
}
|
||||
|
@ -735,6 +735,7 @@ bool ParserKeyValuePair::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
|
||||
{
|
||||
ParserIdentifier id_parser;
|
||||
ParserLiteral literal_parser;
|
||||
ParserFunction func_parser;
|
||||
|
||||
ASTPtr identifier;
|
||||
ASTPtr value;
|
||||
@ -742,8 +743,8 @@ bool ParserKeyValuePair::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
|
||||
if (!id_parser.parse(pos, identifier, expected))
|
||||
return false;
|
||||
|
||||
/// If it's not literal or identifier, than it's possible list of pairs
|
||||
if (!literal_parser.parse(pos, value, expected) && !id_parser.parse(pos, value, expected))
|
||||
/// If it's neither literal, nor identifier, nor function, than it's possible list of pairs
|
||||
if (!func_parser.parse(pos, value, expected) && !literal_parser.parse(pos, value, expected) && !id_parser.parse(pos, value, expected))
|
||||
{
|
||||
ParserKeyValuePairsList kv_pairs_list;
|
||||
ParserToken open(TokenType::OpeningRoundBracket);
|
||||
|
@ -1,5 +1,5 @@
|
||||
=DICTIONARY in Ordinary DB
|
||||
CREATE DICTIONARY db_01018.dict1\n(\n `key_column` UInt64 DEFAULT 0,\n `second_column` UInt8 DEFAULT 1,\n `third_column` String DEFAULT \'qqq\'\n)\nPRIMARY KEY key_column\nSOURCE(CLICKHOUSE(HOST \'localhost\' PORT 9000 USER \'default\' TABLE \'table_for_dict\' PASSWORD \'\' DB \'database_for_dict_01018\'))\nLIFETIME(MIN 1 MAX 10)\nLAYOUT(FLAT())
|
||||
CREATE DICTIONARY db_01018.dict1\n(\n `key_column` UInt64 DEFAULT 0,\n `second_column` UInt8 DEFAULT 1,\n `third_column` String DEFAULT \'qqq\'\n)\nPRIMARY KEY key_column\nSOURCE(CLICKHOUSE(HOST \'localhost\' PORT tcpPort() USER \'default\' TABLE \'table_for_dict\' PASSWORD \'\' DB \'database_for_dict_01018\'))\nLIFETIME(MIN 1 MAX 10)\nLAYOUT(FLAT())
|
||||
dict1
|
||||
1
|
||||
db_01018 dict1
|
||||
|
@ -32,7 +32,7 @@ CREATE DICTIONARY db_01018.dict1
|
||||
third_column String DEFAULT 'qqq'
|
||||
)
|
||||
PRIMARY KEY key_column
|
||||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' PASSWORD '' DB 'database_for_dict_01018'))
|
||||
SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() USER 'default' TABLE 'table_for_dict' PASSWORD '' DB 'database_for_dict_01018'))
|
||||
LIFETIME(MIN 1 MAX 10)
|
||||
LAYOUT(FLAT());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user