org.apache.orc.OrcProto Java Examples

The following examples show how to use org.apache.orc.OrcProto. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 6 votes vote down vote up
@Override
void startStripe(Map<org.apache.orc.impl.StreamName, InStream> streams,
                 OrcProto.StripeFooter stripeFooter
) throws IOException {
  // For each stripe, checks the encoding and initializes the appropriate
  // reader
  switch (stripeFooter.getColumnsList().get(columnId).getKind()) {
    case DIRECT:
    case DIRECT_V2:
      reader = new StringDirectTreeReader(columnId);
      break;
    case DICTIONARY:
    case DICTIONARY_V2:
      reader = new StringDictionaryTreeReader(columnId);
      break;
    default:
      throw new IllegalArgumentException("Unsupported encoding " +
          stripeFooter.getColumnsList().get(columnId).getKind());
  }
  reader.startStripe(streams, stripeFooter);
}
 
Example #2
Source File: DremioORCRecordUtils.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
/**
 * This function is a copy of original implementation from hive-private repository
 */
@Override
public OrcProto.StripeFooter readStripeFooter(StripeInformation stripe) throws IOException {
  if (file == null) {
    open();
  }
  long offset = stripe.getOffset() + stripe.getIndexLength() + stripe.getDataLength();
  int tailLength = (int) stripe.getFooterLength();

  // read the footer
  ByteBuffer tailBuf = ByteBuffer.allocate(tailLength);
  file.readFully(offset, tailBuf.array(), tailBuf.arrayOffset(), tailLength);
  return OrcProto.StripeFooter.parseFrom(InStream.createCodedInputStream("footer",
    Lists.<DiskRange>newArrayList(new BufferChunk(tailBuf, 0)),
    tailLength, codec, bufferSize));
}
 
Example #3
Source File: PhysicalWriterImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void appendRawStripe(ByteBuffer buffer, OrcProto.StripeInformation.Builder dirEntry) throws IOException {
	long start = out.getPos();
	int length = buffer.remaining();
	long availBlockSpace = blockSize - (start % blockSize);

	// see if stripe can fit in the current hdfs block, else pad the remaining
	// space in the block
	if (length < blockSize && length > availBlockSpace &&
		addBlockPadding) {
		byte[] pad = new byte[(int) Math.min(HDFS_BUFFER_SIZE, availBlockSpace)];
		LOG.info(String.format("Padding ORC by %d bytes while merging..",
			availBlockSpace));
		start += availBlockSpace;
		while (availBlockSpace > 0) {
			int writeLen = (int) Math.min(availBlockSpace, pad.length);
			out.write(pad, 0, writeLen);
			availBlockSpace -= writeLen;
		}
	}

	out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), length);
	dirEntry.setOffset(start);
}
 
Example #4
Source File: PhysicalWriterImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public long writePostScript(OrcProto.PostScript.Builder builder) throws IOException {
	builder.setFooterLength(footerLength);
	builder.setMetadataLength(metadataLength);

	OrcProto.PostScript ps = builder.build();
	// need to write this uncompressed
	long startPosition = out.getPos();
	ps.writeTo(out);
	long length = out.getPos() - startPosition;

	if (length > 255) {
		throw new IllegalArgumentException("PostScript too large at " + length);
	}

	out.write((int) length);
	return out.getPos();
}
 
Example #5
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 6 votes vote down vote up
protected TimestampTreeReader(TimeZone timeZone, int columnId, InStream presentStream, InStream dataStream,
                              InStream nanosStream, OrcProto.ColumnEncoding encoding, boolean skipCorrupt)
    throws IOException {
  super(columnId, presentStream);
  this.skipCorrupt = skipCorrupt;
  this.baseTimestampMap = new HashMap<>();
  this.readerTimeZone = timeZone;
  this.writerTimeZone = TimeZone.getDefault();
  this.hasSameTZRules = writerTimeZone.hasSameRules(readerTimeZone);
  this.base_timestamp = getBaseTimestamp(readerTimeZone.getID());
  if (encoding != null) {
    checkEncoding(encoding);

    if (dataStream != null) {
      this.data = createIntegerReader(encoding.getKind(), dataStream, true, skipCorrupt);
    }

    if (nanosStream != null) {
      this.nanos = createIntegerReader(encoding.getKind(), nanosStream, false, skipCorrupt);
    }
  }
}
 
Example #6
Source File: RecordReaderUtils.java    From tajo with Apache License 2.0 6 votes vote down vote up
public static void addRgFilteredStreamToRanges(OrcProto.Stream stream,
                                               boolean[] includedRowGroups, boolean isCompressed, OrcProto.RowIndex index,
                                               OrcProto.ColumnEncoding encoding, OrcProto.Type type, int compressionSize, boolean hasNull,
                                               long offset, long length, DiskRangeList.CreateHelper list, boolean doMergeBuffers) {
  for (int group = 0; group < includedRowGroups.length; ++group) {
    if (!includedRowGroups[group]) continue;
    int posn = getIndexPosition(
        encoding.getKind(), type.getKind(), stream.getKind(), isCompressed, hasNull);
    long start = index.getEntry(group).getPositions(posn);
    final long nextGroupOffset;
    boolean isLast = group == (includedRowGroups.length - 1);
    nextGroupOffset = isLast ? length : index.getEntry(group + 1).getPositions(posn);

    start += offset;
    long end = offset + estimateRgEndOffset(
        isCompressed, isLast, nextGroupOffset, length, compressionSize);
    list.addOrMerge(start, end, doMergeBuffers, true);
  }
}
 
Example #7
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 6 votes vote down vote up
protected StringTreeReader(int columnId, InStream present, InStream data, InStream length,
                           InStream dictionary, OrcProto.ColumnEncoding encoding) throws IOException {
  super(columnId, present);
  if (encoding != null) {
    switch (encoding.getKind()) {
      case DIRECT:
      case DIRECT_V2:
        reader = new StringDirectTreeReader(columnId, present, data, length,
            encoding.getKind());
        break;
      case DICTIONARY:
      case DICTIONARY_V2:
        reader = new StringDictionaryTreeReader(columnId, present, data, length, dictionary,
            encoding);
        break;
      default:
        throw new IllegalArgumentException("Unsupported encoding " +
            encoding.getKind());
    }
  }
}
 
Example #8
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 6 votes vote down vote up
protected StringDictionaryTreeReader(int columnId, InStream present, InStream data,
                                     InStream length, InStream dictionary, OrcProto.ColumnEncoding encoding)
    throws IOException {
  super(columnId, present);
  scratchlcv = new LongColumnVector();
  if (data != null && encoding != null) {
    this.reader = createIntegerReader(encoding.getKind(), data, false, false);
  }

  if (dictionary != null && encoding != null) {
    readDictionaryStream(dictionary);
  }

  if (length != null && encoding != null) {
    readDictionaryLengthStream(length, encoding);
  }
}
 
Example #9
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 6 votes vote down vote up
@Override
void startStripe(Map<StreamName, InStream> streams,
                 OrcProto.StripeFooter stripeFooter
) throws IOException {
  // For each stripe, checks the encoding and initializes the appropriate
  // reader
  switch (stripeFooter.getColumnsList().get(columnId).getKind()) {
    case DIRECT:
    case DIRECT_V2:
      reader = new StringDirectTreeReader(columnId);
      break;
    case DICTIONARY:
    case DICTIONARY_V2:
      reader = new StringDictionaryTreeReader(columnId);
      break;
    default:
      throw new IllegalArgumentException("Unsupported encoding " +
          stripeFooter.getColumnsList().get(columnId).getKind());
  }
  reader.startStripe(streams, stripeFooter);
}
 
Example #10
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 6 votes vote down vote up
protected CharTreeReader(int columnId, InStream present, InStream data, InStream length,
                         InStream dictionary, OrcProto.ColumnEncoding encoding, int maxLength) throws IOException {
  super(columnId, present);
  this.maxLength = maxLength;
  if (encoding != null) {
    switch (encoding.getKind()) {
      case DIRECT:
      case DIRECT_V2:
        reader = new StringDirectTreeReader(columnId, present, data, length,
            encoding.getKind());
        break;
      case DICTIONARY:
      case DICTIONARY_V2:
        reader = new StringDictionaryTreeReader(columnId, present, data, length, dictionary,
            encoding);
        break;
      default:
        throw new IllegalArgumentException("Unsupported encoding " +
            encoding.getKind());
    }
  }
}
 
Example #11
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 6 votes vote down vote up
private void readDictionaryLengthStream(InStream in, OrcProto.ColumnEncoding encoding)
    throws IOException {
  int dictionarySize = encoding.getDictionarySize();
  if (in != null) { // Guard against empty LENGTH stream.
    IntegerReader lenReader = createIntegerReader(encoding.getKind(), in, false, false);
    int offset = 0;
    if (dictionaryOffsets == null ||
        dictionaryOffsets.length < dictionarySize + 1) {
      dictionaryOffsets = new int[dictionarySize + 1];
    }
    for (int i = 0; i < dictionarySize; ++i) {
      dictionaryOffsets[i] = offset;
      offset += (int) lenReader.next();
    }
    dictionaryOffsets[dictionarySize] = offset;
    in.close();
  }

}
 
Example #12
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 6 votes vote down vote up
@Override
void startStripe(Map<org.apache.orc.impl.StreamName, InStream> streams,
                 OrcProto.StripeFooter stripeFooter
) throws IOException {
  super.startStripe(streams, stripeFooter);

  // read the dictionary blob
  org.apache.orc.impl.StreamName name = new org.apache.orc.impl.StreamName(columnId,
      OrcProto.Stream.Kind.DICTIONARY_DATA);
  InStream in = streams.get(name);
  readDictionaryStream(in);

  // read the lengths
  name = new org.apache.orc.impl.StreamName(columnId, OrcProto.Stream.Kind.LENGTH);
  in = streams.get(name);
  readDictionaryLengthStream(in, stripeFooter.getColumnsList().get(columnId));

  // set up the row reader
  name = new org.apache.orc.impl.StreamName(columnId, OrcProto.Stream.Kind.DATA);
  reader = createIntegerReader(stripeFooter.getColumnsList().get(columnId).getKind(),
      streams.get(name), false, false);
}
 
Example #13
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
protected DateTreeReader(int columnId, InStream present, InStream data,
                         OrcProto.ColumnEncoding encoding) throws IOException {
  super(columnId, present);
  if (data != null && encoding != null) {
    checkEncoding(encoding);
    reader = createIntegerReader(encoding.getKind(), data, true, false);
  }
}
 
Example #14
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
void startStripe(Map<org.apache.orc.impl.StreamName, InStream> streams,
                 OrcProto.StripeFooter stripeFooter
) throws IOException {
  super.startStripe(streams, stripeFooter);
  org.apache.orc.impl.StreamName name = new org.apache.orc.impl.StreamName(columnId,
      OrcProto.Stream.Kind.DATA);
  reader = createIntegerReader(stripeFooter.getColumnsList().get(columnId).getKind(),
      streams.get(name), true, false);
}
 
Example #15
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
void checkEncoding(OrcProto.ColumnEncoding encoding) throws IOException {
  if ((encoding.getKind() != OrcProto.ColumnEncoding.Kind.DIRECT) &&
      (encoding.getKind() != OrcProto.ColumnEncoding.Kind.DIRECT_V2)) {
    throw new IOException("Unknown encoding " + encoding + " in column " +
        columnId);
  }
}
 
Example #16
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
void checkEncoding(OrcProto.ColumnEncoding encoding) throws IOException {
  if (encoding.getKind() != OrcProto.ColumnEncoding.Kind.DICTIONARY &&
      encoding.getKind() != OrcProto.ColumnEncoding.Kind.DICTIONARY_V2) {
    throw new IOException("Unknown encoding " + encoding + " in column " +
        columnId);
  }
}
 
Example #17
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
void startStripe(Map<org.apache.orc.impl.StreamName, InStream> streams,
                 OrcProto.StripeFooter stripeFooter
) throws IOException {
  super.startStripe(streams, stripeFooter);
  data = createIntegerReader(stripeFooter.getColumnsList().get(columnId).getKind(),
      streams.get(new org.apache.orc.impl.StreamName(columnId,
          OrcProto.Stream.Kind.DATA)), true, skipCorrupt);
  nanos = createIntegerReader(stripeFooter.getColumnsList().get(columnId).getKind(),
      streams.get(new org.apache.orc.impl.StreamName(columnId,
          OrcProto.Stream.Kind.SECONDARY)), false, skipCorrupt);
  base_timestamp = getBaseTimestamp(stripeFooter.getWriterTimezone());
}
 
Example #18
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
void checkEncoding(OrcProto.ColumnEncoding encoding) throws IOException {
  if ((encoding.getKind() != OrcProto.ColumnEncoding.Kind.DIRECT) &&
      (encoding.getKind() != OrcProto.ColumnEncoding.Kind.DIRECT_V2)) {
    throw new IOException("Unknown encoding " + encoding + " in column " +
        columnId);
  }
}
 
Example #19
Source File: HiveORCVectorizedReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private int[] getOrdinalIdsOfSelectedColumns(List< OrcProto.Type > types, List<Integer> selectedColumns, boolean isOriginal) {
  int rootColumn = isOriginal ? 0 : TRANS_ROW_COLUMN_INDEX + 1;
  int[] ids = new int[types.size()];
  OrcProto.Type root = types.get(rootColumn);

  // iterating over only direct children
  for(int i = 0; i < root.getSubtypesCount(); ++i) {
    if (selectedColumns.contains(i)) {
      // find the position of this column in the types list
      ids[i] = root.getSubtypes(i);
    }
  }

  return ids;
}
 
Example #20
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
protected StringDirectTreeReader(int columnId, InStream present, InStream data,
                                 InStream length, OrcProto.ColumnEncoding.Kind encoding) throws IOException {
  super(columnId, present);
  this.scratchlcv = new LongColumnVector();
  this.stream = data;
  if (length != null && encoding != null) {
    this.lengths = createIntegerReader(encoding, length, false, false);
  }
}
 
Example #21
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
void checkEncoding(OrcProto.ColumnEncoding encoding) throws IOException {
  if (encoding.getKind() != OrcProto.ColumnEncoding.Kind.DIRECT &&
      encoding.getKind() != OrcProto.ColumnEncoding.Kind.DIRECT_V2) {
    throw new IOException("Unknown encoding " + encoding + " in column " +
        columnId);
  }
}
 
Example #22
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
void startStripe(Map<org.apache.orc.impl.StreamName, InStream> streams,
                 OrcProto.StripeFooter stripeFooter
) throws IOException {
  super.startStripe(streams, stripeFooter);
  org.apache.orc.impl.StreamName name = new org.apache.orc.impl.StreamName(columnId,
      OrcProto.Stream.Kind.DATA);
  stream = streams.get(name);
  data = new BasicTextReaderShim(stream);

  lengths = createIntegerReader(stripeFooter.getColumnsList().get(columnId).getKind(),
      streams.get(new org.apache.orc.impl.StreamName(columnId, OrcProto.Stream.Kind.LENGTH)),
      false, false);
}
 
Example #23
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
void startStripe(Map<org.apache.orc.impl.StreamName, InStream> streams,
                 OrcProto.StripeFooter stripeFooter
) throws IOException {
  super.startStripe(streams, stripeFooter);
  org.apache.orc.impl.StreamName name = new org.apache.orc.impl.StreamName(columnId,
      OrcProto.Stream.Kind.DATA);
  stream = streams.get(name);
  lengths = createIntegerReader(stripeFooter.getColumnsList().get(columnId).getKind(),
      streams.get(new org.apache.orc.impl.StreamName(columnId, OrcProto.Stream.Kind.LENGTH)), false, false);
}
 
Example #24
Source File: PhysicalWriterImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void writeIndex(StreamName name, OrcProto.RowIndex.Builder index,
						CompressionCodec codec) throws IOException {
	OutputStream stream = new OutStream(this.toString(), bufferSize, codec, createDataStream(name));
	index.build().writeTo(stream);
	stream.flush();
}
 
Example #25
Source File: PhysicalWriterImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void writeBloomFilter(StreamName name, OrcProto.BloomFilterIndex.Builder bloom,
							CompressionCodec codec) throws IOException {
	OutputStream stream = new OutStream(this.toString(), bufferSize, codec, createDataStream(name));
	bloom.build().writeTo(stream);
	stream.flush();
}
 
Example #26
Source File: PhysicalWriterImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void writeFileMetadata(OrcProto.Metadata.Builder builder) throws IOException {
	long startPosition = out.getPos();
	OrcProto.Metadata metadata = builder.build();
	metadata.writeTo(protobufWriter);
	protobufWriter.flush();
	writer.flush();
	this.metadataLength = (int) (out.getPos() - startPosition);
}
 
Example #27
Source File: PhysicalWriterImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void writeFileFooter(OrcProto.Footer.Builder builder) throws IOException {
	long bodyLength = out.getPos() - metadataLength;
	builder.setContentLength(bodyLength);
	builder.setHeaderLength(headerLength);
	long startPosition = out.getPos();
	OrcProto.Footer footer = builder.build();
	footer.writeTo(protobufWriter);
	protobufWriter.flush();
	writer.flush();
	this.footerLength = (int) (out.getPos() - startPosition);
}
 
Example #28
Source File: PhysicalWriterImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
private void writeStripeFooter(OrcProto.StripeFooter footer, long dataSize,
								long indexSize, OrcProto.StripeInformation.Builder dirEntry) throws IOException {
	footer.writeTo(protobufWriter);
	protobufWriter.flush();
	writer.flush();

	dirEntry.setOffset(stripeStart);
	dirEntry.setFooterLength(out.getPos() - stripeStart - dataSize - indexSize);
}
 
Example #29
Source File: TreeReaderFactory.java    From tajo with Apache License 2.0 5 votes vote down vote up
protected BinaryTreeReader(int columnId, InStream present, InStream data, InStream length,
                           OrcProto.ColumnEncoding encoding) throws IOException {
  super(columnId, present);
  scratchlcv = new LongColumnVector();
  this.stream = data;
  if (length != null && encoding != null) {
    checkEncoding(encoding);
    this.lengths = createIntegerReader(encoding.getKind(), length, false, false);
  }
}
 
Example #30
Source File: HiveORCVectorizedReader.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private int[] getOrdinalIdsOfSelectedColumns(List< OrcProto.Type > types, List<Integer> selectedColumns, boolean isOriginal) {
  int rootColumn = isOriginal ? 0 : TRANS_ROW_COLUMN_INDEX + 1;
  int[] ids = new int[types.size()];
  OrcProto.Type root = types.get(rootColumn);

  // iterating over only direct children
  for(int i = 0; i < root.getSubtypesCount(); ++i) {
    if (selectedColumns.contains(i)) {
      // find the position of this column in the types list
      ids[i] = root.getSubtypes(i);
    }
  }

  return ids;
}