Skip to content

Commit a6ee72a

Browse files
Merge pull request ClickHouse#87742 from ClickHouse/backport/25.8/84020
Backport ClickHouse#84020 to 25.8: Fix geoparquet types breaking client-server protocol
2 parents f42dd80 + b77d228 commit a6ee72a

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

src/Formats/SchemaInferenceUtils.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,11 @@ DataTypePtr makeNullableRecursively(DataTypePtr type, const FormatSettings & set
16391639
if (which.isNullable())
16401640
return type;
16411641

1642+
/// Leave named compound types unchanged.
1643+
/// E.g. don't turn `Point` into `Tuple(Nullable(Float64), Nullable(Float64))`.
1644+
if (type->hasCustomName())
1645+
return makeNullableSafe(type);
1646+
16421647
if (which.isArray())
16431648
{
16441649
const auto * array_type = assert_cast<const DataTypeArray *>(type.get());
@@ -1710,25 +1715,8 @@ DataTypePtr makeNullableRecursively(DataTypePtr type, const FormatSettings & set
17101715
NamesAndTypesList getNamesAndRecursivelyNullableTypes(const Block & header, const FormatSettings & settings)
17111716
{
17121717
NamesAndTypesList result;
1713-
1714-
std::unordered_map<String, DataTypeCustomDescPtr> custom_descs;
1715-
const auto & prev_schema = header.getNamesAndTypesList();
1716-
for (const auto & [name, type] : prev_schema)
1717-
if (type->hasCustomName() && (type->getTypeId() == TypeIndex::Tuple || type->getTypeId() == TypeIndex::Array))
1718-
custom_descs[name] = std::make_unique<DataTypeCustomDesc>(std::make_unique<DataTypeCustomFixedName>(type->getCustomName()->getName()));
1719-
17201718
for (auto & [name, type] : header.getNamesAndTypesList())
17211719
result.emplace_back(name, makeNullableRecursively(type, settings));
1722-
1723-
for (auto & [name, type] : result)
1724-
{
1725-
auto it = custom_descs.find(name);
1726-
if (it != custom_descs.end())
1727-
{
1728-
type->setCustomization(std::move(it->second));
1729-
}
1730-
}
1731-
17321720
return result;
17331721
}
17341722

src/Formats/SchemaInferenceUtils.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ void transformFinalInferredJSONTypeIfNeeded(DataTypePtr & data_type, const Forma
101101
void transformInferredJSONTypesFromDifferentFilesIfNeeded(DataTypePtr & first, DataTypePtr & second, const FormatSettings & settings);
102102

103103
/// Make type Nullable recursively:
104-
/// - Type -> Nullable(type)
105-
/// - Array(Type) -> Array(Nullable(Type))
106-
/// - Tuple(Type1, ..., TypeN) -> Tuple(Nullable(Type1), ..., Nullable(TypeN))
107-
/// - Map(KeyType, ValueType) -> Map(KeyType, Nullable(ValueType))
108-
/// - LowCardinality(Type) -> LowCardinality(Nullable(Type))
104+
/// - Type -> Nullable(type)
105+
/// - Array(Type) -> Array(Nullable(Type))
106+
/// - Tuple(Type1, ..., TypeN) -> Tuple(Nullable(Type1), ..., Nullable(TypeN))
107+
/// - Map(KeyType, ValueType) -> Map(KeyType, Nullable(ValueType))
108+
/// - LowCardinality(Type) -> LowCardinality(Nullable(Type))
109+
/// Does not recurse into types with custom name.
110+
/// E.g. type `Point` (aka `Tuple(Float64, Float64)`) stays unchanged as `Point`, it does not become
111+
/// `Tuple(Nullable(Float64), Nullable(Float64))`.
112+
/// But `Bool` becomes `Nullable(Bool)`.
109113
DataTypePtr makeNullableRecursively(DataTypePtr type, const FormatSettings & settings);
110114

111115
/// Call makeNullableRecursively for all types
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(10,20) [(0,0),(10,0),(10,10),(0,10)] [[(20,20),(50,20),(50,50),(20,50)],[(30,30),(50,50),(50,30)]] [[(0,0),(10,0),(10,10),(0,10)],[(1,1),(2,2),(3,3)]] [[[(0,0),(10,0),(10,10),(0,10)]],[[(20,20),(50,20),(50,50),(20,50)],[(30,30),(50,50),(50,30)]]]
2+
(30,40) [(1,1),(11,1),(11,11),(1,11)] [[(21,21),(51,21),(51,51),(21,51)],[(31,31),(51,51),(51,31)]] [[(1,1),(11,1),(11,11),(1,11)],[(2,2),(3,3),(4,4)]] [[[(1,1),(11,1),(11,11),(1,11)]],[[(21,21),(51,21),(51,51),(21,51)],[(31,31),(51,51),(51,31)]]]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# Tags: no-fasttest
3+
4+
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
5+
# shellcheck source=../shell_config.sh
6+
. "$CURDIR"/../shell_config.sh
7+
8+
$CLICKHOUSE_CLIENT --query="
9+
insert into function file('${CLICKHOUSE_TEST_UNIQUE_NAME}.parquet', Parquet, 'point Point, linestring LineString, polygon Polygon, multilinestring MultiLineString, multipolygon MultiPolygon') values (
10+
(10, 20),
11+
[(0, 0), (10, 0), (10, 10), (0, 10)],
12+
[[(20, 20), (50, 20), (50, 50), (20, 50)], [(30, 30), (50, 50), (50, 30)]],
13+
[[(0, 0), (10, 0), (10, 10), (0, 10)], [(1, 1), (2, 2), (3, 3)]],
14+
[[[(0, 0), (10, 0), (10, 10), (0, 10)]], [[(20, 20), (50, 20), (50, 50), (20, 50)],[(30, 30), (50, 50), (50, 30)]]]
15+
), (
16+
(30, 40),
17+
[(1, 1), (11, 1), (11, 11), (1, 11)],
18+
[[(21, 21), (51, 21), (51, 51), (21, 51)], [(31, 31), (51, 51), (51, 31)]],
19+
[[(1, 1), (11, 1), (11, 11), (1, 11)], [(2, 2), (3, 3), (4, 4)]],
20+
[[[(1, 1), (11, 1), (11, 11), (1, 11)]], [[(21, 21), (51, 21), (51, 51), (21, 51)],[(31, 31), (51, 51), (51, 31)]]]
21+
);
22+
select * from file('${CLICKHOUSE_TEST_UNIQUE_NAME}.parquet');"
23+
24+
rm "${CLICKHOUSE_USER_FILES}/${CLICKHOUSE_TEST_UNIQUE_NAME}.parquet"

0 commit comments

Comments
 (0)