[fix](select join) Make selected slotRef nullable when slotRef is from nullable tuple in outer join sql block (#7290)

This commit is contained in:
caiconghui
2021-12-06 16:17:10 +08:00
committed by GitHub
parent 164b27412c
commit 8660bf69ff
2 changed files with 11 additions and 2 deletions

View File

@ -660,7 +660,7 @@ public class Analyzer {
}
result = globalState.descTbl.addSlotDescriptor(d);
result.setColumn(col);
if (true == col.isAllowNull()) {
if (col.isAllowNull() || globalState.outerJoinedTupleIds.containsKey(d.getId())) {
result.setIsNullable(true);
} else {
result.setIsNullable(false);

View File

@ -111,7 +111,7 @@ public class SelectStmtTest {
String tbl2 = "CREATE TABLE db1.table2 (\n" +
" `siteid` int(11) NULL DEFAULT \"10\" COMMENT \"\",\n" +
" `citycode` smallint(6) NULL COMMENT \"\",\n" +
" `username` varchar(32) NULL DEFAULT \"\" COMMENT \"\",\n" +
" `username` varchar(32) NOT NULL DEFAULT \"\" COMMENT \"\",\n" +
" `pv` bigint(20) NULL DEFAULT \"0\" COMMENT \"\"\n" +
") ENGINE=OLAP\n" +
"UNIQUE KEY(`siteid`, `citycode`, `username`)\n" +
@ -755,4 +755,13 @@ public class SelectStmtTest {
Assert.assertTrue(stmt2.toSql().contains("WITH v1 AS (SELECT `t1`.`k1` AS `k1` FROM " +
"`default_cluster:db1`.`tbl1` t1),v2 AS (SELECT `t2`.`k1` AS `k1` FROM `default_cluster:db1`.`tbl1` t2)"));
}
@Test
public void testSelectOuterJoinSql() throws Exception {
ConnectContext ctx = UtFrameUtils.createDefaultCtx();
String sql1 = "select l.citycode, group_concat(r.username) from db1.table1 l left join db1.table2 r on l.citycode=r.citycode group by l.citycode";
SelectStmt stmt1 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql1, ctx);
Assert.assertTrue(stmt1.getAnalyzer().getSlotDesc(new SlotId(2)).getIsNullable());
Assert.assertTrue(stmt1.getAnalyzer().getSlotDescriptor("r.username").getIsNullable());
}
}