mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Better implementation
This commit is contained in:
parent
f00928afa1
commit
eb300f4f78
@ -4078,6 +4078,26 @@ private:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create wrapper only if we support this conversion.
|
||||||
|
WrapperType createWrapperIfCanConvert(const DataTypePtr & from, const DataTypePtr & to) const
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/// We can avoid try/catch here if we will implement check that 2 types can be casted, but it
|
||||||
|
/// requires quite a lot of work. By now let's simply use try/catch.
|
||||||
|
/// First, check that we can create a wrapper.
|
||||||
|
WrapperType wrapper = prepareUnpackDictionaries(from, to);
|
||||||
|
/// Second, check if we can perform a conversion on empty columns.
|
||||||
|
ColumnsWithTypeAndName column_from = {{from->createColumn(), from, "" }};
|
||||||
|
wrapper(column_from, to, nullptr, 0);
|
||||||
|
return wrapper;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WrapperType createVariantToColumnWrapper(const DataTypeVariant & from_variant, const DataTypePtr & to_type) const
|
WrapperType createVariantToColumnWrapper(const DataTypeVariant & from_variant, const DataTypePtr & to_type) const
|
||||||
{
|
{
|
||||||
const auto & variant_types = from_variant.getVariants();
|
const auto & variant_types = from_variant.getVariants();
|
||||||
@ -4090,17 +4110,8 @@ private:
|
|||||||
WrapperType wrapper;
|
WrapperType wrapper;
|
||||||
if (cast_type == CastType::accurateOrNull)
|
if (cast_type == CastType::accurateOrNull)
|
||||||
{
|
{
|
||||||
/// With accurateOrNull cast type we should insert default values on variants that cannot be casted.
|
/// Create wrapper only if we support conversion from variant to the resulting type.
|
||||||
/// We can avoid try/catch here if we will implement check that 2 types can be casted, but it
|
wrapper = createWrapperIfCanConvert(variant_type, to_type);
|
||||||
/// requires quite a lot of work. By now let's simply use try/catch.
|
|
||||||
try
|
|
||||||
{
|
|
||||||
wrapper = prepareUnpackDictionaries(variant_type, to_type);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
/// Leave wrapper empty and check it later.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -4109,7 +4120,7 @@ private:
|
|||||||
variant_wrappers.push_back(wrapper);
|
variant_wrappers.push_back(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [variant_wrappers, variant_types, to_type, cast_type_ = this->cast_type]
|
return [variant_wrappers, variant_types, to_type]
|
||||||
(ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, const ColumnNullable *, size_t input_rows_count) -> ColumnPtr
|
(ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, const ColumnNullable *, size_t input_rows_count) -> ColumnPtr
|
||||||
{
|
{
|
||||||
const auto & column_variant = assert_cast<const ColumnVariant &>(*arguments.front().column.get());
|
const auto & column_variant = assert_cast<const ColumnVariant &>(*arguments.front().column.get());
|
||||||
@ -4125,26 +4136,7 @@ private:
|
|||||||
ColumnPtr casted_variant;
|
ColumnPtr casted_variant;
|
||||||
/// Check if we have wrapper for this variant.
|
/// Check if we have wrapper for this variant.
|
||||||
if (variant_wrapper)
|
if (variant_wrapper)
|
||||||
{
|
casted_variant = variant_wrapper(variant, result_type, nullptr, variant_col->size());
|
||||||
if (cast_type_ == CastType::accurateOrNull)
|
|
||||||
{
|
|
||||||
/// With accurateOrNull cast type wrapper should throw an exception
|
|
||||||
/// only when the cast between types is not supported.
|
|
||||||
/// In this case we will insert default values on rows with this variant.
|
|
||||||
try
|
|
||||||
{
|
|
||||||
casted_variant = variant_wrapper(variant, result_type, nullptr, variant_col->size());
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
/// Do nothing.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
casted_variant = variant_wrapper(variant, result_type, nullptr, variant_col->size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
casted_variant_columns.push_back(std::move(casted_variant));
|
casted_variant_columns.push_back(std::move(casted_variant));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user