forked from greenplum-db/pxf-archive
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from arenadata/feature/ADBDEV-5568
[ADBDEV-5568] [Java] PXF: Add pushdown filter support for new datatypes
- Loading branch information
Showing
11 changed files
with
230 additions
and
101 deletions.
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
42 changes: 42 additions & 0 deletions
42
...c/main/java/org/greenplum/pxf/plugins/hdfs/parquet/ParquetFixedLenByteArrayUtilities.java
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.greenplum.pxf.plugins.hdfs.parquet; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.apache.hadoop.hive.common.type.HiveDecimal; | ||
import org.apache.parquet.schema.LogicalTypeAnnotation.DecimalLogicalTypeAnnotation; | ||
import org.greenplum.pxf.plugins.hdfs.ParquetFileAccessor; | ||
import org.greenplum.pxf.plugins.hdfs.utilities.DecimalUtilities; | ||
|
||
@UtilityClass | ||
public class ParquetFixedLenByteArrayUtilities { | ||
public static byte[] convertFromBigDecimal(DecimalUtilities decimalUtilities, String value, String columnName, | ||
DecimalLogicalTypeAnnotation typeAnnotation) { | ||
// From org.apache.hadoop.hive.ql.io.parquet.write.DataWritableWriter.DecimalDataWriter#decimalToBinary | ||
int precision = Math.min(HiveDecimal.MAX_PRECISION, typeAnnotation.getPrecision()); | ||
int scale = Math.min(HiveDecimal.MAX_SCALE, typeAnnotation.getScale()); | ||
|
||
HiveDecimal hiveDecimal = decimalUtilities.parseDecimalStringWithHiveDecimal(value, precision, scale, columnName); | ||
if (hiveDecimal == null) { | ||
return null; | ||
} | ||
|
||
byte[] decimalBytes = hiveDecimal.bigIntegerBytesScaled(scale); | ||
|
||
// Estimated number of bytes needed. | ||
int precToBytes = ParquetFileAccessor.PRECISION_TO_BYTE_COUNT[precision - 1]; | ||
if (precToBytes == decimalBytes.length) { | ||
// No padding needed. | ||
return decimalBytes; | ||
} | ||
|
||
byte[] tgt = new byte[precToBytes]; | ||
if (hiveDecimal.signum() == -1) { | ||
// For negative number, initializing bits to 1 | ||
for (int i = 0; i < precToBytes; i++) { | ||
tgt[i] |= (byte) 0xFF; | ||
} | ||
} | ||
System.arraycopy(decimalBytes, 0, tgt, precToBytes - decimalBytes.length, decimalBytes.length); // Padding leading zeroes/ones. | ||
return tgt; | ||
// end -- org.apache.hadoop.hive.ql.io.parquet.write.DataWritableWriter.DecimalDataWriter#decimalToBinary | ||
} | ||
} |
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
Oops, something went wrong.