-
Couldn't load subscription status.
- Fork 3.9k
ARROW-12012: [Java][JDBC] Fix BinaryConsumer reallocation #9744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...apter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/AbstractConsumerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * 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.arrow.adapter.jdbc.consumer; | ||
|
|
||
| import org.apache.arrow.memory.BufferAllocator; | ||
| import org.apache.arrow.memory.RootAllocator; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
|
|
||
| public abstract class AbstractConsumerTest { | ||
|
|
||
| protected BufferAllocator allocator; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| allocator = new RootAllocator(Long.MAX_VALUE); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| allocator.close(); | ||
| } | ||
|
|
||
| } |
117 changes: 117 additions & 0 deletions
117
...adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/consumer/BinaryConsumerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| * 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.arrow.adapter.jdbc.consumer; | ||
|
|
||
| import static org.junit.Assert.assertArrayEquals; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.io.IOException; | ||
|
|
||
| import org.apache.arrow.vector.BaseValueVector; | ||
| import org.apache.arrow.vector.VarBinaryVector; | ||
| import org.junit.Test; | ||
|
|
||
| public class BinaryConsumerTest extends AbstractConsumerTest { | ||
|
|
||
| private static final int INITIAL_VALUE_ALLOCATION = BaseValueVector.INITIAL_VALUE_ALLOCATION; | ||
| private static final int DEFAULT_RECORD_BYTE_COUNT = 8; | ||
|
|
||
| interface InputStreamConsumer { | ||
| void consume(BinaryConsumer consumer) throws IOException; | ||
| } | ||
|
|
||
| protected void assertConsume(boolean nullable, InputStreamConsumer dataConsumer, byte[][] expect) throws IOException { | ||
| try (final VarBinaryVector vector = new VarBinaryVector("binary", allocator)) { | ||
| BinaryConsumer consumer = BinaryConsumer.createConsumer(vector, 0, nullable); | ||
| dataConsumer.consume(consumer); | ||
| assertEquals(expect.length - 1, vector.getLastSet()); | ||
| for (int i = 0; i < expect.length; i++) { | ||
| byte[] value = expect[i]; | ||
| if (value == null) { | ||
| assertTrue(vector.isNull(i)); | ||
| } else { | ||
| assertArrayEquals(expect[i], vector.get(i)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private byte[] createBytes(int length) { | ||
| byte[] bytes = new byte[length]; | ||
| for (int i = 0; i < length; i++) { | ||
| bytes[i] = (byte) (i % 1024); | ||
| } | ||
| return bytes; | ||
| } | ||
|
|
||
|
|
||
| public void testConsumeInputStream(byte[][] values, boolean nullable) throws IOException { | ||
| assertConsume(nullable, binaryConsumer -> { | ||
| for (byte[] value : values) { | ||
| binaryConsumer.consume(new ByteArrayInputStream(value)); | ||
| binaryConsumer.moveWriterPosition(); | ||
| } | ||
| }, values); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConsumeInputStream() throws IOException { | ||
| testConsumeInputStream(new byte[][]{ | ||
| createBytes(DEFAULT_RECORD_BYTE_COUNT) | ||
| }, false); | ||
|
|
||
| testConsumeInputStream(new byte[][]{ | ||
| createBytes(DEFAULT_RECORD_BYTE_COUNT), | ||
| createBytes(DEFAULT_RECORD_BYTE_COUNT) | ||
| }, false); | ||
|
|
||
| testConsumeInputStream(new byte[][]{ | ||
| createBytes(DEFAULT_RECORD_BYTE_COUNT * 2), | ||
| createBytes(DEFAULT_RECORD_BYTE_COUNT), | ||
| createBytes(DEFAULT_RECORD_BYTE_COUNT) | ||
| }, false); | ||
|
|
||
| testConsumeInputStream(new byte[][]{ | ||
| createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT) | ||
| }, false); | ||
|
|
||
| testConsumeInputStream(new byte[][]{ | ||
| createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT * 10), | ||
| }, false); | ||
zxf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| testConsumeInputStream(new byte[][]{ | ||
| createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT), | ||
| createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT) | ||
| }, false); | ||
|
|
||
| testConsumeInputStream(new byte[][]{ | ||
| createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT), | ||
| createBytes(DEFAULT_RECORD_BYTE_COUNT), | ||
| createBytes(INITIAL_VALUE_ALLOCATION * DEFAULT_RECORD_BYTE_COUNT) | ||
| }, false); | ||
|
|
||
| byte[][] testRecords = new byte[INITIAL_VALUE_ALLOCATION * 2][]; | ||
| for (int i = 0; i < testRecords.length; i++) { | ||
| testRecords[i] = createBytes(DEFAULT_RECORD_BYTE_COUNT); | ||
| } | ||
| testConsumeInputStream(testRecords, false); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.