Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import org.apache.doris.mtmv.MTMVBaseTableIf;
import org.apache.doris.mtmv.MTMVRefreshContext;
import org.apache.doris.mtmv.MTMVRelatedTableIf;
import org.apache.doris.mtmv.MTMVSnapshotIdSnapshot;
import org.apache.doris.mtmv.MTMVSnapshotIf;
import org.apache.doris.mtmv.MTMVVersionSnapshot;
import org.apache.doris.statistics.AnalysisInfo;
import org.apache.doris.statistics.BaseAnalysisTask;
import org.apache.doris.statistics.ExternalAnalysisTask;
Expand Down Expand Up @@ -223,15 +223,15 @@ public MTMVSnapshotIf getPartitionSnapshot(String partitionName, MTMVRefreshCont
if (latestSnapshotId <= 0) {
throw new AnalysisException("can not find partition: " + partitionName);
}
return new MTMVVersionSnapshot(latestSnapshotId);
return new MTMVSnapshotIdSnapshot(latestSnapshotId);
}

@Override
public MTMVSnapshotIf getTableSnapshot(MTMVRefreshContext context, Optional<MvccSnapshot> snapshot)
throws AnalysisException {
makeSureInitialized();
IcebergSnapshotCacheValue snapshotValue = getOrFetchSnapshotCacheValue(snapshot);
return new MTMVVersionSnapshot(snapshotValue.getSnapshot().getSnapshotId());
return new MTMVSnapshotIdSnapshot(snapshotValue.getSnapshot().getSnapshotId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import org.apache.doris.mtmv.MTMVBaseTableIf;
import org.apache.doris.mtmv.MTMVRefreshContext;
import org.apache.doris.mtmv.MTMVRelatedTableIf;
import org.apache.doris.mtmv.MTMVSnapshotIdSnapshot;
import org.apache.doris.mtmv.MTMVSnapshotIf;
import org.apache.doris.mtmv.MTMVTimestampSnapshot;
import org.apache.doris.mtmv.MTMVVersionSnapshot;
import org.apache.doris.statistics.AnalysisInfo;
import org.apache.doris.statistics.BaseAnalysisTask;
import org.apache.doris.statistics.ExternalAnalysisTask;
Expand Down Expand Up @@ -206,7 +206,7 @@ public MTMVSnapshotIf getPartitionSnapshot(String partitionName, MTMVRefreshCont
public MTMVSnapshotIf getTableSnapshot(MTMVRefreshContext context, Optional<MvccSnapshot> snapshot)
throws AnalysisException {
PaimonSnapshotCacheValue paimonSnapshot = getOrFetchSnapshotCacheValue(snapshot);
return new MTMVVersionSnapshot(paimonSnapshot.getSnapshot().getSnapshotId());
return new MTMVSnapshotIdSnapshot(paimonSnapshot.getSnapshot().getSnapshotId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@ public void compatible(MTMV mtmv) {
}

private void compatiblePartitions(MTMV mtmv) throws AnalysisException {
MTMVRelatedTableIf relatedTableIf = mtmv.getMvPartitionInfo().getRelatedTable();
// Only olapTable has historical data issues that require compatibility
if (!(relatedTableIf instanceof OlapTable)) {
return;
}
if (!checkHasDataWithoutPartitionId()) {
return;
}
OlapTable relatedTable = (OlapTable) mtmv.getMvPartitionInfo().getRelatedTable();
OlapTable relatedTable = (OlapTable) relatedTableIf;
for (Entry<String, MTMVSnapshotIf> entry : partitions.entrySet()) {
MTMVVersionSnapshot versionSnapshot = (MTMVVersionSnapshot) entry.getValue();
if (versionSnapshot.getId() == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.mtmv;

import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;

/**
* use snapshotId as identification of data changes
*/
public class MTMVSnapshotIdSnapshot implements MTMVSnapshotIf {
@SerializedName("s")
private long snapshotId;

public MTMVSnapshotIdSnapshot(long snapshotId) {
this.snapshotId = snapshotId;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MTMVSnapshotIdSnapshot that = (MTMVSnapshotIdSnapshot) o;
return snapshotId == that.snapshotId;
}

@Override
public int hashCode() {
return Objects.hashCode(snapshotId);
}

@Override
public String toString() {
return "MTMVSnapshotIdSnapshot{"
+ "snapshotId=" + snapshotId
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public class MTMVVersionSnapshot implements MTMVSnapshotIf {
@SerializedName("id")
private long id;

public MTMVVersionSnapshot(long version) {
this.version = version;
}

public MTMVVersionSnapshot(long version, long id) {
this.version = version;
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
import org.apache.doris.load.sync.SyncJob;
import org.apache.doris.load.sync.canal.CanalSyncJob;
import org.apache.doris.mtmv.MTMVMaxTimestampSnapshot;
import org.apache.doris.mtmv.MTMVSnapshotIdSnapshot;
import org.apache.doris.mtmv.MTMVSnapshotIf;
import org.apache.doris.mtmv.MTMVTimestampSnapshot;
import org.apache.doris.mtmv.MTMVVersionSnapshot;
Expand Down Expand Up @@ -451,6 +452,7 @@ public class GsonUtils {
RuntimeTypeAdapterFactory.of(MTMVSnapshotIf.class, "clazz")
.registerSubtype(MTMVMaxTimestampSnapshot.class, MTMVMaxTimestampSnapshot.class.getSimpleName())
.registerSubtype(MTMVTimestampSnapshot.class, MTMVTimestampSnapshot.class.getSimpleName())
.registerSubtype(MTMVSnapshotIdSnapshot.class, MTMVSnapshotIdSnapshot.class.getSimpleName())
.registerSubtype(MTMVVersionSnapshot.class, MTMVVersionSnapshot.class.getSimpleName());

private static RuntimeTypeAdapterFactory<DatabaseIf> dbTypeAdapterFactory = RuntimeTypeAdapterFactory.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class MTMVRefreshSnapshotTest {
private long baseExistTableId = 1L;
private long correctVersion = 1L;
private MTMVRefreshSnapshot refreshSnapshot = new MTMVRefreshSnapshot();
private MTMVVersionSnapshot p1Snapshot = new MTMVVersionSnapshot(correctVersion);
private MTMVVersionSnapshot t1Snapshot = new MTMVVersionSnapshot(correctVersion);
private MTMVVersionSnapshot p1Snapshot = new MTMVVersionSnapshot(correctVersion, 0);
private MTMVVersionSnapshot t1Snapshot = new MTMVVersionSnapshot(correctVersion, 0);
@Mocked
private BaseTableInfo existTable;
@Mocked
Expand Down Expand Up @@ -92,19 +92,19 @@ public void setUp() throws NoSuchMethodException, SecurityException, AnalysisExc
public void testPartitionSync() {
// normal
boolean sync = refreshSnapshot.equalsWithRelatedPartition(mvExistPartitionName, relatedExistPartitionName,
new MTMVVersionSnapshot(correctVersion));
new MTMVVersionSnapshot(correctVersion, 0));
Assert.assertTrue(sync);
// non exist mv partition
sync = refreshSnapshot.equalsWithRelatedPartition("mvp2", relatedExistPartitionName,
new MTMVVersionSnapshot(correctVersion));
new MTMVVersionSnapshot(correctVersion, 0));
Assert.assertFalse(sync);
// non exist related partition
sync = refreshSnapshot
.equalsWithRelatedPartition(mvExistPartitionName, "p2", new MTMVVersionSnapshot(correctVersion));
.equalsWithRelatedPartition(mvExistPartitionName, "p2", new MTMVVersionSnapshot(correctVersion, 0));
Assert.assertFalse(sync);
// snapshot value not equal
sync = refreshSnapshot.equalsWithRelatedPartition(mvExistPartitionName, relatedExistPartitionName,
new MTMVVersionSnapshot(2L));
new MTMVVersionSnapshot(2L, 0));
Assert.assertFalse(sync);
// snapshot type not equal
sync = refreshSnapshot.equalsWithRelatedPartition(mvExistPartitionName, relatedExistPartitionName,
Expand All @@ -116,19 +116,19 @@ public void testPartitionSync() {
public void testTableSync() {
// normal
boolean sync = refreshSnapshot.equalsWithBaseTable(mvExistPartitionName, existTable,
new MTMVVersionSnapshot(correctVersion));
new MTMVVersionSnapshot(correctVersion, 0));
Assert.assertTrue(sync);
// non exist mv partition
sync = refreshSnapshot
.equalsWithBaseTable("mvp2", existTable, new MTMVVersionSnapshot(correctVersion));
.equalsWithBaseTable("mvp2", existTable, new MTMVVersionSnapshot(correctVersion, 0));
Assert.assertFalse(sync);
// non exist related partition
sync = refreshSnapshot
.equalsWithBaseTable(mvExistPartitionName, nonExistTable, new MTMVVersionSnapshot(correctVersion));
.equalsWithBaseTable(mvExistPartitionName, nonExistTable, new MTMVVersionSnapshot(correctVersion, 0));
Assert.assertFalse(sync);
// snapshot value not equal
sync = refreshSnapshot
.equalsWithBaseTable(mvExistPartitionName, existTable, new MTMVVersionSnapshot(2L));
.equalsWithBaseTable(mvExistPartitionName, existTable, new MTMVVersionSnapshot(2L, 0));
Assert.assertFalse(sync);
// snapshot type not equal
sync = refreshSnapshot.equalsWithBaseTable(mvExistPartitionName, existTable,
Expand Down
Loading