Merge pull request #54635 from Avogar/cluster-func-names-with-spaces

Fix schema inference for *Cluster functions for column names with spaces
This commit is contained in:
robot-ch-test-poll4 2023-09-15 20:36:33 +02:00 committed by GitHub
commit 5fb8e46967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 18 deletions

View File

@ -240,4 +240,19 @@ size_t NamesAndTypesList::getPosByName(const std::string &name) const noexcept
return pos;
}
String NamesAndTypesList::toNamesAndTypesDescription() const
{
WriteBufferFromOwnString buf;
bool first = true;
for (const auto & name_and_type : *this)
{
if (!std::exchange(first, false))
writeCString(", ", buf);
writeBackQuotedString(name_and_type.name, buf);
writeChar(' ', buf);
writeString(name_and_type.type->getName(), buf);
}
return buf.str();
}
}

View File

@ -122,6 +122,8 @@ public:
/// Try to get column position by name, returns number of columns if column isn't found
size_t getPosByName(const std::string & name) const noexcept;
String toNamesAndTypesDescription() const;
};
using NamesAndTypesLists = std::vector<NamesAndTypesList>;

View File

@ -105,7 +105,7 @@ ASTPtr DatabaseDictionary::getCreateTableQueryImpl(const String & table_name, Co
auto names_and_types = StorageDictionary::getNamesAndTypes(ExternalDictionariesLoader::getDictionaryStructure(*load_result.config));
buffer << "CREATE TABLE " << backQuoteIfNeed(getDatabaseName()) << '.' << backQuoteIfNeed(table_name) << " (";
buffer << StorageDictionary::generateNamesAndTypesDescription(names_and_types);
buffer << names_and_types.toNamesAndTypesDescription();
buffer << ") Engine = Dictionary(" << backQuoteIfNeed(table_name) << ")";
}

View File

@ -77,7 +77,7 @@ Pipe IStorageCluster::read(
const bool add_agg_info = processed_stage == QueryProcessingStage::WithMergeableState;
if (!structure_argument_was_provided)
addColumnsStructureToQuery(query_to_send, StorageDictionary::generateNamesAndTypesDescription(storage_snapshot->metadata->getColumns().getAll()), context);
addColumnsStructureToQuery(query_to_send, storage_snapshot->metadata->getColumns().getAll().toNamesAndTypesDescription(), context);
RestoreQualifiedNamesVisitor::Data data;
data.distributed_table = DatabaseAndTableWithAlias(*getTableExpression(query_info.query->as<ASTSelectQuery &>(), 0));

View File

@ -39,7 +39,7 @@ namespace
{
throw Exception(ErrorCodes::THERE_IS_NO_COLUMN, "Not found column {} {} in dictionary {}. There are only columns {}",
column.name, column.type->getName(), backQuote(dictionary_name),
StorageDictionary::generateNamesAndTypesDescription(dictionary_names_and_types));
dictionary_names_and_types.toNamesAndTypesDescription());
}
}
}
@ -80,20 +80,6 @@ NamesAndTypesList StorageDictionary::getNamesAndTypes(const DictionaryStructure
return dictionary_names_and_types;
}
String StorageDictionary::generateNamesAndTypesDescription(const NamesAndTypesList & list)
{
WriteBufferFromOwnString ss;
bool first = true;
for (const auto & name_and_type : list)
{
if (!std::exchange(first, false))
ss << ", ";
ss << name_and_type.name << ' ' << name_and_type.type->getName();
}
return ss.str();
}
StorageDictionary::StorageDictionary(
const StorageID & table_id_,
const String & dictionary_name_,

View File

@ -81,7 +81,6 @@ public:
std::shared_ptr<const IDictionary> getDictionary() const;
static NamesAndTypesList getNamesAndTypes(const DictionaryStructure & dictionary_structure);
static String generateNamesAndTypesDescription(const NamesAndTypesList & list);
bool isDictionary() const override { return true; }
void shutdown() override;

View File

@ -0,0 +1,2 @@
a b c Nullable(UInt8)
42

View File

@ -0,0 +1,6 @@
-- Tags: no-fasttest
-- Tag no-fasttest: Depends on AWS
desc s3Cluster(test_cluster_one_shard_three_replicas_localhost, 'http://localhost:11111/test/02876.parquet');
select * from s3Cluster(test_cluster_one_shard_three_replicas_localhost, 'http://localhost:11111/test/02876.parquet');

Binary file not shown.