Skip to content
Closed
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
110 changes: 105 additions & 5 deletions paimon-core/src/main/java/org/apache/paimon/io/DataFileMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ public interface DataFileMeta {
new DataField(17, "_EXTERNAL_PATH", newStringType(true)),
new DataField(18, "_FIRST_ROW_ID", new BigIntType(true)),
new DataField(
19, "_WRITE_COLS", new ArrayType(true, newStringType(false)))));
19, "_WRITE_COLS", new ArrayType(true, newStringType(false))),
new DataField(
20,
"_WRITTEN_FIELD_IDS",
new ArrayType(true, new IntType(false)))));

BinaryRow EMPTY_MIN_KEY = EMPTY_ROW;
BinaryRow EMPTY_MAX_KEY = EMPTY_ROW;
Expand All @@ -108,6 +112,40 @@ static DataFileMeta forAppend(
@Nullable String externalPath,
@Nullable Long firstRowId,
@Nullable List<String> writeCols) {
return forAppend(
fileName,
fileSize,
rowCount,
rowStats,
minSequenceNumber,
maxSequenceNumber,
schemaId,
extraFiles,
embeddedIndex,
fileSource,
valueStatsCols,
externalPath,
firstRowId,
writeCols,
null);
}

static DataFileMeta forAppend(
String fileName,
long fileSize,
long rowCount,
SimpleStats rowStats,
long minSequenceNumber,
long maxSequenceNumber,
long schemaId,
List<String> extraFiles,
@Nullable byte[] embeddedIndex,
@Nullable FileSource fileSource,
@Nullable List<String> valueStatsCols,
@Nullable String externalPath,
@Nullable Long firstRowId,
@Nullable List<String> writeCols,
@Nullable int[] writtenFieldIds) {
return new PojoDataFileMeta(
fileName,
fileSize,
Expand All @@ -128,7 +166,8 @@ static DataFileMeta forAppend(
valueStatsCols,
externalPath,
firstRowId,
writeCols);
writeCols,
writtenFieldIds);
}

static DataFileMeta create(
Expand Down Expand Up @@ -171,7 +210,8 @@ static DataFileMeta create(
valueStatsCols,
externalPath,
firstRowId,
writeCols);
writeCols,
null);
}

static DataFileMeta create(
Expand Down Expand Up @@ -212,7 +252,8 @@ static DataFileMeta create(
valueStatsCols,
null,
firstRowId,
writeCols);
writeCols,
null);
}

static DataFileMeta create(
Expand All @@ -236,6 +277,52 @@ static DataFileMeta create(
@Nullable String externalPath,
@Nullable Long firstRowId,
@Nullable List<String> writeCols) {
return create(
fileName,
fileSize,
rowCount,
minKey,
maxKey,
keyStats,
valueStats,
minSequenceNumber,
maxSequenceNumber,
schemaId,
level,
extraFiles,
creationTime,
deleteRowCount,
embeddedIndex,
fileSource,
valueStatsCols,
externalPath,
firstRowId,
writeCols,
null);
}

static DataFileMeta create(
String fileName,
long fileSize,
long rowCount,
BinaryRow minKey,
BinaryRow maxKey,
SimpleStats keyStats,
SimpleStats valueStats,
long minSequenceNumber,
long maxSequenceNumber,
long schemaId,
int level,
List<String> extraFiles,
Timestamp creationTime,
@Nullable Long deleteRowCount,
@Nullable byte[] embeddedIndex,
@Nullable FileSource fileSource,
@Nullable List<String> valueStatsCols,
@Nullable String externalPath,
@Nullable Long firstRowId,
@Nullable List<String> writeCols,
@Nullable int[] writtenFieldIds) {
return new PojoDataFileMeta(
fileName,
fileSize,
Expand All @@ -256,7 +343,8 @@ static DataFileMeta create(
valueStatsCols,
externalPath,
firstRowId,
writeCols);
writeCols,
writtenFieldIds);
}

String fileName();
Expand Down Expand Up @@ -326,6 +414,18 @@ default Range nonNullRowIdRange() {
@Nullable
List<String> writeCols();

/**
* The field ids of the columns written in this file, or {@code null} if all columns are written
* (or the file was created by an older version that only recorded {@link #writeCols()} names).
* This is the id-based counterpart of {@link #writeCols()}: field ids are stable across column
* renames and can also address nested fields uniformly, since every (nested) field has a
* globally unique id in the table schema.
*/
@Nullable
default int[] writtenFieldIds() {
return null;
}

DataFileMeta upgrade(int newLevel);

DataFileMeta rename(String newFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.paimon.io;

import org.apache.paimon.data.BinaryString;
import org.apache.paimon.data.GenericArray;
import org.apache.paimon.data.GenericRow;
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.manifest.FileSource;
Expand Down Expand Up @@ -61,7 +62,8 @@ public InternalRow toRow(DataFileMeta meta) {
toStringArrayData(meta.valueStatsCols()),
meta.externalPath().map(BinaryString::fromString).orElse(null),
meta.firstRowId(),
meta.writeCols() == null ? null : toStringArrayData(meta.writeCols()));
meta.writeCols() == null ? null : toStringArrayData(meta.writeCols()),
meta.writtenFieldIds() == null ? null : new GenericArray(meta.writtenFieldIds()));
}

@Override
Expand All @@ -86,6 +88,7 @@ public DataFileMeta fromRow(InternalRow row) {
row.isNullAt(16) ? null : fromStringArrayData(row.getArray(16)),
row.isNullAt(17) ? null : row.getString(17).toString(),
row.isNullAt(18) ? null : row.getLong(18),
row.isNullAt(19) ? null : fromStringArrayData(row.getArray(19)));
row.isNullAt(19) ? null : fromStringArrayData(row.getArray(19)),
row.isNullAt(20) ? null : row.getArray(20).toIntArray());
}
}
Original file line number Diff line number Diff line change
@@ -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.paimon.io;

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.types.ArrayType;
import org.apache.paimon.types.BigIntType;
import org.apache.paimon.types.DataField;
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 org.apache.paimon.utils.ObjectSerializer;

import java.util.Arrays;

import static org.apache.paimon.utils.InternalRowUtils.fromStringArrayData;
import static org.apache.paimon.utils.InternalRowUtils.toStringArrayData;
import static org.apache.paimon.utils.SerializationUtils.deserializeBinaryRow;
import static org.apache.paimon.utils.SerializationUtils.newBytesType;
import static org.apache.paimon.utils.SerializationUtils.newStringType;
import static org.apache.paimon.utils.SerializationUtils.serializeBinaryRow;

/**
* Serializer for {@link DataFileMeta} with the legacy 20-field layout, i.e. up to {@code
* _WRITE_COLS} and before {@code _WRITTEN_FIELD_IDS} was appended. It freezes that layout so
* streams written by older versions keep deserializing correctly.
*/
public class DataFileMetaWriteColsLegacySerializer extends ObjectSerializer<DataFileMeta> {

private static final long serialVersionUID = 1L;

/** The frozen {@link DataFileMeta} schema of the {@code _WRITE_COLS} era (fields 0-19). */
public static final RowType SCHEMA =
new RowType(
false,
Arrays.asList(
new DataField(0, "_FILE_NAME", newStringType(false)),
new DataField(1, "_FILE_SIZE", new BigIntType(false)),
new DataField(2, "_ROW_COUNT", new BigIntType(false)),
new DataField(3, "_MIN_KEY", newBytesType(false)),
new DataField(4, "_MAX_KEY", newBytesType(false)),
new DataField(5, "_KEY_STATS", SimpleStats.SCHEMA),
new DataField(6, "_VALUE_STATS", SimpleStats.SCHEMA),
new DataField(7, "_MIN_SEQUENCE_NUMBER", new BigIntType(false)),
new DataField(8, "_MAX_SEQUENCE_NUMBER", new BigIntType(false)),
new DataField(9, "_SCHEMA_ID", new BigIntType(false)),
new DataField(10, "_LEVEL", new IntType(false)),
new DataField(
11, "_EXTRA_FILES", new ArrayType(false, newStringType(false))),
new DataField(12, "_CREATION_TIME", DataTypes.TIMESTAMP_MILLIS()),
new DataField(13, "_DELETE_ROW_COUNT", new BigIntType(true)),
new DataField(14, "_EMBEDDED_FILE_INDEX", newBytesType(true)),
new DataField(15, "_FILE_SOURCE", new TinyIntType(true)),
new DataField(
16,
"_VALUE_STATS_COLS",
DataTypes.ARRAY(DataTypes.STRING().notNull())),
new DataField(17, "_EXTERNAL_PATH", newStringType(true)),
new DataField(18, "_FIRST_ROW_ID", new BigIntType(true)),
new DataField(
19, "_WRITE_COLS", new ArrayType(true, newStringType(false)))));

public DataFileMetaWriteColsLegacySerializer() {
super(SCHEMA);
}

@Override
public InternalRow toRow(DataFileMeta meta) {
return GenericRow.of(
BinaryString.fromString(meta.fileName()),
meta.fileSize(),
meta.rowCount(),
serializeBinaryRow(meta.minKey()),
serializeBinaryRow(meta.maxKey()),
meta.keyStats().toRow(),
meta.valueStats().toRow(),
meta.minSequenceNumber(),
meta.maxSequenceNumber(),
meta.schemaId(),
meta.level(),
toStringArrayData(meta.extraFiles()),
meta.creationTime(),
meta.deleteRowCount().orElse(null),
meta.embeddedIndex(),
meta.fileSource().map(FileSource::toByteValue).orElse(null),
toStringArrayData(meta.valueStatsCols()),
meta.externalPath().map(BinaryString::fromString).orElse(null),
meta.firstRowId(),
meta.writeCols() == null ? null : toStringArrayData(meta.writeCols()));
}

@Override
public DataFileMeta fromRow(InternalRow row) {
return DataFileMeta.create(
row.getString(0).toString(),
row.getLong(1),
row.getLong(2),
deserializeBinaryRow(row.getBinary(3)),
deserializeBinaryRow(row.getBinary(4)),
SimpleStats.fromRow(row.getRow(5, 3)),
SimpleStats.fromRow(row.getRow(6, 3)),
row.getLong(7),
row.getLong(8),
row.getLong(9),
row.getInt(10),
fromStringArrayData(row.getArray(11)),
row.getTimestamp(12, 3),
row.isNullAt(13) ? null : row.getLong(13),
row.isNullAt(14) ? null : row.getBinary(14),
row.isNullAt(15) ? null : FileSource.fromByteValue(row.getByte(15)),
row.isNullAt(16) ? null : fromStringArrayData(row.getArray(16)),
row.isNullAt(17) ? null : row.getString(17).toString(),
row.isNullAt(18) ? null : row.getLong(18),
row.isNullAt(19) ? null : fromStringArrayData(row.getArray(19)));
}
}
Loading
Loading