Repository navigation
PARQUET-246: File recovery and work-arounds #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5c9497c
a10b157
3107362
3236a3b
067d5ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /** | ||
| * 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.parquet; | ||
|
|
||
| import org.apache.parquet.VersionParser.ParsedVersion; | ||
| import org.apache.parquet.column.Encoding; | ||
|
|
||
| public class CorruptDeltaByteArrays { | ||
| private static final Log LOG = Log.getLog(CorruptStatistics.class); | ||
|
|
||
| private static final SemanticVersion PARQUET_246_FIXED_VERSION = | ||
| new SemanticVersion(1, 8, 0); | ||
|
|
||
| public static boolean requiresSequentialReads(ParsedVersion version, Encoding encoding) { | ||
| if (encoding != Encoding.DELTA_BYTE_ARRAY) { | ||
| return false; | ||
| } | ||
|
|
||
| if (version == null) { | ||
| return true; | ||
| } | ||
|
|
||
| if (!"parquet-mr".equals(version.application)) { | ||
| // assume other applications don't have this bug | ||
| return false; | ||
| } | ||
|
|
||
| if (!version.hasSemanticVersion()) { | ||
| LOG.warn("Requiring sequential reads because created_by did not " + | ||
| "contain a valid version (see PARQUET-246): " + version.version); | ||
| return true; | ||
| } | ||
|
|
||
| return requiresSequentialReads(version.getSemanticVersion(), encoding); | ||
| } | ||
|
|
||
| public static boolean requiresSequentialReads(SemanticVersion semver, Encoding encoding) { | ||
| if (encoding != Encoding.DELTA_BYTE_ARRAY) { | ||
| return false; | ||
| } | ||
|
|
||
| if (semver == null) { | ||
| return true; | ||
| } | ||
|
|
||
| if (semver.compareTo(PARQUET_246_FIXED_VERSION) < 0) { | ||
| LOG.info("Requiring sequential reads because this file was created " + | ||
| "prior to " + PARQUET_246_FIXED_VERSION + ". See PARQUET-246" ); | ||
| return true; | ||
| } | ||
|
|
||
| // this file was created after the fix | ||
| return false; | ||
| } | ||
|
|
||
| public static boolean requiresSequentialReads(String createdBy, Encoding encoding) { | ||
| if (encoding != Encoding.DELTA_BYTE_ARRAY) { | ||
| return false; | ||
| } | ||
|
|
||
| if (Strings.isNullOrEmpty(createdBy)) { | ||
| LOG.info("Requiring sequential reads because file version is empty. " + | ||
| "See PARQUET-246"); | ||
| return true; | ||
| } | ||
|
|
||
| try { | ||
| return requiresSequentialReads(VersionParser.parse(createdBy), encoding); | ||
|
|
||
| } catch (RuntimeException e) { | ||
| warnParseError(createdBy, e); | ||
| return true; | ||
| } catch (VersionParser.VersionParseException e) { | ||
| warnParseError(createdBy, e); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| private static void warnParseError(String createdBy, Throwable e) { | ||
| LOG.warn("Requiring sequential reads because created_by could not be " + | ||
| "parsed (see PARQUET-246): " + createdBy, e); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * 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.parquet.column.values; | ||
|
|
||
| public interface RequiresPreviousReader { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this interface/generalization is actually needed. How about:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous is internal state. This method avoids exposing that state to others, allowing access to all private members in the recipient ValuesReader. |
||
| void setPreviousReader(ValuesReader reader); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.apache.parquet.column.values.RequiresPreviousReader; | ||
| import org.apache.parquet.column.values.ValuesReader; | ||
| import org.apache.parquet.column.values.delta.DeltaBinaryPackingValuesReader; | ||
| import org.apache.parquet.column.values.deltalengthbytearray.DeltaLengthByteArrayValuesReader; | ||
|
|
@@ -31,7 +32,7 @@ | |
| * @author Aniket Mokashi | ||
| * | ||
| */ | ||
| public class DeltaByteArrayReader extends ValuesReader { | ||
| public class DeltaByteArrayReader extends ValuesReader implements RequiresPreviousReader { | ||
| private ValuesReader prefixLengthReader; | ||
| private ValuesReader suffixReader; | ||
|
|
||
|
|
@@ -63,7 +64,13 @@ public Binary readBytes() { | |
| // This does not copy bytes | ||
| Binary suffix = suffixReader.readBytes(); | ||
| int length = prefixLength + suffix.length(); | ||
|
|
||
|
|
||
| // NOTE: due to PARQUET-246, it is important that we | ||
| // respect prefixLength which was read from prefixLengthReader, | ||
| // even for the *first* value of a page. Even though the first | ||
| // value of the page should have an empty prefix, it may not | ||
| // because of PARQUET-246. | ||
|
|
||
| // We have to do this to materialize the output | ||
| if(prefixLength != 0) { | ||
| byte[] out = new byte[length]; | ||
|
|
@@ -75,4 +82,18 @@ public Binary readBytes() { | |
| } | ||
| return previous; | ||
| } | ||
|
|
||
| /** | ||
| * There was a bug (PARQUET-246) in which DeltaByteArrayWriter's reset() method did not | ||
| * clear the previous value state that it tracks internally. This resulted in the first | ||
| * value of all pages (except for the first page) to be a delta from the last value of the | ||
| * previous page. In order to read corrupted files written with this bug, when reading a | ||
| * new page we need to recover the previous page's last value to use it (if needed) to | ||
| * read the first value. | ||
| */ | ||
| public void setPreviousReader(ValuesReader reader) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the fix is actually setPreviousValue, not setPreviousReader |
||
| if (reader != null) { | ||
| this.previous = ((DeltaByteArrayReader) reader).previous; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way than doing the type casting here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want this to be a normal part of the API, so using an interface like this to carry the method is a good practice. This also allows the reader to expose just the one method and not expose its internal state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline. If we wanna make it general, we should make encoding to provide a SequentialReader rather than type casting the Reader.
If we wanna make it not that generic, we should not let the "requiresSequentialReads" be part of the normal Encoding's API