Better String to Variant(String) conversion

This commit is contained in:
Kruglov Pavel 2024-04-02 13:41:56 +02:00 committed by GitHub
parent 0d62307178
commit fd58e4d08b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4119,10 +4119,11 @@ private:
};
}
if (isStringOrFixedString(removeNullable(removeLowCardinality(from_type))))
auto variant_discr_opt = to_variant.tryGetVariantDiscriminator(*removeNullableOrLowCardinalityNullable(from_type));
/// Cast String to Variant through parsing if it's not Variant(String).
if (isStringOrFixedString(removeNullable(removeLowCardinality(from_type))) && (!variant_discr_opt || to_variant.getVariants().size() > 1))
return createStringToVariantWrapper();
auto variant_discr_opt = to_variant.tryGetVariantDiscriminator(*removeNullableOrLowCardinalityNullable(from_type));
if (!variant_discr_opt)
throw Exception(ErrorCodes::CANNOT_CONVERT_TYPE, "Cannot convert type {} to {}. Conversion to Variant allowed only for types from this Variant", from_type->getName(), to_variant.getName());