gaborkaszab commented on code in PR #16285: URL: https://github.com/apache/iceberg/pull/16285#discussion_r4294667576
########## core/src/main/java/org/apache/iceberg/ColumnFileStruct.java: ########## @@ -0,0 +1,222 @@ +/* + * 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.Comparator; +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.Lists; +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.LOCATION, + ColumnFile.FIELD_IDS, + ColumnFile.FILE_FORMAT, + ColumnFile.FILE_SIZE_IN_BYTES, + ColumnFile.KEY_METADATA); + + private String location = null; + private int[] fieldIds = null; + private FileFormat fileFormat = null; + private long fileSizeInBytes = -1L; + private byte[] keyMetadata = null; + + /** Used by internal readers to instantiate this class with a projection schema. */ + ColumnFileStruct(Types.StructType projection) { + super(BASE_TYPE, projection); + } + + ColumnFileStruct( + String location, + List<Integer> fieldIds, + FileFormat fileFormat, + long fileSizeInBytes, + ByteBuffer keyMetadata) { + super(BASE_TYPE.fields().size()); + this.location = location; + this.fieldIds = ArrayUtil.toIntArray(fieldIds); + this.fileFormat = fileFormat; + this.fileSizeInBytes = fileSizeInBytes; + this.keyMetadata = ByteBuffers.toByteArray(keyMetadata); + } + + /** Copy constructor. */ + private ColumnFileStruct(ColumnFileStruct toCopy) { + super(toCopy); + this.location = toCopy.location; + this.fieldIds = + toCopy.fieldIds != null ? Arrays.copyOf(toCopy.fieldIds, toCopy.fieldIds.length) : null; + this.fileFormat = toCopy.fileFormat; + this.fileSizeInBytes = toCopy.fileSizeInBytes; + this.keyMetadata = + toCopy.keyMetadata != null + ? Arrays.copyOf(toCopy.keyMetadata, toCopy.keyMetadata.length) + : null; + } + + /** Constructor for Java serialization. */ + ColumnFileStruct() { + super(BASE_TYPE.fields().size()); + } + + @Override + public String location() { + return location; + } + + @Override + public List<Integer> fieldIds() { + return fieldIds != null ? ArrayUtil.toUnmodifiableIntList(fieldIds) : null; + } + + @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 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 -> location; + case 1 -> fieldIds(); + case 2 -> fileFormat != null ? fileFormat.toString() : null; + case 3 -> fileSizeInBytes; + case 4 -> keyMetadata(); + default -> throw new UnsupportedOperationException("Unknown field ordinal: " + pos); + }; + } + + @Override + @SuppressWarnings("unchecked") + protected <T> void internalSet(int pos, T value) { + switch (pos) { + // always coerce to String for Serializable + case 0 -> this.location = value.toString(); Review Comment: I wanted t make this consistent with the same in `TrackedFileStruct` and `DeletionVectorStruct`. ########## core/src/main/java/org/apache/iceberg/ColumnFileStruct.java: ########## @@ -0,0 +1,222 @@ +/* + * 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.Comparator; +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.Lists; +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.LOCATION, + ColumnFile.FIELD_IDS, + ColumnFile.FILE_FORMAT, + ColumnFile.FILE_SIZE_IN_BYTES, + ColumnFile.KEY_METADATA); + + private String location = null; + private int[] fieldIds = null; + private FileFormat fileFormat = null; + private long fileSizeInBytes = -1L; + private byte[] keyMetadata = null; + + /** Used by internal readers to instantiate this class with a projection schema. */ + ColumnFileStruct(Types.StructType projection) { + super(BASE_TYPE, projection); + } + + ColumnFileStruct( + String location, + List<Integer> fieldIds, + FileFormat fileFormat, + long fileSizeInBytes, + ByteBuffer keyMetadata) { + super(BASE_TYPE.fields().size()); + this.location = location; + this.fieldIds = ArrayUtil.toIntArray(fieldIds); + this.fileFormat = fileFormat; + this.fileSizeInBytes = fileSizeInBytes; + this.keyMetadata = ByteBuffers.toByteArray(keyMetadata); + } + + /** Copy constructor. */ + private ColumnFileStruct(ColumnFileStruct toCopy) { + super(toCopy); + this.location = toCopy.location; + this.fieldIds = + toCopy.fieldIds != null ? Arrays.copyOf(toCopy.fieldIds, toCopy.fieldIds.length) : null; + this.fileFormat = toCopy.fileFormat; + this.fileSizeInBytes = toCopy.fileSizeInBytes; + this.keyMetadata = + toCopy.keyMetadata != null + ? Arrays.copyOf(toCopy.keyMetadata, toCopy.keyMetadata.length) + : null; + } + + /** Constructor for Java serialization. */ + ColumnFileStruct() { + super(BASE_TYPE.fields().size()); + } + + @Override + public String location() { + return location; + } + + @Override + public List<Integer> fieldIds() { + return fieldIds != null ? ArrayUtil.toUnmodifiableIntList(fieldIds) : null; + } + + @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 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 -> location; + case 1 -> fieldIds(); + case 2 -> fileFormat != null ? fileFormat.toString() : null; + case 3 -> fileSizeInBytes; + case 4 -> keyMetadata(); + default -> throw new UnsupportedOperationException("Unknown field ordinal: " + pos); + }; + } + + @Override + @SuppressWarnings("unchecked") + protected <T> void internalSet(int pos, T value) { + switch (pos) { + // always coerce to String for Serializable + case 0 -> this.location = value.toString(); Review Comment: I wanted to make this consistent with the same in `TrackedFileStruct` and `DeletionVectorStruct`. -- 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]
