Skip to content

Add the string functions TRIM / LPAD / RPAD #789

Description

@Leomrlin

What & why / 来龙去脉

GeaFlow's DSL already ships 27 string functions (LTrim, RTrim, Substr,
Concat, …), but three everyday ones are missing: TRIM (strip whitespace from
both ends), and LPAD / RPAD (pad a string to a given length). These come up
constantly in data cleaning, so adding them is an immediately useful first PR.

DSL 已经有 27 个字符串函数,但还缺三个数据清洗里天天用的:TRIM(去首尾空格)、
LPAD/RPAD(左右填充到指定长度)。补上它们,第一个 PR 就能让人立刻用上。

The task / 要做的事

Add three scalar functions that match standard SQL behavior:

  • trim(str) — strip leading/trailing whitespace
  • lpad(str, len, pad) / rpad(str, len, pad) — pad to a target length

Where to look / 改哪些文件

  1. Copy the shape of
    geaflow-dsl/geaflow-dsl-plan/src/main/java/org/apache/geaflow/dsl/udf/table/string/LTrim.java.
    In the same folder add Trim.java, LPad.java, RPad.java — extend UDF,
    add the @Description annotation, implement eval(...), and mind the null case.
  2. Register three lines in BuildInSqlFunctionTable.java:
    .add(GeaFlowFunction.of(Trim.class)).
  3. Add function_trim.sql (etc.) under query/ and matching .txt files under expect/.

Done when / 完成标准

  • All three functions implemented and registered, each with @Description
  • null input returns null rather than throwing
  • New .sql tests + .txt expectations pass via mvn test on the right test class
  • Behavior matches MySQL / standard SQL — paste a quick comparison in the PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions