[enhancement](Nereids): catch exception when calling getConstraintMap for external map (#29112)
This commit is contained in:
@ -161,8 +161,11 @@ public interface TableIf {
|
||||
|
||||
void write(DataOutput out) throws IOException;
|
||||
|
||||
// Don't use it outside due to its thread-unsafe, use get specific constraints instead.
|
||||
default Map<String, Constraint> getConstraintsMap() {
|
||||
throw new RuntimeException(String.format("Not implemented constraint for table %s", this));
|
||||
throw new RuntimeException(String.format("Not implemented constraint for table %s. "
|
||||
+ "And the function can't be called outside, consider get specific function "
|
||||
+ "like getForeignKeyConstraints/getPrimaryKeyConstraints/getUniqueConstraints.", this));
|
||||
}
|
||||
|
||||
default Set<ForeignKeyConstraint> getForeignKeyConstraints() {
|
||||
@ -172,6 +175,8 @@ public interface TableIf {
|
||||
.filter(ForeignKeyConstraint.class::isInstance)
|
||||
.map(ForeignKeyConstraint.class::cast)
|
||||
.collect(ImmutableSet.toImmutableSet());
|
||||
} catch (Exception ignored) {
|
||||
return ImmutableSet.of();
|
||||
} finally {
|
||||
readUnlock();
|
||||
}
|
||||
@ -184,6 +189,8 @@ public interface TableIf {
|
||||
.filter(PrimaryKeyConstraint.class::isInstance)
|
||||
.map(PrimaryKeyConstraint.class::cast)
|
||||
.collect(ImmutableSet.toImmutableSet());
|
||||
} catch (Exception ignored) {
|
||||
return ImmutableSet.of();
|
||||
} finally {
|
||||
readUnlock();
|
||||
}
|
||||
@ -196,6 +203,8 @@ public interface TableIf {
|
||||
.filter(UniqueConstraint.class::isInstance)
|
||||
.map(UniqueConstraint.class::cast)
|
||||
.collect(ImmutableSet.toImmutableSet());
|
||||
} catch (Exception ignored) {
|
||||
return ImmutableSet.of();
|
||||
} finally {
|
||||
readUnlock();
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package org.apache.doris.nereids.rules.rewrite;
|
||||
|
||||
import org.apache.doris.catalog.Column;
|
||||
import org.apache.doris.catalog.Table;
|
||||
import org.apache.doris.catalog.TableIf;
|
||||
import org.apache.doris.nereids.jobs.JobContext;
|
||||
import org.apache.doris.nereids.trees.expressions.Alias;
|
||||
@ -90,9 +89,6 @@ public class EliminateJoinByFK extends DefaultPlanRewriter<JobContext> implement
|
||||
if (!(relation instanceof LogicalCatalogRelation)) {
|
||||
return relation;
|
||||
}
|
||||
if (!(((LogicalCatalogRelation) relation).getTable() instanceof Table)) {
|
||||
return relation;
|
||||
}
|
||||
context.putAllForeignKeys(((LogicalCatalogRelation) relation).getTable());
|
||||
relation.getOutput().stream()
|
||||
.filter(SlotReference.class::isInstance)
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
|
||||
package org.apache.doris.nereids.rules.rewrite;
|
||||
|
||||
import org.apache.doris.catalog.constraint.Constraint;
|
||||
import org.apache.doris.catalog.constraint.ForeignKeyConstraint;
|
||||
import org.apache.doris.catalog.constraint.PrimaryKeyConstraint;
|
||||
import org.apache.doris.catalog.constraint.UniqueConstraint;
|
||||
@ -378,48 +377,27 @@ public class PullUpJoinFromUnionAll extends OneRewriteRuleFactory {
|
||||
}
|
||||
|
||||
private ForeignKeyConstraint getFkInfoFromConstraint(LogicalCatalogRelation table) {
|
||||
table.getTable().readLock();
|
||||
try {
|
||||
for (Map.Entry<String, Constraint> constraintMap : table.getTable().getConstraintsMap().entrySet()) {
|
||||
Constraint constraint = constraintMap.getValue();
|
||||
if (constraint instanceof ForeignKeyConstraint) {
|
||||
return (ForeignKeyConstraint) constraint;
|
||||
}
|
||||
}
|
||||
Set<ForeignKeyConstraint> foreignKeyConstraints = table.getTable().getForeignKeyConstraints();
|
||||
if (foreignKeyConstraints.isEmpty()) {
|
||||
return null;
|
||||
} finally {
|
||||
table.getTable().readUnlock();
|
||||
}
|
||||
return foreignKeyConstraints.stream().iterator().next();
|
||||
}
|
||||
|
||||
private Set<String> getPkInfoFromConstraint(LogicalCatalogRelation table) {
|
||||
table.getTable().readLock();
|
||||
try {
|
||||
for (Map.Entry<String, Constraint> constraintMap : table.getTable().getConstraintsMap().entrySet()) {
|
||||
Constraint constraint = constraintMap.getValue();
|
||||
if (constraint instanceof PrimaryKeyConstraint) {
|
||||
return ((PrimaryKeyConstraint) constraint).getPrimaryKeyNames();
|
||||
}
|
||||
}
|
||||
Set<PrimaryKeyConstraint> primaryKeyConstraints = table.getTable().getPrimaryKeyConstraints();
|
||||
if (primaryKeyConstraints.isEmpty()) {
|
||||
return null;
|
||||
} finally {
|
||||
table.getTable().readUnlock();
|
||||
}
|
||||
return primaryKeyConstraints.stream().iterator().next().getPrimaryKeyNames();
|
||||
}
|
||||
|
||||
private Set<String> getUkInfoFromConstraint(LogicalCatalogRelation table) {
|
||||
table.getTable().readLock();
|
||||
try {
|
||||
for (Map.Entry<String, Constraint> constraintMap : table.getTable().getConstraintsMap().entrySet()) {
|
||||
Constraint constraint = constraintMap.getValue();
|
||||
if (constraint instanceof UniqueConstraint) {
|
||||
return ((UniqueConstraint) constraint).getUniqueColumnNames();
|
||||
}
|
||||
}
|
||||
Set<UniqueConstraint> uniqueConstraints = table.getTable().getUniqueConstraints();
|
||||
if (uniqueConstraints.isEmpty()) {
|
||||
return null;
|
||||
} finally {
|
||||
table.getTable().readUnlock();
|
||||
}
|
||||
return uniqueConstraints.stream().iterator().next().getUniqueColumnNames();
|
||||
}
|
||||
|
||||
private boolean checkJoinRoot(LogicalJoin joinRoot) {
|
||||
|
||||
Reference in New Issue
Block a user