Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Antlr rewrite for WITHIN GROUP() for STRING_AGG() (babelfish-for-…
…postgresql#2983) ### 1. Issues - Rewriting logic in antlr of WITHIN GROUP() for STRING_AGG() was incorrect as it involved shifting of order_by_clause. This will cause a problem when there is rewrite in order_by_clause itself as now the index of expressions inside order_by_clause will change and this will result in incorrect rewrite. ### 2. Changes made to fix the issues - Corrected Parser rewiting logic to avoid shifting of order_by_clause and only omit the unwanted phrases in between. ``` # Input 1> CREATE TABLE string_agg_t (id int, a varchar(10), b varchar(10), g int, sbid int) 2> INSERT INTO string_agg_t values (3,'c','x',1,4), (2,'b','y',2,6) 3> go 1> SELECT STRING_AGG(concat(a,b),'-') WITHIN GROUP (ORDER BY trim(a) ASC) FROM string_agg_t GROUP BY g ORDER BY g 2> go ``` ``` # previous output (wrong output) Msg 33557097, Level 16, State 1, Server BABELFISH, Line 1 syntax error at or near ")" ``` ``` # current output (correct output) string_agg ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- cx by ``` - Added Test Cases for these issues Task: BABEL-5290 Signed-off-by: Anikait Agrawal [[email protected]](mailto:[email protected])
- Loading branch information