anoopj commented on code in PR #16285:
URL: https://github.com/apache/iceberg/pull/16285#discussion_r3484586615
##########
core/src/main/java/org/apache/iceberg/TrackedFileBuilder.java:
##########
@@ -306,6 +313,43 @@ TrackedFileBuilder replacedPositions(ByteBuffer
newReplacedPositions) {
return this;
}
+ TrackedFileBuilder columnFiles(List<ColumnFile> newColumnFiles) {
+ Preconditions.checkArgument(newColumnFiles != null, "Invalid column files:
null");
+ Preconditions.checkArgument(!newColumnFiles.isEmpty(), "Invalid column
files: empty");
+ Preconditions.checkArgument(
+ contentType == FileContent.DATA || contentType ==
FileContent.DATA_MANIFEST,
+ "Column files can only be set for DATA or DATA_MANIFEST entries, but
entry type is %s",
Review Comment:
Why do we allow column files for `DATA_MANIFEST` entries? Is this for
metadata updates? (override DV column?)
##########
core/src/main/java/org/apache/iceberg/ColumnFile.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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.types.Types;
+
+/** Information about a column file. */
+interface ColumnFile {
Review Comment:
The Efficient Column Updates proposal had `sequence_number` at the column
file level. Is that stale? ie are we dropping per-file granularity?
##########
core/src/test/java/org/apache/iceberg/TestColumnFileStruct.java:
##########
@@ -0,0 +1,208 @@
+/*
+ * 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 static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+class TestColumnFileStruct {
+
+ private static final List<Integer> FIELD_IDS = Lists.newArrayList(1, 2, 3);
+ private static final String LOCATION = "s3://bucket/data/column.parquet";
+
+ @Test
+ void testFieldAccess() {
+ ColumnFile columnFile =
+ ColumnFileStruct.builder()
+ .fieldIds(FIELD_IDS)
+ .location(LOCATION)
+ .fileSizeInBytes(1024L)
+ .build();
+
+ assertThat(columnFile.fieldIds()).containsExactlyElementsOf(FIELD_IDS);
+ assertThat(columnFile.location()).isEqualTo(LOCATION);
+ assertThat(columnFile.fileSizeInBytes()).isEqualTo(1024L);
+ }
+
+ @Test
+ void testCopy() {
+ ColumnFile columnFile =
+ ColumnFileStruct.builder()
+ .fieldIds(FIELD_IDS)
+ .location(LOCATION)
+ .fileSizeInBytes(2048L)
+ .build();
+
+ ColumnFile copy = columnFile.copy();
+
+ assertThat(copy.fieldIds()).containsExactlyElementsOf(FIELD_IDS);
+ assertThat(copy.location()).isEqualTo(LOCATION);
+ assertThat(copy.fileSizeInBytes()).isEqualTo(2048L);
+
+ // verify deep copy
+ assertThat(copy.fieldIds()).isNotSameAs(columnFile.fieldIds());
Review Comment:
This will always pass because the `fieldIds()` wrap a
`Collections.umodifiableList()` which will always be different. I think the
only way to test deep copy is to actually mutate the field IDs in the source
and verify that the values don't change in the copy.
##########
core/src/main/java/org/apache/iceberg/ColumnFileStruct.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.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.types.Types;
+import org.apache.iceberg.util.ArrayUtil;
+
+/** 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.FIELD_IDS, ColumnFile.LOCATION,
ColumnFile.FILE_SIZE_IN_BYTES);
+
+ private int[] fieldIds = null;
+ private String location = null;
+ private long fileSizeInBytes = -1L;
+
+ /** Used by internal readers to instantiate this class with a projection
schema. */
+ ColumnFileStruct(Types.StructType projection) {
+ super(BASE_TYPE, projection);
+ }
+
+ private ColumnFileStruct(int[] fieldIds, String location, long
fileSizeInBytes) {
+ super(BASE_TYPE.fields().size());
+ this.fieldIds = fieldIds;
+ this.location = location;
+ this.fileSizeInBytes = fileSizeInBytes;
+ }
+
+ /** Copy constructor. */
+ private ColumnFileStruct(ColumnFileStruct toCopy) {
+ super(toCopy);
+ this.fieldIds =
+ toCopy.fieldIds != null ? Arrays.copyOf(toCopy.fieldIds,
toCopy.fieldIds.length) : null;
+ this.location = toCopy.location;
+ this.fileSizeInBytes = toCopy.fileSizeInBytes;
+ }
+
+ /** Constructor for Java serialization. */
+ ColumnFileStruct() {
+ super(BASE_TYPE.fields().size());
+ }
+
+ @Override
+ public List<Integer> fieldIds() {
+ return fieldIds != null ? ArrayUtil.toUnmodifiableIntList(fieldIds) : null;
+ }
+
+ @Override
+ public String location() {
+ return location;
+ }
+
+ @Override
+ public long fileSizeInBytes() {
+ return fileSizeInBytes;
+ }
+
+ @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) {
+ switch (pos) {
+ case 0:
+ return fieldIds();
+ case 1:
+ return location;
+ case 2:
+ return fileSizeInBytes;
+ default:
+ throw new UnsupportedOperationException("Unknown field ordinal: " +
pos);
+ }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected <T> void internalSet(int pos, T value) {
+ switch (pos) {
+ case 0:
+ this.fieldIds = ArrayUtil.toIntArray((List<Integer>) value);
+ break;
+ case 1:
+ // always coerce to String for Serializable
+ this.location = value.toString();
+ break;
+ case 2:
+ this.fileSizeInBytes = (long) value;
+ break;
+ default:
+ // ignore the object, it must be from a newer version of the format
+ }
+ }
+
+ static Builder builder() {
+ return new Builder();
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("field_ids", fieldIds)
Review Comment:
ToStringHelper() should handle arrays just fine. No need to add a test for
this.
--
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]