[fix](planner) cannot recogonize column's table when analyze rewrite expr (#13597)

We save mv column with alias as table name, and search it with original table name.
This commit is contained in:
morrySnow
2022-10-26 11:15:48 +08:00
committed by GitHub
parent e5b33abd3c
commit 15130c469f
4 changed files with 73 additions and 1 deletions

View File

@ -34,6 +34,7 @@ import org.apache.doris.thrift.TSlotRef;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -189,6 +190,10 @@ public class SlotRef extends Expr {
if (type.equals(Type.BOOLEAN)) {
selectivity = DEFAULT_SELECTIVITY;
}
if (tblName == null && StringUtils.isNotEmpty(desc.getParent().getLastAlias())
&& !desc.getParent().getLastAlias().equals(desc.getParent().getTable().getName())) {
tblName = new TableName(null, null, desc.getParent().getLastAlias());
}
}
@Override

View File

@ -192,6 +192,10 @@ public class TupleDescriptor {
return (aliases != null) ? aliases[0] : null;
}
public String getLastAlias() {
return (aliases != null) ? aliases[aliases.length - 1] : null;
}
public TableName getAliasAsName() {
return (aliases != null) ? new TableName(null, null, aliases[0]) : null;
}

View File

@ -189,7 +189,7 @@ public class PolicyTest extends TestWithFeService {
String subQuerySql = "select * from table2 where k1 in (select k1 from table1)";
Assertions.assertTrue(getSQLPlanOrErrorMsg(subQuerySql).contains("PREDICATES: `k1` = 1, `k2` = 1"));
String aliasSql = "select * from table1 t1 join table2 t2 on t1.k1=t2.k1";
Assertions.assertTrue(getSQLPlanOrErrorMsg(aliasSql).contains("PREDICATES: `k1` = 1, `k2` = 1"));
Assertions.assertTrue(getSQLPlanOrErrorMsg(aliasSql).contains("PREDICATES: `t1`.`k1` = 1, `t1`.`k2` = 1"));
dropPolicy("DROP ROW POLICY test_row_policy1 ON test.table1");
dropPolicy("DROP ROW POLICY test_row_policy2 ON test.table1");
}