diff --git a/java/core/src/java/org/apache/orc/impl/PhysicalFsWriter.java b/java/core/src/java/org/apache/orc/impl/PhysicalFsWriter.java index 47744dce23..ad6c19878e 100644 --- a/java/core/src/java/org/apache/orc/impl/PhysicalFsWriter.java +++ b/java/core/src/java/org/apache/orc/impl/PhysicalFsWriter.java @@ -57,7 +57,7 @@ public class PhysicalFsWriter implements PhysicalWriter { // a protobuf outStream around streamFactory private CodedOutputStream codedCompressStream; - private final Path path; + private Path path; private final HadoopShims shims; private final long blockSize; private final int maxPadding; @@ -91,7 +91,18 @@ public PhysicalFsWriter(FileSystem fs, OrcFile.WriterOptions opts, WriterEncryptionVariant[] encryption ) throws IOException { + this(fs.create(path, opts.getOverwrite(), HDFS_BUFFER_SIZE, + fs.getDefaultReplication(path), opts.getBlockSize()), opts, encryption); this.path = path; + LOG.info("ORC writer created for path: {} with stripeSize: {} blockSize: {}" + + " compression: {}", path, opts.getStripeSize(), blockSize, compress); + } + + public PhysicalFsWriter(FSDataOutputStream outputStream, + OrcFile.WriterOptions opts, + WriterEncryptionVariant[] encryption + ) throws IOException { + this.rawWriter = outputStream; long defaultStripeSize = opts.getStripeSize(); this.addBlockPadding = opts.getBlockPadding(); if (opts.isEnforceBufferSize()) { @@ -109,10 +120,6 @@ public PhysicalFsWriter(FileSystem fs, this.compressionStrategy = opts.getCompressionStrategy(); this.maxPadding = (int) (opts.getPaddingTolerance() * defaultStripeSize); this.blockSize = opts.getBlockSize(); - LOG.info("ORC writer created for path: {} with stripeSize: {} blockSize: {}" + - " compression: {}", path, defaultStripeSize, blockSize, compress); - rawWriter = fs.create(path, opts.getOverwrite(), HDFS_BUFFER_SIZE, - fs.getDefaultReplication(path), blockSize); blockOffset = 0; unencrypted = new VariantTracker(opts.getSchema(), compress); writeVariableLengthBlocks = opts.getWriteVariableLengthBlocks(); @@ -763,6 +770,10 @@ public void writeStatistics(StreamName name, @Override public String toString() { - return path.toString(); + if (path != null) { + return path.toString(); + } else { + return ByteString.EMPTY.toString(); + } } }