Hi community,

I want to override the `trim` function. Currently the function it cannot
support signature like this: `trim(string, characters)`, which is supported
by database like DuckDB[1].

I implemented a function like the following:

```
public class SqlTrim2Function extends SqlFunction {
    public static final SqlTrim2Function INSTANCE = new SqlTrim2Function();
    public SqlTrim2Function() {
        super(
                "TRIM",
                SqlKind.OTHER_FUNCTION,
                ReturnTypes.VARCHAR,
                null,
                OperandTypes.STRING
                        .or(OperandTypes.sequence("TRIM(<STRING>,
<STRING>)",
                                OperandTypes.STRING, OperandTypes.STRING)),
                SqlFunctionCategory.STRING);
    }
}
```

and added to the operator table like this:

```
        SqlOperatorTable sqlOperatorTable = SqlOperatorTables.chain(
                SqlOperatorTables.of(
                        SqlTrim2Function.INSTANCE
                )
        );

        FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
                ...
                .operatorTable(sqlOperatorTable)
                ...
                .build();
```

However, I still got the parsing error (saying there is a ',').

The reason is that the `TRIM` expression directly goes to the
`BuiltinFunctionCall` since `jj_2_60(2)` is true inside
`AtomicRowExpression` of `SqlParserImpl` instead of goes to
`NamedFunctionCall·. So it does not goes to the function I defined.

Currently I workaround this by changing the function name to `trim2` so
that it is not recognized as a built-in function, which works but is not
ideal. Is there a easy way to override the `trim` function inside
SqlParserImpl (seems like it is generated)?

Best,
Xiaoying


[1] https://duckdb.org/docs/sql/functions/char.html

Reply via email to