-
Notifications
You must be signed in to change notification settings - Fork 3k
Add reader and writer for Puffin, indexes and stats file format #4537
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
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 |
|---|---|---|
|
|
@@ -22,12 +22,16 @@ | |
| import java.io.EOFException; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.nio.ByteBuffer; | ||
|
|
||
| public class IOUtil { | ||
| // not meant to be instantiated | ||
| private IOUtil() { | ||
| } | ||
|
|
||
| private static final int WRITE_CHUNK_SIZE = 8192; | ||
|
|
||
| /** | ||
| * Reads into a buffer from a stream, making multiple read calls if necessary. | ||
| * | ||
|
|
@@ -46,6 +50,21 @@ public static void readFully(InputStream stream, byte[] bytes, int offset, int l | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Writes a buffer into a stream, making multiple write calls if necessary. | ||
| */ | ||
| public static void writeFully(OutputStream outputStream, ByteBuffer buffer) throws IOException { | ||
| if (!buffer.hasRemaining()) { | ||
| return; | ||
| } | ||
| byte[] chunk = new byte[WRITE_CHUNK_SIZE]; | ||
|
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. Rather than allocating every time this is called, can you create a
Member
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.
This poses sizing challenge. I.e. the caller needs to provide a reasonably sized buffer.
Sure, this is feasible. Do you happen to know what would be the expected reuse ratio for such a buffer? Alternatively we can have a static buffer pool that lends buffers to the current thread. |
||
| while (buffer.hasRemaining()) { | ||
| int chunkSize = Math.min(chunk.length, buffer.remaining()); | ||
| buffer.get(chunk, 0, chunkSize); | ||
| outputStream.write(chunk, 0, chunkSize); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Reads into a buffer from a stream, making multiple read calls if necessary | ||
| * returning the number of bytes read until end of stream. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * 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.puffin; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
|
|
||
| public final class Blob { | ||
| private final String type; | ||
| private final List<Integer> inputFields; | ||
| private final ByteBuffer blobData; | ||
| private final PuffinCompressionCodec requestedCompression; | ||
| private final Map<String, String> properties; | ||
|
|
||
| public Blob(String type, List<Integer> inputFields, ByteBuffer blobData) { | ||
| this(type, inputFields, blobData, null, ImmutableMap.of()); | ||
| } | ||
|
|
||
| public Blob( | ||
| String type, List<Integer> inputFields, ByteBuffer blobData, | ||
| @Nullable PuffinCompressionCodec requestedCompression, Map<String, String> properties) { | ||
| Preconditions.checkNotNull(type, "type is null"); | ||
| Preconditions.checkNotNull(inputFields, "inputFields is null"); | ||
| Preconditions.checkNotNull(blobData, "blobData is null"); | ||
| Preconditions.checkNotNull(properties, "properties is null"); | ||
| this.type = type; | ||
| this.inputFields = ImmutableList.copyOf(inputFields); | ||
| this.blobData = blobData; | ||
| this.requestedCompression = requestedCompression; | ||
| this.properties = ImmutableMap.copyOf(properties); | ||
| } | ||
|
|
||
| public String type() { | ||
| return type; | ||
| } | ||
|
|
||
| public List<Integer> inputFields() { | ||
| return inputFields; | ||
| } | ||
|
|
||
| public ByteBuffer blobData() { | ||
| return blobData; | ||
| } | ||
|
|
||
| @Nullable | ||
| public PuffinCompressionCodec requestedCompression() { | ||
| return requestedCompression; | ||
| } | ||
|
|
||
| public Map<String, String> properties() { | ||
| return properties; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * 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.puffin; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
|
|
||
| public class BlobMetadata { | ||
| private final String type; | ||
| private final List<Integer> inputFields; | ||
| private final long offset; | ||
| private final long length; | ||
| private final String compressionCodec; | ||
| private final Map<String, String> properties; | ||
|
|
||
| public BlobMetadata( | ||
| String type, List<Integer> inputFields, long offset, long length, | ||
| @Nullable String compressionCodec, Map<String, String> properties) { | ||
| Preconditions.checkNotNull(type, "type is null"); | ||
| Preconditions.checkNotNull(inputFields, "inputFields is null"); | ||
| Preconditions.checkNotNull(properties, "properties is null"); | ||
| this.type = type; | ||
| this.inputFields = ImmutableList.copyOf(inputFields); | ||
| this.offset = offset; | ||
| this.length = length; | ||
| this.compressionCodec = compressionCodec; | ||
| this.properties = ImmutableMap.copyOf(properties); | ||
| } | ||
|
|
||
| public String type() { | ||
| return type; | ||
| } | ||
|
|
||
| public List<Integer> inputFields() { | ||
|
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. the spec mentions that input fields are JSON longs, so I'm just wondering whether this should be a
Member
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. Iceberg field IDs are integers, so the implementation is chosen to be limited to integers. We can maybe change
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. Yes, we should update the spec to match the type used by the table spec for field IDs.
Member
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. |
||
| return inputFields; | ||
| } | ||
|
|
||
| /** | ||
| * Offset in the file | ||
| */ | ||
| public long offset() { | ||
| return offset; | ||
| } | ||
|
|
||
| /** | ||
| * Length in the file | ||
| */ | ||
| public long length() { | ||
| return length; | ||
| } | ||
|
|
||
| @Nullable | ||
| public String compressionCodec() { | ||
| return compressionCodec; | ||
| } | ||
|
|
||
| public Map<String, String> properties() { | ||
| return properties; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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.puffin; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
|
|
||
| public class FileMetadata { | ||
| private final List<BlobMetadata> blobs; | ||
| private final Map<String, String> properties; | ||
|
|
||
| public FileMetadata(List<BlobMetadata> blobs, Map<String, String> properties) { | ||
| Preconditions.checkNotNull(blobs, "blobs is null"); | ||
| Preconditions.checkNotNull(properties, "properties is null"); | ||
| this.blobs = ImmutableList.copyOf(blobs); | ||
| this.properties = ImmutableMap.copyOf(properties); | ||
| } | ||
|
|
||
| public List<BlobMetadata> blobs() { | ||
| return blobs; | ||
| } | ||
|
|
||
| public Map<String, String> properties() { | ||
| return properties; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.