mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 02:52:13 +00:00
Fix issue #7834
This commit is contained in:
parent
052b532025
commit
aa9a367d45
@ -14,13 +14,13 @@
|
|||||||
#include <DataTypes/DataTypeDateTime.h>
|
#include <DataTypes/DataTypeDateTime.h>
|
||||||
#include <DataTypes/DataTypeDateTime64.h>
|
#include <DataTypes/DataTypeDateTime64.h>
|
||||||
#include <DataTypes/DataTypeEnum.h>
|
#include <DataTypes/DataTypeEnum.h>
|
||||||
|
#include <DataTypes/DataTypeUUID.h>
|
||||||
|
#include <DataTypes/DataTypeLowCardinality.h>
|
||||||
#include <DataTypes/DataTypeNullable.h>
|
#include <DataTypes/DataTypeNullable.h>
|
||||||
|
|
||||||
#include <Core/AccurateComparison.h>
|
#include <Core/AccurateComparison.h>
|
||||||
#include <Common/typeid_cast.h>
|
#include <Common/typeid_cast.h>
|
||||||
#include <Common/NaNUtils.h>
|
#include <Common/NaNUtils.h>
|
||||||
#include <DataTypes/DataTypeUUID.h>
|
|
||||||
#include <DataTypes/DataTypeLowCardinality.h>
|
|
||||||
|
|
||||||
#include <common/DateLUT.h>
|
#include <common/DateLUT.h>
|
||||||
#include <DataTypes/DataTypeAggregateFunction.h>
|
#include <DataTypes/DataTypeAggregateFunction.h>
|
||||||
@ -141,7 +141,6 @@ static Field convertDecimalType(const Field & from, const To & type)
|
|||||||
|
|
||||||
Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const IDataType * from_type_hint)
|
Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const IDataType * from_type_hint)
|
||||||
{
|
{
|
||||||
// This was added to mitigate converting DateTime64-Field (a typedef to a Decimal64) to DataTypeDate64-compatible type.
|
|
||||||
if (from_type_hint && from_type_hint->equals(type))
|
if (from_type_hint && from_type_hint->equals(type))
|
||||||
{
|
{
|
||||||
return src;
|
return src;
|
||||||
@ -149,6 +148,7 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
|
|||||||
|
|
||||||
WhichDataType which_type(type);
|
WhichDataType which_type(type);
|
||||||
WhichDataType which_from_type;
|
WhichDataType which_from_type;
|
||||||
|
|
||||||
if (from_type_hint)
|
if (from_type_hint)
|
||||||
{
|
{
|
||||||
which_from_type = WhichDataType(*from_type_hint);
|
which_from_type = WhichDataType(*from_type_hint);
|
||||||
@ -195,12 +195,6 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
|
|||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (which_type.isUUID() && src.getType() == Field::Types::UInt128)
|
|
||||||
{
|
|
||||||
/// Already in needed type.
|
|
||||||
return src;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (which_type.isDateTime64() && src.getType() == Field::Types::Decimal64)
|
if (which_type.isDateTime64() && src.getType() == Field::Types::Decimal64)
|
||||||
{
|
{
|
||||||
/// Already in needed type.
|
/// Already in needed type.
|
||||||
@ -209,6 +203,11 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
|
|||||||
|
|
||||||
/// TODO Conversion from integers to DateTime64
|
/// TODO Conversion from integers to DateTime64
|
||||||
}
|
}
|
||||||
|
else if (which_type.isUUID() && src.getType() == Field::Types::UUID)
|
||||||
|
{
|
||||||
|
/// Already in needed type.
|
||||||
|
return src;
|
||||||
|
}
|
||||||
else if (which_type.isStringOrFixedString())
|
else if (which_type.isStringOrFixedString())
|
||||||
{
|
{
|
||||||
if (src.getType() == Field::Types::String)
|
if (src.getType() == Field::Types::String)
|
||||||
@ -380,6 +379,7 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Field convertFieldToType(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint)
|
Field convertFieldToType(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint)
|
||||||
{
|
{
|
||||||
if (from_value.isNull())
|
if (from_value.isNull())
|
||||||
@ -406,18 +406,22 @@ Field convertFieldToType(const Field & from_value, const IDataType & to_type, co
|
|||||||
return convertFieldToTypeImpl(from_value, to_type, from_type_hint);
|
return convertFieldToTypeImpl(from_value, to_type, from_type_hint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Field convertFieldToTypeOrThrow(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint)
|
Field convertFieldToTypeOrThrow(const Field & from_value, const IDataType & to_type, const IDataType * from_type_hint)
|
||||||
{
|
{
|
||||||
bool is_null = from_value.isNull();
|
bool is_null = from_value.isNull();
|
||||||
if (is_null && !to_type.isNullable())
|
if (is_null && !to_type.isNullable())
|
||||||
throw Exception(ErrorCodes::TYPE_MISMATCH, "Cannot convert NULL to {}", to_type.getName());
|
throw Exception(ErrorCodes::TYPE_MISMATCH, "Cannot convert NULL to {}", to_type.getName());
|
||||||
|
|
||||||
Field converted = convertFieldToType(from_value, to_type, from_type_hint);
|
Field converted = convertFieldToType(from_value, to_type, from_type_hint);
|
||||||
|
|
||||||
if (!is_null && converted.isNull())
|
if (!is_null && converted.isNull())
|
||||||
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND,
|
throw Exception(ErrorCodes::ARGUMENT_OUT_OF_BOUND,
|
||||||
"Cannot convert value '{}'{}: it cannot be represented as {}",
|
"Cannot convert value '{}'{}: it cannot be represented as {}",
|
||||||
toString(from_value),
|
toString(from_value),
|
||||||
from_type_hint ? " from " + from_type_hint->getName() : "",
|
from_type_hint ? " from " + from_type_hint->getName() : "",
|
||||||
to_type.getName());
|
to_type.getName());
|
||||||
|
|
||||||
return converted;
|
return converted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user