gaborkaszab commented on code in PR #16285:
URL: https://github.com/apache/iceberg/pull/16285#discussion_r3685569699
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -130,9 +137,11 @@ class TrackedFileStruct extends SupportsIndexProjection
implements TrackedFile,
this.keyMetadata = ByteBuffers.toByteArray(keyMetadata);
this.splitOffsets = ArrayUtil.toLongArray(splitOffsets);
this.equalityIds = ArrayUtil.toIntArray(equalityIds);
+ this.columnFiles = columnFiles != null ? Lists.newArrayList(columnFiles) :
null;
}
/** Copy constructor. */
+ @SuppressWarnings("CyclomaticComplexity")
Review Comment:
Yes, this is because the null checks. I didn't want to extract any of these
into separate methods as that would have harmed readability.
##########
core/src/main/java/org/apache/iceberg/ColumnFile.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.nio.ByteBuffer;
+import java.util.List;
+import org.apache.iceberg.types.Types;
+
+interface ColumnFile {
+ Types.NestedField FORMAT_VERSION =
+ Types.NestedField.required(
+ 161, "format_version", Types.IntegerType.get(), "Format version of
this column file");
+ Types.NestedField FIELD_IDS =
+ Types.NestedField.required(
+ 162,
+ "field_ids",
+ Types.ListType.ofRequired(163, Types.IntegerType.get()),
+ "Live field IDs in this column file");
+ Types.NestedField LOCATION =
+ Types.NestedField.required(
+ 164, "location", Types.StringType.get(), "Location of the column
file");
+ Types.NestedField FILE_FORMAT =
+ Types.NestedField.required(
+ 165,
+ "file_format",
+ Types.StringType.get(),
+ "String file format name for this column file");
+ Types.NestedField FILE_SIZE_IN_BYTES =
+ Types.NestedField.required(
+ 166, "file_size_in_bytes", Types.LongType.get(), "Total column file
size in bytes");
+ Types.NestedField KEY_METADATA =
+ Types.NestedField.optional(
+ 167,
+ "key_metadata",
+ Types.BinaryType.get(),
+ "Implementation-specific key metadata for encryption");
+ Types.NestedField SPLIT_OFFSETS =
+ Types.NestedField.optional(
+ 168,
+ "split_offsets",
+ Types.ListType.ofRequired(169, Types.LongType.get()),
+ "Split offsets for the data file");
+
+ static Types.StructType schema() {
+ return Types.StructType.of(
+ FORMAT_VERSION,
+ FIELD_IDS,
+ LOCATION,
+ FILE_FORMAT,
+ FILE_SIZE_IN_BYTES,
+ KEY_METADATA,
+ SPLIT_OFFSETS);
+ }
+
+ /** Returns the format version of this column file. */
+ int formatVersion();
+
+ /** Returns the field IDs contained in this column file. */
+ List<Integer> fieldIds();
+
+ /** Returns the location of this column file. */
+ String location();
+
+ /** Returns the format of this column file. */
+ FileFormat fileFormat();
+
+ /** Returns the total size of this column file in bytes. */
+ long fileSizeInBytes();
+
+ /** Returns encryption key metadata, or null if this column file is not
encrypted. */
+ ByteBuffer keyMetadata();
+
+ /** Returns the list of recommended split locations for this column file, or
null. */
+ List<Long> splitOffsets();
Review Comment:
I brought this up once on the sync, we didn't have a deep dive but there
were no objections either. Rational might be that when we project fields in a
way that we don't have to read the base file, we can use the split offsets of
one of the column files.
Now, with regular column updates, the column files usually contain a column
or two and they have a single row group. However, later for column families we
can have wider column files with more than one row groups where we can have
split offsets.
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -167,6 +176,13 @@ private TrackedFileStruct(TrackedFileStruct toCopy,
Set<Integer> statsIds) {
toCopy.equalityIds != null
? Arrays.copyOf(toCopy.equalityIds, toCopy.equalityIds.length)
: null;
+ this.columnFiles =
Review Comment:
Sure, done.
##########
core/src/main/java/org/apache/iceberg/ColumnFileStruct.java:
##########
@@ -0,0 +1,271 @@
+/*
+ * 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.io.Serializable;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.iceberg.avro.SupportsIndexProjection;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.ArrayUtil;
+import org.apache.iceberg.util.ByteBuffers;
+
+/** Mutable {@link StructLike} implementation of {@link ColumnFile}. */
+class ColumnFileStruct extends SupportsIndexProjection implements ColumnFile,
Serializable {
+ private static final Types.StructType BASE_TYPE =
+ Types.StructType.of(
+ ColumnFile.FORMAT_VERSION,
+ ColumnFile.FIELD_IDS,
+ ColumnFile.LOCATION,
+ ColumnFile.FILE_FORMAT,
+ ColumnFile.FILE_SIZE_IN_BYTES,
+ ColumnFile.KEY_METADATA,
+ ColumnFile.SPLIT_OFFSETS);
+
+ private int formatVersion = -1;
+ private int[] fieldIds = null;
+ private String location = null;
+ private FileFormat fileFormat = null;
+ private long fileSizeInBytes = -1L;
+ private byte[] keyMetadata = null;
+ private long[] splitOffsets = null;
+
+ /** Used by internal readers to instantiate this class with a projection
schema. */
+ ColumnFileStruct(Types.StructType projection) {
+ super(BASE_TYPE, projection);
+ }
+
+ ColumnFileStruct(
+ int formatVersion,
+ List<Integer> fieldIds,
+ String location,
+ FileFormat fileFormat,
+ long fileSizeInBytes,
+ ByteBuffer keyMetadata,
+ List<Long> splitOffsets) {
+ super(BASE_TYPE.fields().size());
+ this.formatVersion = formatVersion;
+ this.fieldIds = ArrayUtil.toIntArray(fieldIds);
+ this.location = location;
+ this.fileFormat = fileFormat;
+ this.fileSizeInBytes = fileSizeInBytes;
+ this.keyMetadata = ByteBuffers.toByteArray(keyMetadata);
+ this.splitOffsets = ArrayUtil.toLongArray(splitOffsets);
+ }
+
+ /** Copy constructor. */
+ private ColumnFileStruct(ColumnFileStruct toCopy) {
+ super(toCopy);
+ this.formatVersion = toCopy.formatVersion;
+ this.fieldIds =
+ toCopy.fieldIds != null ? Arrays.copyOf(toCopy.fieldIds,
toCopy.fieldIds.length) : null;
+ this.location = toCopy.location;
+ this.fileFormat = toCopy.fileFormat;
+ this.fileSizeInBytes = toCopy.fileSizeInBytes;
+ this.keyMetadata =
+ toCopy.keyMetadata != null
+ ? Arrays.copyOf(toCopy.keyMetadata, toCopy.keyMetadata.length)
+ : null;
+ this.splitOffsets =
+ toCopy.splitOffsets != null
+ ? Arrays.copyOf(toCopy.splitOffsets, toCopy.splitOffsets.length)
+ : null;
+ }
+
+ /** Constructor for Java serialization. */
+ ColumnFileStruct() {
+ super(BASE_TYPE.fields().size());
+ }
+
+ @Override
+ public int formatVersion() {
+ return formatVersion;
+ }
+
+ @Override
+ public List<Integer> fieldIds() {
+ return fieldIds != null ? ArrayUtil.toUnmodifiableIntList(fieldIds) : null;
+ }
+
+ @Override
+ public String location() {
+ return location;
+ }
+
+ @Override
+ public FileFormat fileFormat() {
+ return fileFormat;
+ }
+
+ @Override
+ public long fileSizeInBytes() {
+ return fileSizeInBytes;
+ }
+
+ @Override
+ public ByteBuffer keyMetadata() {
+ return keyMetadata != null ? ByteBuffer.wrap(keyMetadata) : null;
+ }
+
+ @Override
+ public List<Long> splitOffsets() {
+ return splitOffsets != null ?
ArrayUtil.toUnmodifiableLongList(splitOffsets) : null;
+ }
+
+ @Override
+ public ColumnFile copy() {
+ return new ColumnFileStruct(this);
+ }
+
+ @Override
+ protected <T> T internalGet(int pos, Class<T> javaClass) {
+ return javaClass.cast(getByPos(pos));
+ }
+
+ private Object getByPos(int pos) {
+ return switch (pos) {
+ case 0 -> formatVersion;
+ case 1 -> fieldIds();
+ case 2 -> location;
+ case 3 -> fileFormat != null ? fileFormat.toString() : null;
Review Comment:
I took this from `TrackedFileStruct` where we guard against `fileFormat` and
`contentType` being null, however both of them are required. Maybe makes sense
when we have a projected read and we don't project those fields?
##########
core/src/main/java/org/apache/iceberg/TrackingBuilder.java:
##########
@@ -25,13 +25,14 @@
class TrackingBuilder {
private final long newSnapshotId;
private final Long snapshotId;
- private final Long dataSequenceNumber;
Review Comment:
It's no longer final, I moved it to the non-final section.
--
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]