-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-13582] [SQL] defer dictionary decoding in parquet reader #11437
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -257,8 +257,7 @@ private void initializeInternal() throws IOException { | |
| throw new IOException("Unsupported type: " + t); | ||
| } | ||
| if (originalTypes[i] == OriginalType.DECIMAL && | ||
| primitiveType.getDecimalMetadata().getPrecision() > | ||
| CatalystSchemaConverter.MAX_PRECISION_FOR_INT64()) { | ||
| primitiveType.getDecimalMetadata().getPrecision() > Decimal.MAX_LONG_DIGITS()) { | ||
| throw new IOException("Decimal with high precision is not supported."); | ||
| } | ||
| if (primitiveType.getPrimitiveTypeName() == PrimitiveType.PrimitiveTypeName.INT96) { | ||
|
|
@@ -439,7 +438,7 @@ private void decodeFixedLenArrayAsDecimalBatch(int col, int num) throws IOExcept | |
| PrimitiveType type = requestedSchema.getFields().get(col).asPrimitiveType(); | ||
| int precision = type.getDecimalMetadata().getPrecision(); | ||
| int scale = type.getDecimalMetadata().getScale(); | ||
| Preconditions.checkState(precision <= CatalystSchemaConverter.MAX_PRECISION_FOR_INT64(), | ||
| Preconditions.checkState(precision <= Decimal.MAX_LONG_DIGITS(), | ||
| "Unsupported precision."); | ||
|
|
||
| for (int n = 0; n < num; ++n) { | ||
|
|
@@ -611,6 +610,11 @@ private boolean next() throws IOException { | |
| */ | ||
| private void readBatch(int total, ColumnVector column) throws IOException { | ||
| int rowId = 0; | ||
| if (useDictionary) { | ||
| dictionaryIds = column.reserveDictionaryIds(total); | ||
| } else { | ||
| column.setDictionary(null); | ||
| } | ||
| while (total > 0) { | ||
| // Compute the number of values we want to read in this page. | ||
| int leftInPage = (int)(endOfPageValueCount - valuesRead); | ||
|
|
@@ -620,13 +624,6 @@ private void readBatch(int total, ColumnVector column) throws IOException { | |
| } | ||
| int num = Math.min(total, leftInPage); | ||
| if (useDictionary) { | ||
| // Data is dictionary encoded. We will vector decode the ids and then resolve the values. | ||
| if (dictionaryIds == null) { | ||
| dictionaryIds = ColumnVector.allocate(total, DataTypes.IntegerType, MemoryMode.ON_HEAP); | ||
| } else { | ||
| dictionaryIds.reset(); | ||
| dictionaryIds.reserve(total); | ||
| } | ||
| // Read and decode dictionary ids. | ||
| defColumn.readIntegers( | ||
| num, dictionaryIds, column, rowId, maxDefLevel, (VectorizedValuesReader) dataColumn); | ||
|
|
@@ -672,21 +669,13 @@ private void decodeDictionaryIds(int rowId, int num, ColumnVector column) { | |
| switch (descriptor.getType()) { | ||
| case INT32: | ||
| if (column.dataType() == DataTypes.IntegerType) { | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| column.putInt(i, dictionary.decodeToInt(dictionaryIds.getInt(i))); | ||
| } | ||
| column.setDictionary(dictionary); | ||
| } else if (column.dataType() == DataTypes.ByteType) { | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| column.putByte(i, (byte) dictionary.decodeToInt(dictionaryIds.getInt(i))); | ||
| } | ||
| column.setDictionary(dictionary); | ||
| } else if (column.dataType() == DataTypes.ShortType) { | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| column.putShort(i, (short) dictionary.decodeToInt(dictionaryIds.getInt(i))); | ||
| } | ||
| } else if (DecimalType.is64BitDecimalType(column.dataType())) { | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| column.putLong(i, dictionary.decodeToInt(dictionaryIds.getInt(i))); | ||
| } | ||
| column.setDictionary(dictionary); | ||
| } else if (DecimalType.is32BitDecimalType(column.dataType())) { | ||
| column.setDictionary(dictionary); | ||
| } else { | ||
| throw new NotImplementedException("Unimplemented type: " + column.dataType()); | ||
| } | ||
|
|
@@ -695,28 +684,28 @@ private void decodeDictionaryIds(int rowId, int num, ColumnVector column) { | |
| case INT64: | ||
| if (column.dataType() == DataTypes.LongType || | ||
| DecimalType.is64BitDecimalType(column.dataType())) { | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| column.putLong(i, dictionary.decodeToLong(dictionaryIds.getInt(i))); | ||
| } | ||
| column.setDictionary(dictionary); | ||
| } else { | ||
| throw new NotImplementedException("Unimplemented type: " + column.dataType()); | ||
| } | ||
| break; | ||
|
|
||
| case FLOAT: | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| column.putFloat(i, dictionary.decodeToFloat(dictionaryIds.getInt(i))); | ||
| } | ||
| column.setDictionary(dictionary); | ||
| break; | ||
|
|
||
| case DOUBLE: | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| column.putDouble(i, dictionary.decodeToDouble(dictionaryIds.getInt(i))); | ||
| } | ||
| column.setDictionary(dictionary); | ||
| break; | ||
|
|
||
| case FIXED_LEN_BYTE_ARRAY: | ||
| if (DecimalType.is64BitDecimalType(column.dataType())) { | ||
| // DecimalType written in the legacy mode | ||
| if (DecimalType.is32BitDecimalType(column.dataType())) { | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| Binary v = dictionary.decodeToBinary(dictionaryIds.getInt(i)); | ||
| column.putInt(i,(int) CatalystRowConverter.binaryToUnscaledLong(v)); | ||
|
||
| } | ||
| } else if (DecimalType.is64BitDecimalType(column.dataType())) { | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| Binary v = dictionary.decodeToBinary(dictionaryIds.getInt(i)); | ||
| column.putLong(i, CatalystRowConverter.binaryToUnscaledLong(v)); | ||
|
|
@@ -727,14 +716,7 @@ private void decodeDictionaryIds(int rowId, int num, ColumnVector column) { | |
| break; | ||
|
|
||
| case BINARY: | ||
| // TODO: this is incredibly inefficient as it blows up the dictionary right here. We | ||
| // need to do this better. We should probably add the dictionary data to the ColumnVector | ||
| // and reuse it across batches. This should mean adding a ByteArray would just update | ||
| // the length and offset. | ||
| for (int i = rowId; i < rowId + num; ++i) { | ||
| Binary v = dictionary.decodeToBinary(dictionaryIds.getInt(i)); | ||
| column.putByteArray(i, v.getBytes()); | ||
| } | ||
| column.setDictionary(dictionary); | ||
| break; | ||
|
|
||
| default: | ||
|
|
@@ -756,15 +738,13 @@ private void readBooleanBatch(int rowId, int num, ColumnVector column) throws IO | |
| private void readIntBatch(int rowId, int num, ColumnVector column) throws IOException { | ||
| // This is where we implement support for the valid type conversions. | ||
| // TODO: implement remaining type conversions | ||
| if (column.dataType() == DataTypes.IntegerType || column.dataType() == DataTypes.DateType) { | ||
| if (column.dataType() == DataTypes.IntegerType || column.dataType() == DataTypes.DateType || | ||
| DecimalType.is32BitDecimalType(column.dataType())) { | ||
| defColumn.readIntegers( | ||
| num, column, rowId, maxDefLevel, (VectorizedValuesReader) dataColumn); | ||
| } else if (column.dataType() == DataTypes.ByteType) { | ||
| defColumn.readBytes( | ||
| num, column, rowId, maxDefLevel, (VectorizedValuesReader) dataColumn); | ||
| } else if (DecimalType.is64BitDecimalType(column.dataType())) { | ||
| defColumn.readIntsAsLongs( | ||
| num, column, rowId, maxDefLevel, (VectorizedValuesReader) dataColumn); | ||
| } else if (column.dataType() == DataTypes.ShortType) { | ||
| defColumn.readShorts( | ||
| num, column, rowId, maxDefLevel, (VectorizedValuesReader) dataColumn); | ||
|
|
@@ -822,7 +802,16 @@ private void readFixedLenByteArrayBatch(int rowId, int num, | |
| VectorizedValuesReader data = (VectorizedValuesReader) dataColumn; | ||
| // This is where we implement support for the valid type conversions. | ||
| // TODO: implement remaining type conversions | ||
| if (DecimalType.is64BitDecimalType(column.dataType())) { | ||
| if (DecimalType.is32BitDecimalType(column.dataType())) { | ||
| for (int i = 0; i < num; i++) { | ||
| if (defColumn.readInteger() == maxDefLevel) { | ||
| column.putInt(rowId + i, | ||
| (int) CatalystRowConverter.binaryToUnscaledLong(data.readBinary(arrayLen))); | ||
| } else { | ||
| column.putNull(rowId + i); | ||
| } | ||
| } | ||
| } else if (DecimalType.is64BitDecimalType(column.dataType())) { | ||
| for (int i = 0; i < num; i++) { | ||
| if (defColumn.readInteger() == maxDefLevel) { | ||
| column.putLong(rowId + i, | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Remove dictionaryIds from this class.