Skip to content

Accept leading whitespace in readWKT - #110706

Merged
PedroTadim merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-readwkt-leading-whitespace
Jul 21, 2026
Merged

PedroTadim merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-readwkt-leading-whitespace

Conversation

@groeneai

@groeneai groeneai commented Jul 16, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed readWKT rejecting WKT strings with leading whitespace (e.g. readWKT(' POINT(1 2)')), which are accepted by the typed readWKTPoint/readWKTPolygon/... readers and by the WKT grammar.

Description

readWKT detected the geometry type by matching a lowercased prefix (point, linestring, ...) against the raw string before skipping leading whitespace, so ' POINT(1 2)' matched no prefix and the loop threw BAD_ARGUMENTS, while readWKTPoint(' POINT(1 2)') parses fine. Fix: boost::trim_left the lowercased string before the prefix comparison so readWKT accepts the same inputs as the typed readers.

This PR also rewrites the hand-rolled WKT parser used by the native GeoParquet reader (parseWKTFormat in ArrowGeoTypes.cpp): a shared separator-skipping helper, strict validation of ( / ) / item separators (throwing BAD_ARGUMENTS instead of silently scanning), tolerance for interior whitespace between the type keyword and coordinates, and rejection of trailing data after the geometry, making GeoParquet WKT import consistent with readWKT. Note: some values previously silently accepted on GeoParquet import (e.g. 3D POINT(1 2 3), POINT x(1 2), trailing garbage) are now rejected.

Closes: #110700

readWKT detected the geometry type by matching a lowercased prefix
(point, linestring, ...) against the raw string before skipping leading
whitespace, so an input like '  POINT(1 2)' matched no prefix and threw
BAD_ARGUMENTS, while the typed readWKT* readers and the WKT grammar
accept the same input. Strip leading whitespace before the prefix match.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. readWKT(' POINT(1 2)') throws Code: 36 BAD_ARGUMENTS: Incorrect WKT format value: POINT(1 2) on every run (baseline binary).
b Root cause explained? FunctionReadWKTCommon::executeImpl's try_deserialize_type lowercases the input then does lower_data.starts_with("point") etc. without skipping leading whitespace, so " point(1 2)" matches no prefix and the loop falls through to throw. The typed readWKT* readers call boost::geometry::read_wkt directly, which skips leading whitespace per the WKT grammar.
c Fix matches root cause? Yes. boost::trim_left(lower_data) before the prefix comparison, so readWKT accepts the same whitespace-prefixed inputs as the typed readers.
d Test intent preserved / new tests added? New test 04545_read_wkt_leading_whitespace asserts leading whitespace parses for POINT/LINESTRING/POLYGON/MULTILINESTRING/MULTIPOLYGON and that readWKT(' POINT(1 2)') = readWKTPoint(' POINT(1 2)').
e Demonstrated in both directions? Yes. Baseline (Build ID 4470055f): the POINT query throws BAD_ARGUMENTS. Fixed (Build ID 3d325f72): all queries parse; typed-reader equality returns 1.
f Fix general, not narrow? Yes. The trim applies to the shared prefix-match path, so all six geometry types benefit; only the type-detection prefix match is affected, boost::geometry::read_wkt handles the rest of the whitespace as before.
g Generalizes across inputs (wrappers, params, boundaries)? Trim covers spaces and tabs; empty/whitespace-only input still falls through to the existing BAD_ARGUMENTS path (unchanged). Only leading whitespace before the type keyword is affected; interior whitespace was always handled by boost.
h Backward compatible? Yes. Strictly widens accepted inputs (previously-thrown inputs now parse); no setting, format, or default change. No SettingsChangesHistory needed.
i Invariants / contracts preserved? Yes. Only the local lower_data copy used for prefix detection is trimmed; the original str passed to boost::geometry::read_wkt is unchanged, and the ColumnVariant discriminator assignment is untouched.

Session id: cron:clickhouse-worker-slot-11:20260716-143400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @nikitamikhaylov — small geo consistency fix: readWKT now trims leading whitespace before the type-prefix match so it accepts the same inputs as the typed readWKT* readers.

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai can you check if other reading functions have this issue?

Comment thread src/Functions/readWkt.cpp
/// The type prefix may be preceded by whitespace, which the WKT grammar (and the typed
/// readWKT* readers) accept; strip it before matching so readWKT stays consistent.
auto lower_data = boost::to_lower_copy(data);
boost::trim_left(lower_data);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai what about whitespaces after the geometry value? Can you add a test case for that?

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [039a740]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
04507_mvt_encode_state_serialize FAIL cidb IGNORED
03707_statistics_cache NOT_FAILED cidb IGNORED
01147_partial_merge_full_join NOT_FAILED cidb IGNORED
02499_monotonicity_toUnixTimestamp64 NOT_FAILED cidb IGNORED
01010_partial_merge_join NOT_FAILED cidb IGNORED
02345_implicit_transaction NOT_FAILED cidb IGNORED
Integration tests (arm_binary, distributed plan, 1/4) FAIL
test_backup_restore_on_cluster/test.py::test_backup_restore_on_single_replica FAIL cidb IGNORED
Performance Comparison (arm_release, master_head, 6/6) ERROR IGNORED

AI Review

Summary

This PR correctly fixes the whitespace-related readWKT and GeoParquet WKT regressions and closes the earlier silent-trailing-garbage holes, but the GeoParquet parser still does not share the full WKT entry grammar with readWKT. I would keep this in request-changes until that remaining type-token divergence is removed.

Findings

⚠️ Majors

  • [src/Processors/Formats/Impl/ArrowGeoTypes.cpp:252-287] parseWKTFormat still hard-codes only the uppercase bare geometry tags. readWKT delegates to boost::geometry::read_wkt, which matches the geometry keyword case-insensitively and accepts EMPTY before parsing coordinates, so inputs like point(1 2) or LINESTRING EMPTY still work through SQL but fail on WKT-encoded GeoParquet import. Suggested fix: canonicalize the type token case-insensitively and share the same EMPTY handling, or route WKT GeoParquet decoding through the same readWKT parser to avoid another partial grammar drift.
Tests
  • ⚠️ Add a focused WKT-encoded GeoParquet regression for lowercase geometry keywords and EMPTY geometries, e.g. point(1 2) and LINESTRING EMPTY. The current coverage only exercises uppercase non-empty inputs, so this remaining divergence is still untested.
Final Verdict
  • Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 16, 2026
Comment thread src/Functions/readWkt.cpp Resolved
parseWKTFormat (ArrowGeoTypes.cpp) reads the geometry type keyword from
the raw buffer and only trimmed trailing spaces, so a WKT-encoded
GeoParquet value with leading whitespace like '  POINT (1 2)' produced
BAD_ARGUMENTS on the Arrow / ArrowIPC / Parquet import path, while the
same value now parses via readWKT and the WKT grammar. Skip leading
whitespace before accumulating the type keyword.

This is the import-path sibling of the readWKT fix in this PR (ClickHouse#110700).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Audited the geometry readers and the type/format dispatchers in src/Functions/.

One sibling had the same bug: parseWKTFormat in src/Processors/Formats/Impl/ArrowGeoTypes.cpp. It reads the type keyword from the raw buffer and trimmed only trailing spaces, so a WKT-encoded GeoParquet value like POINT (1 2) matched no type and threw BAD_ARGUMENTS on the Arrow / ArrowIPC / Parquet import path (callers in ArrowColumnToCHColumn.cpp, ArrowIPCBlockInputFormat.cpp, Parquet/Decoding.cpp). Fixed in this PR (skip leading whitespace before the type keyword) with a GeoParquet regression test (04546_geoparquet_wkt_leading_whitespace) covering all five types. Confirmed it fails before the change and passes after.

The others are fine:

  • Typed readWKT* and readWKTPoint etc. hand the full string to boost::geometry::read_wkt, whose grammar skips leading whitespace.
  • readWKB / readWKB* and parseWKBFormat are binary and dispatch on the parsed variant (std::holds_alternative), so leading whitespace is not a factor.
  • No other src/Functions/ code sniffs a geometry/format type from a text prefix on user input; the remaining starts_with uses (part-info, AES mode names, file paths, ZK node names, JSON-path keys) are internal and not WKT dispatch.

readWKT already accepts trailing whitespace after the geometry value via the
WKT grammar, consistently with the typed readWKT* readers. Add regression
coverage per review request.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Trailing whitespace already parses fine and matches the typed readers: boost::geometry::read_wkt skips it, and this fix only touched the leading prefix-match dispatch. Added regression cases to 04545 (POINT(1 2) , LINESTRING trailing tab, leading+trailing, and readWKT == readWKTPoint on the trailing-space input). Commit 9b1ab28.

@groeneai

Copy link
Copy Markdown
Collaborator Author

The premise here does not hold empirically, so switching to isWhitespaceASCII would introduce the opposite inconsistency.

I checked what the boost WKT grammar (backing both readWKT and the typed readWKT* readers) actually accepts as leading whitespace, byte by byte, on the debug build:

leading byte readWKT readWKTPoint
0x20 space ok ok
0x09 \t ok ok
0x0a \n ok ok
0x0d \r ok ok
0x0c \f Code 6 CANNOT_PARSE_TEXT Code 6 CANNOT_PARSE_TEXT
0x0b \v Code 6 CANNOT_PARSE_TEXT Code 6 CANNOT_PARSE_TEXT

So readWKT itself rejects \f/\v. The boost::trim_left in try_deserialize_type only strips them from the lowercased copy used for the prefix match; the untouched original string is still handed to boost::geometry::read_wkt, whose grammar skips only \t\n\r and throws on \f/\v. End to end, readWKT('\fPOINT(1 2)') throws.

parseWKTFormat's explicit ' ' '\t' '\n' '\r' list therefore already matches exactly the whitespace class readWKT accepts. Switching it to isWhitespaceASCII (which adds \f/\v) would make GeoParquet WKT import accept \fPOINT (1 2) while readWKT on the same value throws, which is a new divergence, not an alignment. Keeping the four-character list keeps the two paths consistent.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 9b1ab28

All red checks are pre-existing flaky/infra issues unrelated to this readWKT/GeoParquet whitespace fix, each with an owning fixing PR.

Check / test Reason Owner / fixing PR
Stateless tests (amd_tsan, s3 storage, parallel, 2/3) / 01730_distributed_group_by_no_merge_order_by_long flaky (reruns 4/4 passed; 120 PRs / 14 master in 30d, MEMORY_LIMIT in AggregatingTransform) #109847 (external, open)
Stateless tests (amd_tsan, s3 storage, parallel, 2/3) / Scraping system tables (minio_audit_logs dump timed out 600s) CI-infra (s3-only, bounded-timeout residual) #110099 (ours, open)
CH Inc sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260716-213000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 9b1ab28

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_tsan, s3 storage, parallel, 2/3) / 01730_distributed_group_by_no_merge_order_by_long flaky (14 master hits + 15+ unrelated PRs in 30d; MEMORY_LIMIT distributed GROUP BY, unrelated to readWKT) #109847 (external, open)
Stateless tests (amd_tsan, s3 storage, parallel, 2/3) / Scraping system tables infra (minio_audit_logs dump timeout on s3 configs) a fix task is moved to pending (investigating at full effort — fixing-PR link to follow here)
CH Inc sync — CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260717-070000

@PedroTadim PedroTadim self-assigned this Jul 17, 2026
if (current_symbol == '(')
break;
/// Skip leading whitespace before the type keyword, consistent with the WKT grammar and readWKT.
if (!seen_type_char && (current_symbol == ' ' || current_symbol == '\t' || current_symbol == '\n' || current_symbol == '\r'))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@groeneai isn't there a isWhiteSpace check function?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the existing helpers accept a wider set than readWKT does, so none matches exactly.

  • isWhitespaceASCII (Common/StringUtils.h:127) = space, \t, \n, \r, \f, \v
  • skipWhitespaceIfAny (IO/ReadHelpers.h:1934) uses isWhitespaceASCII (same set)
  • isWhitespaceASCIIOneLine = space, \t, \f, \v

All three include \f and \v. But readWKT (and the typed readWKT* readers) reject \f/\v: boost::geometry read_wkt skips only space/\t/\n/\r, and our try_deserialize_type only left-trims the lowercased copy used for the prefix match, so the untouched original still hits the boost grammar. A/B on the debug build: readWKT and readWKTPoint both return Code 6 CANNOT_PARSE_TEXT for a leading \f or \v.

So the explicit space/\t/\n/\r list here is intentional: it matches readWKT exactly. Switching to isWhitespaceASCII/skipWhitespaceIfAny would make GeoParquet WKT import accept \fPOINT(1 2) while readWKT rejects it, i.e. re-introduce the divergence this PR removes.

Happy to swap to a helper if you prefer readability over the \f/\v alignment; there is just no existing helper that matches readWKT's space/\t/\n/\r class, so it would need a small local one.

@PedroTadim
PedroTadim enabled auto-merge July 20, 2026 14:42
parseWKTFormat only handled a single space between coordinates and only
skipped ' ' when trimming the type keyword, while readWKT (boost WKT
grammar) treats ' \t\n\r' as token separators throughout. So GeoParquet
WKT imports like 'POINT\t(1 2)', 'POINT(1  2)' threw BAD_ARGUMENTS /
CANNOT_PARSE_NUMBER, and 'LINESTRING(1 1,\n2 2)' silently dropped a
coordinate, even though readWKT parsed all of them.

Normalize the same ' \t\n\r' class (not isWhitespaceASCII, which also
matches \f and \v that read_wkt rejects) at the type-keyword and
coordinate boundaries. Widen the 04546 regression test with interior
whitespace cases.
auto-merge was automatically disabled July 20, 2026 16:25

Head branch was pushed to by a user without write access

…ng readWKT

parseWKTFormat silently accepted inputs that readWKT rejects: non-separator
bytes before '(' (POINT x(1 2)), trailing data after the geometry
(POINT(1 2) trailing, POINT(1 2))), garbage inside the coordinate list
(LINESTRING(1 1 xx, 2 2)), and a missing ')'. readOpenBracket/readItemEnding
skipped arbitrary bytes and the POINT branch never consumed its ')', so
GeoParquet WKT import produced wrong or partial geometries instead of an error.

Make the token boundaries strict (only ' \t\n\r' separators allowed), consume
the closing ')' for POINT, and require the value to end after the geometry.
Whitespace class unchanged; valid values including leading/interior/trailing
separators still parse identically to readWKT.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
type.pop_back();

GeometricObject result;
if (type == "POINT")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't fully match the readWKT contract you're aligning to. boost::geometry::read_wkt matches the geometry keyword with boost::iequals and handles EMPTY before the coordinate parser runs, but this path only accepts the exact uppercase bare tags. As a result, values like point(1 2) or LINESTRING EMPTY continue to work through SQL readWKT, while WKT-encoded GeoParquet import still throws BAD_ARGUMENTS here.

Can we canonicalize the type token case-insensitively and teach this entry point the same EMPTY handling, or just reuse readWKT for WKT decoding so the two parsers actually share one grammar?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The divergence is partly real, but "reuse readWKT" / mirror its EMPTY handling is unsafe here. A/B on the current build (SQL readWKT, which uses boost::geometry::read_wkt, as the oracle vs the GeoParquet parseWKTFormat path):

input readWKT (SQL) parseWKTFormat (GeoParquet)
point(1 2) (lowercase) (1,2) Code 36 BAD_ARGUMENTS
LINESTRING EMPTY [] Code 36
POLYGON EMPTY [[]] Code 36
POINT EMPTY (6.95e-310, 6.95e-310) [1] Code 36

[1] readWKT('POINT EMPTY') returns different uninitialized floats on every run (6.9530e-310, 6.9531e-310, 6.9532e-310 across three runs); boost has no defined value for an empty point, so this is an uninitialized read. Mirroring readWKT for POINT EMPTY would import garbage coordinates.

So the two genuine gaps are the case-insensitive type keyword and container EMPTY (LINESTRING / POLYGON / MULTI*). Both are inputs the importer currently rejects with a clear BAD_ARGUMENTS: no silent wrong data, unlike the interior-whitespace and trailing-garbage rounds that were fixed here. Accepting lowercase keywords and EMPTY geometries is a feature expansion of the GeoParquet WKT importer beyond this PR's whitespace-consistency scope (Closes #110700), and it needs the POINT EMPTY uninitialized read in readWKT resolved first. Tracking it as a follow-up rather than widening this already-approved PR. No code change this round.

@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.20% 78.20% +0.00%

Changed lines: Changed C/C++ lines covered: 65/67 (97.01%) · Uncovered code

Full report · Diff report

@PedroTadim
PedroTadim added this pull request to the merge queue Jul 21, 2026
Merged via the queue into ClickHouse:master with commit d529ed8 Jul 21, 2026
344 of 351 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 21, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.

TL;DR

Accept leading whitespace in readWKT

ClickGap verified: reproduced it with the script below on 26.6; tested 7 version(s) — 6 affected, 1 clean (see Affects); long-standing (not a recent regression); introducing PR not yet pinned.

Reproduction

SELECT readWKT('  POINT(1 2)');
-- pre-fix (all supported releases 26.1-26.6): Code: 36 BAD_ARGUMENTS "Incorrect WKT format value:   POINT(1 2)".
-- expected (post-fix, matching readWKTPoint('  POINT(1 2)') -> (1,2)):
SELECT readWKT('  POINT(1 2)') = readWKTPoint('  POINT(1 2)');  -- 1

▶ Run on ClickHouse Fiddle

Bisect

  • Reproduces on every release line tested down to v25.12.11.4 (the oldest with a downloadable binary for this repro). The introducing change predates v25.12.11.4, so it can't be pinned from release binaries — this is a long-standing issue, not a recent regression. A maintainer with full git history can git blame the relevant file/line to find the exact change.

Affects

  • ✓ Fix is on master — this PR's change fixes the bug on master. Branches below still have the bug and need the backport.
  • Reproduces on: 26.6, 26.5, 26.4, 26.3, 26.2, 26.1
  • Does NOT reproduce on: master
  • Backport needed: 26.6, 26.5, 26.4, 26.3, 26.2, 26.1

Suggested next step

The fix has landed on master; the affected release branches above still need the backport.

Component: comp-geo
Severity: P2

cc fix PR author: @groeneai


ClickGap · Finding: phase_d_pr110706

Triage metadata

@clickgapai

Copy link
Copy Markdown
Contributor

Hi @groeneai @PedroTadim — a couple of suggestions to make this PR easier for reviewers and the changelog reader.

Description (currently incomplete):

  • Why: The body explains only the readWKT prefix-trim fix and does not mention the ArrowGeoTypes.cpp GeoParquet parser refactor, which changes import behavior (rejects malformed WKT that was previously silently accepted, tolerates interior/trailing whitespace).

  • Suggested addition:

    This PR also rewrites the hand-rolled WKT parser used by the native GeoParquet reader (parseWKTFormat): it introduces a shared separator-skipping helper, strictly validates '(' / ')' / item separators (throwing BAD_ARGUMENTS instead of silently scanning), tolerates interior whitespace between the type keyword and coordinates, and rejects trailing data after the geometry — making GeoParquet WKT import consistent with readWKT. Note: values previously silently accepted (e.g. 3D 'POINT(1 2 3)', 'POINT x(1 2)', trailing garbage) are now rejected on import.

Ignore this if the current title/body is intentional.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks. Applied the description suggestion: the PR body now documents the parseWKTFormat (ArrowGeoTypes.cpp) GeoParquet rewrite and the inputs it now rejects on import.

On the backport: this is confirmed long-standing (repros on 26.1-26.6, clean on master), but backport labeling is a maintainer call, so leaving pr-must-backport to the maintainers.

Separately, the GeoParquet WKT importer still diverges from readWKT on two acceptance cases not covered here (lowercase/mixed-case type keyword, and container EMPTY for LINESTRING/POLYGON); those are tracked as a follow-up and sequenced after #110692 (POINT EMPTY semantics) merges.

Manerone pushed a commit to Manerone/ClickHouse that referenced this pull request Jul 28, 2026
parseWKTFormat decodes WKT geometry columns for GeoParquet, Arrow and
ArrowStream. Its grammar was missing two productions that the WKT spec
allows and that the readWKT function accepts, so valid files failed to
import:

  point(1 2)                    Code 36: type point
  LINESTRING EMPTY, POLYGON()   Code 36 / Code 72

The empty-container gap also broke a round trip through ClickHouse's own
functions, since wkt emits LINESTRING() and POLYGON() for empty
geometries. The WKB branch of this same importer already accepted every
one of these empty geometries with the same values, so the WKT branch was
the only outlier.

Three changes: the type keyword is uppercased before dispatch;
readWKTEmptyToken accepts EMPTY in place of the coordinate list, only
right after the type keyword, so POLYGON(EMPTY) keeps failing as it does
in readWKT; checkWKTEmptyList accepts () as an empty element list in each
container reader, which is valid at every nesting depth.

readWKTEmptyToken reads the whole token and reports an unrecognized one
rather than leaving it half-consumed, so LINESTRING E(1 1, 2 2) stays
rejected instead of having its stray E swallowed and the rest parsed.

POINT EMPTY, POINT() and MULTIPOINT(()) stay rejected: a Point is
Tuple(Float64, Float64) with no empty representation, and readWKT returns
fabricated coordinates for the latter two, which must not be imported.
The change only widens acceptance, every input that imported before still
imports with the identical value.

Related: ClickHouse#110706

Co-Authored-By: Claude Fable 5 <[email protected]>
scanhex12 pushed a commit to scanhex12/ClickHouse that referenced this pull request Jul 29, 2026
parseWKTFormat decodes WKT geometry columns for GeoParquet, Arrow and
ArrowStream. Its grammar was missing two productions that the WKT spec
allows and that the readWKT function accepts, so valid files failed to
import:

  point(1 2)                    Code 36: type point
  LINESTRING EMPTY, POLYGON()   Code 36 / Code 72

The empty-container gap also broke a round trip through ClickHouse's own
functions, since wkt emits LINESTRING() and POLYGON() for empty
geometries. The WKB branch of this same importer already accepted every
one of these empty geometries with the same values, so the WKT branch was
the only outlier.

Three changes: the type keyword is uppercased before dispatch;
readWKTEmptyToken accepts EMPTY in place of the coordinate list, only
right after the type keyword, so POLYGON(EMPTY) keeps failing as it does
in readWKT; checkWKTEmptyList accepts () as an empty element list in each
container reader, which is valid at every nesting depth.

readWKTEmptyToken reads the whole token and reports an unrecognized one
rather than leaving it half-consumed, so LINESTRING E(1 1, 2 2) stays
rejected instead of having its stray E swallowed and the rest parsed.

POINT EMPTY, POINT() and MULTIPOINT(()) stay rejected: a Point is
Tuple(Float64, Float64) with no empty representation, and readWKT returns
fabricated coordinates for the latter two, which must not be imported.
The change only widens acceptance, every input that imported before still
imports with the identical value.

Related: ClickHouse#110706

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…kt-leading-whitespace

Accept leading whitespace in readWKT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readWKT rejects leading whitespace that the typed WKT readers (and the WKT grammar) accept

4 participants