You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "jbewing (via GitHub)" <gi...@apache.org> on 2026/02/19 05:01:44 UTC
[PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
jbewing opened a new pull request, #15362:
URL: https://github.com/apache/iceberg/pull/15362
### What
This PR adds vectorized read support to Iceberg for the Apache Parquet v2 specification (see https://github.com/apache/iceberg/issues/7162). This builds on top of the existing support for reading [DELTA_BINARY_PACKED](https://parquet.apache.org/docs/file-format/data-pages/encodings/#delta-encoding-delta_binary_packed--5) implemented by @eric-maynard in https://github.com/apache/iceberg/pull/13391 with:
- Building upon @eric-maynard 's support for [DELTA_LENGTH_BYTE_ARRAY encoding](https://parquet.apache.org/docs/file-format/data-pages/encodings/#delta-length-byte-array-delta_length_byte_array--6) in https://github.com/apache/iceberg/pull/13709
* I made a couple of changes to that implementation around using temporary on-heap buffers rather than off-heap buffers as while it's possible to use temporary off-heap buffers, the plumbing required is significant and I wasn't able to get things totally resolved with that path working as there was a remaining subtle bug around leaked off-heap buffers & correctness
- Implementing vectorized read support for [DELTA_BYTE_ARRAY encoding](https://parquet.apache.org/docs/file-format/data-pages/encodings/#delta-strings-delta_byte_array--7)
- Bolstering golden files test coverage to cover each of the paths above. In addition, I added golden file tests that include rows with null values for each data type as well to ensure our handling of those is correct
### Background
This solves a longstanding issue of: the reference Apache Iceberg Spark implementation with the default settings enabled (e.g. `spark.sql.iceberg.vectorization.enabled` = `true`) isn't able to read iceberg tables that may have been written by other compute engines that utilize the not so new anymore Apache Parquet v2 writer specification. It's a widely known workaround to need to disable the vectorized reader in Spark if you need to interop with other compute engines or adjust all compute engines to use the Apache Parquet v1 writer specification when writing parquet files. With disabling the vectorization flag, clients take a performance hit that we've anecdotally measured is _quite_ large in some cases/workloads. If forcing all writers of an iceberg table to write in Apache Parquet v1 format, clients are incurring additional performance and storage penalties (files written with parquet v2 tend to be smaller than those written with the v1 spec as the new encodings tend to save spa
ce and are often faster to read/write). So really, it's a lose-lose for performance & data size in the current setup with the additional papercut of Apache Iceberg not being super portable across engines in it's default setup. This PR seeks to solve that by finishing the swing on implementing vectorized parquet read support for the v2 format. In the future, we may also consider allowing clients to write Apache Parquet v2 files natively gated via a setting from Apache Iceberg. Even longer down that road, we may even consider changing that to be the "default" setting.
### Previous Work / Thanks
This PR is a revival + extension to the work that @eric-maynard was doing in https://github.com/apache/iceberg/pull/13709. That PR had been active for a little while, so I literally started from where Eric left off. Thank you for the great work here @eric-maynard, you made implementing the rest of the changes required for vectorized read support _way_ easier!
### Note to Reviewers
This is the `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` bits of https://github.com/apache/iceberg/pull/14800 broken off at the request of @nastra.
### Testing
I've tested this on a fork of Spark 3.5 & Iceberg 1.10.0 and verified that a Spark job is able to read a table written with Parquet V2 writer without issues.
Successor to: https://github.com/apache/iceberg/pull/13290, https://github.com/apache/iceberg/pull/13391, https://github.com/apache/iceberg/pull/13709, https://github.com/apache/iceberg/pull/14800
Issue: https://github.com/apache/iceberg/issues/7162
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828397901
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_BYTE_ARRAY encoding. This encoding
+ * stores delta-encoded prefix lengths followed by suffixes encoded as DELTA_LENGTH_BYTE_ARRAY. Each
+ * value is reconstructed by taking the prefix of the previous value and appending the suffix. This
+ * is adapted from Spark's VectorizedDeltaByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-strings-delta_byte_array--7">
+ * Parquet format encodings: DELTA_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private int[] prefixLengths;
+ private VectorizedDeltaLengthByteArrayValuesReader suffixReader;
+ private Binary previous = Binary.EMPTY;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader prefixLengthReader =
+ new VectorizedDeltaEncodedValuesReader();
+ prefixLengthReader.initFromPage(valueCount, in);
+ this.prefixLengths = prefixLengthReader.readIntegers(prefixLengthReader.totalValueCount(), 0);
+ this.suffixReader = new VectorizedDeltaLengthByteArrayValuesReader();
+ this.suffixReader.initFromPage(valueCount, in);
+ }
+
+ @Override
+ public int readInteger() {
+ return prefixLengths[currentRow] + suffixReader.lengthForCurrentRow();
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ Binary suffix = suffixReader.readBinary(len);
+ int prefixLength = prefixLengths[currentRow];
+ this.currentRow++;
+
+ if (prefixLength == 0) {
+ this.previous = suffix;
+ return suffix;
+ }
+
+ byte[] prefixBytes = previous.getBytes();
+ byte[] suffixBytes = suffix.getBytes();
+ byte[] out = new byte[prefixLength + suffixBytes.length];
+ System.arraycopy(prefixBytes, 0, out, 0, prefixLength);
+ System.arraycopy(suffixBytes, 0, out, prefixLength, suffixBytes.length);
+ this.previous = Binary.fromConstantByteArray(out);
+ return this.previous;
+ }
+
+ @Override
+ public boolean readBoolean() {
+ throw new UnsupportedOperationException("readBoolean is not supported");
+ }
+
+ @Override
+ public byte readByte() {
+ throw new UnsupportedOperationException("readByte is not supported");
+ }
+
+ @Override
+ public short readShort() {
+ throw new UnsupportedOperationException("readShort is not supported");
+ }
+
+ @Override
+ public long readLong() {
+ throw new UnsupportedOperationException("readLong is not supported");
+ }
+
+ @Override
+ public float readFloat() {
+ throw new UnsupportedOperationException("readFloat is not supported");
+ }
+
+ @Override
+ public double readDouble() {
+ throw new UnsupportedOperationException("readDouble is not supported");
+ }
+
+ @Override
+ public void readIntegers(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readIntegers is not supported");
+ }
+
+ @Override
+ public void readLongs(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readLongs is not supported");
+ }
+
+ @Override
+ public void readFloats(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readFloats is not supported");
+ }
+
+ @Override
+ public void readDoubles(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readDoubles is not supported");
+ }
Review Comment:
```suggestion
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "singhpk234 (via GitHub)" <gi...@apache.org>.
singhpk234 commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2834298282
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaByteArrayValuesReader.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_BYTE_ARRAY encoding. This encoding
+ * stores delta-encoded prefix lengths followed by suffixes encoded as DELTA_LENGTH_BYTE_ARRAY. Each
+ * value is reconstructed by taking the prefix of the previous value and appending the suffix. This
+ * is adapted from Spark's VectorizedDeltaByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-strings-delta_byte_array--7">
+ * Parquet format encodings: DELTA_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private int[] prefixLengths;
+ private VectorizedDeltaLengthByteArrayValuesReader suffixReader;
+ private Binary previous = Binary.EMPTY;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader prefixLengthReader =
+ new VectorizedDeltaEncodedValuesReader();
+ prefixLengthReader.initFromPage(valueCount, in);
+ this.prefixLengths = prefixLengthReader.readIntegers(prefixLengthReader.totalValueCount(), 0);
+ this.suffixReader = new VectorizedDeltaLengthByteArrayValuesReader();
+ this.suffixReader.initFromPage(valueCount, in);
+ }
+
+ @Override
+ public int readInteger() {
+ return prefixLengths[currentRow] + suffixReader.lengthForCurrentRow();
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ int prefixLength = prefixLengths[currentRow];
+ Binary suffix = suffixReader.readBinary(len - prefixLength);
+ this.currentRow++;
+
+ if (prefixLength == 0) {
+ this.previous = suffix;
+ return suffix;
+ }
+
+ byte[] prefixBytes = previous.getBytes();
+ byte[] suffixBytes = suffix.getBytes();
+ byte[] out = new byte[prefixLength + suffixBytes.length];
+ System.arraycopy(prefixBytes, 0, out, 0, prefixLength);
+ System.arraycopy(suffixBytes, 0, out, prefixLength, suffixBytes.length);
+ this.previous = Binary.fromConstantByteArray(out);
+ return previous;
+ }
+
+ @Override
+ public void skip() {
Review Comment:
wonder if we should just make the skip() default as `UnsupportedOps` ?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828458795
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_BYTE_ARRAY encoding. This encoding
+ * stores delta-encoded prefix lengths followed by suffixes encoded as DELTA_LENGTH_BYTE_ARRAY. Each
+ * value is reconstructed by taking the prefix of the previous value and appending the suffix. This
+ * is adapted from Spark's VectorizedDeltaByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-strings-delta_byte_array--7">
+ * Parquet format encodings: DELTA_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private int[] prefixLengths;
+ private VectorizedDeltaLengthByteArrayValuesReader suffixReader;
+ private Binary previous = Binary.EMPTY;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader prefixLengthReader =
+ new VectorizedDeltaEncodedValuesReader();
+ prefixLengthReader.initFromPage(valueCount, in);
+ this.prefixLengths = prefixLengthReader.readIntegers(prefixLengthReader.totalValueCount(), 0);
+ this.suffixReader = new VectorizedDeltaLengthByteArrayValuesReader();
+ this.suffixReader.initFromPage(valueCount, in);
+ }
+
+ @Override
+ public int readInteger() {
+ return prefixLengths[currentRow] + suffixReader.lengthForCurrentRow();
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ Binary suffix = suffixReader.readBinary(len);
+ int prefixLength = prefixLengths[currentRow];
Review Comment:
I believe this would then also ensure that the length aligns with `lengths[currentRow]` in the suffix reader that I mentioned in https://github.com/apache/iceberg/pull/15362/changes#r2828014446
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828396815
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_BYTE_ARRAY encoding. This encoding
+ * stores delta-encoded prefix lengths followed by suffixes encoded as DELTA_LENGTH_BYTE_ARRAY. Each
+ * value is reconstructed by taking the prefix of the previous value and appending the suffix. This
+ * is adapted from Spark's VectorizedDeltaByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-strings-delta_byte_array--7">
+ * Parquet format encodings: DELTA_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private int[] prefixLengths;
+ private VectorizedDeltaLengthByteArrayValuesReader suffixReader;
+ private Binary previous = Binary.EMPTY;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader prefixLengthReader =
+ new VectorizedDeltaEncodedValuesReader();
+ prefixLengthReader.initFromPage(valueCount, in);
+ this.prefixLengths = prefixLengthReader.readIntegers(prefixLengthReader.totalValueCount(), 0);
+ this.suffixReader = new VectorizedDeltaLengthByteArrayValuesReader();
+ this.suffixReader.initFromPage(valueCount, in);
+ }
+
+ @Override
+ public int readInteger() {
+ return prefixLengths[currentRow] + suffixReader.lengthForCurrentRow();
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ Binary suffix = suffixReader.readBinary(len);
+ int prefixLength = prefixLengths[currentRow];
+ this.currentRow++;
+
+ if (prefixLength == 0) {
+ this.previous = suffix;
+ return suffix;
+ }
+
+ byte[] prefixBytes = previous.getBytes();
+ byte[] suffixBytes = suffix.getBytes();
+ byte[] out = new byte[prefixLength + suffixBytes.length];
+ System.arraycopy(prefixBytes, 0, out, 0, prefixLength);
+ System.arraycopy(suffixBytes, 0, out, prefixLength, suffixBytes.length);
+ this.previous = Binary.fromConstantByteArray(out);
+ return this.previous;
+ }
+
+ @Override
+ public boolean readBoolean() {
+ throw new UnsupportedOperationException("readBoolean is not supported");
+ }
+
+ @Override
+ public byte readByte() {
+ throw new UnsupportedOperationException("readByte is not supported");
+ }
+
+ @Override
+ public short readShort() {
+ throw new UnsupportedOperationException("readShort is not supported");
+ }
+
+ @Override
+ public long readLong() {
+ throw new UnsupportedOperationException("readLong is not supported");
+ }
+
+ @Override
+ public float readFloat() {
+ throw new UnsupportedOperationException("readFloat is not supported");
+ }
+
+ @Override
+ public double readDouble() {
+ throw new UnsupportedOperationException("readDouble is not supported");
+ }
+
+ @Override
+ public void readIntegers(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readIntegers is not supported");
+ }
+
+ @Override
+ public void readLongs(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readLongs is not supported");
+ }
+
+ @Override
+ public void readFloats(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readFloats is not supported");
+ }
Review Comment:
these can all be removed once we throw the UOE in `VectorizedValuesReader`
```suggestion
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra merged PR #15362:
URL: https://github.com/apache/iceberg/pull/15362
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828321961
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_LENGTH_BYTE_ARRAY encoding. This
+ * encoding stores delta-encoded byte array lengths followed by the concatenated byte array data.
+ * This is adapted from Spark's VectorizedDeltaLengthByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-length-byte-array-delta_length_byte_array--6">
+ * Parquet format encodings: DELTA_LENGTH_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaLengthByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private ByteBufferInputStream dataStream;
+ private int[] lengths;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader lengthReader = new VectorizedDeltaEncodedValuesReader();
+ lengthReader.initFromPage(valueCount, in);
+ this.lengths = lengthReader.readIntegers(lengthReader.totalValueCount(), 0);
+ this.dataStream = in;
+ }
+
+ int lengthForCurrentRow() {
+ return lengths[currentRow];
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ try {
+ ByteBuffer buffer = dataStream.slice(lengths[currentRow]);
+ this.currentRow++;
+ if (buffer.hasArray()) {
+ return Binary.fromConstantByteArray(
+ buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
+ } else {
+ byte[] bytes = new byte[buffer.remaining()];
+ buffer.get(bytes);
+ return Binary.fromConstantByteArray(bytes);
+ }
+ } catch (IOException e) {
+ throw new UncheckedIOException("Failed to read binary data", e);
+ }
+ }
+
+ @Override
+ public int readInteger() {
+ return lengths[currentRow];
+ }
+
+ @Override
+ public boolean readBoolean() {
+ throw new UnsupportedOperationException("readBoolean is not supported");
Review Comment:
I think it's better to remove all of those overrides to only throw an exception and rather do this at the interface level:
```
diff --git a/arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedValuesReader.java b/arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedValuesReader.java
index 7c23149b18..85216dd94a 100644
--- a/arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedValuesReader.java
+++ b/arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedValuesReader.java
@@ -37,44 +37,68 @@ interface VectorizedValuesReader {
int DOUBLE_SIZE = 8;
/** Read a single boolean */
- boolean readBoolean();
+ default boolean readBoolean() {
+ throw new UnsupportedOperationException("readBoolean is not supported");
+ }
/** Read a single byte */
- byte readByte();
+ default byte readByte() {
+ throw new UnsupportedOperationException("readByte is not supported");
+ }
/** Read a single short */
- short readShort();
+ default short readShort() {
+ throw new UnsupportedOperationException("readShort is not supported");
+ }
/** Read a single integer */
- int readInteger();
+ default int readInteger() {
+ throw new UnsupportedOperationException("readInteger is not supported");
+ }
/** Read a single long */
- long readLong();
+ default long readLong() {
+ throw new UnsupportedOperationException("readLong is not supported");
+ }
/** Read a single float */
- float readFloat();
+ default float readFloat() {
+ throw new UnsupportedOperationException("readFloat is not supported");
+ }
/** Read a single double */
- double readDouble();
+ default double readDouble() {
+ throw new UnsupportedOperationException("readDouble is not supported");
+ }
/**
* Read binary data of some length
*
* @param len The number of bytes to read
*/
- Binary readBinary(int len);
+ default Binary readBinary(int len) {
+ throw new UnsupportedOperationException("readBinary is not supported");
+ }
/** Read `total` integers into `vec` starting at `vec[rowId]` */
- void readIntegers(int total, FieldVector vec, int rowId);
+ default void readIntegers(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readIntegers is not supported");
+ }
/** Read `total` longs into `vec` starting at `vec[rowId]` */
- void readLongs(int total, FieldVector vec, int rowId);
+ default void readLongs(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readLongs is not supported");
+ }
/** Read `total` floats into `vec` starting at `vec[rowId]` */
- void readFloats(int total, FieldVector vec, int rowId);
+ default void readFloats(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readFloats is not supported");
+ }
/** Read `total` doubles into `vec` starting at `vec[rowId]` */
- void readDoubles(int total, FieldVector vec, int rowId);
+ default void readDoubles(int total, FieldVector vec, int rowId) {
+ throw new UnsupportedOperationException("readDoubles is not supported");
+ }
/**
* Initialize the reader from a page. See {@link ValuesReader#initFromPage(int,
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2835946305
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaByteArrayValuesReader.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_BYTE_ARRAY encoding. This encoding
+ * stores delta-encoded prefix lengths followed by suffixes encoded as DELTA_LENGTH_BYTE_ARRAY. Each
+ * value is reconstructed by taking the prefix of the previous value and appending the suffix. This
+ * is adapted from Spark's VectorizedDeltaByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-strings-delta_byte_array--7">
+ * Parquet format encodings: DELTA_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private int[] prefixLengths;
+ private VectorizedDeltaLengthByteArrayValuesReader suffixReader;
+ private Binary previous = Binary.EMPTY;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader prefixLengthReader =
+ new VectorizedDeltaEncodedValuesReader();
+ prefixLengthReader.initFromPage(valueCount, in);
+ this.prefixLengths = prefixLengthReader.readIntegers(prefixLengthReader.totalValueCount(), 0);
+ this.suffixReader = new VectorizedDeltaLengthByteArrayValuesReader();
+ this.suffixReader.initFromPage(valueCount, in);
+ }
+
+ @Override
+ public int readInteger() {
+ return prefixLengths[currentRow] + suffixReader.lengthForCurrentRow();
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ int prefixLength = prefixLengths[currentRow];
+ Binary suffix = suffixReader.readBinary(len - prefixLength);
+ this.currentRow++;
+
+ if (prefixLength == 0) {
+ this.previous = suffix;
+ return suffix;
+ }
+
+ byte[] prefixBytes = previous.getBytes();
+ byte[] suffixBytes = suffix.getBytes();
+ byte[] out = new byte[prefixLength + suffixBytes.length];
+ System.arraycopy(prefixBytes, 0, out, 0, prefixLength);
+ System.arraycopy(suffixBytes, 0, out, prefixLength, suffixBytes.length);
+ this.previous = Binary.fromConstantByteArray(out);
+ return previous;
+ }
+
+ @Override
+ public void skip() {
Review Comment:
we can't move throwing UOE into the interface unfortunately because that method comes from Parquet's `ValuesReader` where it's defined as an abstract method
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828462214
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_LENGTH_BYTE_ARRAY encoding. This
+ * encoding stores delta-encoded byte array lengths followed by the concatenated byte array data.
+ * This is adapted from Spark's VectorizedDeltaLengthByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-length-byte-array-delta_length_byte_array--6">
+ * Parquet format encodings: DELTA_LENGTH_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaLengthByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private ByteBufferInputStream dataStream;
+ private int[] lengths;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader lengthReader = new VectorizedDeltaEncodedValuesReader();
+ lengthReader.initFromPage(valueCount, in);
+ this.lengths = lengthReader.readIntegers(lengthReader.totalValueCount(), 0);
+ this.dataStream = in;
+ }
+
+ int lengthForCurrentRow() {
+ return lengths[currentRow];
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ try {
+ ByteBuffer buffer = dataStream.slice(lengths[currentRow]);
Review Comment:
so I think this code block should be using `len` everywhere.
```
--- a/arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java
+++ b/arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java
@@ -57,13 +57,13 @@ public class VectorizedDeltaLengthByteArrayValuesReader extends ValuesReader
@Override
public Binary readBinary(int len) {
try {
- ByteBuffer buffer = dataStream.slice(lengths[currentRow]);
+ ByteBuffer buffer = dataStream.slice(len);
this.currentRow++;
if (buffer.hasArray()) {
return Binary.fromConstantByteArray(
- buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
+ buffer.array(), buffer.arrayOffset() + buffer.position(), len);
} else {
- byte[] bytes = new byte[buffer.remaining()];
+ byte[] bytes = new byte[len];
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828090101
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_LENGTH_BYTE_ARRAY encoding. This
+ * encoding stores delta-encoded byte array lengths followed by the concatenated byte array data.
+ * This is adapted from Spark's VectorizedDeltaLengthByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-length-byte-array-delta_length_byte_array--6">
+ * Parquet format encodings: DELTA_LENGTH_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaLengthByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private ByteBufferInputStream dataStream;
+ private int[] lengths;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader lengthReader = new VectorizedDeltaEncodedValuesReader();
+ lengthReader.initFromPage(valueCount, in);
+ this.lengths = lengthReader.readIntegers(lengthReader.totalValueCount(), 0);
+ this.dataStream = in;
+ }
+
+ int lengthForCurrentRow() {
+ return lengths[currentRow];
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ try {
+ ByteBuffer buffer = dataStream.slice(lengths[currentRow]);
Review Comment:
also when debugging through the tests I see that there are scenarios where `len != lengths[currentRow]`
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828439633
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_BYTE_ARRAY encoding. This encoding
+ * stores delta-encoded prefix lengths followed by suffixes encoded as DELTA_LENGTH_BYTE_ARRAY. Each
+ * value is reconstructed by taking the prefix of the previous value and appending the suffix. This
+ * is adapted from Spark's VectorizedDeltaByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-strings-delta_byte_array--7">
+ * Parquet format encodings: DELTA_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private int[] prefixLengths;
+ private VectorizedDeltaLengthByteArrayValuesReader suffixReader;
+ private Binary previous = Binary.EMPTY;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader prefixLengthReader =
+ new VectorizedDeltaEncodedValuesReader();
+ prefixLengthReader.initFromPage(valueCount, in);
+ this.prefixLengths = prefixLengthReader.readIntegers(prefixLengthReader.totalValueCount(), 0);
+ this.suffixReader = new VectorizedDeltaLengthByteArrayValuesReader();
+ this.suffixReader.initFromPage(valueCount, in);
+ }
+
+ @Override
+ public int readInteger() {
+ return prefixLengths[currentRow] + suffixReader.lengthForCurrentRow();
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ Binary suffix = suffixReader.readBinary(len);
+ int prefixLength = prefixLengths[currentRow];
Review Comment:
I think passing `len` here is probably wrong without adjusting it? Because `len` here would also include the prefix length for the current row and we'd need to subtract that from `len` when passing that down to the suffix reader?
```suggestion
int prefixLength = prefixLengths[currentRow];
Binary suffix = suffixReader.readBinary(len - prefixLength);
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#issuecomment-3938376258
thanks @jbewing and thanks @singhpk234 for reviewing
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828014446
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_LENGTH_BYTE_ARRAY encoding. This
+ * encoding stores delta-encoded byte array lengths followed by the concatenated byte array data.
+ * This is adapted from Spark's VectorizedDeltaLengthByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-length-byte-array-delta_length_byte_array--6">
+ * Parquet format encodings: DELTA_LENGTH_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaLengthByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private ByteBufferInputStream dataStream;
+ private int[] lengths;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader lengthReader = new VectorizedDeltaEncodedValuesReader();
+ lengthReader.initFromPage(valueCount, in);
+ this.lengths = lengthReader.readIntegers(lengthReader.totalValueCount(), 0);
+ this.dataStream = in;
+ }
+
+ int lengthForCurrentRow() {
+ return lengths[currentRow];
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ try {
+ ByteBuffer buffer = dataStream.slice(lengths[currentRow]);
Review Comment:
it seems weird that `len` is ignored here
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "jbewing (via GitHub)" <gi...@apache.org>.
jbewing commented on PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#issuecomment-3931366898
I believe I've addressed all your great feedback in the latest commit @nastra, let me know what you think!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "jbewing (via GitHub)" <gi...@apache.org>.
jbewing commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2834225008
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedValuesReader.java:
##########
@@ -37,44 +37,68 @@ interface VectorizedValuesReader {
int DOUBLE_SIZE = 8;
/** Read a single boolean */
- boolean readBoolean();
+ default boolean readBoolean() {
+ throw new UnsupportedOperationException();
Review Comment:
Addressed in https://github.com/apache/iceberg/pull/15362/changes/c40a7a4b80683967d506db2ea68c24451dc180e8
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828014446
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_LENGTH_BYTE_ARRAY encoding. This
+ * encoding stores delta-encoded byte array lengths followed by the concatenated byte array data.
+ * This is adapted from Spark's VectorizedDeltaLengthByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-length-byte-array-delta_length_byte_array--6">
+ * Parquet format encodings: DELTA_LENGTH_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaLengthByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private ByteBufferInputStream dataStream;
+ private int[] lengths;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader lengthReader = new VectorizedDeltaEncodedValuesReader();
+ lengthReader.initFromPage(valueCount, in);
+ this.lengths = lengthReader.readIntegers(lengthReader.totalValueCount(), 0);
+ this.dataStream = in;
+ }
+
+ int lengthForCurrentRow() {
+ return lengths[currentRow];
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ try {
+ ByteBuffer buffer = dataStream.slice(lengths[currentRow]);
Review Comment:
I believe instead of using `lengths[currentRow]` this should be using `len` instead?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828323806
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaLengthByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_LENGTH_BYTE_ARRAY encoding. This
+ * encoding stores delta-encoded byte array lengths followed by the concatenated byte array data.
+ * This is adapted from Spark's VectorizedDeltaLengthByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-length-byte-array-delta_length_byte_array--6">
+ * Parquet format encodings: DELTA_LENGTH_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaLengthByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private ByteBufferInputStream dataStream;
+ private int[] lengths;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader lengthReader = new VectorizedDeltaEncodedValuesReader();
+ lengthReader.initFromPage(valueCount, in);
+ this.lengths = lengthReader.readIntegers(lengthReader.totalValueCount(), 0);
+ this.dataStream = in;
+ }
+
+ int lengthForCurrentRow() {
+ return lengths[currentRow];
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ try {
+ ByteBuffer buffer = dataStream.slice(lengths[currentRow]);
+ this.currentRow++;
+ if (buffer.hasArray()) {
+ return Binary.fromConstantByteArray(
+ buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
+ } else {
+ byte[] bytes = new byte[buffer.remaining()];
+ buffer.get(bytes);
+ return Binary.fromConstantByteArray(bytes);
+ }
+ } catch (IOException e) {
+ throw new UncheckedIOException("Failed to read binary data", e);
+ }
+ }
+
+ @Override
+ public int readInteger() {
+ return lengths[currentRow];
+ }
+
+ @Override
+ public boolean readBoolean() {
+ throw new UnsupportedOperationException("readBoolean is not supported");
Review Comment:
that way you don't have to override unsupported functionality everywhere
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2828390991
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedDeltaByteArrayValuesReader.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.arrow.vectorized.parquet;
+
+import java.io.IOException;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.apache.parquet.column.values.ValuesReader;
+import org.apache.parquet.io.api.Binary;
+
+/**
+ * A {@link VectorizedValuesReader} implementation for DELTA_BYTE_ARRAY encoding. This encoding
+ * stores delta-encoded prefix lengths followed by suffixes encoded as DELTA_LENGTH_BYTE_ARRAY. Each
+ * value is reconstructed by taking the prefix of the previous value and appending the suffix. This
+ * is adapted from Spark's VectorizedDeltaByteArrayReader.
+ *
+ * @see <a
+ * href="https://github.com/apache/parquet-format/blob/master/Encodings.md#delta-strings-delta_byte_array--7">
+ * Parquet format encodings: DELTA_BYTE_ARRAY</a>
+ */
+public class VectorizedDeltaByteArrayValuesReader extends ValuesReader
+ implements VectorizedValuesReader {
+
+ private int[] prefixLengths;
+ private VectorizedDeltaLengthByteArrayValuesReader suffixReader;
+ private Binary previous = Binary.EMPTY;
+ private int currentRow = 0;
+
+ @Override
+ public void initFromPage(int valueCount, ByteBufferInputStream in) throws IOException {
+ VectorizedDeltaEncodedValuesReader prefixLengthReader =
+ new VectorizedDeltaEncodedValuesReader();
+ prefixLengthReader.initFromPage(valueCount, in);
+ this.prefixLengths = prefixLengthReader.readIntegers(prefixLengthReader.totalValueCount(), 0);
+ this.suffixReader = new VectorizedDeltaLengthByteArrayValuesReader();
+ this.suffixReader.initFromPage(valueCount, in);
+ }
+
+ @Override
+ public int readInteger() {
+ return prefixLengths[currentRow] + suffixReader.lengthForCurrentRow();
+ }
+
+ @Override
+ public Binary readBinary(int len) {
+ Binary suffix = suffixReader.readBinary(len);
+ int prefixLength = prefixLengths[currentRow];
+ this.currentRow++;
+
+ if (prefixLength == 0) {
+ this.previous = suffix;
+ return suffix;
+ }
+
+ byte[] prefixBytes = previous.getBytes();
+ byte[] suffixBytes = suffix.getBytes();
+ byte[] out = new byte[prefixLength + suffixBytes.length];
+ System.arraycopy(prefixBytes, 0, out, 0, prefixLength);
+ System.arraycopy(suffixBytes, 0, out, prefixLength, suffixBytes.length);
+ this.previous = Binary.fromConstantByteArray(out);
+ return this.previous;
Review Comment:
```suggestion
return previous;
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Spark, Arrow, Parquet: Add vectorized parquet read support for `DELTA_LENGTH_BYTE_ARRAY` & `DELTA_BYTE_ARRAY` encodings [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #15362:
URL: https://github.com/apache/iceberg/pull/15362#discussion_r2831522246
##########
arrow/src/main/java/org/apache/iceberg/arrow/vectorized/parquet/VectorizedValuesReader.java:
##########
@@ -37,44 +37,68 @@ interface VectorizedValuesReader {
int DOUBLE_SIZE = 8;
/** Read a single boolean */
- boolean readBoolean();
+ default boolean readBoolean() {
+ throw new UnsupportedOperationException();
Review Comment:
I would probably still mention the method name in the error msg here and in all the other ones: `readBoolean is not supported`.
This makes it slightly easier when someone accidentally calls such a method
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org