Skip to content

Commit b9e5064

Browse files
committed
[fix](fe) Guard catalog scan state comparisons
Add a shared exact-class and non-null check for catalog scan semantic comparisons. Key changes: - Add Utils.isSameClass - Validate scan types before casting - Apply to OLAP, stream, file, Hudi, schema, ODBC, and test scans Unit Test: - Fast FE compile passed
1 parent f5cea12 commit b9e5064

9 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ public final boolean hasSameScanSemantics(LogicalCatalogRelation other) {
272272
}
273273

274274
protected boolean hasSameTableIdentity(LogicalCatalogRelation other) {
275+
if (!Utils.isSameClass(this, other)) {
276+
return false;
277+
}
275278
return new TableIdentifier(table).equals(new TableIdentifier(other.table));
276279
}
277280

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalFileScan.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ public boolean equals(Object o) {
200200

201201
@Override
202202
protected boolean hasSameScanState(LogicalCatalogRelation other) {
203+
if (!Utils.isSameClass(this, other)) {
204+
return false;
205+
}
203206
LogicalFileScan that = (LogicalFileScan) other;
204207
return Objects.equals(selectedPartitions, that.selectedPartitions)
205208
&& Objects.equals(tableSample, that.tableSample)

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalHudiScan.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ public Optional<IncrementalRelation> getIncrementalRelation() {
123123

124124
@Override
125125
protected boolean hasSameScanState(LogicalCatalogRelation other) {
126+
if (!Utils.isSameClass(this, other)) {
127+
return false;
128+
}
126129
LogicalHudiScan that = (LogicalHudiScan) other;
127130
// IncrementalRelation contains the resolved Hudi timeline and split state and has no value equality.
128131
return super.hasSameScanState(other) && Objects.equals(incrementalRelation, that.incrementalRelation);

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOdbcScan.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public LogicalOdbcScan withTableAlias(String tableAlias) {
9797

9898
@Override
9999
protected boolean hasSameScanState(LogicalCatalogRelation other) {
100-
return true;
100+
return Utils.isSameClass(this, other);
101101
}
102102

103103
@Override

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,9 @@ public LogicalOlapScan withTableScanParams(TableScanParams scanParams) {
12091209

12101210
@Override
12111211
protected boolean hasSameScanState(LogicalCatalogRelation other) {
1212+
if (!Utils.isSameClass(this, other)) {
1213+
return false;
1214+
}
12121215
LogicalOlapScan that = (LogicalOlapScan) other;
12131216
return selectedIndexId == that.selectedIndexId
12141217
&& indexSelected == that.indexSelected

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapTableStreamScan.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ public LogicalOlapTableStreamScan withReadMode(StreamReadMode readMode) {
467467

468468
@Override
469469
protected boolean hasSameTableIdentity(LogicalCatalogRelation other) {
470+
if (!Utils.isSameClass(this, other)) {
471+
return false;
472+
}
470473
LogicalOlapTableStreamScan that = (LogicalOlapTableStreamScan) other;
471474
return Objects.equals(getTable().getStreamDbId(), that.getTable().getStreamDbId())
472475
&& Objects.equals(getTable().getStreamId(), that.getTable().getStreamId())
@@ -476,6 +479,9 @@ && new TableIdentifier(getTable().getBaseTable())
476479

477480
@Override
478481
protected boolean hasSameScanState(LogicalCatalogRelation other) {
482+
if (!Utils.isSameClass(this, other)) {
483+
return false;
484+
}
479485
LogicalOlapTableStreamScan that = (LogicalOlapTableStreamScan) other;
480486
return super.hasSameScanState(other)
481487
&& readMode == that.readMode

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalSchemaScan.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public List<Expression> getFrontendConjuncts() {
115115

116116
@Override
117117
protected boolean hasSameScanState(LogicalCatalogRelation other) {
118+
if (!Utils.isSameClass(this, other)) {
119+
return false;
120+
}
118121
LogicalSchemaScan that = (LogicalSchemaScan) other;
119122
return filterPushed == that.filterPushed
120123
&& Objects.equals(schemaCatalog, that.schemaCatalog)

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalTestScan.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public LogicalTestScan withTableAlias(String tableAlias) {
8787

8888
@Override
8989
protected boolean hasSameScanState(LogicalCatalogRelation other) {
90-
return true;
90+
return Utils.isSameClass(this, other);
9191
}
9292

9393
@Override

‎fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
public class Utils {
6363
public static final boolean enableAssert;
6464

65+
/**
66+
* Check whether two objects are non-null and have the same concrete class.
67+
*/
68+
public static boolean isSameClass(Object left, Object right) {
69+
return left != null && right != null && left.getClass() == right.getClass();
70+
}
71+
6572
static {
6673
boolean enabled = false;
6774
// if run jvm with -ea or -enableassertions, the assert statement will be executed

0 commit comments

Comments
 (0)