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

[Java] Adding java read compression files with LZ4 codec #289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions java/source/demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<artifactId>arrow-avro</artifactId>
<version>${arrow.version}</version>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-compression</artifactId>
<version>${arrow.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
59 changes: 59 additions & 0 deletions java/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,65 @@ We are providing a path with auto generated arrow files for testing purposes, ch
Jhon 29
Thomy 33

Read - From Compressed File
---------------------------

We are providing a path with auto generated arrow files for testing purposes, change that at your convenience.
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to provide a write-compressed-file example too?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. There's no practical way to write a compressed file.


Compressed file generated through this code example:

.. code:: python

import pandas as pd
import pyarrow as pa

pd.DataFrame({'key': range(4)}).to_feather('lz4.arrow', compression='lz4')
pd.DataFrame({'key': range(4)}).to_feather('zstd.arrow', compression='zstd')
Copy link
Member

Choose a reason for hiding this comment

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

This isn't checked in?


.. note::

Java Vector module offer read files without compression codec, in case reading
compressed files is required consider to also add Java Compression module
dependency.
Comment on lines +340 to +342
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Java Vector module offer read files without compression codec, in case reading
compressed files is required consider to also add Java Compression module
dependency.
The ``arrow-vector`` module can only read uncompressed files by itself. Add
a dependency on ``arrow-compression`` to also be able to read compressed files.


.. testcode::

import org.apache.arrow.compression.CommonsCompressionFactory;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.ipc.ArrowFileReader;
import org.apache.arrow.vector.ipc.message.ArrowBlock;
import org.apache.arrow.vector.VectorSchemaRoot;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

File file = new File("./thirdpartydeps/arrowfiles/lz4.arrow");
try(
BufferAllocator rootAllocator = new RootAllocator();
FileInputStream fileInputStream = new FileInputStream(file);
ArrowFileReader reader = new ArrowFileReader(fileInputStream.getChannel(),
rootAllocator, CommonsCompressionFactory.INSTANCE)
){
System.out.println("Record batches in file: " + reader.getRecordBlocks().size());
for (ArrowBlock arrowBlock : reader.getRecordBlocks()) {
reader.loadRecordBatch(arrowBlock);
VectorSchemaRoot vectorSchemaRootRecover = reader.getVectorSchemaRoot();
System.out.print(vectorSchemaRootRecover.contentToTSVString());
}
} catch (IOException e) {
e.printStackTrace();
}

.. testoutput::

Record batches in file: 1
key
0
1
2
3

Read - From Buffer
------------------

Expand Down
Binary file added java/thirdpartydeps/arrowfiles/lz4.arrow
Binary file not shown.