Skip to content

Commit 1644690

Browse files
[fix](binlog) Report missing row binlog for INCR queries (#65481)
### What problem does this PR solve? Issue Number: close #65309 Problem Summary: INCR analysis constructed the row-binlog table wrapper before validating that ROW binlog was enabled. Tables without ROW binlog therefore hit an unmessaged precondition in getRowBinlogMeta(), returning an empty detailMessage. Validate INCR conditions before wrapper construction so clients receive the actionable analysis error.
1 parent 2c5f157 commit 1644690

3 files changed

Lines changed: 62 additions & 13 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.apache.doris.catalog.FunctionRegistry;
2929
import org.apache.doris.catalog.KeysType;
3030
import org.apache.doris.catalog.OlapTable;
31-
import org.apache.doris.catalog.OlapTableWrapper;
3231
import org.apache.doris.catalog.Partition;
3332
import org.apache.doris.catalog.RowBinlogTableWrapper;
3433
import org.apache.doris.catalog.SchemaTable;
@@ -242,9 +241,8 @@ private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation,
242241
LogicalOlapScan scan;
243242
List<Long> partIds = getPartitionIds(table, unboundRelation, qualifier);
244243
List<Long> tabletIds = unboundRelation.getTabletIds();
245-
boolean isChangeRead = unboundRelation.getScanParams() != null
246-
&& unboundRelation.getScanParams().incrementalRead();
247-
if (isChangeRead) {
244+
StreamScanType changeScanType = checkChangeScanCondition((OlapTable) table, unboundRelation.getScanParams());
245+
if (changeScanType != null) {
248246
table = new RowBinlogTableWrapper((OlapTable) table);
249247
} else if (unboundRelation.getScanParams() != null) {
250248
unboundRelation.getScanParams().validateOlapTable();
@@ -265,7 +263,7 @@ private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation,
265263
throw new AnalysisException("Table " + olapTable.getName()
266264
+ " doesn't have materialized view " + indexName.get());
267265
}
268-
if (isChangeRead && olapTable.getBaseIndexId() != indexId) {
266+
if (changeScanType != null && olapTable.getBaseIndexId() != indexId) {
269267
throw new AnalysisException("Change read is not supported on non-base index " + indexName.get());
270268
}
271269
if (unboundRelation.getTableSnapshot().isPresent() && olapTable.getBaseIndexId() != indexId) {
@@ -291,15 +289,13 @@ private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation,
291289
// This tabletIds is set manually, so need to set specifiedTabletIds
292290
scan = scan.withManuallySpecifiedTabletIds(tabletIds);
293291
}
294-
if (isChangeRead) {
292+
if (changeScanType != null) {
295293
if (cascadesContext.getStatementContext().isHintForcePreAggOn()) {
296294
throw new AnalysisException(
297295
"PREAGGOPEN hint is not supported on @incr (change-read) scans.");
298296
}
299-
StreamScanType scanType = checkChangeScanCondition(((OlapTableWrapper) table).getOriginTable(),
300-
unboundRelation.getScanParams());
301-
return checkAndAddChangeScanFilter(scan, scanType, parseTimestampRange(unboundRelation.getScanParams()),
302-
false);
297+
return checkAndAddChangeScanFilter(scan, changeScanType,
298+
parseTimestampRange(unboundRelation.getScanParams()), false);
303299
}
304300
// Time-travel (FOR VERSION/TIME AS OF): wrap the scan with a __DORIS_COMMIT_TSO_COL__
305301
// predicate (dup) or a base/binlog union (mow).
@@ -647,10 +643,11 @@ private Optional<LogicalPlan> handleMetaTable(TableIf table, UnboundRelation unb
647643

648644
private StreamScanType checkChangeScanCondition(OlapTable olapTable, TableScanParams scanParams)
649645
throws AnalysisException {
646+
if (scanParams == null || !scanParams.incrementalRead()) {
647+
return null;
648+
}
650649
if (!olapTable.needRowBinlog()) {
651-
throw new AnalysisException("INCR query requires ROW binlog enabled on base table "
652-
+ "(PROPERTIES('binlog.enable'='true','binlog.format'='ROW')). "
653-
+ "Table " + olapTable.getQualifiedName() + " doesn't enable row binlog.");
650+
throw new AnalysisException("INCR query requires ROW binlog enabled on base table.");
654651
}
655652
HashSet<String> keys = new HashSet(scanParams.getMapParams().keySet());
656653
keys.remove(OlapScanNode.OLAP_INCREMENT_TYPE);

‎fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindRelationTest.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.doris.nereids.rules.analysis;
1919

2020
import org.apache.doris.nereids.analyzer.UnboundRelation;
21+
import org.apache.doris.nereids.exceptions.AnalysisException;
2122
import org.apache.doris.nereids.pattern.GeneratedPlanPatterns;
2223
import org.apache.doris.nereids.rules.RulePromise;
2324
import org.apache.doris.nereids.trees.expressions.Alias;
@@ -90,6 +91,16 @@ void bindByDbQualifier() {
9091
((LogicalOlapScan) plan).qualified());
9192
}
9293

94+
@Test
95+
void rejectIncrementalReadWithoutRowBinlog() {
96+
AnalysisException exception = Assertions.assertThrows(AnalysisException.class,
97+
() -> PlanChecker.from(connectContext)
98+
.analyze("SELECT a, b, __DORIS_BINLOG_OP__ "
99+
+ "FROM db1.t@incr(\"incrementType\" = \"DETAIL\")"));
100+
101+
Assertions.assertEquals("INCR query requires ROW binlog enabled on base table.", exception.getMessage());
102+
}
103+
93104
@Test
94105
void bindSchemaTable() {
95106
boolean originValue = connectContext.getSessionVariable().isFetchAllFeForSystemTable();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("test_incr_without_row_binlog") {
19+
if (isCloudMode()) {
20+
return
21+
}
22+
23+
sql "DROP TABLE IF EXISTS base_incr_no_binlog"
24+
sql """
25+
CREATE TABLE base_incr_no_binlog (
26+
k1 INT,
27+
v1 INT
28+
)
29+
DUPLICATE KEY(k1)
30+
DISTRIBUTED BY HASH(k1) BUCKETS 1
31+
PROPERTIES ("replication_num" = "1")
32+
"""
33+
34+
test {
35+
sql """
36+
SELECT k1, v1, __DORIS_BINLOG_OP__
37+
FROM base_incr_no_binlog@incr("incrementType" = "DETAIL")
38+
"""
39+
exception "errCode = 2, detailMessage = INCR query requires ROW binlog enabled on base table."
40+
}
41+
}

0 commit comments

Comments
 (0)