Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ project(':iceberg-core') {
exclude group: 'org.tukaani' // xz compression is not supported
}

implementation 'io.airlift:aircompressor'
implementation 'org.apache.httpcomponents.client5:httpclient5'
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.core:jackson-core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.google.common.hash.Hashing;
import com.google.common.io.CountingOutputStream;
import com.google.common.io.Files;
import com.google.common.io.Resources;
import com.google.common.primitives.Bytes;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class GuavaClasses {
Hashing.class.getName();
Files.class.getName();
Bytes.class.getName();
Resources.class.getName();
MoreExecutors.class.getName();
ThreadFactoryBuilder.class.getName();
Iterables.class.getName();
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/org/apache/iceberg/io/IOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than allocating every time this is called, can you create a ThreadLocal to share this buffer? Alternatively, you could pass the temporary buffer in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could pass the temporary buffer in.

This poses sizing challenge. I.e. the caller needs to provide a reasonably sized buffer.

Rather than allocating every time this is called, can you create a ThreadLocal to share this 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.
(assuming we have a problem that we want to fix here)

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.
Expand Down
75 changes: 75 additions & 0 deletions core/src/main/java/org/apache/iceberg/puffin/Blob.java
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;
}
}
81 changes: 81 additions & 0 deletions core/src/main/java/org/apache/iceberg/puffin/BlobMetadata.java
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 List<Long>?

Copy link
Member Author

Choose a reason for hiding this comment

The 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 fields | list of JSON long in the puffin spec to be list of integers.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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;
}
}
46 changes: 46 additions & 0 deletions core/src/main/java/org/apache/iceberg/puffin/FileMetadata.java
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;
}
}
Loading