github-actions[bot] commented on code in PR #62453:
URL: https://github.com/apache/doris/pull/62453#discussion_r3093783414
##########
fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java:
##########
@@ -433,6 +436,10 @@ private void addScanRangeLocations(Partition partition,
// assign a snapshot version of all partitions.
if (!(Config.isCloudMode() && Config.enable_cloud_snapshot_version)) {
Review Comment:
`streamUpdate` only affects `visibleVersion` in the non-cloud branch. When
`Config.enable_cloud_snapshot_version` is on,
`ScanNode.updateScanRangeVersions()` later rewrites every scan range from
`CloudPartition.getSnapshotVisibleVersion(...)` and never consults the stream
offset.
So even after the partition-wrapper issue is fixed, a cloud stream scan
still reads the partition snapshot version instead of the stream-consume
target. Since stream creation does not reject cloud OLAP tables, the cloud
snapshot path needs the same stream-aware override.
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/OlapTableStreamWrapper.java:
##########
@@ -0,0 +1,137 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog.stream;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.MaterializedIndexMeta;
+import org.apache.doris.catalog.OlapTable;
+import org.apache.doris.catalog.Partition;
+import org.apache.doris.common.util.Util;
+import org.apache.doris.thrift.TColumn;
+import org.apache.doris.thrift.TPrimitiveType;
+
+import java.util.List;
+
+// runtime-only class for unified query/insert experience, created when bind
relation with OlapTableStream
+public class OlapTableStreamWrapper extends OlapTable {
+ private OlapTableStream stream;
+ private OlapTable baseTable;
+
+ public OlapTableStreamWrapper(OlapTableStream stream, OlapTable baseTable)
{
+ super(stream.getId(), stream.getName(), stream.getFullSchema(),
baseTable.getKeysType(),
+ baseTable.getPartitionInfo(),
baseTable.getDefaultDistributionInfo());
+ this.stream = stream;
+ this.baseTable = baseTable;
+ this.getOrCreatTableProperty().setEnableUniqueKeyMergeOnWrite(false);
+ }
+
+ @Override
+ public List<Column> getBaseSchema(boolean full) {
+ return baseTable.getBaseSchema(full);
+ }
+
+ @Override
+ public List<Column> getBaseSchema() {
+ return baseTable.getBaseSchema();
+ }
+
+ // for display
+ public String getIndexNameById(long indexId) {
+ // always returns base index name
+ return baseTable.getName();
+ }
+
+ // for olap table to thrift
+ @Override
+ public void getColumnDesc(long selectedIndexId, List<TColumn> columnsDesc,
List<String> keyColumnNames,
+ List<TPrimitiveType> keyColumnTypes) {
+ baseTable.getColumnDesc(selectedIndexId, columnsDesc, keyColumnNames,
keyColumnTypes);
+ }
+
+ @Override
+ public int getIndexSchemaVersion(long indexId) {
+ return baseTable.getIndexSchemaVersion(indexId);
+ }
+
+ // no need for pre agg on olap table stream
+ @Override
+ public boolean isDupKeysOrMergeOnWrite() {
+ return false;
+ }
+
+ @Override
+ public long getBaseIndexId() {
+ return baseTable.getBaseIndexId();
+ }
+
+ @Override
+ public MaterializedIndexMeta getIndexMetaByIndexId(long indexId) {
+ return baseTable.getIndexMetaByIndexId(indexId);
+ }
+
+ @Override
+ public List<Column> getSchemaByIndexId(Long indexId) {
+ // here is base table indexId, we can ignore it and use olap table
stream schema
+ return getBaseSchema(Util.showHiddenColumns());
+ }
+
+ // override all partition methods, olap table stream inherit all
partitions from base table
+ @Override
+ public Partition getPartition(String partitionName) {
+ return generateProxyPartition(baseTable.getPartition(partitionName));
+ }
+
+ @Override
+ public Partition getPartition(long partitionId) {
+ return generateProxyPartition(baseTable.getPartition(partitionId));
+ }
+
+ @Override
+ public Partition getPartition(String partitionName, boolean
isTempPartition) {
+ return generateProxyPartition(baseTable.getPartition(partitionName,
isTempPartition));
+ }
+
+ @Override
+ public List<Long> getPartitionIds() {
+ return baseTable.getPartitionIds();
+ }
+
+ public OlapTableStreamUpdate getStreamUpdate(List<Long>
selectedPartitionIds) {
+ return stream.getStreamUpdate(selectedPartitionIds);
+ }
+
+ public Long getStreamDbId() {
+ return stream.getDatabase().getId();
+ }
+
+ public Long getStreamId() {
+ return stream.getId();
+ }
+
+ private Partition generateProxyPartition(Partition partition) {
+ if (partition == null) {
+ return null;
+ }
+ partition = new Partition(partition);
Review Comment:
In cloud snapshot mode this clone strips `CloudPartition` down to plain
`Partition`. The wrapper then inherits
`OlapTable.selectNonEmptyPartitionIds()`, whose cloud branch keeps only `p
instanceof CloudPartition` before calling
`CloudPartition.selectNonEmptyPartitionIds(...)`.
That means `OlapScanNode.computePartitionInfo()` can prune every partition
for stream scans (`selectedPartitionIds =
olapTable.selectNonEmptyPartitionIds(selectedPartitionIds)`), so cloud
table-stream queries plan as empty. This wrapper needs to preserve the cloud
partition type here, or override the non-empty-partition path instead of
reusing the base implementation.
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/OlapTableStream.java:
##########
@@ -154,4 +163,56 @@ void fillTableStreamConsumptionInfo(List<TRow> dataBatch) {
}
}
}
+
+ public boolean hasData(Partition partition) {
+ // if all available visible data has been consumed, return false
+ // todo(TsukiokaKogane): change offset from partition version to
commit tso
+ return !partitionOffset.containsKey(partition.getId())
+ ||
!partitionOffset.get(partition.getId()).equals(partition.getVisibleVersion())
+ || historicalPartitionOffset.containsKey(partition.getId());
+ }
+
+ public OlapTableStreamUpdate getStreamUpdate(List<Long>
selectedPartitionIds) {
+ if (selectedPartitionIds.isEmpty()) {
+ return null;
+ }
+ Map<Long, Long> next = new HashMap<>();
+ Map<Long, Long> prev = new HashMap<>();
+ for (Long partitionId : selectedPartitionIds) {
+ if (historicalPartitionOffset.containsKey(partitionId)) {
+ next.put(partitionId,
historicalPartitionOffset.get(partitionId));
+ } else {
+ next.put(partitionId,
partitionOffset.getOrDefault(partitionId, Partition.PARTITION_INIT_VERSION));
Review Comment:
When `show_initial_rows=false`, `partitionOffset` is initialized to the
current visible version `V`. After the partition publishes `V+1`, `hasData()`
returns true, but this branch still sends `next=V`.
`OlapScanNode.addScanRangeLocations()` then scans version `V`, and
`unprotectedUpdateStreamUpdate()` writes `V` back into `partitionOffset`, so
the stream never advances to the newly published data.
The same thing happens after the historical pass: once
`historicalPartitionOffset` is removed, subsequent consumes keep reusing the
old offset as `next`. Can we move `next` to the current target version here (or
otherwise carry both previous and target bounds) before persisting the update?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]