Basic Usage
Creating Records
To use Carpet, start by defining your data structure using Java records. You don't need to generate classes or inherit from Carpet classes:
Carpet provides a writer and a reader with a default configuration and convenience methods.
Writing to Parquet
Carpet can use reflection to define the Parquet file schema and writes all the content of your objects into the file:
List<MyRecord> data = calculateDataToPersist();
try (OutputStream outputStream = new FileOutputStream("my_file.parquet")) {
try (CarpetWriter<MyRecord> writer = new CarpetWriter<>(outputStream, MyRecord.class)) {
writer.write(data);
}
}
Reading from Parquet
To read a Parquet file, you just need to provide a File and Record class that matches the Parquet schema:
Reading as Map
If you don't know the schema of the file, or a Map is valid for your use case, you can deserialize to Map<String, Object>
:
Next Steps
Once you're familiar with the basics, you can explore more advanced features:
- Writer API for detailed write operations
- Reader API for reading capabilities
- Data Types for supported data types and nested structures
- Configuration for customizing Parquet settings