in java/core/src/java/org/apache/orc/impl/writer/TreeWriter.java [62:193]
void writeRootBatch(VectorizedRowBatch batch, int offset,
int length) throws IOException;
/**
* Write a ColumnVector to the file. This is called recursively by
* writeRootBatch.
* @param vector the data to write
* @param offset the first value offset to write.
* @param length the number of values to write
*/
void writeBatch(ColumnVector vector, int offset,
int length) throws IOException;
/**
* Create a row index entry at the current point in the stripe.
*/
void createRowIndexEntry() throws IOException;
/**
* Flush the TreeWriter stream
* @throws IOException
*/
void flushStreams() throws IOException;
/**
* Write the stripe out to the file.
* @param requiredIndexEntries the number of index entries that are
* required. this is to check to make sure the
* row index is well formed.
*/
void writeStripe(int requiredIndexEntries) throws IOException;
/**
* During a stripe append, we need to handle the stripe statistics.
* @param stripeStatistics the statistics for the new stripe across the
* encryption variants
*/
void addStripeStatistics(StripeStatistics[] stripeStatistics
) throws IOException;
/**
* Write the FileStatistics for each column in each encryption variant.
*/
void writeFileStatistics() throws IOException;
/**
* Get the current file statistics for each column. If a column is encrypted,
* the encrypted variant statistics are used.
* @param output an array that is filled in with the results
*/
void getCurrentStatistics(ColumnStatistics[] output);
class Factory {
/**
* Create a new tree writer for the given types and insert encryption if
* required.
* @param schema the type to build a writer for
* @param encryption the encryption status
* @param streamFactory the writer context
* @return a new tree writer
*/
public static TreeWriter create(TypeDescription schema,
WriterEncryptionVariant encryption,
WriterContext streamFactory) throws IOException {
if (encryption == null) {
// If we are the root of an encryption variant, create a special writer.
encryption = streamFactory.getEncryption(schema.getId());
if (encryption != null) {
return new EncryptionTreeWriter(schema, encryption, streamFactory);
}
}
return createSubtree(schema, encryption, streamFactory);
}
/**
* Create a subtree without inserting encryption nodes
* @param schema the schema to create
* @param encryption the encryption variant
* @param streamFactory the writer context
* @return a new tree writer
*/
static TreeWriter createSubtree(TypeDescription schema,
WriterEncryptionVariant encryption,
WriterContext streamFactory) throws IOException {
OrcFile.Version version = streamFactory.getVersion();
switch (schema.getCategory()) {
case BOOLEAN:
return new BooleanTreeWriter(schema, encryption, streamFactory);
case BYTE:
return new ByteTreeWriter(schema, encryption, streamFactory);
case SHORT:
case INT:
case LONG:
return new IntegerTreeWriter(schema, encryption, streamFactory);
case FLOAT:
return new FloatTreeWriter(schema, encryption, streamFactory);
case DOUBLE:
return new DoubleTreeWriter(schema, encryption, streamFactory);
case STRING:
return new StringTreeWriter(schema, encryption, streamFactory);
case CHAR:
return new CharTreeWriter(schema, encryption, streamFactory);
case VARCHAR:
return new VarcharTreeWriter(schema, encryption, streamFactory);
case BINARY:
return new BinaryTreeWriter(schema, encryption, streamFactory);
case TIMESTAMP:
return new TimestampTreeWriter(schema, encryption, streamFactory, false);
case TIMESTAMP_INSTANT:
return new TimestampTreeWriter(schema, encryption, streamFactory, true);
case DATE:
return new DateTreeWriter(schema, encryption, streamFactory);
case DECIMAL:
if (version == OrcFile.Version.UNSTABLE_PRE_2_0 &&
schema.getPrecision() <= TypeDescription.MAX_DECIMAL64_PRECISION) {
return new Decimal64TreeWriter(schema, encryption, streamFactory);
}
return new DecimalTreeWriter(schema, encryption, streamFactory);
case STRUCT:
return new StructTreeWriter(schema, encryption, streamFactory);
case MAP:
return new MapTreeWriter(schema, encryption, streamFactory);
case LIST:
return new ListTreeWriter(schema, encryption, streamFactory);
case UNION:
return new UnionTreeWriter(schema, encryption, streamFactory);
default:
throw new IllegalArgumentException("Bad category: " +
schema.getCategory());
}
}
}