mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
Prevent types too large for UInt64 from being used
This commit is contained in:
parent
e2d4e08c3b
commit
70a8d7ef08
@ -144,6 +144,7 @@ namespace
|
||||
"transform(T, Array(T), Array(U), U) -> U; "
|
||||
"or transform(T, Array(T), Array(T)) -> T; where T and U are types.",
|
||||
getName());
|
||||
checkAllowedType(ret);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
@ -156,6 +157,7 @@ namespace
|
||||
"transform(T, Array(T), Array(U), U) -> U; "
|
||||
"or transform(T, Array(T), Array(T)) -> T; where T and U are types.",
|
||||
getName());
|
||||
checkAllowedType(ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -633,6 +635,24 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
static void checkAllowedType(const DataTypePtr & dt)
|
||||
{
|
||||
if (dt->isNullable())
|
||||
checkAllowedTypeHelper(static_cast<const DataTypeNullable *>(dt.get())->getNestedType());
|
||||
else
|
||||
checkAllowedTypeHelper(dt);
|
||||
}
|
||||
|
||||
static void checkAllowedTypeHelper(const DataTypePtr & dt)
|
||||
{
|
||||
if (isStringOrFixedString(dt))
|
||||
return;
|
||||
auto dtsize = dt->getMaximumSizeOfValueInMemory();
|
||||
if (dtsize <= sizeof(UInt64))
|
||||
return;
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected type {} in function 'transform'", dt->getName());
|
||||
}
|
||||
|
||||
/// Can be called from different threads. It works only on the first call.
|
||||
void initialize(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type) const
|
||||
{
|
||||
|
@ -29,3 +29,4 @@ sep4
|
||||
8000
|
||||
sep5
|
||||
8000
|
||||
sep6
|
||||
|
@ -29,3 +29,7 @@ select 'sep4';
|
||||
SELECT transform(8000, [1], [toDecimal32(2, 1)]);
|
||||
select 'sep5';
|
||||
SELECT transform(toDecimal32(8000,0), [1], [toDecimal32(2, 1)]);
|
||||
select 'sep6';
|
||||
SELECT transform(-9223372036854775807, [-1], [toDecimal32(1024, 3)]) FROM system.numbers LIMIT 7; -- { serverError BAD_ARGUMENTS }
|
||||
SELECT [NULL, NULL, NULL, NULL], transform(number, [2147483648], [toDecimal32(1, 2)]) AS x FROM numbers(257) WHERE materialize(10); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT transform(-2147483649, [1], [toDecimal32(1, 2)]) GROUP BY [1] WITH TOTALS; -- { serverError BAD_ARGUMENTS }
|
||||
|
Loading…
Reference in New Issue
Block a user