Skip to content

Commit 1be095e

Browse files
airborne12claude
andcommitted
[fix](nereids) Reject score() over a table stream
### What problem does this PR solve? Issue Number: None Related PR: apache#69292 Problem Summary: Review of 73497b3 found that score() over a table stream fails to plan: SELECT id, score() AS relevance FROM s WHERE c1 MATCH 'apple' ORDER BY relevance DESC LIMIT 10; -- column __score not found in child output LogicalOlapTableStreamScan is a LogicalOlapScan, so BindScoreToOlapScan added the score column to it. NormalizeOlapTableStreamScan then replaces the stream with new scans of its table and of its changes, possibly unioned, which do not have that column. A table stream is not the one table that score() is computed for, so the binder now rejects it with the unsupported-SELECT error. ### Release note None ### Check List (For Author) - Test: Unit Test - BindScoreToOlapScanTest.testUnsupportedSelectIsRejected covers the query above on an append-only stream; all 75 tests pass. Checkstyle passes. The regression suites were not run again: none of them reads a table stream. - Behavior changed: Yes. score() over a table stream, an experimental feature, fails with the unsupported-SELECT error instead of a planning error. - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 73497b3 commit 1be095e

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/BindScoreToOlapScan.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
4242
import org.apache.doris.nereids.trees.plans.logical.LogicalLimit;
4343
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
44+
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapTableStreamScan;
4445
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
4546
import org.apache.doris.nereids.trees.plans.logical.LogicalRecursiveUnionAnchor;
4647
import org.apache.doris.nereids.trees.plans.logical.LogicalRecursiveUnionProducer;
@@ -176,7 +177,8 @@ private static boolean callsScore(Plan plan) {
176177
}
177178

178179
// The plan nodes from the root of the SELECT down to its olap scan; empty when the SELECT reads
179-
// anything else than one olap table, e.g. a join, a subquery or a lateral view.
180+
// anything else than one olap table, e.g. a join, a subquery, a lateral view or a table stream,
181+
// which is read by separate scans of its table and of its changes.
180182
private static List<Plan> pathToScan(Plan root) {
181183
List<Plan> path = new ArrayList<>();
182184
Plan node = root;
@@ -193,6 +195,9 @@ private static List<Plan> pathToScan(Plan root) {
193195
return ImmutableList.of();
194196
}
195197
}
198+
if (node instanceof LogicalOlapTableStreamScan) {
199+
return ImmutableList.of();
200+
}
196201
path.add(node);
197202
return path;
198203
}

‎fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/BindScoreToOlapScanTest.java‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.doris.nereids.rules.rewrite;
1919

20+
import org.apache.doris.common.Config;
2021
import org.apache.doris.nereids.NereidsPlanner;
2122
import org.apache.doris.nereids.exceptions.AnalysisException;
2223
import org.apache.doris.nereids.processor.post.PlanPostProcessors;
@@ -42,6 +43,8 @@
4243
import java.util.stream.Stream;
4344

4445
class BindScoreToOlapScanTest extends TestWithFeService {
46+
private boolean originalEnableFeatureBinlog;
47+
private boolean originalEnableTableStream;
4548

4649
@Override
4750
protected void runBeforeAll() throws Exception {
@@ -66,6 +69,22 @@ protected void runBeforeAll() throws Exception {
6669
+ "PROPERTIES ('replication_num' = '1', 'inverted_index_storage_format' = 'V3')");
6770
createView("CREATE VIEW score_usage_top AS SELECT id, score() AS s FROM score_usage_V2"
6871
+ " WHERE c1 MATCH 'apple' ORDER BY s DESC LIMIT 2");
72+
originalEnableFeatureBinlog = Config.enable_feature_binlog;
73+
originalEnableTableStream = Config.enable_table_stream;
74+
Config.enable_feature_binlog = true;
75+
Config.enable_table_stream = true;
76+
createTable("CREATE TABLE score_usage_binlog (id INT, c1 TEXT, "
77+
+ "INDEX idx_c1 (c1) USING INVERTED PROPERTIES ('parser' = 'english')) "
78+
+ "DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1 "
79+
+ "PROPERTIES ('replication_num' = '1', 'binlog.enable' = 'true', 'binlog.format' = 'ROW')");
80+
createTable("CREATE STREAM score_usage_stream ON TABLE score_usage_binlog "
81+
+ "PROPERTIES ('type' = 'append_only')");
82+
}
83+
84+
@Override
85+
protected void runAfterAll() {
86+
Config.enable_feature_binlog = originalEnableFeatureBinlog;
87+
Config.enable_table_stream = originalEnableTableStream;
6988
}
7089

7190
static Stream<Arguments> scoringPredicates() {
@@ -266,7 +285,9 @@ void testViewWithScoreTopN() {
266285
"SELECT id, score() FROM score_usage_V2 WHERE c1 MATCH 'apple'"
267286
+ " AND id IN (SELECT id FROM score_usage_V3)",
268287
"SELECT id, e, score() FROM score_usage_V2 LATERAL VIEW explode(array(1, 2)) t AS e"
269-
+ " WHERE c1 MATCH 'apple'"})
288+
+ " WHERE c1 MATCH 'apple'",
289+
// A table stream is read by separate scans of its table and of its changes.
290+
"SELECT id, score() AS s FROM score_usage_stream WHERE c1 MATCH 'apple' ORDER BY s DESC LIMIT 10"})
270291
void testUnsupportedSelectIsRejected(String query) {
271292
assertScoreUsageError(query, BindScoreToOlapScan.UNSUPPORTED_SELECT_ERROR);
272293
}

0 commit comments

Comments
 (0)