[Bug]: embedded SDK crashes on TRIM variants (LTRIM/RTRIM/position/character) in output columns

Open Beginner friendly
#3,469 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, python
Domain
backend, databases

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.

Description

Problem

Any TRIM variant beyond a bare trim(col) crashes the embedded SDK:

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:

>>> 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.

Dominant language
C++
Stars
4.7k
Forks
445
Avg merge
2d 9h
Merged PRs (30d)
8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from infiniflow/infinity

All issues in infiniflow/infinity

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.