diff --git a/lib/trino-orc/pom.xml b/lib/trino-orc/pom.xml index 386a540ab0ceb..2bafa397fbdd7 100644 --- a/lib/trino-orc/pom.xml +++ b/lib/trino-orc/pom.xml @@ -128,6 +128,12 @@ test + + io.trino + trino-aircompressor-bridge + test + + io.trino trino-main diff --git a/lib/trino-parquet/pom.xml b/lib/trino-parquet/pom.xml index 81a7acc63b855..041403e78fc0b 100644 --- a/lib/trino-parquet/pom.xml +++ b/lib/trino-parquet/pom.xml @@ -131,6 +131,12 @@ test + + io.trino + trino-aircompressor-bridge + test + + io.trino trino-main diff --git a/plugin/trino-hive/pom.xml b/plugin/trino-hive/pom.xml index 2463ffdf80705..6c76d0044c88a 100644 --- a/plugin/trino-hive/pom.xml +++ b/plugin/trino-hive/pom.xml @@ -421,6 +421,12 @@ test + + io.trino + trino-aircompressor-bridge + test + + io.trino trino-exchange-filesystem diff --git a/plugin/trino-iceberg/pom.xml b/plugin/trino-iceberg/pom.xml index 13d73910435df..3f6326d07e8b5 100644 --- a/plugin/trino-iceberg/pom.xml +++ b/plugin/trino-iceberg/pom.xml @@ -60,6 +60,11 @@ failsafe + + io.airlift + aircompressor + + io.airlift bootstrap diff --git a/plugin/trino-iceberg/src/main/java/io/airlift/compress/Compressor.java b/plugin/trino-iceberg/src/main/java/io/airlift/compress/Compressor.java new file mode 100644 index 0000000000000..9719dbad45b23 --- /dev/null +++ b/plugin/trino-iceberg/src/main/java/io/airlift/compress/Compressor.java @@ -0,0 +1,28 @@ +/* + * Licensed 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 io.airlift.compress; + +import java.nio.ByteBuffer; + +public interface Compressor +{ + int maxCompressedLength(int uncompressedSize); + + /** + * @return number of bytes written to the output + */ + int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength); + + void compress(ByteBuffer input, ByteBuffer output); +} diff --git a/plugin/trino-iceberg/src/main/java/io/airlift/compress/Decompressor.java b/plugin/trino-iceberg/src/main/java/io/airlift/compress/Decompressor.java new file mode 100644 index 0000000000000..6cf290cc82d88 --- /dev/null +++ b/plugin/trino-iceberg/src/main/java/io/airlift/compress/Decompressor.java @@ -0,0 +1,28 @@ +/* + * Licensed 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 io.airlift.compress; + +import java.nio.ByteBuffer; + +public interface Decompressor +{ + /** + * @return number of bytes written to the output + */ + int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + throws MalformedInputException; + + void decompress(ByteBuffer input, ByteBuffer output) + throws MalformedInputException; +} diff --git a/plugin/trino-iceberg/src/main/java/io/airlift/compress/MalformedInputException.java b/plugin/trino-iceberg/src/main/java/io/airlift/compress/MalformedInputException.java new file mode 100644 index 0000000000000..eb487a39f44a1 --- /dev/null +++ b/plugin/trino-iceberg/src/main/java/io/airlift/compress/MalformedInputException.java @@ -0,0 +1,36 @@ +/* + * Licensed 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 io.airlift.compress; + +public class MalformedInputException + extends RuntimeException +{ + private final long offset; + + public MalformedInputException(long offset) + { + this(offset, "Malformed input"); + } + + public MalformedInputException(long offset, String reason) + { + super(reason + ": offset=" + offset); + this.offset = offset; + } + + public long getOffset() + { + return offset; + } +} diff --git a/plugin/trino-iceberg/src/main/java/io/airlift/compress/zstd/ZstdCompressor.java b/plugin/trino-iceberg/src/main/java/io/airlift/compress/zstd/ZstdCompressor.java new file mode 100644 index 0000000000000..a99ce4ffafa91 --- /dev/null +++ b/plugin/trino-iceberg/src/main/java/io/airlift/compress/zstd/ZstdCompressor.java @@ -0,0 +1,57 @@ +/* + * Licensed 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 io.airlift.compress.zstd; + +import io.airlift.compress.Compressor; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class ZstdCompressor + implements Compressor +{ + private final io.airlift.compress.v2.zstd.ZstdCompressor compressor; + + public ZstdCompressor() + { + this.compressor = io.airlift.compress.v2.zstd.ZstdCompressor.create(); + } + + @Override + public int maxCompressedLength(int uncompressedSize) + { + return compressor.maxCompressedLength(uncompressedSize); + } + + @Override + public int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(compressor.compress(inputSegment, outputSegment)); + } + + @Override + public void compress(ByteBuffer input, ByteBuffer output) + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = compressor.compress(inputSegment, outputSegment); + output.position(output.position() + written); + } +} diff --git a/plugin/trino-iceberg/src/main/java/io/airlift/compress/zstd/ZstdDecompressor.java b/plugin/trino-iceberg/src/main/java/io/airlift/compress/zstd/ZstdDecompressor.java new file mode 100644 index 0000000000000..e1d0420bfe19c --- /dev/null +++ b/plugin/trino-iceberg/src/main/java/io/airlift/compress/zstd/ZstdDecompressor.java @@ -0,0 +1,59 @@ +/* + * Licensed 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 io.airlift.compress.zstd; + +import io.airlift.compress.Decompressor; +import io.airlift.compress.MalformedInputException; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class ZstdDecompressor + implements Decompressor +{ + private final io.airlift.compress.v2.zstd.ZstdDecompressor decompressor; + + public ZstdDecompressor() + { + this.decompressor = io.airlift.compress.v2.zstd.ZstdDecompressor.create(); + } + + @Override + public int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(decompressor.decompress(inputSegment, outputSegment)); + } + + @Override + public void decompress(ByteBuffer input, ByteBuffer output) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = decompressor.decompress(inputSegment, outputSegment); + output.position(output.position() + written); + } + + public static long getDecompressedSize(byte[] input, int offset, int length) + { + return io.airlift.compress.v2.zstd.ZstdDecompressor.create().getDecompressedSize(input, offset, length); + } +} diff --git a/pom.xml b/pom.xml index edd543afd987f..fd7fec793f297 100644 --- a/pom.xml +++ b/pom.xml @@ -118,6 +118,7 @@ plugin/trino-tpch service/trino-proxy service/trino-verifier + testing/trino-aircompressor-bridge testing/trino-benchmark-queries testing/trino-benchto-benchmarks testing/trino-faulttolerant-tests @@ -953,6 +954,12 @@ ${dep.swagger.version} + + io.trino + trino-aircompressor-bridge + ${project.version} + + io.trino trino-array diff --git a/testing/trino-aircompressor-bridge/pom.xml b/testing/trino-aircompressor-bridge/pom.xml new file mode 100644 index 0000000000000..203ec7d2de265 --- /dev/null +++ b/testing/trino-aircompressor-bridge/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + io.trino + trino-root + 454-SNAPSHOT + ../../pom.xml + + + trino-aircompressor-bridge + Trino - Aircompressor v1 to v2 bridge + + + true + + + + + + io.airlift + aircompressor + + + + io.trino.hadoop + hadoop-apache + provided + + + + io.airlift + junit-extensions + test + + + + org.assertj + assertj-core + test + + + + org.junit.jupiter + junit-jupiter-api + test + + + + org.junit.jupiter + junit-jupiter-engine + test + + + diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/Compressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/Compressor.java new file mode 100644 index 0000000000000..9719dbad45b23 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/Compressor.java @@ -0,0 +1,28 @@ +/* + * Licensed 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 io.airlift.compress; + +import java.nio.ByteBuffer; + +public interface Compressor +{ + int maxCompressedLength(int uncompressedSize); + + /** + * @return number of bytes written to the output + */ + int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength); + + void compress(ByteBuffer input, ByteBuffer output); +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/Decompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/Decompressor.java new file mode 100644 index 0000000000000..6cf290cc82d88 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/Decompressor.java @@ -0,0 +1,28 @@ +/* + * Licensed 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 io.airlift.compress; + +import java.nio.ByteBuffer; + +public interface Decompressor +{ + /** + * @return number of bytes written to the output + */ + int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + throws MalformedInputException; + + void decompress(ByteBuffer input, ByteBuffer output) + throws MalformedInputException; +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/MalformedInputException.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/MalformedInputException.java new file mode 100644 index 0000000000000..eb487a39f44a1 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/MalformedInputException.java @@ -0,0 +1,36 @@ +/* + * Licensed 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 io.airlift.compress; + +public class MalformedInputException + extends RuntimeException +{ + private final long offset; + + public MalformedInputException(long offset) + { + this(offset, "Malformed input"); + } + + public MalformedInputException(long offset, String reason) + { + super(reason + ": offset=" + offset); + this.offset = offset; + } + + public long getOffset() + { + return offset; + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/bzip2/BZip2Codec.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/bzip2/BZip2Codec.java new file mode 100644 index 0000000000000..662084e80cab4 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/bzip2/BZip2Codec.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.bzip2; + +public class BZip2Codec + extends io.airlift.compress.v2.bzip2.BZip2Codec +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/deflate/JdkDeflateCodec.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/deflate/JdkDeflateCodec.java new file mode 100644 index 0000000000000..b582cb2fd06f2 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/deflate/JdkDeflateCodec.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.deflate; + +public class JdkDeflateCodec + extends io.airlift.compress.v2.deflate.JdkDeflateCodec +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/gzip/JdkGzipCodec.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/gzip/JdkGzipCodec.java new file mode 100644 index 0000000000000..c76229003bc12 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/gzip/JdkGzipCodec.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.gzip; + +public class JdkGzipCodec + extends io.airlift.compress.v2.gzip.JdkGzipCodec +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/hadoop/HadoopStreams.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/hadoop/HadoopStreams.java new file mode 100644 index 0000000000000..84f1aad74bbad --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/hadoop/HadoopStreams.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.hadoop; + +public interface HadoopStreams + extends io.airlift.compress.v2.hadoop.HadoopStreams +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Codec.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Codec.java new file mode 100644 index 0000000000000..c1ed17ceffa2c --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Codec.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.lz4; + +public class Lz4Codec + extends io.airlift.compress.v2.lz4.Lz4Codec +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Compressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Compressor.java new file mode 100644 index 0000000000000..966e610461827 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Compressor.java @@ -0,0 +1,57 @@ +/* + * Licensed 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 io.airlift.compress.lz4; + +import io.airlift.compress.Compressor; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class Lz4Compressor + implements Compressor +{ + private final io.airlift.compress.v2.lz4.Lz4Compressor compressor; + + public Lz4Compressor() + { + this.compressor = io.airlift.compress.v2.lz4.Lz4Compressor.create(); + } + + @Override + public int maxCompressedLength(int uncompressedSize) + { + return compressor.maxCompressedLength(uncompressedSize); + } + + @Override + public int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(compressor.compress(inputSegment, outputSegment)); + } + + @Override + public void compress(ByteBuffer input, ByteBuffer output) + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = compressor.compress(inputSegment, outputSegment); + output.position(output.position() + written); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Decompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Decompressor.java new file mode 100644 index 0000000000000..32a724e15d14a --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4Decompressor.java @@ -0,0 +1,54 @@ +/* + * Licensed 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 io.airlift.compress.lz4; + +import io.airlift.compress.Decompressor; +import io.airlift.compress.MalformedInputException; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class Lz4Decompressor + implements Decompressor +{ + private final io.airlift.compress.v2.lz4.Lz4Decompressor decompressor; + + public Lz4Decompressor() + { + this.decompressor = io.airlift.compress.v2.lz4.Lz4Decompressor.create(); + } + + @Override + public int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(decompressor.decompress(inputSegment, outputSegment)); + } + + @Override + public void decompress(ByteBuffer input, ByteBuffer output) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = decompressor.decompress(inputSegment, outputSegment); + output.position(output.position() + written); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4RawCompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4RawCompressor.java new file mode 100644 index 0000000000000..6d955743c46e7 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lz4/Lz4RawCompressor.java @@ -0,0 +1,28 @@ +/* + * Licensed 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 io.airlift.compress.lz4; + +public class Lz4RawCompressor +{ + private static final int HASH_LOG = 12; + + public static final int MAX_TABLE_SIZE = (1 << HASH_LOG); + + private Lz4RawCompressor() {} + + public static int maxCompressedLength(int sourceLength) + { + return sourceLength + sourceLength / 255 + 16; + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoCodec.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoCodec.java new file mode 100644 index 0000000000000..d25b15ae6fdce --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoCodec.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.lzo; + +public class LzoCodec + extends io.airlift.compress.v2.lzo.LzoCodec +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoCompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoCompressor.java new file mode 100644 index 0000000000000..4628193512369 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoCompressor.java @@ -0,0 +1,57 @@ +/* + * Licensed 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 io.airlift.compress.lzo; + +import io.airlift.compress.Compressor; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class LzoCompressor + implements Compressor +{ + private final io.airlift.compress.v2.lzo.LzoCompressor compressor; + + public LzoCompressor() + { + this.compressor = new io.airlift.compress.v2.lzo.LzoCompressor(); + } + + @Override + public int maxCompressedLength(int uncompressedSize) + { + return compressor.maxCompressedLength(uncompressedSize); + } + + @Override + public int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(compressor.compress(inputSegment, outputSegment)); + } + + @Override + public void compress(ByteBuffer input, ByteBuffer output) + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = compressor.compress(inputSegment, outputSegment); + output.position(output.position() + written); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoDecompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoDecompressor.java new file mode 100644 index 0000000000000..1ead9de7e6c15 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzoDecompressor.java @@ -0,0 +1,54 @@ +/* + * Licensed 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 io.airlift.compress.lzo; + +import io.airlift.compress.Decompressor; +import io.airlift.compress.MalformedInputException; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class LzoDecompressor + implements Decompressor +{ + private final io.airlift.compress.v2.lzo.LzoDecompressor decompressor; + + public LzoDecompressor() + { + this.decompressor = new io.airlift.compress.v2.lzo.LzoDecompressor(); + } + + @Override + public int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(decompressor.decompress(inputSegment, outputSegment)); + } + + @Override + public void decompress(ByteBuffer input, ByteBuffer output) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = decompressor.decompress(inputSegment, outputSegment); + output.position(output.position() + written); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzopCodec.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzopCodec.java new file mode 100644 index 0000000000000..2d74d40fd3fb3 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/lzo/LzopCodec.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.lzo; + +public class LzopCodec + extends io.airlift.compress.v2.lzo.LzopCodec +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyCodec.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyCodec.java new file mode 100644 index 0000000000000..73095e50c8f67 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyCodec.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.snappy; + +public class SnappyCodec + extends io.airlift.compress.v2.snappy.SnappyCodec +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyCompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyCompressor.java new file mode 100644 index 0000000000000..6e5f7b0f4b3ef --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyCompressor.java @@ -0,0 +1,57 @@ +/* + * Licensed 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 io.airlift.compress.snappy; + +import io.airlift.compress.Compressor; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class SnappyCompressor + implements Compressor +{ + private final io.airlift.compress.v2.snappy.SnappyCompressor compressor; + + public SnappyCompressor() + { + this.compressor = io.airlift.compress.v2.snappy.SnappyCompressor.create(); + } + + @Override + public int maxCompressedLength(int uncompressedSize) + { + return compressor.maxCompressedLength(uncompressedSize); + } + + @Override + public int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(compressor.compress(inputSegment, outputSegment)); + } + + @Override + public void compress(ByteBuffer input, ByteBuffer output) + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = compressor.compress(inputSegment, outputSegment); + output.position(output.position() + written); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyDecompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyDecompressor.java new file mode 100644 index 0000000000000..8749cd40bbce1 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/snappy/SnappyDecompressor.java @@ -0,0 +1,58 @@ +/* + * Licensed 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 io.airlift.compress.snappy; + +import io.airlift.compress.Decompressor; +import io.airlift.compress.MalformedInputException; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class SnappyDecompressor + implements Decompressor +{ + private final io.airlift.compress.v2.snappy.SnappyDecompressor decompressor; + + public SnappyDecompressor() + { + this.decompressor = io.airlift.compress.v2.snappy.SnappyDecompressor.create(); + } + + @Override + public int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + return toIntExact(decompressor.decompress(inputSegment, outputSegment)); + } + + @Override + public void decompress(ByteBuffer input, ByteBuffer output) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = decompressor.decompress(inputSegment, outputSegment); + output.position(output.position() + written); + } + + public static int getUncompressedLength(byte[] input, int offset) + { + return io.airlift.compress.v2.snappy.SnappyDecompressor.create().getUncompressedLength(input, offset); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdCodec.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdCodec.java new file mode 100644 index 0000000000000..38a79e2165657 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdCodec.java @@ -0,0 +1,19 @@ +/* + * Licensed 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 io.airlift.compress.zstd; + +public class ZstdCodec + extends io.airlift.compress.v2.zstd.ZstdCodec +{ +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdCompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdCompressor.java new file mode 100644 index 0000000000000..a99ce4ffafa91 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdCompressor.java @@ -0,0 +1,57 @@ +/* + * Licensed 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 io.airlift.compress.zstd; + +import io.airlift.compress.Compressor; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class ZstdCompressor + implements Compressor +{ + private final io.airlift.compress.v2.zstd.ZstdCompressor compressor; + + public ZstdCompressor() + { + this.compressor = io.airlift.compress.v2.zstd.ZstdCompressor.create(); + } + + @Override + public int maxCompressedLength(int uncompressedSize) + { + return compressor.maxCompressedLength(uncompressedSize); + } + + @Override + public int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(compressor.compress(inputSegment, outputSegment)); + } + + @Override + public void compress(ByteBuffer input, ByteBuffer output) + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = compressor.compress(inputSegment, outputSegment); + output.position(output.position() + written); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdDecompressor.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdDecompressor.java new file mode 100644 index 0000000000000..e1d0420bfe19c --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdDecompressor.java @@ -0,0 +1,59 @@ +/* + * Licensed 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 io.airlift.compress.zstd; + +import io.airlift.compress.Decompressor; +import io.airlift.compress.MalformedInputException; + +import java.lang.foreign.MemorySegment; +import java.nio.ByteBuffer; + +import static java.lang.Math.toIntExact; + +public class ZstdDecompressor + implements Decompressor +{ + private final io.airlift.compress.v2.zstd.ZstdDecompressor decompressor; + + public ZstdDecompressor() + { + this.decompressor = io.airlift.compress.v2.zstd.ZstdDecompressor.create(); + } + + @Override + public int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofArray(input).asSlice(inputOffset, inputLength); + MemorySegment outputSegment = MemorySegment.ofArray(output).asSlice(outputOffset, maxOutputLength); + + return toIntExact(decompressor.decompress(inputSegment, outputSegment)); + } + + @Override + public void decompress(ByteBuffer input, ByteBuffer output) + throws MalformedInputException + { + MemorySegment inputSegment = MemorySegment.ofBuffer(input); + MemorySegment outputSegment = MemorySegment.ofBuffer(output); + + int written = decompressor.decompress(inputSegment, outputSegment); + output.position(output.position() + written); + } + + public static long getDecompressedSize(byte[] input, int offset, int length) + { + return io.airlift.compress.v2.zstd.ZstdDecompressor.create().getDecompressedSize(input, offset, length); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdInputStream.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdInputStream.java new file mode 100644 index 0000000000000..8bd08cbc201ba --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdInputStream.java @@ -0,0 +1,25 @@ +/* + * Licensed 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 io.airlift.compress.zstd; + +import java.io.InputStream; + +public class ZstdInputStream + extends io.airlift.compress.v2.zstd.ZstdInputStream +{ + public ZstdInputStream(InputStream inputStream) + { + super(inputStream); + } +} diff --git a/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdOutputStream.java b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdOutputStream.java new file mode 100644 index 0000000000000..e7d6ffba3158f --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/main/java/io/airlift/compress/zstd/ZstdOutputStream.java @@ -0,0 +1,27 @@ +/* + * Licensed 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 io.airlift.compress.zstd; + +import java.io.IOException; +import java.io.OutputStream; + +public class ZstdOutputStream + extends io.airlift.compress.v2.zstd.ZstdOutputStream +{ + public ZstdOutputStream(OutputStream outputStream) + throws IOException + { + super(outputStream); + } +} diff --git a/testing/trino-aircompressor-bridge/src/test/java/io/airlift/compress/TestDummy.java b/testing/trino-aircompressor-bridge/src/test/java/io/airlift/compress/TestDummy.java new file mode 100644 index 0000000000000..3aa409a89b269 --- /dev/null +++ b/testing/trino-aircompressor-bridge/src/test/java/io/airlift/compress/TestDummy.java @@ -0,0 +1,22 @@ +/* + * Licensed 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 io.airlift.compress; + +import org.junit.jupiter.api.Test; + +public class TestDummy +{ + @Test + public void buildRequiresTestToExist() {} +}