Avoid calling type->getName

This commit is contained in:
avogar 2024-07-16 10:06:21 +00:00
parent 941898a6d9
commit 47e3e99924
4 changed files with 10 additions and 6 deletions

View File

@ -57,10 +57,10 @@ ColumnDynamic::MutablePtr ColumnDynamic::create(MutableColumnPtr variant_column,
return create(std::move(variant_column), variant_info, max_dynamic_types_, statistics_);
}
bool ColumnDynamic::addNewVariant(const DB::DataTypePtr & new_variant)
bool ColumnDynamic::addNewVariant(const DataTypePtr & new_variant, const String & variant_name)
{
/// Check if we already have such variant.
if (variant_info.variant_name_to_discriminator.contains(new_variant->getName()))
if (variant_info.variant_name_to_discriminator.contains(variant_name))
return true;
/// Check if we reached maximum number of variants.
@ -75,7 +75,7 @@ bool ColumnDynamic::addNewVariant(const DB::DataTypePtr & new_variant)
}
/// If we have (max_dynamic_types - 1) number of variants and don't have String variant, we can add only String variant.
if (variant_info.variant_names.size() == max_dynamic_types - 1 && new_variant->getName() != "String" && !variant_info.variant_name_to_discriminator.contains("String"))
if (variant_info.variant_names.size() == max_dynamic_types - 1 && variant_name != "String" && !variant_info.variant_name_to_discriminator.contains("String"))
return false;
const DataTypes & current_variants = assert_cast<const DataTypeVariant &>(*variant_info.variant_type).getVariants();

View File

@ -334,7 +334,8 @@ public:
const ColumnVariant & getVariantColumn() const { return assert_cast<const ColumnVariant &>(*variant_column); }
ColumnVariant & getVariantColumn() { return assert_cast<ColumnVariant &>(*variant_column); }
bool addNewVariant(const DataTypePtr & new_variant);
bool addNewVariant(const DataTypePtr & new_variant) { return addNewVariant(new_variant, new_variant->getName()); }
bool addNewVariant(const DataTypePtr & new_variant, const String & variant_name);
void addStringVariant();
bool hasDynamicStructure() const override { return true; }

View File

@ -447,6 +447,9 @@ public:
static size_t getArrayLevel(const SubstreamPath & path);
static bool hasSubcolumnForPath(const SubstreamPath & path, size_t prefix_len);
static SubstreamData createFromPath(const SubstreamPath & path, size_t prefix_len);
/// Returns true if subcolumn doesn't actually stores any data in column and doen'st require a separate stream
/// for writing/reading data. For example, it's a null-map subcolumn of Variant type (it's always constructed from discriminators);.
static bool isFictitiousSubcolumn(const SubstreamPath & path, size_t prefix_len);
protected:

View File

@ -1384,9 +1384,9 @@ public:
jsonElementToString<JSONParser>(element, format_settings));
}
if (column_dynamic.addNewVariant(element_type))
auto element_type_name = element_type->getName();
if (column_dynamic.addNewVariant(element_type, element_type_name))
{
auto element_type_name = element_type->getName();
auto it = json_extract_nodes_cache.find(element_type_name);
if (it == json_extract_nodes_cache.end())
it = json_extract_nodes_cache.emplace(element_type_name, buildJSONExtractTree<JSONParser>(element_type, "Dynamic inference")).first;