diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/OutStream.java b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/OutStream.java index ef1b6b6..e2096eb 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/io/orc/OutStream.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/io/orc/OutStream.java @@ -240,8 +240,8 @@ public void flush() throws IOException { if (compressed != null && compressed.position() != 0) { compressed.flip(); receiver.output(compressed); - compressed = null; } + compressed = null; uncompressedBytes = 0; compressedBytes = 0; overflow = null; diff --git a/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOutStream.java b/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOutStream.java new file mode 100644 index 0000000..58c1bfb --- /dev/null +++ b/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOutStream.java @@ -0,0 +1,41 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.io.orc; + +import org.junit.Test; +import org.mockito.Mockito; + +import java.nio.ByteBuffer; + +import static org.junit.Assert.assertEquals; + +public class TestOutStream { + @Test + public void testFlush() throws Exception { + OutStream.OutputReceiver receiver = + Mockito.mock(OutStream.OutputReceiver.class); + CompressionCodec codec = new ZlibCodec(); + OutStream stream = new OutStream("test", 128*1024, codec, receiver); + assertEquals(0L, stream.getBufferSize()); + stream.write(new byte[]{0, 1, 2}); + stream.flush(); + Mockito.verify(receiver).output(Mockito.any(ByteBuffer.class)); + assertEquals(0L, stream.getBufferSize()); + } +} \ No newline at end of file