Skip to content

Commit

Permalink
Fix the issue about Like collation not properly transformed (#3141) (#…
Browse files Browse the repository at this point in the history
…3179)


There is a missing condition for transforming an OpExpr when the like
node is in the ars list of OpExpr

Task: BABEL-5397, BABEL-5424
Signed-off-by: Zhibai Song <[email protected]>
  • Loading branch information
forestkeeper authored Dec 4, 2024
1 parent 45bc806 commit 21901c2
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
9 changes: 7 additions & 2 deletions contrib/babelfishpg_tsql/src/collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,13 @@ pltsql_predicate_transformer(Node *expr)

if (IsA(expr, OpExpr))
{
/* Singleton predicate */
return transform_likenode(expr);
Node *ret = transform_likenode(expr);
if (expr == ret)
/* If it's not a like Opexpr, then walk through args */
return expression_tree_mutator(expr, pgtsql_expression_tree_mutator, NULL);
else
/* Singleton predicate */
return ret;
}
else
{
Expand Down
86 changes: 86 additions & 0 deletions test/JDBC/expected/BABEL-4046-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,92 @@ int#!#nvarchar#!#nvarchar
~~END~~


;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc = 'A' order by DM.empno
GO
~~START~~
int#!#nvarchar#!#nvarchar
7566#!#JONES#!#A
7654#!#MARTIN#!#A
7839#!#KING#!#A
~~END~~


;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc > 'A' order by DM.empno
GO
~~START~~
int#!#nvarchar#!#nvarchar
7369#!#SMITH#!#BOSTON
7499#!#ALLEN#!#CHICAGO
7521#!#WARD#!#CHICAGO
7698#!#BLAKE#!#BOSTON
7782#!#CLARK#!#NEW YORK
7788#!#SCOTT#!#NEW YORK
~~END~~


;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc < 'Z' order by DM.empno
GO
~~START~~
int#!#nvarchar#!#nvarchar
7369#!#SMITH#!#BOSTON
7499#!#ALLEN#!#CHICAGO
7521#!#WARD#!#CHICAGO
7566#!#JONES#!#A
7654#!#MARTIN#!#A
7698#!#BLAKE#!#BOSTON
7782#!#CLARK#!#NEW YORK
7788#!#SCOTT#!#NEW YORK
7839#!#KING#!#A
~~END~~


;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc >= 'A' order by DM.empno
GO
~~START~~
int#!#nvarchar#!#nvarchar
7369#!#SMITH#!#BOSTON
7499#!#ALLEN#!#CHICAGO
7521#!#WARD#!#CHICAGO
7566#!#JONES#!#A
7654#!#MARTIN#!#A
7698#!#BLAKE#!#BOSTON
7782#!#CLARK#!#NEW YORK
7788#!#SCOTT#!#NEW YORK
7839#!#KING#!#A
~~END~~


;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc <= 'W' order by DM.empno
GO
~~START~~
int#!#nvarchar#!#nvarchar
7369#!#SMITH#!#BOSTON
7499#!#ALLEN#!#CHICAGO
7521#!#WARD#!#CHICAGO
7566#!#JONES#!#A
7654#!#MARTIN#!#A
7698#!#BLAKE#!#BOSTON
7782#!#CLARK#!#NEW YORK
7788#!#SCOTT#!#NEW YORK
7839#!#KING#!#A
~~END~~


;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc1,
CASE WHEN baseloc LIKE 'CHI%' THEN REPLACE(baseloc,'CHICAGO','C') ELSE baseloc END AS baseloc2,
deptno from t3)
select DM.empno, DM.ename, DM.baseloc1, DM.baseloc2 from EMP_T DM where DM.baseloc1 < DM.baseloc2 order by DM.empno
GO
~~START~~
int#!#nvarchar#!#nvarchar#!#nvarchar
7566#!#JONES#!#A#!#AUSTIN
7654#!#MARTIN#!#A#!#AUSTIN
7839#!#KING#!#A#!#AUSTIN
~~END~~


23 changes: 23 additions & 0 deletions test/JDBC/input/BABEL-4046-vu-verify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ GO
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc in (select baseloc from t4) order by DM.empno
GO

;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc = 'A' order by DM.empno
GO

;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc > 'A' order by DM.empno
GO

;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc < 'Z' order by DM.empno
GO

;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc >= 'A' order by DM.empno
GO

;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc, deptno from t3)
select DM.empno, DM.ename, DM.baseloc from EMP_T DM where DM.baseloc <= 'W' order by DM.empno
GO

;with EMP_T AS ( select empno, ename, CASE WHEN baseloc LIKE 'AUS%' THEN REPLACE(baseloc,'AUSTIN','A') ELSE baseloc END AS baseloc1,
CASE WHEN baseloc LIKE 'CHI%' THEN REPLACE(baseloc,'CHICAGO','C') ELSE baseloc END AS baseloc2,
deptno from t3)
select DM.empno, DM.ename, DM.baseloc1, DM.baseloc2 from EMP_T DM where DM.baseloc1 < DM.baseloc2 order by DM.empno
GO

0 comments on commit 21901c2

Please sign in to comment.