Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/SlotRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.util.ToSqlContext;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.thrift.TExprNode;
import org.apache.doris.thrift.TExprNodeType;
import org.apache.doris.thrift.TSlotRef;
Expand Down Expand Up @@ -205,9 +206,15 @@ public String toSqlImpl() {
StringBuilder sb = new StringBuilder();

if (tblName != null) {
return tblName.toSql() + "." + label + sb.toString();
return tblName.toSql() + "." + label;
} else if (label != null) {
return label + sb.toString();
if (ConnectContext.get() != null
&& ConnectContext.get().getSessionVariable() != null
&& ConnectContext.get().getSessionVariable().isEnableNereidsPlanner()) {
return label + "[#" + desc.getId().asInt() + "]";
} else {
return label;
}
} else if (desc.getSourceExprs() != null) {
if (ToSqlContext.get() == null || ToSqlContext.get().isNeedSlotRefId()) {
if (desc.getId().asInt() != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ public void setNameWithLock(String newName) {
writeLock();
try {
this.fullQualifiedName = newName;
for (Table table : idToTable.values()) {
table.setQualifiedDbName(fullQualifiedName);
}
} finally {
writeUnlock();
}
Expand Down Expand Up @@ -361,6 +364,7 @@ public Pair<Boolean, Boolean> createTableWithLock(

public boolean createTable(Table table) {
boolean result = true;
table.setQualifiedDbName(fullQualifiedName);
String tableName = table.getName();
if (Env.isStoredTableNamesLowerCase()) {
tableName = tableName.toLowerCase();
Expand Down Expand Up @@ -564,6 +568,7 @@ public void readFields(DataInput in) throws IOException {
int numTables = in.readInt();
for (int i = 0; i < numTables; ++i) {
Table table = Table.read(in);
table.setQualifiedDbName(fullQualifiedName);
String tableName = table.getName();
nameToTable.put(tableName, table);
idToTable.put(table.getId(), table);
Expand Down Expand Up @@ -651,6 +656,9 @@ public String getAttachDb() {

public void setName(String name) {
this.fullQualifiedName = name;
for (Table table : nameToTable.values()) {
table.setQualifiedDbName(name);
}
}

public synchronized void addFunction(Function function) throws UserException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class PartitionInfo implements Writable {
protected Map<Long, TTabletType> idToTabletType;

public PartitionInfo() {
this.type = PartitionType.UNPARTITIONED;
this.idToDataProperty = new HashMap<>();
this.idToReplicaAllocation = new HashMap<>();
this.idToInMemory = new HashMap<>();
Expand Down
14 changes: 14 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -60,6 +61,7 @@ public abstract class Table extends MetaObject implements Writable, TableIf {

protected long id;
protected volatile String name;
protected volatile String qualifiedDbName;
protected TableType type;
protected long createTime;
protected ReentrantReadWriteLock rwLock;
Expand Down Expand Up @@ -248,6 +250,18 @@ public void setName(String newName) {
name = newName;
}

void setQualifiedDbName(String qualifiedDbName) {
this.qualifiedDbName = qualifiedDbName;
}

public String getQualifiedName() {
if (StringUtils.isEmpty(qualifiedDbName)) {
Comment thread
morrySnow marked this conversation as resolved.
return name;
} else {
return qualifiedDbName + "." + name;
}
}

public TableType getType() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ public PlanFragment visitPhysicalOlapScan(PhysicalOlapScan olapScan, PlanTransla
OlapTable olapTable = olapScan.getTable();
TupleDescriptor tupleDescriptor = generateTupleDesc(slotList, olapTable, context);
tupleDescriptor.setTable(olapTable);
OlapScanNode olapScanNode = new OlapScanNode(context.nextPlanNodeId(), tupleDescriptor, olapTable.getName());
OlapScanNode olapScanNode = new OlapScanNode(context.nextPlanNodeId(), tupleDescriptor, "OlapScanNode");
// TODO: Do we really need tableName here?
TableName tableName = new TableName(null, "", "");
TableRef ref = new TableRef(tableName, null, null);
BaseTableRef tableRef = new BaseTableRef(ref, olapTable, tableName);
tupleDescriptor.setRef(tableRef);
olapScanNode.setSelectedPartitionIds(olapScan.getSelectedPartitionId());
olapScanNode.setSelectedPartitionIds(olapScan.getSelectedPartitionIds());
try {
olapScanNode.updateScanRangeInfoByNewMVSelector(olapScan.getSelectedIndexId(), false, "");
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public SlotDescriptor createSlotDesc(TupleDescriptor tupleDesc, SlotReference sl
}
slotDescriptor.setType(slotReference.getDataType().toCatalogDataType());
slotDescriptor.setIsMaterialized(true);
this.addExprIdSlotRefPair(slotReference.getExprId(), new SlotRef(slotDescriptor));
SlotRef slotRef = new SlotRef(slotDescriptor);
slotRef.setLabel(slotReference.getName());
this.addExprIdSlotRefPair(slotReference.getExprId(), slotRef);
slotDescriptor.setIsNullable(slotReference.nullable());
return slotDescriptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public OlapTable getTable() {
@Override
public String toString() {
return Utils.toSqlString("LogicalOlapScan",
"qualifier", qualifiedName(),
"qualified", qualifiedName(),
"output", getOutput()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.doris.nereids.util.Utils;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.util.Collections;
import java.util.List;
Expand All @@ -43,8 +42,7 @@ public abstract class LogicalRelation extends LogicalLeaf implements Scan {

protected final Table table;
protected final List<String> qualifier;

protected List<Long> selectedPartitionIds = Lists.newArrayList();
protected final List<Long> selectedPartitionIds;

public LogicalRelation(PlanType type, Table table, List<String> qualifier) {
this(type, table, qualifier, Optional.empty(), Optional.empty(), Collections.emptyList());
Expand All @@ -57,13 +55,13 @@ public LogicalRelation(PlanType type, Table table, List<String> qualifier) {
* @param qualifier qualified relation name
*/
public LogicalRelation(PlanType type, Table table, List<String> qualifier,
Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties,
List<Long> selectedPartitionIdList) {
Optional<GroupExpression> groupExpression, Optional<LogicalProperties> logicalProperties,
List<Long> selectedPartitionIds) {
super(type, groupExpression, logicalProperties);
this.table = Objects.requireNonNull(table, "table can not be null");
this.qualifier = ImmutableList.copyOf(Objects.requireNonNull(qualifier, "qualifier can not be null"));
this.selectedPartitionIds = selectedPartitionIdList;
this.selectedPartitionIds = ImmutableList.copyOf(
Objects.requireNonNull(selectedPartitionIds, "selectedPartitionIds can not be null"));
}

public Table getTable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class PhysicalOlapScan extends PhysicalRelation {
private final OlapTable olapTable;
private final DistributionSpec distributionSpec;
private final long selectedIndexId;
private final List<Long> selectedTabletId;
private final List<Long> selectedPartitionId;
private final List<Long> selectedTabletIds;
private final List<Long> selectedPartitionIds;

/**
* Constructor for PhysicalOlapScan.
Expand All @@ -47,27 +47,26 @@ public class PhysicalOlapScan extends PhysicalRelation {
* @param qualifier qualifier of table name
*/
public PhysicalOlapScan(OlapTable olapTable, List<String> qualifier, long selectedIndexId,
List<Long> selectedTabletId, List<Long> selectedPartitionId, DistributionSpec distributionSpec,
List<Long> selectedTabletIds, List<Long> selectedPartitionIds, DistributionSpec distributionSpec,
Optional<GroupExpression> groupExpression, LogicalProperties logicalProperties) {
super(PlanType.PHYSICAL_OLAP_SCAN, qualifier, groupExpression, logicalProperties);

this.olapTable = olapTable;
this.selectedIndexId = selectedIndexId;
this.selectedTabletId = selectedTabletId;
this.selectedPartitionId = selectedPartitionId;
this.selectedTabletIds = selectedTabletIds;
this.selectedPartitionIds = selectedPartitionIds;
this.distributionSpec = distributionSpec;
}

public long getSelectedIndexId() {
return selectedIndexId;
}

public List<Long> getSelectedTabletId() {
return selectedTabletId;
public List<Long> getSelectedTabletIds() {
return selectedTabletIds;
}

public List<Long> getSelectedPartitionId() {
return selectedPartitionId;
public List<Long> getSelectedPartitionIds() {
return selectedPartitionIds;
}

public OlapTable getTable() {
Expand All @@ -81,7 +80,7 @@ public DistributionSpec getDistributionSpec() {
@Override
public String toString() {
return Utils.toSqlString("PhysicalOlapScan",
"qualifier", Utils.qualifiedName(qualifier, olapTable.getName()),
"qualified", Utils.qualifiedName(qualifier, olapTable.getName()),
"output", getOutput()
);
}
Expand All @@ -96,14 +95,14 @@ public boolean equals(Object o) {
}
PhysicalOlapScan that = (PhysicalOlapScan) o;
return selectedIndexId == that.selectedIndexId
&& Objects.equals(selectedTabletId, that.selectedTabletId)
&& Objects.equals(selectedPartitionId, that.selectedPartitionId)
&& Objects.equals(selectedTabletIds, that.selectedTabletIds)
&& Objects.equals(selectedPartitionIds, that.selectedPartitionIds)
&& Objects.equals(olapTable, that.olapTable);
}

@Override
public int hashCode() {
return Objects.hash(selectedIndexId, selectedPartitionId, selectedTabletId, olapTable);
return Objects.hash(selectedIndexId, selectedPartitionIds, selectedTabletIds, olapTable);
}

@Override
Expand All @@ -113,13 +112,13 @@ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {

@Override
public Plan withGroupExpression(Optional<GroupExpression> groupExpression) {
return new PhysicalOlapScan(olapTable, qualifier, selectedIndexId, selectedTabletId, selectedPartitionId,
distributionSpec, groupExpression, logicalProperties);
return new PhysicalOlapScan(olapTable, qualifier, selectedIndexId, selectedTabletIds,
selectedPartitionIds, distributionSpec, groupExpression, logicalProperties);
}

@Override
public Plan withLogicalProperties(Optional<LogicalProperties> logicalProperties) {
return new PhysicalOlapScan(olapTable, qualifier, selectedIndexId, selectedTabletId, selectedPartitionId,
distributionSpec, Optional.empty(), logicalProperties.get());
return new PhysicalOlapScan(olapTable, qualifier, selectedIndexId, selectedTabletIds,
selectedPartitionIds, distributionSpec, Optional.empty(), logicalProperties.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public abstract class PhysicalRelation extends PhysicalLeaf implements Scan {
* @param type node type
* @param qualifier table's name
*/
public PhysicalRelation(PlanType type, List<String> qualifier, Optional<GroupExpression> groupExpression,
LogicalProperties logicalProperties) {
public PhysicalRelation(PlanType type, List<String> qualifier,
Optional<GroupExpression> groupExpression, LogicalProperties logicalProperties) {
super(type, groupExpression, logicalProperties);
this.qualifier = Objects.requireNonNull(qualifier, "qualifier can not be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ public String getNodeExplainString(String prefix, TExplainLevel detailLevel) {
StringBuilder output = new StringBuilder();

String indexName = olapTable.getIndexNameById(selectedIndexId);
output.append(prefix).append("TABLE: ").append(olapTable.getName()).append("(").append(indexName).append(")");
output.append(prefix).append("TABLE: ").append(olapTable.getQualifiedName())
.append("(").append(indexName).append(")");
if (detailLevel == TExplainLevel.BRIEF) {
return output.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public class PhysicalPlanTranslatorTest {

@Test
public void testOlapPrune(@Mocked OlapTable t1, @Injectable LogicalProperties placeHolder) throws Exception {
List<String> qualifierList = new ArrayList<>();
qualifierList.add("test");
qualifierList.add("t1");
List<String> qualifier = new ArrayList<>();
qualifier.add("test");
List<Slot> t1Output = new ArrayList<>();
SlotReference col1 = new SlotReference("col1", IntegerType.INSTANCE);
SlotReference col2 = new SlotReference("col2", IntegerType.INSTANCE);
Expand All @@ -59,17 +58,17 @@ public void testOlapPrune(@Mocked OlapTable t1, @Injectable LogicalProperties pl
t1Output.add(col2);
t1Output.add(col3);
LogicalProperties t1Properties = new LogicalProperties(() -> t1Output);
PhysicalOlapScan scan = new PhysicalOlapScan(t1, qualifierList, 0L,
PhysicalOlapScan scan = new PhysicalOlapScan(t1, qualifier, 0L,
Collections.emptyList(), Collections.emptyList(), null,
Optional.empty(),
t1Properties);
Literal t1FilterRight = new IntegerLiteral(1);
Expression t1FilterExpr = new GreaterThan(col1, t1FilterRight);
PhysicalFilter<PhysicalOlapScan> filter =
new PhysicalFilter(t1FilterExpr, placeHolder, scan);
new PhysicalFilter<>(t1FilterExpr, placeHolder, scan);
List<NamedExpression> projList = new ArrayList<>();
projList.add(col2);
PhysicalProject<PhysicalFilter> project = new PhysicalProject(projList,
PhysicalProject<PhysicalFilter<PhysicalOlapScan>> project = new PhysicalProject<>(projList,
placeHolder, filter);
PlanTranslatorContext planTranslatorContext = new PlanTranslatorContext();
PhysicalPlanTranslator translator = new PhysicalPlanTranslator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public LogicalBoundRelation(Table table, List<String> qualifier) {

public LogicalBoundRelation(Table table, List<String> qualifier, Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties) {
super(PlanType.LOGICAL_BOUND_RELATION, table, qualifier, groupExpression, logicalProperties,
Collections.emptyList());
super(PlanType.LOGICAL_BOUND_RELATION, table, qualifier,
groupExpression, logicalProperties, Collections.emptyList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class AggregateDisassembleTest {

@BeforeAll
public final void beforeAll() {
rStudent = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of("student"));
rStudent = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of(""));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
class FindHashConditionForJoinTest {
@Test
public void testFindHashCondition() {
Plan student = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of("student"));
Plan score = new LogicalOlapScan(PlanConstructor.score, ImmutableList.of("score"));
Plan student = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of(""));
Plan score = new LogicalOlapScan(PlanConstructor.score, ImmutableList.of(""));

Slot studentId = student.getOutput().get(0);
Slot gender = student.getOutput().get(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class NormalizeAggregateTest implements PatternMatchSupported {

@BeforeAll
public final void beforeAll() {
rStudent = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of("student"));
rStudent = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of(""));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public class PushDownPredicateTest {
*/
@BeforeAll
public final void beforeAll() {
rStudent = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of("student"));
rStudent = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of(""));

rScore = new LogicalOlapScan(PlanConstructor.score, ImmutableList.of("score"));
rScore = new LogicalOlapScan(PlanConstructor.score, ImmutableList.of(""));

rCourse = new LogicalOlapScan(PlanConstructor.course, ImmutableList.of("course"));
rCourse = new LogicalOlapScan(PlanConstructor.course, ImmutableList.of(""));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class PushDownPredicateThroughAggregationTest {
*/
@Test
public void pushDownPredicateOneFilterTest() {
Plan scan = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of("student"));
Plan scan = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of(""));
Slot gender = scan.getOutput().get(1);
Slot age = scan.getOutput().get(3);

Expand Down Expand Up @@ -130,7 +130,7 @@ public void pushDownPredicateOneFilterTest() {
*/
@Test
public void pushDownPredicateTwoFilterTest() {
Plan scan = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of("student"));
Plan scan = new LogicalOlapScan(PlanConstructor.student, ImmutableList.of(""));
Slot gender = scan.getOutput().get(1);
Slot name = scan.getOutput().get(2);
Slot age = scan.getOutput().get(3);
Expand Down
Loading