Skip to content
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
24d8691
Flink: init streaming rewrite.
Reo-LEI Oct 19, 2021
4d94772
Merge remote-tracking branch 'community/master' into flink-streaming-…
Reo-LEI Oct 19, 2021
c9c125b
refactor rewrite files committer.
Reo-LEI Oct 19, 2021
1df1814
Add rewrite parallelism config.
Reo-LEI Oct 20, 2021
d96704f
Add unittest for stream rewriter.
Reo-LEI Oct 20, 2021
98e2832
Add unittest for rewrite rile committer.
Reo-LEI Oct 21, 2021
0ff66bf
Add unittest for file committer.
Reo-LEI Oct 21, 2021
69689e5
Merge remote-tracking branch 'community/master' into flink-streaming-…
Reo-LEI Oct 21, 2021
c5ca44b
Fix unittest.
Reo-LEI Oct 21, 2021
47f4765
Fix unittest.
Reo-LEI Oct 21, 2021
d8a7f69
Fix unittest.
Reo-LEI Oct 21, 2021
6439bbb
Fix rewrite commit error when no rewrite result.
Reo-LEI Oct 23, 2021
5a1739d
Merge remote-tracking branch 'community/master' into flink-streaming-…
Reo-LEI Nov 5, 2021
8fadd91
Merge remote-tracking branch 'community/master' into flink-streaming-…
Reo-LEI Nov 17, 2021
971d1c7
Move to flink v1.13.
Reo-LEI Nov 17, 2021
682a2b2
Wrap PartitionData by StructLikeWrapper.
Reo-LEI Nov 18, 2021
11814e9
Merge branch 'apache:master' into flink-streaming-rewrite
Reo-LEI Nov 18, 2021
25a2a90
support to emit all needed files for restore and concurrent writer.
Reo-LEI Dec 25, 2021
2a52cd5
Fix unittest.
Reo-LEI Dec 26, 2021
189c946
Merge remote-tracking branch 'origin/master' into flink-streaming-rew…
Reo-LEI Dec 26, 2021
268392a
fix class not found.
Reo-LEI Dec 26, 2021
25a93e0
not swallow exception when rewrite fail.
Reo-LEI Dec 26, 2021
328c876
port to flink 0.14
Reo-LEI Dec 26, 2021
1e5c7a5
Flink: fix streaming rewrite kryo serialization error for partition b…
Reo-LEI Jan 3, 2022
7d131f3
Flink: refactor streaming rewrite.
Reo-LEI Jan 27, 2022
521d62f
Merge branch 'master' into flink-streaming-rewrite
Reo-LEI Jan 27, 2022
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
17 changes: 17 additions & 0 deletions api/src/main/java/org/apache/iceberg/types/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Objects;

public interface Type extends Serializable {
enum TypeID {
Expand Down Expand Up @@ -111,6 +112,22 @@ public PrimitiveType asPrimitiveType() {
Object writeReplace() throws ObjectStreamException {
return new PrimitiveHolder(toString());
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (!(o instanceof PrimitiveType)) {
return false;
}
PrimitiveType that = (PrimitiveType) o;
return this.typeId().equals(that.typeId());
}

@Override
public int hashCode() {
return Objects.hash(this.getClass(), this.typeId());
}
}

abstract class NestedType implements Type {
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/org/apache/iceberg/types/TypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ public static boolean isPromotionAllowed(Type from, Type.PrimitiveType to) {

switch (from.typeId()) {
case INTEGER:
return to == Types.LongType.get();
return to.equals(Types.LongType.get());
Comment thread
Reo-LEI marked this conversation as resolved.
Outdated

case FLOAT:
return to == Types.DoubleType.get();
return to.equals(Types.DoubleType.get());

case DECIMAL:
Types.DecimalType fromDecimal = (Types.DecimalType) from;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/apache/iceberg/DeleteFileIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ private Iterable<CloseableIterable<ManifestEntry<DeleteFile>>> deleteManifestRea
Iterable<ManifestFile> matchingManifests = evalCache == null ? deleteManifests :
Iterables.filter(deleteManifests, manifest ->
manifest.content() == ManifestContent.DELETES &&
(manifest.hasAddedFiles() || manifest.hasDeletedFiles()) &&
(manifest.hasAddedFiles() || manifest.hasExistingFiles() || manifest.hasDeletedFiles()) &&
evalCache.get(manifest.partitionSpecId()).eval(manifest));

return Iterables.transform(
Expand Down
125 changes: 125 additions & 0 deletions core/src/main/java/org/apache/iceberg/StaticDataTableScan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* 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.iceberg;

import java.util.List;
import org.apache.iceberg.events.Listeners;
import org.apache.iceberg.events.ScanEvent;
import org.apache.iceberg.expressions.Expression;
import org.apache.iceberg.io.CloseableIterable;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.util.ThreadPools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class StaticDataTableScan extends DataTableScan {
private static final Logger LOG = LoggerFactory.getLogger(StaticDataTableScan.class);

private static final long DUMMY_SNAPSHOT_ID = 0L;

private final List<ManifestFile> dataManifests;
private final List<ManifestFile> deleteManifests;

private StaticDataTableScan(Table table,
TableOperations ops) {
super(ops, table);
this.dataManifests = Lists.newArrayList();
this.deleteManifests = Lists.newArrayList();
}

@Override
public TableScan useSnapshot(long scanSnapshotId) {
throw new UnsupportedOperationException(String.format(
"Scan table using scan snapshot id %s is not supported", scanSnapshotId));
}

@Override
public TableScan asOfTime(long timestampMillis) {
throw new UnsupportedOperationException(String.format(
"Scan table as of time %s is not supported", timestampMillis));
}

@Override
public TableScan appendsBetween(long fromSnapshotId, long toSnapshotId) {
throw new UnsupportedOperationException("Incremental scan is not supported");
}

@Override
public TableScan appendsAfter(long fromSnapshotId) {
throw new UnsupportedOperationException("Incremental scan is not supported");
}

@Override
public Snapshot snapshot() {
return null;
}

public TableScan scan(Iterable<ManifestFile> newManifests) {
for (ManifestFile manifestFile : newManifests) {
Preconditions.checkArgument(manifestFile != null, "Cannot scan a null manifest file");
switch (manifestFile.content()) {
case DATA:
dataManifests.add(manifestFile);
break;
case DELETES:
deleteManifests.add(manifestFile);
break;
default: throw new IllegalArgumentException("Unknown ManifestContent type: " + manifestFile.content());
}
}
return this;
}

@Override
public CloseableIterable<FileScanTask> planFiles() {
LOG.info("Scanning table {} partially with filter {}", table(), context().rowFilter());

Listeners.notifyAll(new ScanEvent(table().name(), DUMMY_SNAPSHOT_ID, context().rowFilter(), schema()));
Comment thread
Reo-LEI marked this conversation as resolved.
Outdated

return planFiles(tableOps(), null,
context().rowFilter(), context().ignoreResiduals(), context().caseSensitive(), context().returnColumnStats());
}

@Override
public CloseableIterable<FileScanTask> planFiles(TableOperations ops, Snapshot snapshot, Expression rowFilter,
boolean ignoreResiduals, boolean caseSensitive, boolean colStats) {
ManifestGroup manifestGroup = new ManifestGroup(ops.io(), dataManifests, deleteManifests)
.caseSensitive(caseSensitive)
.select(colStats ? SCAN_WITH_STATS_COLUMNS : SCAN_COLUMNS)
.filterData(rowFilter)
.specsById(ops.current().specsById())
.ignoreDeleted();

if (ignoreResiduals) {
manifestGroup = manifestGroup.ignoreResiduals();
}

if (PLAN_SCANS_WITH_WORKER_POOL && dataManifests.size() > 1) {
manifestGroup = manifestGroup.planWith(ThreadPools.getWorkerPool());
}

return manifestGroup.planFiles();
}

public static StaticDataTableScan of(Table table, TableOperations ops) {
return new StaticDataTableScan(table, ops);
}
}
114 changes: 114 additions & 0 deletions flink/src/main/java/org/apache/iceberg/flink/sink/CommitResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.iceberg.flink.sink;

import java.io.Serializable;
import java.util.Collection;
import org.apache.iceberg.DataFile;
import org.apache.iceberg.DeleteFile;
import org.apache.iceberg.StructLike;
import org.apache.iceberg.io.WriteResult;

class CommitResult implements Serializable {

private final long snapshotId;
private final long sequenceNumber;
private final int specId;
private final StructLike partition;
private final WriteResult writeResult;

private CommitResult(long snapshotId,
long sequenceNumber,
int specId,
StructLike partition,
WriteResult writeResult) {
this.snapshotId = snapshotId;
this.sequenceNumber = sequenceNumber;
this.specId = specId;
this.partition = partition;
this.writeResult = writeResult;
}

long snapshotId() {
return snapshotId;
}

long sequenceNumber() {
return sequenceNumber;
}

public int specId() {
return specId;
}

StructLike partition() {
return partition;
}

WriteResult writeResult() {
return writeResult;
}

static Builder builder(long snapshotId, long sequenceNumber) {
return new Builder(snapshotId, sequenceNumber);
}

static class Builder {

private final long snapshotId;
private final long sequenceNumber;
private int specId;
private StructLike partition;
private final WriteResult.Builder writeResult;

private Builder(long snapshotId, long sequenceNumber) {
this.snapshotId = snapshotId;
this.sequenceNumber = sequenceNumber;
this.specId = 0;
this.partition = null;
this.writeResult = WriteResult.builder();
}

Builder partition(int newSpecId, StructLike newPartition) {
this.specId = newSpecId;
this.partition = newPartition;
return this;
}

Builder addDataFile(Collection<DataFile> files) {
writeResult.addDataFiles(files);
return this;
}

Builder addDeleteFile(Collection<DeleteFile> files) {
writeResult.addDeleteFiles(files);
return this;
}

Builder addReferencedDataFile(Collection<CharSequence> files) {
writeResult.addReferencedDataFiles(files);
Comment thread
Reo-LEI marked this conversation as resolved.
Outdated
return this;
}

CommitResult build() {
return new CommitResult(snapshotId, sequenceNumber, specId, partition, writeResult.build());
}
}
}
Loading