Repository navigation
Core: Basic fields and schemas for column files #16285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * 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.Set; | ||
| import org.apache.iceberg.types.Types; | ||
|
|
||
| interface ColumnFile { | ||
| Types.NestedField LOCATION = | ||
| Types.NestedField.required( | ||
| 160, "location", Types.StringType.get(), "Location of the column file"); | ||
| Types.NestedField FIELD_IDS = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we keep the field id's here, does that mean we need to update all column file entities whenever we add a new column file? I think that's probably alright but we should probably add some text on that requirement?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, when we add a new column file, we have to remove its field IDs from other column files' field ID lists. I'm not sure we should document it here, this just the storage representation of such a structure. The "deduplication" of field IDs happen on a different level, maybe document this on the API where we add the new column files (non-existing as of now)? |
||
| Types.NestedField.required( | ||
| 161, | ||
| "field_ids", | ||
| Types.ListType.ofRequired(162, Types.IntegerType.get()), | ||
| "Live field IDs in this column file"); | ||
| Types.NestedField FILE_FORMAT = | ||
| Types.NestedField.required( | ||
| 163, | ||
| "file_format", | ||
| Types.StringType.get(), | ||
| "String file format name for this column file"); | ||
| Types.NestedField FILE_SIZE_IN_BYTES = | ||
| Types.NestedField.required( | ||
| 164, "file_size_in_bytes", Types.LongType.get(), "Total column file size in bytes"); | ||
| Types.NestedField KEY_METADATA = | ||
| Types.NestedField.optional( | ||
| 165, | ||
| "key_metadata", | ||
| Types.BinaryType.get(), | ||
| "Key metadata for encryption; specific to the encryption scheme."); | ||
|
|
||
| static Types.StructType schema() { | ||
| return Types.StructType.of(LOCATION, FIELD_IDS, FILE_FORMAT, FILE_SIZE_IN_BYTES, KEY_METADATA); | ||
| } | ||
|
|
||
| /** Returns the location of this column file. */ | ||
| String location(); | ||
|
|
||
| /** Returns the field IDs contained in this column file. */ | ||
| Set<Integer> fieldIds(); | ||
|
|
||
| /** 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(); | ||
|
|
||
| /** Copies this column file. */ | ||
| ColumnFile copy(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| /* | ||
| * 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 java.util.Set; | ||
| import org.apache.iceberg.avro.SupportsIndexProjection; | ||
| import org.apache.iceberg.relocated.com.google.common.base.MoreObjects; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet; | ||
| import org.apache.iceberg.relocated.com.google.common.primitives.Ints; | ||
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side Question: Did we actually formalize the location and naming of column files? I had a offline discussion with @gaborkaszab and it's not specified on purpose. We'll update the doc accordingly.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment in the spec doc
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the comment! |
||
| 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, | ||
| Set<Integer> fieldIds, | ||
| FileFormat fileFormat, | ||
| long fileSizeInBytes, | ||
| ByteBuffer keyMetadata) { | ||
| super(BASE_TYPE.fields().size()); | ||
| this.location = location; | ||
| this.fieldIds = fieldIds != null ? Ints.toArray(fieldIds) : null; | ||
| 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 Set<Integer> fieldIds() { | ||
| return fieldIds != null ? ImmutableSet.copyOf(Ints.asList(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 -> ArrayUtil.toUnmodifiableIntList(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 | ||
|
stevenzwu marked this conversation as resolved.
|
||
| case 0 -> this.location = value.toString(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the location always non-null here? I think we could also just cast directly to a string?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to make this consistent with the same in |
||
| case 1 -> this.fieldIds = ArrayUtil.toIntArray((List<Integer>) value); | ||
| case 2 -> this.fileFormat = FileFormat.fromString(value.toString()); | ||
| case 3 -> this.fileSizeInBytes = (long) value; | ||
| case 4 -> this.keyMetadata = ByteBuffers.toByteArray((ByteBuffer) value); | ||
| default -> { | ||
| // ignore the object, it must be from a newer version of the format | ||
|
gaborkaszab marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return MoreObjects.toStringHelper(this) | ||
| .add("location", location) | ||
| .add("field_ids", fieldIds) | ||
| .add("file_format", fileFormat) | ||
| .add("file_size_in_bytes", fileSizeInBytes) | ||
| .add("key_metadata", keyMetadata == null ? "null" : "(redacted)") | ||
| .toString(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.