xiedeyantu commented on code in PR #4748:
URL: https://github.com/apache/calcite/pull/4748#discussion_r2698156236
##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -6426,6 +6426,25 @@ private void checkLiteral2(String expression, String
expected) {
sql(query).withConfig(c -> c.withExpand(false)).ok(expected);
}
+ /** Test case of
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7378">[CALCITE-7378]
+ * Potential incorrect column attribution in RelToSqlConverter due to
implicit
+ * table alias handling</a>. */
+ @Test void testSubQueryWithSelfJoin() {
+ String query = "select \"product_name\" from \"product\" t1 "
+ + "where \"product_id\" not in (select \"product_id\" "
+ + "from \"product\" t2 "
+ + "where t2.\"product_id\" = t1.\"product_id\" "
+ + "and t1.\"product_id\" = 2 and t2.\"product_id\" = 1)";
+ String expected = "SELECT \"product_name\"\n"
Review Comment:
You misunderstood what mihai and I meant. The SQL should be placed in a file
such as join.iq, and CoreQuidemTest will test this file and verify the results,
not written in RelToSqlConverterTest.
If you would like to add my case, you can do so in a way similar to the
following:
```
!use blank
CREATE TABLE a (
deptno INTEGER PRIMARY KEY,
ename VARCHAR(10)
);
!update
CREATE TABLE b (
deptno INTEGER,
ename VARCHAR(10)
);
!update
INSERT INTO a VALUES
(10, 'ALLEN'),
(20, 'WARD'),
(30, 'WARD'),
(40, 'SMITH');
!update
INSERT INTO b VALUES
(20, 'WARD'),
(30, 'WARD'),
(30, 'ALLEN'),
(10, 'KING');
!update
SELECT deptno
FROM b as b1
WHERE deptno NOT IN (
SELECT deptno
FROM a
WHERE deptno = b1.deptno AND ename = 'WARD' AND b1.ename = 'WARD'
);
!ok
SELECT deptno
FROM b as a
WHERE deptno NOT IN (
SELECT deptno
FROM a
WHERE deptno = a.deptno AND ename = 'WARD' AND a.ename = 'WARD'
);
!ok
SELECT deptno
FROM b as a
WHERE deptno NOT IN (
SELECT deptno
FROM a as a2
WHERE deptno = a.deptno AND ename = 'WARD' AND a.ename = 'WARD'
);
!ok
```
If you want to use your table, you might want to use `!use post.`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]