apache / datafusion-sqlparser-rs

Extensible SQL Lexer and Parser for Rust
Apache License 2.0
2.8k stars 543 forks source link

Add support for MSSQL's `JSON_ARRAY`/`JSON_OBJECT` expr #1507

Closed gaoqiangz closed 4 days ago

gaoqiangz commented 1 week ago

Solves #1506

gaoqiangz commented 1 week ago

I modified existing Function parsing,include a break change because JSON_OBJECT support FUNC(<expr> : <expr>) syntax:

DECLARE @id_key nvarchar(10) = N'id',@id_value nvarchar(64) = NEWID();
SELECT JSON_OBJECT(LOWER('USER_NAME') : USER_NAME(), LOWER(@id_key) : @id_value, 'sid':(SELECT @@SPID));

Break change:

pub enum FunctionArg {
    Named {
        name: Expr, // <<
        arg: FunctionArgExpr,
        operator: FunctionArgOperator,
    },
    Unnamed(FunctionArgExpr),
}

Please take a look!

gaoqiangz commented 1 week ago

I refactored function parameter list parsing,add some supports_named_fn_args_with_xxx functions to the Dialect trait,please take a look!

alamb commented 4 days ago

Thanks again @gaoqiangz and @iffyio and @lovasoa