VividByteWorker commented on code in PR #62453:
URL: https://github.com/apache/doris/pull/62453#discussion_r3083854449
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/TableStreamManager.java:
##########
@@ -38,6 +38,7 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
+import java.util.ArrayList;
Review Comment:
useless? delete it
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/SetPreAggStatus.java:
##########
@@ -148,17 +149,21 @@ public Plan visit(Plan plan, Stack<PreAggInfoContext>
context) {
@Override
public Plan visitLogicalOlapScan(LogicalOlapScan logicalOlapScan,
Stack<PreAggInfoContext> context) {
+ if (logicalOlapScan instanceof LogicalOlapTableStreamScan) {
+ // no pre-agg for LogicalOlapTableStreamScan
+ return logicalOlapScan;
+ }
if (logicalOlapScan.isPreAggStatusUnSet()) {
long selectIndexId = logicalOlapScan.getSelectedIndexId();
MaterializedIndexMeta meta =
logicalOlapScan.getTable().getIndexMetaByIndexId(selectIndexId);
if (meta.getKeysType() == KeysType.DUP_KEYS || (meta.getKeysType()
== KeysType.UNIQUE_KEYS
&&
logicalOlapScan.getTable().getEnableUniqueKeyMergeOnWrite())
|| (meta.getKeysType() == KeysType.UNIQUE_KEYS
- && logicalOlapScan.getTable().isMorTable()
- && ConnectContext.get() != null
- &&
ConnectContext.get().getSessionVariable().isReadMorAsDupEnabled(
- logicalOlapScan.getTable().getQualifiedDbName(),
- logicalOlapScan.getTable().getName()))) {
+ && logicalOlapScan.getTable().isMorTable()
Review Comment:
seems no change?
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/OlapTableStream.java:
##########
@@ -154,4 +164,69 @@ 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 Map<Long, Long> getPartitionOffset(List<Long> selectedPartitionIds)
{
+ if (selectedPartitionIds.isEmpty()) {
+ return null;
+ }
+ Map<Long, Long> result = new HashMap<>(selectedPartitionIds.size());
+ for (Long partitionId : selectedPartitionIds) {
+ if (historicalPartitionOffset.containsKey(partitionId)) {
+ result.put(partitionId,
historicalPartitionOffset.get(partitionId));
+ } else {
+ result.put(partitionId,
partitionOffset.getOrDefault(partitionId, Partition.PARTITION_INIT_VERSION));
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public void unprotectedCheckStreamOffset(Map<Long, Long> offset, Map<Long,
Long> nextOffset)
+ throws UserException {
+ // check valid
+ for (Map.Entry<Long, Long> entry : offset.entrySet()) {
+ if (historicalPartitionOffset.containsKey(entry.getKey())) {
+ if
(!historicalPartitionOffset.get(entry.getKey()).equals(entry.getValue())) {
+ throw new TransactionCommitFailedException("history offset
already consumed: "
+ + getDatabase().getId() + '-' + getId() + '-' +
entry.getKey() + '-' + entry.getValue()
+ + " vs " +
historicalPartitionOffset.get(entry.getKey()));
+ }
+ } else if (partitionOffset.containsKey(entry.getKey())) {
+ if
(!partitionOffset.get(entry.getKey()).equals(entry.getValue())) {
+ throw new TransactionCommitFailedException("target offset
already consumed: "
+ + getDatabase().getId() + '-' + getId() + '-' +
entry.getKey() + '-' + entry.getValue()
+ + " vs " + partitionOffset.get(entry.getKey()));
+ }
+ if (nextOffset == null ||
!nextOffset.containsKey(entry.getKey())) {
+ throw new TransactionCommitFailedException(
+ "nextOffset missing for partition=" +
entry.getKey() + ", db=" + getDatabase().getId()
+ + ", stream=" + getId());
+ }
+ } else {
+ // the new partition id may not be updated in time, so key in
table stream not exist is also valid
+ }
+ }
+ }
+
+ @Override
+ public void unprotectedUpdateStreamOffset(Map<Long, Long> offset,
Map<Long, Long> nextOffset, Long ts) {
+ for (Map.Entry<Long, Long> entry : offset.entrySet()) {
+ if (historicalPartitionOffset.containsKey(entry.getKey())) {
+ historicalPartitionOffset.remove(entry.getKey());
+ partitionOffset.put(entry.getKey(), entry.getValue());
+ } else {
+ // todo(TsukiokaKogane): update partition offset
Review Comment:
invalid todo? remove it
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java:
##########
@@ -71,6 +71,10 @@ public class Column implements GsonPostProcessable {
public static final int COLUMN_UNIQUE_ID_INIT_VALUE = -1;
private static final String COLUMN_MAP_KEY = "key";
private static final String COLUMN_MAP_VALUE = "value";
+ public static final Column STREAM_SEQ_VIRTUAL_COLUMN =
+ new Column(STREAM_SEQ_COL, Type.BIGINT, false, null, false, null,
false);
+ public static final Column STREAM_CHANGE_TYPE_VIRTUAL_COLUMN =
+ new Column(STREAM_CHANGE_TYPE_COL, Type.STRING, false, null,
false, null, false);
Review Comment:
move these two column to BaseTableStream?
##########
fe/fe-core/src/main/java/org/apache/doris/transaction/TransactionState.java:
##########
@@ -322,6 +323,10 @@ public SchemaInfo(OlapTable olapTable) {
@Getter
@Setter
private Set<Long> involvedBackends = Sets.newHashSet();
+ @Getter
Review Comment:
add an empty line before?
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/stream/OlapTableStream.java:
##########
@@ -154,4 +164,69 @@ 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 Map<Long, Long> getPartitionOffset(List<Long> selectedPartitionIds)
{
+ if (selectedPartitionIds.isEmpty()) {
+ return null;
+ }
+ Map<Long, Long> result = new HashMap<>(selectedPartitionIds.size());
+ for (Long partitionId : selectedPartitionIds) {
+ if (historicalPartitionOffset.containsKey(partitionId)) {
+ result.put(partitionId,
historicalPartitionOffset.get(partitionId));
+ } else {
+ result.put(partitionId,
partitionOffset.getOrDefault(partitionId, Partition.PARTITION_INIT_VERSION));
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public void unprotectedCheckStreamOffset(Map<Long, Long> offset, Map<Long,
Long> nextOffset)
+ throws UserException {
+ // check valid
+ for (Map.Entry<Long, Long> entry : offset.entrySet()) {
+ if (historicalPartitionOffset.containsKey(entry.getKey())) {
+ if
(!historicalPartitionOffset.get(entry.getKey()).equals(entry.getValue())) {
+ throw new TransactionCommitFailedException("history offset
already consumed: "
+ + getDatabase().getId() + '-' + getId() + '-' +
entry.getKey() + '-' + entry.getValue()
+ + " vs " +
historicalPartitionOffset.get(entry.getKey()));
+ }
+ } else if (partitionOffset.containsKey(entry.getKey())) {
+ if
(!partitionOffset.get(entry.getKey()).equals(entry.getValue())) {
+ throw new TransactionCommitFailedException("target offset
already consumed: "
+ + getDatabase().getId() + '-' + getId() + '-' +
entry.getKey() + '-' + entry.getValue()
Review Comment:
```suggestion
+ getDatabase().getId() + '-' + getId() + '-' +
entry.getKey() + ':' + entry.getValue()
```
--
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]