-
Notifications
You must be signed in to change notification settings - Fork 988
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
[core] fix parquet can not read empty row with first column is array. #4711
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.apache.parquet.column.ValuesType.DEFINITION_LEVEL; | ||
|
@@ -106,6 +107,11 @@ public class NestedPrimitiveColumnReader implements ColumnReader<WritableColumnV | |
|
||
private boolean isFirstRow = true; | ||
|
||
// When reading array, we need to read the next value's repetition level to know whether it's a | ||
// new row. This is a flag to tell whether we need to cut the repetition level when getting | ||
// LevelDelegation. | ||
private boolean cutLevel = false; | ||
|
||
private final LastValueContainer lastValue = new LastValueContainer(); | ||
|
||
public NestedPrimitiveColumnReader( | ||
|
@@ -168,7 +174,10 @@ public WritableColumnVector readAndNewVector(int readNumber, WritableColumnVecto | |
|
||
int valueIndex = collectDataFromParquetPage(readNumber, valueList); | ||
|
||
return fillColumnVector(valueIndex, valueList); | ||
if (!valueList.isEmpty()) { | ||
return fillColumnVector(valueIndex, valueList); | ||
} | ||
return fillColumnVectorWithNone(valueIndex); | ||
} | ||
|
||
private int collectDataFromParquetPage(int total, List<Object> valueList) throws IOException { | ||
|
@@ -196,11 +205,13 @@ private int collectDataFromParquetPage(int total, List<Object> valueList) throws | |
boolean needFilterSkip = pageRowId < rangeStart; | ||
|
||
do { | ||
|
||
if (!lastValue.shouldSkip && !needFilterSkip) { | ||
valueList.add(lastValue.value); | ||
valueIndex++; | ||
} else if (readRowField) { | ||
valueIndex++; | ||
} | ||
readState.valuesToReadInPage = readState.valuesToReadInPage - 1; | ||
} while (readValue() && (repetitionLevel != 0)); | ||
|
||
if (pageRowId == readState.rowId) { | ||
|
@@ -212,6 +223,12 @@ private int collectDataFromParquetPage(int total, List<Object> valueList) throws | |
} | ||
} | ||
|
||
// When the values to read in page > 0 and row to read in batch == 0, it means the | ||
// repetition level contains the next value's, so need to set the cutLevel flag to true. | ||
if (readState.valuesToReadInPage > 0 && readState.rowsToReadInBatch == 0) { | ||
cutLevel = true; | ||
} | ||
|
||
return valueIndex; | ||
} | ||
|
||
|
@@ -222,6 +239,11 @@ public LevelDelegation getLevelDelegation() { | |
definitionLevelList.clear(); | ||
repetitionLevelList.add(repetitionLevel); | ||
definitionLevelList.add(definitionLevel); | ||
if (cutLevel) { | ||
repetition = Arrays.copyOf(repetition, repetition.length - 1); | ||
definition = Arrays.copyOf(definition, definition.length - 1); | ||
cutLevel = false; | ||
} | ||
return new LevelDelegation(repetition, definition); | ||
} | ||
|
||
|
@@ -285,7 +307,6 @@ private void readAndSaveRepetitionAndDefinitionLevels() { | |
// get the values of repetition and definitionLevel | ||
repetitionLevel = repetitionLevelColumn.nextInt(); | ||
definitionLevel = definitionLevelColumn.nextInt(); | ||
readState.valuesToReadInPage = readState.valuesToReadInPage - 1; | ||
repetitionLevelList.add(repetitionLevel); | ||
definitionLevelList.add(definitionLevel); | ||
} | ||
|
@@ -549,6 +570,53 @@ private WritableColumnVector fillColumnVector(int total, List valueList) { | |
} | ||
} | ||
|
||
private WritableColumnVector fillColumnVectorWithNone(int total) { | ||
boolean[] isNull = new boolean[total]; | ||
Arrays.fill(isNull, true); | ||
switch (dataType.getTypeRoot()) { | ||
case CHAR: | ||
case VARCHAR: | ||
case BINARY: | ||
case VARBINARY: | ||
return new HeapBytesVector(total, isNull); | ||
case BOOLEAN: | ||
return new HeapBooleanVector(total, isNull); | ||
case TINYINT: | ||
return new HeapByteVector(total, isNull); | ||
case SMALLINT: | ||
return new HeapShortVector(total, isNull); | ||
case INTEGER: | ||
case DATE: | ||
case TIME_WITHOUT_TIME_ZONE: | ||
return new HeapIntVector(total, isNull); | ||
case FLOAT: | ||
return new HeapFloatVector(total, isNull); | ||
case BIGINT: | ||
return new HeapLongVector(total, isNull); | ||
case DOUBLE: | ||
return new HeapDoubleVector(total, isNull); | ||
case TIMESTAMP_WITHOUT_TIME_ZONE: | ||
case TIMESTAMP_WITH_LOCAL_TIME_ZONE: | ||
return new HeapTimestampVector(total, isNull); | ||
case DECIMAL: | ||
PrimitiveType.PrimitiveTypeName primitiveTypeName = | ||
descriptor.getPrimitiveType().getPrimitiveTypeName(); | ||
switch (primitiveTypeName) { | ||
case INT32: | ||
HeapIntVector phiv = new HeapIntVector(total, isNull); | ||
return new ParquetDecimalVector(phiv, total); | ||
case INT64: | ||
HeapLongVector phlv = new HeapLongVector(total, isNull); | ||
return new ParquetDecimalVector(phlv, total); | ||
default: | ||
HeapBytesVector phbv = new HeapBytesVector(total, isNull); | ||
return new ParquetDecimalVector(phbv, total); | ||
} | ||
default: | ||
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. I wonder if all the existing types are covered. 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. yes except the INT32 and INT64, other primitiveType should deserialize as HeapBytesVector |
||
throw new RuntimeException("Unsupported type in the list: " + type); | ||
} | ||
} | ||
|
||
private static HeapBytesVector getHeapBytesVector(int total, List valueList) { | ||
HeapBytesVector phbv = new HeapBytesVector(total); | ||
for (int i = 0; i < valueList.size(); i++) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you add a comment for this boolean?
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.
ok