Skip to content

feat(clickhouse): parse trimLeft/trimRight/trimBoth into Trim - #8240

Merged
geooo109 merged 2 commits into
tobymao:mainfrom
raghav-reglobe:clickhouse-trim-functions
Aug 22, 2026
Merged

feat(clickhouse): parse trimLeft/trimRight/trimBoth into Trim#8240
geooo109 merged 2 commits into
tobymao:mainfrom
raghav-reglobe:clickhouse-trim-functions

Conversation

@raghav-reglobe

@raghav-reglobe raghav-reglobe commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

ClickHouse's trimLeft, trimRight and trimBoth take an optional second argument naming the characters to strip, but the parser left all three as Anonymous, so they reached every target dialect verbatim (TRIMLEFT(s, 'x')).

This registers them on exp.Trim with the LEADING/TRAILING/BOTH position (reusing parser.build_trim for the left/right cases), so they transpile — DuckDB LTRIM(s, 'x'), Doris/Postgres TRIM(LEADING 'x' FROM s) — and round-trip to the TRIM(... FROM ...) form the ClickHouse generator already emits (and which the existing identity tests at the same spot assert as canonical).

Before:

q = "SELECT trimLeft(s, 'x')"
transpile(q, read="clickhouse", write="doris")
# SELECT TRIMLEFT(s, 'x')
transpile(q, read="clickhouse", write="duckdb")
# SELECT TRIMLEFT(s, 'x')

After:

# doris:  SELECT TRIM(LEADING 'x' FROM s)
# duckdb: SELECT LTRIM(s, 'x')

ClickHouse's trimLeft, trimRight and trimBoth take an optional second
argument naming the characters to strip, but the parser left all three as
Anonymous, so they reached every target dialect verbatim as
TRIMLEFT(s, 'x'). Register them on exp.Trim with the LEADING/TRAILING/
BOTH position so they transpile (DuckDB LTRIM(s, 'x'), Postgres
TRIM(LEADING 'x' FROM s), ...) and round-trip to the TRIM(... FROM ...)
form the ClickHouse generator already emits.
@geooo109
geooo109 merged commit 69b059e into tobymao:main Aug 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants