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 @@ -32,6 +32,7 @@
import org.apache.paimon.io.DataFilePathFactory;
import org.apache.paimon.io.DataIncrement;
import org.apache.paimon.io.RowDataRollingFileWriter;
import org.apache.paimon.manifest.FileSource;
import org.apache.paimon.memory.MemoryOwner;
import org.apache.paimon.memory.MemorySegmentPool;
import org.apache.paimon.operation.AppendOnlyFileStoreWrite;
Expand Down Expand Up @@ -256,7 +257,8 @@ private RowDataRollingFileWriter createRollingRowWriter() {
seqNumCounter,
fileCompression,
statsCollectors,
fileIndexOptions);
fileIndexOptions,
FileSource.APPEND);
}

private void trySyncLatestCompaction(boolean blocking)
Expand Down
49 changes: 36 additions & 13 deletions paimon-core/src/main/java/org/apache/paimon/io/DataFileMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.paimon.data.BinaryRow;
import org.apache.paimon.data.Timestamp;
import org.apache.paimon.fs.Path;
import org.apache.paimon.manifest.FileSource;
import org.apache.paimon.stats.SimpleStats;
import org.apache.paimon.stats.SimpleStatsConverter;
import org.apache.paimon.types.ArrayType;
Expand All @@ -30,6 +31,7 @@
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.types.IntType;
import org.apache.paimon.types.RowType;
import org.apache.paimon.types.TinyIntType;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -83,14 +85,17 @@ public class DataFileMeta {
// file index filter bytes, if it is small, store in data file meta
private final @Nullable byte[] embeddedIndex;

private final @Nullable FileSource fileSource;

public static DataFileMeta forAppend(
String fileName,
long fileSize,
long rowCount,
SimpleStats rowStats,
long minSequenceNumber,
long maxSequenceNumber,
long schemaId) {
long schemaId,
@Nullable FileSource fileSource) {
return forAppend(
fileName,
fileSize,
Expand All @@ -100,7 +105,8 @@ public static DataFileMeta forAppend(
maxSequenceNumber,
schemaId,
Collections.emptyList(),
null);
null,
fileSource);
}

public static DataFileMeta forAppend(
Expand All @@ -112,7 +118,8 @@ public static DataFileMeta forAppend(
long maxSequenceNumber,
long schemaId,
List<String> extraFiles,
@Nullable byte[] embeddedIndex) {
@Nullable byte[] embeddedIndex,
@Nullable FileSource fileSource) {
return new DataFileMeta(
fileName,
fileSize,
Expand All @@ -128,7 +135,8 @@ public static DataFileMeta forAppend(
extraFiles,
Timestamp.fromLocalDateTime(LocalDateTime.now()).toMillisTimestamp(),
0L,
embeddedIndex);
embeddedIndex,
fileSource);
}

public DataFileMeta(
Expand All @@ -144,7 +152,8 @@ public DataFileMeta(
long schemaId,
int level,
@Nullable Long deleteRowCount,
@Nullable byte[] embeddedIndex) {
@Nullable byte[] embeddedIndex,
@Nullable FileSource fileSource) {
this(
fileName,
fileSize,
Expand All @@ -160,7 +169,8 @@ public DataFileMeta(
Collections.emptyList(),
Timestamp.fromLocalDateTime(LocalDateTime.now()).toMillisTimestamp(),
deleteRowCount,
embeddedIndex);
embeddedIndex,
fileSource);
}

public DataFileMeta(
Expand All @@ -178,7 +188,8 @@ public DataFileMeta(
List<String> extraFiles,
Timestamp creationTime,
@Nullable Long deleteRowCount,
@Nullable byte[] embeddedIndex) {
@Nullable byte[] embeddedIndex,
@Nullable FileSource fileSource) {
this.fileName = fileName;
this.fileSize = fileSize;

Expand All @@ -198,6 +209,7 @@ public DataFileMeta(
this.creationTime = creationTime;

this.deleteRowCount = deleteRowCount;
this.fileSource = fileSource;
}

public String fileName() {
Expand Down Expand Up @@ -291,6 +303,10 @@ public String fileFormat() {
return split[split.length - 1];
}

public Optional<FileSource> fileSource() {
return Optional.ofNullable(fileSource);
}

public DataFileMeta upgrade(int newLevel) {
checkArgument(newLevel > this.level);
return new DataFileMeta(
Expand All @@ -308,7 +324,8 @@ public DataFileMeta upgrade(int newLevel) {
extraFiles,
creationTime,
deleteRowCount,
embeddedIndex);
embeddedIndex,
fileSource);
}

public List<Path> collectFiles(DataFilePathFactory pathFactory) {
Expand All @@ -334,7 +351,8 @@ public DataFileMeta copy(List<String> newExtraFiles) {
newExtraFiles,
creationTime,
deleteRowCount,
embeddedIndex);
embeddedIndex,
fileSource);
}

@Override
Expand All @@ -360,7 +378,8 @@ public boolean equals(Object o) {
&& level == that.level
&& Objects.equals(extraFiles, that.extraFiles)
&& Objects.equals(creationTime, that.creationTime)
&& Objects.equals(deleteRowCount, that.deleteRowCount);
&& Objects.equals(deleteRowCount, that.deleteRowCount)
&& Objects.equals(fileSource, that.fileSource);
}

@Override
Expand All @@ -380,7 +399,8 @@ public int hashCode() {
level,
extraFiles,
creationTime,
deleteRowCount);
deleteRowCount,
fileSource);
}

@Override
Expand All @@ -389,7 +409,8 @@ public String toString() {
"{fileName: %s, fileSize: %d, rowCount: %d, embeddedIndex: %s, "
+ "minKey: %s, maxKey: %s, keyStats: %s, valueStats: %s, "
+ "minSequenceNumber: %d, maxSequenceNumber: %d, "
+ "schemaId: %d, level: %d, extraFiles: %s, creationTime: %s, deleteRowCount: %d}",
+ "schemaId: %d, level: %d, extraFiles: %s, creationTime: %s, "
+ "deleteRowCount: %d, fileSource: %s}",
fileName,
fileSize,
rowCount,
Expand All @@ -404,7 +425,8 @@ public String toString() {
level,
extraFiles,
creationTime,
deleteRowCount);
deleteRowCount,
fileSource);
}

public static RowType schema() {
Expand All @@ -424,6 +446,7 @@ public static RowType schema() {
fields.add(new DataField(12, "_CREATION_TIME", DataTypes.TIMESTAMP_MILLIS()));
fields.add(new DataField(13, "_DELETE_ROW_COUNT", new BigIntType(true)));
fields.add(new DataField(14, "_EMBEDDED_FILE_INDEX", newBytesType(true)));
fields.add(new DataField(15, "_FILE_SOURCE", new TinyIntType(true)));
return new RowType(fields);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.paimon.data.BinaryString;
import org.apache.paimon.data.GenericRow;
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.manifest.FileSource;
import org.apache.paimon.stats.SimpleStats;
import org.apache.paimon.utils.ObjectSerializer;

Expand Down Expand Up @@ -55,7 +56,8 @@ public InternalRow toRow(DataFileMeta meta) {
toStringArrayData(meta.extraFiles()),
meta.creationTime(),
meta.deleteRowCount().orElse(null),
meta.embeddedIndex());
meta.embeddedIndex(),
meta.fileSource().map(FileSource::toByteValue).orElse(null));
}

@Override
Expand All @@ -75,6 +77,7 @@ public DataFileMeta fromRow(InternalRow row) {
fromStringArrayData(row.getArray(11)),
row.getTimestamp(12, 3),
row.isNullAt(13) ? null : row.getLong(13),
row.isNullAt(14) ? null : row.getBinary(14));
row.isNullAt(14) ? null : row.getBinary(14),
row.isNullAt(15) ? null : FileSource.fromByteValue(row.getByte(15)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.paimon.format.SimpleStatsExtractor;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.manifest.FileSource;
import org.apache.paimon.stats.SimpleStats;
import org.apache.paimon.stats.SimpleStatsConverter;
import org.apache.paimon.types.RowType;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class KeyValueDataFileWriter
private final SimpleStatsConverter keyStatsConverter;
private final SimpleStatsConverter valueStatsConverter;
private final InternalRowSerializer keySerializer;
private final FileSource fileSource;

private BinaryRow minKey = null;
private InternalRow maxKey = null;
Expand All @@ -80,7 +82,8 @@ public KeyValueDataFileWriter(
long schemaId,
int level,
String compression,
CoreOptions options) {
CoreOptions options,
FileSource fileSource) {
super(
fileIO,
factory,
Expand All @@ -100,6 +103,7 @@ public KeyValueDataFileWriter(
this.keyStatsConverter = new SimpleStatsConverter(keyType);
this.valueStatsConverter = new SimpleStatsConverter(valueType);
this.keySerializer = new InternalRowSerializer(keyType);
this.fileSource = fileSource;
}

@Override
Expand Down Expand Up @@ -170,6 +174,7 @@ public DataFileMeta result() throws IOException {
level,
deleteRecordCount,
// TODO: enable file filter for primary key table (e.g. deletion table).
null);
null,
fileSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.paimon.format.SimpleStatsExtractor;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.manifest.FileSource;
import org.apache.paimon.statistics.SimpleColStatsCollector;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.FileStorePathFactory;
Expand Down Expand Up @@ -81,21 +82,27 @@ public DataFilePathFactory pathFactory(int level) {
return formatContext.pathFactory(level);
}

public RollingFileWriter<KeyValue, DataFileMeta> createRollingMergeTreeFileWriter(int level) {
public RollingFileWriter<KeyValue, DataFileMeta> createRollingMergeTreeFileWriter(
int level, FileSource fileSource) {
return new RollingFileWriter<>(
() -> createDataFileWriter(formatContext.pathFactory(level).newPath(), level),
() ->
createDataFileWriter(
formatContext.pathFactory(level).newPath(), level, fileSource),
suggestedFileSize);
}

public RollingFileWriter<KeyValue, DataFileMeta> createRollingChangelogFileWriter(int level) {
return new RollingFileWriter<>(
() ->
createDataFileWriter(
formatContext.pathFactory(level).newChangelogPath(), level),
formatContext.pathFactory(level).newChangelogPath(),
level,
FileSource.APPEND),
suggestedFileSize);
}

private KeyValueDataFileWriter createDataFileWriter(Path path, int level) {
private KeyValueDataFileWriter createDataFileWriter(
Path path, int level, FileSource fileSource) {
KeyValueSerializer kvSerializer = new KeyValueSerializer(keyType, valueType);
return new KeyValueDataFileWriter(
fileIO,
Expand All @@ -108,7 +115,8 @@ private KeyValueDataFileWriter createDataFileWriter(Path path, int level) {
schemaId,
level,
formatContext.compression(level),
options);
options,
fileSource);
}

public void deleteFile(String filename, int level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.paimon.format.SimpleStatsExtractor;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.manifest.FileSource;
import org.apache.paimon.statistics.SimpleColStatsCollector;
import org.apache.paimon.stats.SimpleStats;
import org.apache.paimon.stats.SimpleStatsConverter;
Expand All @@ -48,6 +49,7 @@ public class RowDataFileWriter extends StatsCollectingSingleFileWriter<InternalR
private final LongCounter seqNumCounter;
private final SimpleStatsConverter statsArraySerializer;
@Nullable private final FileIndexWriter fileIndexWriter;
private final FileSource fileSource;

public RowDataFileWriter(
FileIO fileIO,
Expand All @@ -59,7 +61,8 @@ public RowDataFileWriter(
LongCounter seqNumCounter,
String fileCompression,
SimpleColStatsCollector.Factory[] statsCollectors,
FileIndexOptions fileIndexOptions) {
FileIndexOptions fileIndexOptions,
FileSource fileSource) {
super(
fileIO,
factory,
Expand All @@ -75,6 +78,7 @@ public RowDataFileWriter(
this.fileIndexWriter =
FileIndexWriter.create(
fileIO, toFileIndexPath(path), writeSchema, fileIndexOptions);
this.fileSource = fileSource;
}

@Override
Expand Down Expand Up @@ -111,6 +115,7 @@ public DataFileMeta result() throws IOException {
indexResult.independentIndexFile() == null
? Collections.emptyList()
: Collections.singletonList(indexResult.independentIndexFile()),
indexResult.embeddedIndexBytes());
indexResult.embeddedIndexBytes(),
fileSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.paimon.format.FileFormat;
import org.apache.paimon.format.avro.AvroFileFormat;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.manifest.FileSource;
import org.apache.paimon.statistics.SimpleColStatsCollector;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.LongCounter;
Expand All @@ -40,7 +41,8 @@ public RowDataRollingFileWriter(
LongCounter seqNumCounter,
String fileCompression,
SimpleColStatsCollector.Factory[] statsCollectors,
FileIndexOptions fileIndexOptions) {
FileIndexOptions fileIndexOptions,
FileSource fileSource) {
super(
() ->
new RowDataFileWriter(
Expand All @@ -57,7 +59,8 @@ public RowDataRollingFileWriter(
seqNumCounter,
fileCompression,
statsCollectors,
fileIndexOptions),
fileIndexOptions,
fileSource),
targetFileSize);
}
}
Loading