Parquet.Net
4.8.0-alpha-00
See the version list below for details.
dotnet add package Parquet.Net --version 4.8.0-alpha-00
NuGet\Install-Package Parquet.Net -Version 4.8.0-alpha-00
<PackageReference Include="Parquet.Net" Version="4.8.0-alpha-00" />
paket add Parquet.Net --version 4.8.0-alpha-00
#r "nuget: Parquet.Net, 4.8.0-alpha-00"
// Install Parquet.Net as a Cake Addin #addin nuget:?package=Parquet.Net&version=4.8.0-alpha-00&prerelease // Install Parquet.Net as a Cake Tool #tool nuget:?package=Parquet.Net&version=4.8.0-alpha-00&prerelease
Apache Parquet for .NET
Fully managed, safe, extremely fast .NET library to 📖read and ✍️write Apache Parquet files designed for .NET world (not a wrapper). Targets .NET 7
, .NET 6.0
, .NET Core 3.1
, .NET Standard 2.1
and .NET Standard 2.0
.
Whether you want to build apps for Linux, MacOS, Windows, iOS, Android, Tizen, Xbox, PS4, Raspberry Pi, Samsung TVs or much more, Parquet.NET has you covered.
Index
Diving Deeper
Integration with Microsoft.Data.Analysis.
Make sure to check out Apache Parquet Viewer built with this library:
Why
Parquet is a great format for storing and processing large amounts of data, but it can be tricky to use with .NET. That's why this library is here to help. It's a pure library that doesn't need any external dependencies, and it's super fast - faster than Python and Java, and other C# solutions. It's also native to .NET, so you don't have to deal with any wrappers or adapters that might slow you down or limit your options.
This library is the best option for parquet files in .NET. It has a simple and intuitive API, supports all the parquet features you need, and handles complex scenarios with ease.
Also it:
- Has zero dependencies - pure library that just works.
- Really fast. Faster than Python and Java, and alternative C# implementations out there. It's often even faster than native C++ implementations.
- .NET native. Designed to utilise .NET and made for .NET developers, not the other way around.
- Not a "wrapper" that forces you to fit in. It's the other way around - forces parquet to fit into .NET.
Quick Start
Parquet is designed to handle complex data in bulk. It's column-oriented meaning that data is physically stored in columns rather than rows. This is very important for big data systems if you want to process only a subset of columns - reading just the right columns is extremely efficient.
As a quick start, suppose we have the following data records we'd like to save to parquet:
- Timestamp.
- Event name.
- Meter value.
Or, to translate it to C# terms, this can be expressed as the following class:
class Record {
public DateTime Timestamp { get; set; }
public string EventName { get; set; }
public double MeterValue { get; set; }
}
✍️Writing Data
Let's say you have around a million of events like that to save to a .parquet
file. There are three ways to do that with this library, starting from easiest to hardest.
🚤Class Serialisation
The first one is the easiest to work with, and the most straightforward. Let's generate those million fake records:
var data = Enumerable.Range(0, 1_000_000).Select(i => new Record {
Timestamp = DateTime.UtcNow.AddSeconds(i),
EventName = i % 2 == 0 ? "on" : "off",
MeterValue = i
}).ToList();
Now, to write these to a file in say /mnt/storage/data.parquet
you can use the following line of code:
await ParquetSerializer.SerializeAsync(data, "/mnt/storage/data.parquet");
That's pretty much it! You can customise many things in addition to the magical magic process, but if you are a really lazy person that will do just fine for today.
🌛Row Based API
Another way to serialise data is to use row-based API. They look at your data as a Table
, which consists of a set of Row
s. Basically looking at the data backwards from the point of view of how Parquet format sees it. However, that's how most people think about data. This is also useful when converting data from row-based formats to parquet and vice versa. Anyway, use it, I won't judge you (very often).
Let's generate a million of rows for our table, which is slightly more complicated. First, we need to declare table and it's schema:
var table = new Table(
new DataField<DateTime>("Timestamp"),
new DataField<string>("EventName"),
new DataField<double>("MeterName"));
The code above says we are creating a new empty table with 3 fields, identical to example above with class serialisation. We are essentially declaring table's schema here. Parquet format is strongly typed and all the rows will have to have identical amount of values and their types.
Now that empty table is ready, add a million rows to it:
for(int i = 0; i < 1_000_000; i++) {
table.Add(
DateTime.UtcNow.AddSeconds(1),
i % 2 == 0 ? "on" : "off",
(double)i);
}
The data will be identical to example above. And to write the table to a file:
await table.WriteAsync("/mnt/storage/data.parquet");
Of course this is a trivial example, and you can customise it further.
⚙️Low Level API
And finally, the lowest level API is the third method. This is the most performant, most Parquet-resembling way to work with data, but least intuitive and involves some knowledge of Parquet data structures.
First of all, you need schema. Always. Just like in row-based example, schema can be declared in the following way:
var schema = new ParquetSchema(
new DataField<DateTime>("Timestamp"),
new DataField<string>("EventName"),
new DataField<double>("MeterName"));
Then, data columns need to be prepared for writing. As parquet is column-based format, low level APIs expect that low level column slice of data. I'll just shut up and show you the code:
var column1 = new DataColumn(
schema.DataFields[0],
Enumerable.Range(0, 1_000_000).Select(i => DateTime.UtcNow.AddSeconds(i)).ToArray());
var column2 = new DataColumn(
schema.DataFields[1],
Enumerable.Range(0, 1_000_000).Select(i => i % 2 == 0 ? "on" : "off").ToArray());
var column3 = new DataColumn(
schema.DataFields[2],
Enumerable.Range(0, 1_000_000).Select(i => (double)i).ToArray());
Important thing to note here - columnX
variables represent data in an entire column, all the values in that column independently from other columns. Values in other columns have the same order as well. So we have created three columns with data identical to the two examples above.
Time to write it down:
using(Stream fs = System.IO.File.OpenWrite("/mnt/storage/data.parquet")) {
using(ParquetWriter writer = await ParquetWriter.CreateAsync(schema, fs)) {
using(ParquetRowGroupWriter groupWriter = writer.CreateRowGroup()) {
await groupWriter.WriteColumnAsync(column1);
await groupWriter.WriteColumnAsync(column2);
await groupWriter.WriteColumnAsync(column3);
}
}
}
What's going on?:?:
- We are creating output file stream. You can probably use one of the overloads in the next line though. This will be the receiver of parquet data. The stream needs to be writeable and seekable.
ParquetWriter
is low-level class and is a root object to start writing from. It mostly performs coordination, check summing and enveloping of other data.- Row group is like a data partition inside the file. In this example we have just one, but you can create more if there are too many values that are hard to fit in computer memory.
- Three calls to row group writer write out the columns. Note that those are performed sequentially, and in the same order as schema defines them.
Read more on writing here which also includes guides on writing nested types such as lists, maps, and structs.
📖Reading Data
Reading data also has three different approaches, so I'm going to unwrap them here in the same order as above.
🚤Class Serialisation
Provided that you have written the data, or just have some external data with the same structure as above, you can read those by simply doing the following:
IList<Record> data = await ParquetSerializer.DeserializeAsync<Record>("/mnt/storage/data.parquet");
This will give us an array with one million class instances similar to this:
Of course class serialisation has more to it, and you can customise it further than that.
🌛Row Based API
A read counterpart to the write example above is also a simple one-liner:
Table tbl = await Table.ReadAsync("/mnt/storage/data.parquet");
This will do the magic behind the scenes, give you table schema and rows, similar to this:
As always, there's more to it.
⚙️Low Level API
And with low level API the reading is even more flexible:
using(Stream fs = System.IO.File.OpenRead("/mnt/storage/data.parquet")) {
using(ParquetReader reader = await ParquetReader.CreateAsync(fs)) {
for(int i = 0; i < reader.RowGroupCount; i++) {
using(ParquetRowGroupReader rowGroupReader = reader.OpenRowGroupReader(i)) {
foreach(DataField df in reader.Schema.GetDataFields()) {
DataColumn columnData = await rowGroupReader.ReadColumnAsync(df);
// do something to the column...
}
}
}
}
}
This is what's happening:
- Create read stream
fs
. - Create
ParquetReader
- root class for read operations. - The reader has
RowGroupCount
property which indicates how many row groups (like partitions) the file contains. - Explicitly open row group for reading.
- Read each
DataField
from the row group, in the same order as it's declared in the schema.
Hint: you can also use web based reader app to test your files, which was created using this library!
Choosing the API
If you have a choice, then the choice is easy - use Low Level API. They are the fastest and the most flexible. But what if you for some reason don't have a choice? Then think about this:
Feature | 🚤Class Serialisation | 🌛Table API | ⚙️Low Level API |
---|---|---|---|
Performance | high | very low | very high |
Developer Convenience | C# native | feels like Excel | close to Parquet internals |
Row based access | easy | easy | hard |
Column based access | C# native | hard | easy |
Contributing
Any contributions are welcome, in any form. Documentation, code, tests, donations or anything else. I don't like processes so anything goes. If you happen to get interested in parquet development, there are some interesting links. The first important thing you can do is simply star ⭐ this project.
Special Thanks
Without these tools development would be really painful.
- Visual Studio Community - free IDE from Microsoft. The best in class C# and C++ development tool. It's worth using Windows just because Visual Studio exists there.
- JetBrains Rider - for their cross-platform C# IDE, which has some great features.
- IntelliJ IDEA - the best Python, Scala and Java IDE.
- LINQPad - extremely powerful C# REPL with unique visualisation features, IL decompiler, expression tree visualiser, benchmarking, charting and so on. Again it's worth having Windows just for this tool. Please support the author and purchase it.
- Benchmarkdotnet - the best cross-platform tool that can microbenchmark C# code. This library is faster than native ones only thanks for this.
- You starring ⭐ this project!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- IronCompress (>= 1.3.0)
- Microsoft.Data.Analysis (>= 0.20.1)
- Microsoft.IO.RecyclableMemoryStream (>= 2.3.2)
-
.NETStandard 2.0
- IronCompress (>= 1.3.0)
- Microsoft.Data.Analysis (>= 0.20.1)
- Microsoft.IO.RecyclableMemoryStream (>= 2.3.2)
- System.Reflection.Emit.Lightweight (>= 4.7.0)
- System.Text.Json (>= 7.0.2)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
.NETStandard 2.1
- IronCompress (>= 1.3.0)
- Microsoft.Data.Analysis (>= 0.20.1)
- Microsoft.IO.RecyclableMemoryStream (>= 2.3.2)
- System.Text.Json (>= 7.0.2)
-
net6.0
- IronCompress (>= 1.3.0)
- Microsoft.Data.Analysis (>= 0.20.1)
- Microsoft.IO.RecyclableMemoryStream (>= 2.3.2)
-
net7.0
- IronCompress (>= 1.3.0)
- Microsoft.Data.Analysis (>= 0.20.1)
- Microsoft.IO.RecyclableMemoryStream (>= 2.3.2)
NuGet packages (30)
Showing the top 5 NuGet packages that depend on Parquet.Net:
Package | Downloads |
---|---|
ChoETL.Parquet
Parquet extension to Cinchoo ETL framework |
|
Microsoft.DataPrep
Microsoft Azure Machine Learning Data Preparation SDK. |
|
Komodo.Core
Komodo core libraries for crawling (file, object, web, database), parsing (JSON, XML, SQL, Sqlite, HTML, text), postings (inverted index, token extraction), indexing (search), metadata generation, and integrating within your application. Komodo is an information search, metadata, storage, and retrieval platform. |
|
PCAxis.Serializers
Paxiom serializers for formats like Excel, jsonstat, jsonstat2, sdmx |
|
Microsoft.ML.Parquet
ML.NET components for Apache Parquet support. |
GitHub repositories (8)
Showing the top 5 popular GitHub repositories that depend on Parquet.Net:
Repository | Stars |
---|---|
dotnet/machinelearning
ML.NET is an open source and cross-platform machine learning framework for .NET.
|
|
ravendb/ravendb
ACID Document Database
|
|
Cinchoo/ChoETL
ETL framework for .NET (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
|
|
mukunku/ParquetViewer
Simple Windows desktop application for viewing & querying Apache Parquet files
|
|
compomics/ThermoRawFileParser
Thermo RAW file parser that runs on Linux/Mac and all other platforms that support Mono
|
Version | Downloads | Last updated |
---|---|---|
5.0.3-pre.3 | 294 | 12/4/2024 |
5.0.3-pre.2 | 70 | 12/3/2024 |
5.0.3-pre.1 | 155 | 11/19/2024 |
5.0.2 | 55,483 | 11/14/2024 |
5.0.2-pre.2 | 436 | 11/12/2024 |
5.0.2-pre.1 | 88 | 11/11/2024 |
5.0.1 | 90,132 | 10/14/2024 |
5.0.1-pre.1 | 936 | 10/3/2024 |
5.0.0 | 22,119 | 10/3/2024 |
5.0.0-pre.4 | 70 | 10/2/2024 |
5.0.0-pre.3 | 65 | 10/2/2024 |
5.0.0-pre.2 | 721 | 9/30/2024 |
5.0.0-pre.1 | 134 | 9/23/2024 |
4.25.0 | 112,186 | 9/9/2024 |
4.25.0-pre.3 | 151 | 9/6/2024 |
4.25.0-pre.2 | 2,911 | 6/11/2024 |
4.25.0-pre.1 | 110 | 6/7/2024 |
4.24.0 | 361,497 | 6/6/2024 |
4.24.0-pre.8 | 79 | 6/4/2024 |
4.24.0-pre.7 | 77 | 6/4/2024 |
4.24.0-pre.6 | 82 | 6/3/2024 |
4.24.0-pre.5 | 63 | 6/3/2024 |
4.24.0-pre.4 | 91 | 5/31/2024 |
4.24.0-pre.3 | 79 | 5/31/2024 |
4.24.0-pre.2 | 804 | 5/28/2024 |
4.24.0-pre.1 | 123 | 5/22/2024 |
4.23.5 | 250,021 | 4/4/2024 |
4.23.4 | 500,863 | 2/2/2024 |
4.23.3 | 21,610 | 1/25/2024 |
4.23.2 | 9,712 | 1/22/2024 |
4.23.1 | 7,012 | 1/19/2024 |
4.23.0 | 2,657 | 1/18/2024 |
4.22.1 | 9,481 | 1/17/2024 |
4.22.0 | 59,179 | 1/11/2024 |
4.20.1 | 5,061 | 1/10/2024 |
4.20.0 | 14,221 | 1/8/2024 |
4.19.0 | 25,544 | 1/5/2024 |
4.18.1 | 11,665 | 12/31/2023 |
4.18.0 | 25,681 | 12/22/2023 |
4.17.0 | 302,443 | 11/14/2023 |
4.16.4 | 547,866 | 9/11/2023 |
4.16.3 | 29,116 | 9/4/2023 |
4.16.2 | 100,918 | 8/22/2023 |
4.16.1 | 4,230 | 8/21/2023 |
4.16.0 | 2,648 | 8/17/2023 |
4.15.0 | 152,228 | 6/30/2023 |
4.14.0 | 28,519 | 6/28/2023 |
4.13.0 | 89,748 | 6/20/2023 |
4.12.0 | 135,214 | 5/22/2023 |
4.11.3 | 11,243 | 5/18/2023 |
4.11.2 | 54,507 | 5/16/2023 |
4.11.1 | 36,096 | 5/10/2023 |
4.11.0 | 4,988 | 5/9/2023 |
4.10.1 | 39,641 | 5/2/2023 |
4.10.0 | 31,577 | 4/26/2023 |
4.9.2 | 2,851 | 4/25/2023 |
4.9.1 | 3,433 | 4/21/2023 |
4.9.0 | 2,207 | 4/21/2023 |
4.8.1 | 11,176 | 4/19/2023 |
4.8.0 | 2,532 | 4/18/2023 |
4.8.0-alpha-00 | 1,560 | 4/17/2023 |
4.7.1 | 6,478 | 4/14/2023 |
4.7.0 | 7,400 | 4/13/2023 |
4.6.2 | 69,722 | 3/28/2023 |
4.6.1 | 6,273 | 3/23/2023 |
4.6.0 | 12,581 | 3/21/2023 |
4.5.4 | 331,702 | 2/23/2023 |
4.5.3 | 16,938 | 2/22/2023 |
4.5.2 | 11,119 | 2/20/2023 |
4.5.1 | 8,159 | 2/14/2023 |
4.5.0 | 7,928 | 2/13/2023 |
4.4.7 | 13,713 | 2/8/2023 |
4.4.6 | 48,813 | 1/31/2023 |
4.4.5 | 3,306 | 1/30/2023 |
4.4.4 | 2,583 | 1/27/2023 |
4.4.3 | 3,532 | 1/26/2023 |
4.4.2 | 1,738 | 1/26/2023 |
4.4.1 | 2,152 | 1/25/2023 |
4.4.0 | 3,169 | 1/24/2023 |
4.3.4 | 1,974 | 1/23/2023 |
4.3.3 | 2,160 | 1/20/2023 |
4.3.2 | 2,066 | 1/19/2023 |
4.3.1 | 1,693 | 1/19/2023 |
4.3.0 | 2,719 | 1/18/2023 |
4.2.3 | 6,796 | 1/16/2023 |
4.2.2 | 10,166 | 1/11/2023 |
4.2.1 | 7,509 | 1/10/2023 |
4.2.0 | 1,970 | 1/10/2023 |
4.1.3 | 65,279 | 12/21/2022 |
4.1.2 | 29,725 | 12/1/2022 |
4.1.1 | 118,485 | 11/10/2022 |
4.1.0 | 257,602 | 10/13/2022 |
4.0.2 | 10,556 | 10/12/2022 |
4.0.1 | 28,985 | 10/11/2022 |
4.0.0 | 58,403 | 9/22/2022 |
3.10.0 | 322,239 | 9/20/2022 |
3.9.1 | 1,566,121 | 10/14/2021 |
3.9.0 | 375,909 | 6/25/2021 |
3.8.6 | 470,140 | 3/5/2021 |
3.8.5 | 26,406 | 2/23/2021 |
3.8.4 | 279,813 | 12/13/2020 |
3.8.3 | 2,408 | 12/10/2020 |
3.8.2 | 1,954 | 12/10/2020 |
3.8.1 | 31,950 | 11/6/2020 |
3.8.0 | 4,348 | 11/6/2020 |
3.7.7 | 330,737 | 6/25/2020 |
3.7.6 | 25,919 | 6/16/2020 |
3.7.5 | 14,439 | 6/8/2020 |
3.7.4 | 190,688 | 5/19/2020 |
3.7.2 | 3,894 | 5/18/2020 |
3.7.1 | 48,897 | 4/21/2020 |
3.7.0 | 60,244 | 4/19/2020 |
3.6.0 | 5,488,746 | 1/23/2020 |
3.5.3 | 14,662 | 1/8/2020 |
3.5.2 | 3,538 | 1/3/2020 |
3.5.1 | 2,258 | 12/31/2019 |
3.5.0 | 10,674 | 12/18/2019 |
3.4.3 | 7,380 | 12/16/2019 |
3.4.2 | 3,790 | 12/13/2019 |
3.4.1 | 2,189 | 12/11/2019 |
3.4.0 | 3,044 | 12/11/2019 |
3.3.11 | 6,907 | 12/1/2019 |
3.3.10 | 51,481 | 11/6/2019 |
3.3.9 | 188,644 | 8/15/2019 |
3.3.8 | 8,799 | 8/1/2019 |
3.3.7 | 2,173 | 8/1/2019 |
3.3.6 | 2,289 | 7/31/2019 |
3.3.5 | 33,953 | 7/5/2019 |
3.3.4 | 187,214 | 3/11/2019 |
3.3.3 | 20,502 | 2/1/2019 |
3.3.2 | 26,518 | 1/21/2019 |
3.3.1 | 4,610 | 1/14/2019 |
3.3.0 | 3,727 | 1/11/2019 |
3.2.6 | 2,897 | 1/11/2019 |
3.2.5 | 4,563 | 1/3/2019 |
3.2.4 | 10,977 | 11/21/2018 |
3.2.3 | 53,386 | 11/7/2018 |
3.2.2 | 5,388 | 10/30/2018 |
3.2.1 | 2,485 | 10/30/2018 |
3.2.0 | 3,186 | 10/24/2018 |
3.1.4 | 2,513 | 10/15/2018 |
3.1.3 | 2,403 | 10/15/2018 |
3.1.2 | 47,825 | 10/11/2018 |
3.1.1 | 2,875 | 10/4/2018 |
3.1.0 | 2,840 | 10/3/2018 |
3.1.0-preview-390 | 2,085 | 10/3/2018 |
3.1.0-preview-373 | 2,348 | 10/2/2018 |
3.0.5 | 9,043 | 8/13/2018 |
3.0.4 | 2,546 | 7/25/2018 |
3.0.3 | 2,400 | 7/25/2018 |
3.0.2 | 2,861 | 7/24/2018 |
3.0.1 | 2,395 | 7/24/2018 |
3.0.0 | 3,370 | 7/19/2018 |
2.1.4 | 97,190 | 6/7/2018 |
2.1.3 | 261,292 | 3/30/2018 |
2.1.2 | 445,466 | 1/10/2018 |
2.1.1 | 120,457 | 12/1/2017 |
2.1.0 | 2,736 | 11/29/2017 |
2.0.1 | 2,540 | 11/27/2017 |
2.0.0 | 3,477 | 11/27/2017 |
1.5.1 | 3,356 | 11/14/2017 |
1.4.0 | 6,671 | 10/23/2017 |
1.3.0 | 5,389 | 9/12/2017 |
1.2.139 | 3,469 | 9/6/2017 |
1.1.128 | 3,336 | 8/15/2017 |
1.0.114 | 2,703 | 7/31/2017 |