From e04e37916e00309b19a426fd32e23321ec10610d Mon Sep 17 00:00:00 2001 From: kssenii Date: Sat, 23 Oct 2021 18:20:31 +0300 Subject: [PATCH] Review fixes --- src/Parsers/ASTHelpers.h | 7 ------- src/Storages/ExternalDataSourceConfiguration.cpp | 4 ++-- src/Storages/StorageExternalDistributed.cpp | 5 ++--- src/Storages/StorageMongoDB.cpp | 5 ++--- src/Storages/StorageMySQL.cpp | 5 ++--- src/Storages/StoragePostgreSQL.cpp | 3 +-- src/Storages/StorageS3.cpp | 5 ++--- src/TableFunctions/TableFunctionRemote.cpp | 3 +-- src/TableFunctions/TableFunctionS3.cpp | 5 ++--- .../02046_remote_table_function_named_collections.sql | 4 ++-- 10 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/Parsers/ASTHelpers.h b/src/Parsers/ASTHelpers.h index b175049d777..086b361bf85 100644 --- a/src/Parsers/ASTHelpers.h +++ b/src/Parsers/ASTHelpers.h @@ -1,18 +1,11 @@ #pragma once #include -#include namespace DB { -template -static inline ValueType safeGetFromASTLiteral(const ASTPtr & ast) -{ - return ast->as()->value.safeGet(); -} - static inline bool isFunctionCast(const ASTFunction * function) { if (function) diff --git a/src/Storages/ExternalDataSourceConfiguration.cpp b/src/Storages/ExternalDataSourceConfiguration.cpp index 8433885df18..71be37e4b5b 100644 --- a/src/Storages/ExternalDataSourceConfiguration.cpp +++ b/src/Storages/ExternalDataSourceConfiguration.cpp @@ -111,7 +111,7 @@ std::optional getExternalDataSourceConfiguration(const } auto arg_value_ast = evaluateConstantExpressionOrIdentifierAsLiteral(function_args[1], context); - auto * arg_value_literal = evaluateConstantExpressionOrIdentifierAsLiteral(function_args[1], context)->as(); + auto * arg_value_literal = arg_value_ast->as(); if (arg_value_literal) { auto arg_value = arg_value_literal->value; @@ -315,7 +315,7 @@ std::optional getURLBasedDataSourceConfiguration(const auto arg_name = function_args[0]->as()->name(); auto arg_value_ast = evaluateConstantExpressionOrIdentifierAsLiteral(function_args[1], context); - auto arg_value = evaluateConstantExpressionOrIdentifierAsLiteral(function_args[1], context)->as()->value; + auto arg_value = arg_value_ast->as()->value; if (arg_name == "url") configuration.url = arg_value.safeGet(); diff --git a/src/Storages/StorageExternalDistributed.cpp b/src/Storages/StorageExternalDistributed.cpp index b4132edfec9..021cd9815d7 100644 --- a/src/Storages/StorageExternalDistributed.cpp +++ b/src/Storages/StorageExternalDistributed.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -234,7 +233,7 @@ void registerStorageExternalDistributed(StorageFactory & factory) for (const auto & [name, value] : storage_specific_args) { if (name == "description") - cluster_description = safeGetFromASTLiteral(value); + cluster_description = value->as()->value.safeGet(); else throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unknown key-value argument {} for table engine URL", name); @@ -280,7 +279,7 @@ void registerStorageExternalDistributed(StorageFactory & factory) for (const auto & [name, value] : storage_specific_args) { if (name == "description") - cluster_description = safeGetFromASTLiteral(value); + cluster_description = value->as()->value.safeGet(); else throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unknown key-value argument {} for table function URL", name); diff --git a/src/Storages/StorageMongoDB.cpp b/src/Storages/StorageMongoDB.cpp index 9721a5d1fc4..9b48f3fc3b3 100644 --- a/src/Storages/StorageMongoDB.cpp +++ b/src/Storages/StorageMongoDB.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -114,9 +113,9 @@ StorageMongoDBConfiguration StorageMongoDB::getConfiguration(ASTs engine_args, C for (const auto & [arg_name, arg_value] : storage_specific_args) { if (arg_name == "collection") - configuration.collection = safeGetFromASTLiteral(arg_value); + configuration.collection = arg_value->as()->value.safeGet(); else if (arg_name == "options") - configuration.options = safeGetFromASTLiteral(arg_value); + configuration.options = arg_value->as()->value.safeGet(); else throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected key-value argument." diff --git a/src/Storages/StorageMySQL.cpp b/src/Storages/StorageMySQL.cpp index b8d422d20db..0b6095e033b 100644 --- a/src/Storages/StorageMySQL.cpp +++ b/src/Storages/StorageMySQL.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -251,9 +250,9 @@ StorageMySQLConfiguration StorageMySQL::getConfiguration(ASTs engine_args, Conte for (const auto & [arg_name, arg_value] : storage_specific_args) { if (arg_name == "replace_query") - configuration.replace_query = safeGetFromASTLiteral(arg_value); + configuration.replace_query = arg_value->as()->value.safeGet(); else if (arg_name == "on_duplicate_clause") - configuration.on_duplicate_clause = safeGetFromASTLiteral(arg_value); + configuration.on_duplicate_clause = arg_value->as()->value.safeGet(); else throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected key-value argument." diff --git a/src/Storages/StoragePostgreSQL.cpp b/src/Storages/StoragePostgreSQL.cpp index 390d87ab696..8327bb92a38 100644 --- a/src/Storages/StoragePostgreSQL.cpp +++ b/src/Storages/StoragePostgreSQL.cpp @@ -38,7 +38,6 @@ #include #include -#include namespace DB @@ -399,7 +398,7 @@ StoragePostgreSQLConfiguration StoragePostgreSQL::getConfiguration(ASTs engine_a for (const auto & [arg_name, arg_value] : storage_specific_args) { if (arg_name == "on_conflict") - configuration.on_conflict = safeGetFromASTLiteral(arg_value); + configuration.on_conflict = arg_value->as()->value.safeGet(); else throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected key-value argument." diff --git a/src/Storages/StorageS3.cpp b/src/Storages/StorageS3.cpp index ec77bb6e1a1..aa036e9b955 100644 --- a/src/Storages/StorageS3.cpp +++ b/src/Storages/StorageS3.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -751,9 +750,9 @@ StorageS3Configuration StorageS3::getConfiguration(ASTs & engine_args, ContextPt for (const auto & [arg_name, arg_value] : storage_specific_args) { if (arg_name == "access_key_id") - configuration.access_key_id = safeGetFromASTLiteral(arg_value); + configuration.access_key_id = arg_value->as()->value.safeGet(); else if (arg_name == "secret_access_key") - configuration.secret_access_key = safeGetFromASTLiteral(arg_value); + configuration.secret_access_key = arg_value->as()->value.safeGet(); else throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Unknown key-value argument `{}` for StorageS3, expected: url, [access_key_id, secret_access_key], name of used format and [compression_method].", diff --git a/src/TableFunctions/TableFunctionRemote.cpp b/src/TableFunctions/TableFunctionRemote.cpp index 5fcca1d876c..ca13b7277ce 100644 --- a/src/TableFunctions/TableFunctionRemote.cpp +++ b/src/TableFunctions/TableFunctionRemote.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -80,7 +79,7 @@ void TableFunctionRemote::parseArguments(const ASTPtr & ast_function, ContextPtr else { auto database_literal = evaluateConstantExpressionOrIdentifierAsLiteral(arg_value, context); - configuration.database = safeGetFromASTLiteral(database_literal); + configuration.database = database_literal->as()->value.safeGet(); } } else diff --git a/src/TableFunctions/TableFunctionS3.cpp b/src/TableFunctions/TableFunctionS3.cpp index 6bcf7271de6..e26c282c622 100644 --- a/src/TableFunctions/TableFunctionS3.cpp +++ b/src/TableFunctions/TableFunctionS3.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include "registerTableFunctions.h" @@ -49,9 +48,9 @@ void TableFunctionS3::parseArguments(const ASTPtr & ast_function, ContextPtr con for (const auto & [arg_name, arg_value] : storage_specific_args) { if (arg_name == "access_key_id") - configuration.access_key_id = safeGetFromASTLiteral(arg_value); + configuration.access_key_id = arg_value->as()->value.safeGet(); else if (arg_name == "secret_access_key") - configuration.secret_access_key = safeGetFromASTLiteral(arg_value); + configuration.secret_access_key = arg_value->as()->value.safeGet(); else throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Unknown key-value argument `{}` for StorageS3, expected: " diff --git a/tests/queries/0_stateless/02046_remote_table_function_named_collections.sql b/tests/queries/0_stateless/02046_remote_table_function_named_collections.sql index a198c388781..18aa6faf357 100644 --- a/tests/queries/0_stateless/02046_remote_table_function_named_collections.sql +++ b/tests/queries/0_stateless/02046_remote_table_function_named_collections.sql @@ -6,6 +6,6 @@ INSERT INTO FUNCTION remote(remote1, database=currentDatabase()) VALUES(1); INSERT INTO FUNCTION remote(remote1, database=currentDatabase()) VALUES(2); INSERT INTO FUNCTION remote(remote1, database=currentDatabase()) VALUES(3); INSERT INTO FUNCTION remote(remote1, database=currentDatabase()) VALUES(4); -SELECT COUNT(*) FROM remote(remote1, database=currentDatabase()); -SELECT count(*) FROM remote(remote2, database=merge(currentDatabase(), '^remote_test')); +SELECT count() FROM remote(remote1, database=currentDatabase()); +SELECT count() FROM remote(remote2, database=merge(currentDatabase(), '^remote_test')); DROP TABLE remote_test;