本文整理了Java中parquet.io.api.Binary.fromByteArray()
方法的一些代码示例,展示了Binary.fromByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binary.fromByteArray()
方法的具体详情如下:
包路径:parquet.io.api.Binary
类名称:Binary
方法名:fromByteArray
暂无
代码示例来源:origin: prestodb/presto
public BinaryDictionary(DictionaryPage dictionaryPage, Integer length)
throws IOException
{
super(dictionaryPage.getEncoding());
byte[] dictionaryBytes = dictionaryPage.getSlice().getBytes();
content = new Binary[dictionaryPage.getDictionarySize()];
int offset = 0;
if (length == null) {
for (int i = 0; i < content.length; i++) {
int len = readIntLittleEndian(dictionaryBytes, offset);
offset += 4;
content[i] = Binary.fromByteArray(dictionaryBytes, offset, len);
offset += len;
}
}
else {
checkArgument(length > 0, "Invalid byte array length: %s", length);
for (int i = 0; i < content.length; i++) {
content[i] = Binary.fromByteArray(dictionaryBytes, offset, length);
offset += length;
}
}
}
代码示例来源:origin: prestodb/presto
@Test
public void testInvalidBinaryLength()
{
try {
byte[] invalidLengthBinaryTimestamp = new byte[8];
getTimestampMillis(Binary.fromByteArray(invalidLengthBinaryTimestamp));
}
catch (PrestoException e) {
assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode());
assertEquals(e.getMessage(), "Parquet timestamp must be 12 bytes, actual 8");
}
}
代码示例来源:origin: prestodb/presto
private Binary decimalToBinary(final HiveDecimal hiveDecimal, final DecimalTypeInfo decimalTypeInfo)
{
int prec = decimalTypeInfo.precision();
int scale = decimalTypeInfo.scale();
byte[] decimalBytes = hiveDecimal.setScale(scale).unscaledValue().toByteArray();
// Estimated number of bytes needed.
int precToBytes = ParquetHiveSerDe.PRECISION_TO_BYTE_COUNT[prec - 1];
if (precToBytes == decimalBytes.length) {
// No padding needed.
return Binary.fromByteArray(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] |= 0xFF;
}
}
System.arraycopy(decimalBytes, 0, tgt, precToBytes - decimalBytes.length, decimalBytes.length); // Padding leading zeroes/ones.
return Binary.fromByteArray(tgt);
}
}
代码示例来源:origin: prestodb/presto
case BINARY:
byte[] vBinary = ((BinaryObjectInspector) inspector).getPrimitiveJavaObject(value);
recordConsumer.addBinary(Binary.fromByteArray(vBinary));
break;
case TIMESTAMP:
代码示例来源:origin: com.facebook.presto.hive/hive-apache
@Override
public void setMinMaxFromBytes(byte[] minBytes, byte[] maxBytes) {
max = Binary.fromByteArray(maxBytes);
min = Binary.fromByteArray(minBytes);
this.markAsNotEmpty();
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
@Override
public Binary readBytes() {
int length = lengthReader.readInteger();
int start = offset;
offset = start + length;
return Binary.fromByteArray(in, start, length);
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
@Override
public Binary readBytes() {
try {
int start = offset;
offset = start + length;
return Binary.fromByteArray(in, start, length);
} catch (RuntimeException e) {
throw new ParquetDecodingException("could not read bytes at offset " + offset, e);
}
}
代码示例来源:origin: com.twitter/parquet-thrift
private void writeBinaryToRecordConsumer(ByteBuffer buf) {
recordConsumer.addBinary(Binary.fromByteArray(buf.array(), buf.position(), buf.limit() - buf.position()));
}
代码示例来源:origin: asakusafw/asakusafw
private void writeAsBinary(RecordConsumer consumer, BigDecimal original, BigInteger unscaled) {
byte[] bytes = unscaled.toByteArray();
Binary binary;
if (bytes.length == byteLength) {
binary = Binary.fromByteArray(bytes);
} else if (bytes.length < byteLength) {
byte[] newBytes = new byte[byteLength];
if (unscaled.signum() < 0) {
Arrays.fill(newBytes, 0, newBytes.length - bytes.length, (byte) -1);
}
System.arraycopy(bytes, 0, newBytes, newBytes.length - bytes.length, bytes.length);
binary = Binary.fromByteArray(newBytes);
} else {
throw new IllegalStateException(MessageFormat.format(
Messages.getString("DecimalValueDriver.errorPrecisionTooSmall"), //$NON-NLS-1$
original,
precision));
}
consumer.addBinary(binary);
}
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
protected static Binary copy(Binary binary) {
return Binary.fromByteArray(
Arrays.copyOf(binary.getBytes(), binary.length()));
}
}
代码示例来源:origin: asakusafw/asakusafw
@Override
public void write(Object value, RecordConsumer consumer) {
Text text = ((StringOption) value).get();
consumer.addBinary(Binary.fromByteArray(text.getBytes(), 0, text.getLength()));
}
},
代码示例来源:origin: com.facebook.presto.hive/hive-apache
public DeltaByteArrayReader() {
this.prefixLengthReader = new DeltaBinaryPackingValuesReader();
this.suffixReader = new DeltaLengthByteArrayValuesReader();
this.previous = Binary.fromByteArray(new byte[0]);
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
private Binary decimalToBinary(final HiveDecimal hiveDecimal, final DecimalTypeInfo decimalTypeInfo) {
int prec = decimalTypeInfo.precision();
int scale = decimalTypeInfo.scale();
byte[] decimalBytes = hiveDecimal.setScale(scale).unscaledValue().toByteArray();
// Estimated number of bytes needed.
int precToBytes = ParquetHiveSerDe.PRECISION_TO_BYTE_COUNT[prec - 1];
if (precToBytes == decimalBytes.length) {
// No padding needed.
return Binary.fromByteArray(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] |= 0xFF;
}
}
System.arraycopy(decimalBytes, 0, tgt, precToBytes - decimalBytes.length, decimalBytes.length); // Padding leading zeroes/ones.
return Binary.fromByteArray(tgt);
}
}
代码示例来源:origin: asakusafw/asakusafw
@Override
public void write(Object value, RecordConsumer consumer) {
StringOption option = (StringOption) value;
Text text = option.get();
byte[] bytes = text.getBytes();
int length = text.getLength();
if (length > limit) {
// if byte-length > limit, the string may code-point-count >= limit
String stripped = HiveBaseChar.getPaddedValue(text.toString(), limit);
consumer.addBinary(Binary.fromString(stripped));
} else {
consumer.addBinary(Binary.fromByteArray(bytes, 0, length));
}
}
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
@Override
public Binary readBytes() {
try {
int length = BytesUtils.readIntLittleEndian(in, offset);
int start = offset + 4;
offset = start + length;
return Binary.fromByteArray(in, start, length);
} catch (IOException e) {
throw new ParquetDecodingException("could not read bytes at offset " + offset, e);
} catch (RuntimeException e) {
throw new ParquetDecodingException("could not read bytes at offset " + offset, e);
}
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
@Override
public void writeBytes(Binary v) {
int i = 0;
byte[] vb = v.getBytes();
int length = previous.length < vb.length ? previous.length : vb.length;
for(i = 0; (i < length) && (previous[i] == vb[i]); i++);
prefixLengthWriter.writeInteger(i);
suffixWriter.writeBytes(Binary.fromByteArray(vb, i, vb.length - i));
previous = vb;
}
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
@Override
public Binary readBytes() {
int prefixLength = prefixLengthReader.readInteger();
// This does not copy bytes
Binary suffix = suffixReader.readBytes();
int length = prefixLength + suffix.length();
// We have to do this to materialize the output
if(prefixLength != 0) {
byte[] out = new byte[length];
System.arraycopy(previous.getBytes(), 0, out, 0, prefixLength);
System.arraycopy(suffix.getBytes(), 0, out, prefixLength, suffix.length());
previous = Binary.fromByteArray(out);
} else {
previous = suffix;
}
return previous;
}
}
代码示例来源:origin: uk.co.nichesolutions.presto/presto-hive
@Test
public void testInvalidBinaryLength()
{
try {
byte[] invalidLengthBinaryTimestamp = new byte[8];
getTimestampMillis(Binary.fromByteArray(invalidLengthBinaryTimestamp));
}
catch (PrestoException e) {
assertEquals(e.getErrorCode(), HIVE_BAD_DATA.toErrorCode());
assertEquals(e.getMessage(), "Parquet timestamp must be 12 bytes, actual 8");
}
}
代码示例来源:origin: com.facebook.presto/presto-parquet
@Test
public void testInvalidBinaryLength()
{
try {
byte[] invalidLengthBinaryTimestamp = new byte[8];
getTimestampMillis(Binary.fromByteArray(invalidLengthBinaryTimestamp));
}
catch (PrestoException e) {
assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode());
assertEquals(e.getMessage(), "Parquet timestamp must be 12 bytes, actual 8");
}
}
代码示例来源:origin: com.facebook.presto/presto-hive
private Binary decimalToBinary(final HiveDecimal hiveDecimal, final DecimalTypeInfo decimalTypeInfo)
{
int prec = decimalTypeInfo.precision();
int scale = decimalTypeInfo.scale();
byte[] decimalBytes = hiveDecimal.setScale(scale).unscaledValue().toByteArray();
// Estimated number of bytes needed.
int precToBytes = ParquetHiveSerDe.PRECISION_TO_BYTE_COUNT[prec - 1];
if (precToBytes == decimalBytes.length) {
// No padding needed.
return Binary.fromByteArray(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] |= 0xFF;
}
}
System.arraycopy(decimalBytes, 0, tgt, precToBytes - decimalBytes.length, decimalBytes.length); // Padding leading zeroes/ones.
return Binary.fromByteArray(tgt);
}
}
内容来源于网络,如有侵权,请联系作者删除!