Backport #71369 to 24.9: Check suspicious and experimental types in JSON type hints

This commit is contained in:
robot-clickhouse 2024-11-11 14:09:16 +00:00
parent d06dc59000
commit dcd4726768
5 changed files with 21 additions and 0 deletions

View File

@ -230,6 +230,15 @@ MutableColumnPtr DataTypeObject::createColumn() const
return ColumnObject::create(std::move(typed_path_columns), max_dynamic_paths, max_dynamic_types);
}
void DataTypeObject::forEachChild(const ChildCallback & callback) const
{
for (const auto & [path, type] : typed_paths)
{
callback(*type);
type->forEachChild(callback);
}
}
namespace
{

View File

@ -50,6 +50,8 @@ public:
bool equals(const IDataType & rhs) const override;
void forEachChild(const ChildCallback &) const override;
bool hasDynamicSubcolumnsData() const override { return true; }
std::unique_ptr<SubstreamData> getDynamicSubcolumnData(std::string_view subcolumn_name, const SubstreamData & data, bool throw_if_null) const override;

View File

@ -1,6 +1,7 @@
-- Tags: no-fasttest
set allow_experimental_json_type = 1;
set allow_experimental_dynamic_type = 1;
drop table if exists test;
create table test (json JSON(a Dynamic)) engine=MergeTree order by tuple() settings min_rows_for_wide_part=1, min_bytes_for_wide_part=1;
insert into test select '{"a" : 42}';

View File

@ -0,0 +1,9 @@
set allow_experimental_json_type=1;
set allow_experimental_variant_type=0;
set allow_experimental_object_type=0;
select '{}'::JSON(a LowCardinality(Int128)); -- {serverError SUSPICIOUS_TYPE_FOR_LOW_CARDINALITY}
select '{}'::JSON(a FixedString(100000)); -- {serverError ILLEGAL_COLUMN}
select '{}'::JSON(a Variant(Int32)); -- {serverError ILLEGAL_COLUMN}
select '{}'::JSON(a Object('json')); -- {serverError ILLEGAL_COLUMN}