Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -170,27 +170,27 @@ private LogicalPlan bindWithCurrentDb(CascadesContext cascadesContext, UnboundRe
}

private LogicalPlan bind(CascadesContext cascadesContext, UnboundRelation unboundRelation) {
List<String> tableQualifier = RelationUtil.getQualifierName(cascadesContext.getConnectContext(),
List<String> qualifiedTablName = RelationUtil.getQualifierName(cascadesContext.getConnectContext(),
unboundRelation.getNameParts());
TableIf table = null;
if (customTableResolver.isPresent()) {
table = customTableResolver.get().apply(tableQualifier);
table = customTableResolver.get().apply(qualifiedTablName);
}
// In some cases even if we have already called the "cascadesContext.getTableByName",
// it also gets the null. So, we just check it in the catalog again for safety.
if (table == null) {
table = RelationUtil.getTable(tableQualifier, cascadesContext.getConnectContext().getEnv());
table = RelationUtil.getTable(qualifiedTablName, cascadesContext.getConnectContext().getEnv());
}
return getLogicalPlan(table, unboundRelation, tableQualifier, cascadesContext);
return getLogicalPlan(table, unboundRelation, qualifiedTablName, cascadesContext);
}

private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation, List<String> tableQualifier) {
private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation, List<String> qualifier) {
LogicalOlapScan scan;
List<Long> partIds = getPartitionIds(table, unboundRelation);
List<Long> partIds = getPartitionIds(table, unboundRelation, qualifier);
List<Long> tabletIds = unboundRelation.getTabletIds();
if (!CollectionUtils.isEmpty(partIds) && !unboundRelation.getIndexName().isPresent()) {
scan = new LogicalOlapScan(unboundRelation.getRelationId(),
(OlapTable) table, tableQualifier, partIds,
(OlapTable) table, qualifier, partIds,
tabletIds, unboundRelation.getHints(), unboundRelation.getTableSample());
} else {
Optional<String> indexName = unboundRelation.getIndexName();
Expand All @@ -208,13 +208,13 @@ private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation,
: PreAggStatus.off("For direct index scan.");

scan = new LogicalOlapScan(unboundRelation.getRelationId(),
(OlapTable) table, tableQualifier, tabletIds,
(OlapTable) table, qualifier, tabletIds,
CollectionUtils.isEmpty(partIds) ? ((OlapTable) table).getPartitionIds() : partIds, indexId,
preAggStatus, CollectionUtils.isEmpty(partIds) ? ImmutableList.of() : partIds,
unboundRelation.getHints(), unboundRelation.getTableSample());
} else {
scan = new LogicalOlapScan(unboundRelation.getRelationId(),
(OlapTable) table, tableQualifier, tabletIds, unboundRelation.getHints(),
(OlapTable) table, qualifier, tabletIds, unboundRelation.getHints(),
unboundRelation.getTableSample());
}
}
Expand All @@ -241,15 +241,15 @@ private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation,
}

private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelation,
List<String> tableQualifier, CascadesContext cascadesContext) {
// for create view stmt replace tablename to ctl.db.tablename
List<String> qualifiedTableName, CascadesContext cascadesContext) {
// for create view stmt replace tablNname to ctl.db.tableName
unboundRelation.getIndexInSqlString().ifPresent(pair -> {
StatementContext statementContext = cascadesContext.getStatementContext();
statementContext.addIndexInSqlToString(pair,
Utils.qualifiedNameWithBackquote(tableQualifier));
Utils.qualifiedNameWithBackquote(qualifiedTableName));
});
List<String> qualifierWithoutTableName = Lists.newArrayList();
qualifierWithoutTableName.addAll(tableQualifier.subList(0, tableQualifier.size() - 1));
qualifierWithoutTableName.addAll(qualifiedTableName.subList(0, qualifiedTableName.size() - 1));
boolean isView = false;
try {
switch (table.getType()) {
Expand All @@ -262,15 +262,15 @@ private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelatio
String inlineViewDef = view.getInlineViewDef();
Plan viewBody = parseAndAnalyzeView(view, inlineViewDef, cascadesContext);
LogicalView<Plan> logicalView = new LogicalView<>(view, viewBody);
return new LogicalSubQueryAlias<>(tableQualifier, logicalView);
return new LogicalSubQueryAlias<>(qualifiedTableName, logicalView);
case HMS_EXTERNAL_TABLE:
HMSExternalTable hmsTable = (HMSExternalTable) table;
if (Config.enable_query_hive_views && hmsTable.isView()) {
isView = true;
String hiveCatalog = hmsTable.getCatalog().getName();
String ddlSql = hmsTable.getViewText();
Plan hiveViewPlan = parseAndAnalyzeHiveView(hmsTable, hiveCatalog, ddlSql, cascadesContext);
return new LogicalSubQueryAlias<>(tableQualifier, hiveViewPlan);
return new LogicalSubQueryAlias<>(qualifiedTableName, hiveViewPlan);
}
if (hmsTable.getDlaType() == DLAType.HUDI) {
LogicalHudiScan hudiScan = new LogicalHudiScan(unboundRelation.getRelationId(), hmsTable,
Expand Down Expand Up @@ -357,7 +357,7 @@ private Plan parseAndAnalyzeView(TableIf view, String ddlSql, CascadesContext pa
return viewContext.getRewritePlan();
}

private List<Long> getPartitionIds(TableIf t, UnboundRelation unboundRelation) {
private List<Long> getPartitionIds(TableIf t, UnboundRelation unboundRelation, List<String> qualifier) {
List<String> parts = unboundRelation.getPartNames();
if (CollectionUtils.isEmpty(parts)) {
return ImmutableList.of();
Expand All @@ -370,7 +370,15 @@ private List<Long> getPartitionIds(TableIf t, UnboundRelation unboundRelation) {
return parts.stream().map(name -> {
Partition part = ((OlapTable) t).getPartition(name, unboundRelation.isTempPart());
if (part == null) {
throw new AnalysisException(String.format("Partition: %s is not exists", name));
List<String> qualified;
if (!CollectionUtils.isEmpty(qualifier)) {
qualified = qualifier;
} else {
qualified = Lists.newArrayList();
}
qualified.add(unboundRelation.getTableName());
throw new AnalysisException(String.format("Partition: %s is not exists on table %s",
name, String.join(".", qualified)));
}
return part.getId();
}).collect(ImmutableList.toImmutableList());
Expand Down