Skip to content
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

GH-317: [Java] add recipe for vector schema root appender cases #318

Merged
merged 8 commits into from
Sep 4, 2023

Conversation

davisusanibar
Copy link
Contributor

To solve #317

import org.apache.arrow.vector.ipc.ArrowReader;
import org.apache.arrow.vector.util.VectorSchemaRootAppender;

VectorSchemaRoot appendVectorSchemaRootAsOne(BufferAllocator allocator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer if we just constructed the vectors in-memory instead of having to pull in dataset for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Parquet file with three row groups, gets the three vectors separately, and then
appends the three vectors together:

There will be another cases of integration w
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cut off?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted

Comment on lines 29 to 32
In some cases, VectorSchemaRoot needs to be modeled as a container. To accomplish
this, you can use ``VectorSchemaRootAppender.append``. The following code reads a
Parquet file with three row groups, gets the three vectors separately, and then
appends the three vectors together:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text needs updating

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 48 to 67
try (
IntVector appenderOne = new IntVector("column",
allocator);
IntVector appenderTwo = new IntVector("column",
allocator)
) {
appenderOne.allocateNew(2);
appenderOne.set(0, 100);
appenderOne.set(1, 20);
appenderOne.setValueCount(2);
appenderTwo.allocateNew(2);
appenderTwo.set(0, 34);
appenderTwo.set(1, 75);
appenderTwo.setValueCount(2);
try (
final VectorSchemaRoot rootOne = new VectorSchemaRoot(
Collections.singletonList(appenderOne));
final VectorSchemaRoot rootTwo = new VectorSchemaRoot(
Collections.singletonList(appenderTwo))
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so much nesting? This can be written more clearly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

final VectorSchemaRoot rootTwo = new VectorSchemaRoot(
Collections.singletonList(appenderTwo))
) {
if (result == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result is always null...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

VectorSchemaRootAppender.append(result, rootOne, rootTwo);
System.out.print(result.contentToTSVString());
}
result.close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-with-resources

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

appenderTwo.set(1, 75);
appenderTwo.setValueCount(2);
try (
final VectorSchemaRoot rootOne = new VectorSchemaRoot(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just use a schema and VectorSchemaRoot.create to get rid of the nesting here by initializing everything in the top-level try-with-resources

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

java/source/data.rst Outdated Show resolved Hide resolved
java/source/data.rst Outdated Show resolved Hide resolved
@lidavidm lidavidm merged commit c20eea0 into apache:main Sep 4, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants