infiniflow / infiniflow/infinity
[Bug]: embedded SDK crashes on TRIM variants (LTRIM/RTRIM/position/character) in output columns
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 445
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 7
Description
## Problem
Any `TRIM` variant beyond a bare `trim(col)` crashes the embedded SDK:
```python
from sqlglot import parse_one
from infinity_embedded.local_infinity.utils import parse_expr
parse_expr(parse_one("trim(both ' ' from name)")) # Exception: unknown expression type: TRIM(name, ' ')
parse_expr(parse_one("trim(leading 'x' from name)")) # same
parse_expr(parse_one("ltrim(name)")) # same
```
## Root cause
sqlglot parses all of these — including `ltrim(...)` / `rtrim(...)` — as `exp.Trim`, whose `position` arg is a plain string (`'LEADING'` / `'TRAILING'` / `'BOTH'`) and whose `expression` arg is the character literal:
```python
>>> parse_one("trim(both ' ' from name)").args
{'this': Column(...), 'position': 'BOTH', 'expression': Literal(...), 'collation': None}
```
The embedded SDK's generic `exp.Func` arm in `python/infinity_embedded/local_infinity/utils.py` feeds every value in `cons.args.values()` to `parse_expr`, and the raw string `'BOTH'` (or the character literal) matches no arm and raises.
The thrift SDK maps `Trim` to the server's `trim` / `ltrim` / `rtrim` by position, and the server registers all three (`src/function/scalar/trim_impl.cpp`, `ltrim_impl.cpp`, `rtrim_impl.cpp`).
## Fix
Add a dedicated `exp.Trim` arm before the generic `Func` arm that maps the position flag to `trim` / `ltrim` / `rtrim`, mirroring the thrift SDK.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at parse_expr in python/infinity_embedded/local_infinity/utils.py and inspect the generic exp.Func handling alongside the thrift SDK's Trim mapping. Check the registered server functions in src/function/scalar/trim_impl.cpp, ltrim_impl.cpp, and rtrim_impl.cpp. Done means trim, ltrim, and rtrim variants with position or character arguments no longer raise the unknown expression type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100