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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,29 @@ public ValuesReader getValuesReader(ColumnDescriptor descriptor,
* Suffixes are stored as delta length byte arrays.
*/
DELTA_BYTE_ARRAY {
private DeltaByteArrayReader previous;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a good fix for the bug, but now this class and its getter are stateful, which is why I am a little worried about putting it directly into parquet instead of a branch or repair tool or something.


@Override
public ValuesReader getValuesReader(ColumnDescriptor descriptor,
ValuesType valuesType) {
if (descriptor.getType() != BINARY) {
throw new ParquetDecodingException("Encoding DELTA_BYTE_ARRAY is only supported for type BINARY");
}
return new DeltaByteArrayReader();

DeltaByteArrayReader current = new DeltaByteArrayReader();

//A bug was found on PARQUET-246 where DeltaByteArrayWriter was not cleaning the previous binary
//value before starting a new page reader, causing that the first value of the page being encoded uses
//a prefix value from the last page. This issue was fixed by resetting the previous binary value
//when writing data to a new page.
//However, buggy files were written with this issue. This line passes the previous binary
//value of the last page reader to the new page reader so that data can be recovered.
if (previous != null) {
current.setPreviousBinary(previous.getPreviousBinary());
}

previous = current;
return current;
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ public DeltaByteArrayReader() {
this.previous = Binary.fromByteArray(new byte[0]);
}

public void setPreviousBinary(Binary previous) {
this.previous = previous;
}

public Binary getPreviousBinary() {
return previous;
}

@Override
public void initFromPage(int valueCount, byte[] page, int offset)
throws IOException {
prefixLengthReader.initFromPage(valueCount, page, offset);
int next = prefixLengthReader.getNextOffset();
suffixReader.initFromPage(valueCount, page, next);
suffixReader.initFromPage(valueCount, page, next);
}

@Override
Expand Down