parquet.io.api.Binary.length()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中parquet.io.api.Binary.length()方法的一些代码示例,展示了Binary.length()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binary.length()方法的具体详情如下:
包路径:parquet.io.api.Binary
类名称:Binary
方法名:length

Binary.length介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

  1. /**
  2. * Returns GMT timestamp from binary encoded parquet timestamp (12 bytes - julian date + time of day nanos).
  3. *
  4. * @param timestampBinary INT96 parquet timestamp
  5. * @return timestamp in millis, GMT timezone
  6. */
  7. public static long getTimestampMillis(Binary timestampBinary)
  8. {
  9. if (timestampBinary.length() != 12) {
  10. throw new PrestoException(HIVE_BAD_DATA, "Parquet timestamp must be 12 bytes, actual " + timestampBinary.length());
  11. }
  12. byte[] bytes = timestampBinary.getBytes();
  13. // little endian encoding - need to invert byte order
  14. long timeOfDayNanos = Longs.fromBytes(bytes[7], bytes[6], bytes[5], bytes[4], bytes[3], bytes[2], bytes[1], bytes[0]);
  15. int julianDay = Ints.fromBytes(bytes[11], bytes[10], bytes[9], bytes[8]);
  16. return julianDayToMillis(julianDay) + (timeOfDayNanos / NANOS_PER_MILLISECOND);
  17. }

代码示例来源:origin: prestodb/presto

  1. /**
  2. * Returns GMT timestamp from binary encoded parquet timestamp (12 bytes - julian date + time of day nanos).
  3. *
  4. * @param timestampBinary INT96 parquet timestamp
  5. * @return timestamp in millis, GMT timezone
  6. */
  7. public static long getTimestampMillis(Binary timestampBinary)
  8. {
  9. if (timestampBinary.length() != 12) {
  10. throw new PrestoException(NOT_SUPPORTED, "Parquet timestamp must be 12 bytes, actual " + timestampBinary.length());
  11. }
  12. byte[] bytes = timestampBinary.getBytes();
  13. // little endian encoding - need to invert byte order
  14. long timeOfDayNanos = Longs.fromBytes(bytes[7], bytes[6], bytes[5], bytes[4], bytes[3], bytes[2], bytes[1], bytes[0]);
  15. int julianDay = Ints.fromBytes(bytes[11], bytes[10], bytes[9], bytes[8]);
  16. return julianDayToMillis(julianDay) + (timeOfDayNanos / NANOS_PER_MILLISECOND);
  17. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. protected void readValue(BlockBuilder blockBuilder, Type type)
  3. {
  4. if (definitionLevel == columnDescriptor.getMaxDefinitionLevel()) {
  5. Binary binary = valuesReader.readBytes();
  6. Slice value;
  7. if (binary.length() == 0) {
  8. value = EMPTY_SLICE;
  9. }
  10. else {
  11. value = wrappedBuffer(binary.getBytes());
  12. }
  13. if (isVarcharType(type)) {
  14. value = truncateToLength(value, type);
  15. }
  16. if (isCharType(type)) {
  17. value = truncateToLengthAndTrimSpaces(value, type);
  18. }
  19. type.writeSlice(blockBuilder, value);
  20. }
  21. else if (isValueNull()) {
  22. blockBuilder.appendNull();
  23. }
  24. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. @Override
  2. public final void writeBytes(Binary v) {
  3. if (v.length() != length) {
  4. throw new IllegalArgumentException("Fixed Binary size " + v.length() +
  5. " does not match field type length " + length);
  6. }
  7. try {
  8. v.writeTo(out);
  9. } catch (IOException e) {
  10. throw new ParquetEncodingException("could not write fixed bytes", e);
  11. }
  12. }

代码示例来源:origin: asakusafw/asakusafw

  1. private void setBinary(Text text, Binary binary) {
  2. // TODO check it length?
  3. text.set(binary.getBytes(), 0, binary.length());
  4. }
  5. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. @Override
  2. public String toString() {
  3. return "Binary{" + length() + " bytes, " + Arrays.toString(getBytes()) + "}";
  4. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. protected static Binary copy(Binary binary) {
  2. return Binary.fromByteArray(
  3. Arrays.copyOf(binary.getBytes(), binary.length()));
  4. }
  5. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. public static NanoTime fromBinary(Binary bytes) {
  2. Preconditions.checkArgument(bytes.length() == 12, "Must be 12 bytes");
  3. ByteBuffer buf = bytes.toByteBuffer();
  4. buf.order(ByteOrder.LITTLE_ENDIAN);
  5. long timeOfDayNanos = buf.getLong();
  6. int julianDay = buf.getInt();
  7. return new NanoTime(julianDay, timeOfDayNanos);
  8. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. public static NanoTime fromBinary(Binary bytes) {
  2. Preconditions.checkArgument(bytes.length() == 12, "Must be 12 bytes");
  3. ByteBuffer buf = bytes.toByteBuffer();
  4. buf.order(ByteOrder.LITTLE_ENDIAN);
  5. long timeOfDayNanos = buf.getLong();
  6. int julianDay = buf.getInt();
  7. return new NanoTime(julianDay, timeOfDayNanos);
  8. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. public void writeBytes(Binary v) {
  2. //for rawdata, length(4 bytes int) is stored, followed by the binary content itself
  3. rawDataByteSize += v.length() + 4;
  4. currentWriter.writeBytes(v);
  5. checkFallback();
  6. }

代码示例来源:origin: asakusafw/asakusafw

  1. @Override
  2. public void addBinary(Binary value) {
  3. target.reset();
  4. target.get().set(value.getBytes(), 0, value.length());
  5. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. @Override
  2. public Binary readBytes() {
  3. int prefixLength = prefixLengthReader.readInteger();
  4. // This does not copy bytes
  5. Binary suffix = suffixReader.readBytes();
  6. int length = prefixLength + suffix.length();
  7. // We have to do this to materialize the output
  8. if(prefixLength != 0) {
  9. byte[] out = new byte[length];
  10. System.arraycopy(previous.getBytes(), 0, out, 0, prefixLength);
  11. System.arraycopy(suffix.getBytes(), 0, out, prefixLength, suffix.length());
  12. previous = Binary.fromByteArray(out);
  13. } else {
  14. previous = suffix;
  15. }
  16. return previous;
  17. }
  18. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. @Override
  2. public final void writeBytes(Binary v) {
  3. try {
  4. out.writeInt(v.length());
  5. v.writeTo(out);
  6. } catch (IOException e) {
  7. throw new ParquetEncodingException("could not write bytes", e);
  8. }
  9. }

代码示例来源:origin: uk.co.nichesolutions.presto/presto-hive

  1. /**
  2. * Returns GMT timestamp from binary encoded parquet timestamp (12 bytes - julian date + time of day nanos).
  3. *
  4. * @param timestampBinary INT96 parquet timestamp
  5. * @return timestamp in millis, GMT timezone
  6. */
  7. public static long getTimestampMillis(Binary timestampBinary)
  8. {
  9. if (timestampBinary.length() != 12) {
  10. throw new PrestoException(HIVE_BAD_DATA, "Parquet timestamp must be 12 bytes, actual " + timestampBinary.length());
  11. }
  12. byte[] bytes = timestampBinary.getBytes();
  13. // little endian encoding - need to invert byte order
  14. long timeOfDayNanos = Longs.fromBytes(bytes[7], bytes[6], bytes[5], bytes[4], bytes[3], bytes[2], bytes[1], bytes[0]);
  15. int julianDay = Ints.fromBytes(bytes[11], bytes[10], bytes[9], bytes[8]);
  16. return julianDayToMillis(julianDay) + (timeOfDayNanos / NANOS_PER_MILLISECOND);
  17. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. @Override
  2. public void writeBytes(Binary v) {
  3. try {
  4. lengthWriter.writeInteger(v.length());
  5. out.write(v.getBytes());
  6. } catch (IOException e) {
  7. throw new ParquetEncodingException("could not write bytes", e);
  8. }
  9. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. @Override
  2. public void writeBytes(Binary v) {
  3. int id = binaryDictionaryContent.getInt(v);
  4. if (id == -1) {
  5. id = binaryDictionaryContent.size();
  6. binaryDictionaryContent.put(copy(v), id);
  7. // length as int (4 bytes) + actual bytes
  8. dictionaryByteSize += 4 + v.length();
  9. }
  10. encodedValues.add(id);
  11. }

代码示例来源:origin: com.facebook.presto.hive/hive-apache

  1. @Override
  2. public void addBinary(Binary value) {
  3. if (DEBUG) log("addBinary(" + value.length() + " bytes)");
  4. emptyField = false;
  5. getColumnWriter().write(value, r[currentLevel], currentColumnIO.getDefinitionLevel());
  6. setRepetitionLevel();
  7. if (DEBUG) printState();
  8. }

代码示例来源:origin: uk.co.nichesolutions.presto/presto-hive

  1. @Override
  2. public void readValues(BlockBuilder blockBuilder, int valueNumber)
  3. {
  4. for (int i = 0; i < valueNumber; i++) {
  5. if (definitionReader.readLevel() == columnDescriptor.getMaxDefinitionLevel()) {
  6. Binary binary = valuesReader.readBytes();
  7. if (binary.length() == 0) {
  8. VARCHAR.writeSlice(blockBuilder, Slices.EMPTY_SLICE);
  9. }
  10. else {
  11. VARCHAR.writeSlice(blockBuilder, Slices.wrappedBuffer(binary.getBytes()));
  12. }
  13. }
  14. else {
  15. blockBuilder.appendNull();
  16. }
  17. }
  18. }

相关文章