-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Support reading delta tables #190
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
Binary file added
BIN
+1.51 KB
__tests__/examples/delta/sample.table/0-07808ab0-6b13-421c-bb67-ca09945eb281-0.parquet
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
__tests__/examples/delta/sample.table/_delta_log/00000000000000000000.json
This file contains 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,4 @@ | ||
{"protocol":{"minReaderVersion":1,"minWriterVersion":2}} | ||
{"metaData":{"id":"b27252b0-26cc-49c5-b79d-12dd6647ffba","name":null,"description":null,"format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"foo\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"fruits\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"B\",\"type\":\"long\",\"nullable\":true,\"metadata\":{}},{\"name\":\"cars\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":[],"createdTime":1711300448856,"configuration":{}}} | ||
{"add":{"path":"0-07808ab0-6b13-421c-bb67-ca09945eb281-0.parquet","partitionValues":{},"size":1550,"modificationTime":1711300448855,"dataChange":true,"stats":"{\"numRecords\": 5, \"minValues\": {\"foo\": \"5\", \"fruits\": \"apple\", \"B\": 1, \"cars\": \"audi\"}, \"maxValues\": {\"foo\": \"you have a,b,c\", \"fruits\": \"banana\", \"B\": 5, \"cars\": \"beetle\"}, \"nullCount\": {\"foo\": 0, \"fruits\": 0, \"B\": 0, \"cars\": 0}}","tags":null,"deletionVector":null,"baseRowId":null,"defaultRowCommitVersion":null,"clusteringProvider":null}} | ||
{"commitInfo":{"timestamp":1711300448856,"operation":"CREATE TABLE","operationParameters":{"location":"file:///examples/delta/sample.table","protocol":"{\"minReaderVersion\":1,\"minWriterVersion\":2}","metadata":"{\"configuration\":{},\"createdTime\":1711300448856,\"description\":null,\"format\":{\"options\":{},\"provider\":\"parquet\"},\"id\":\"b27252b0-26cc-49c5-b79d-12dd6647ffba\",\"name\":null,\"partitionColumns\":[],\"schemaString\":\"{\\\"type\\\":\\\"struct\\\",\\\"fields\\\":[{\\\"name\\\":\\\"foo\\\",\\\"type\\\":\\\"string\\\",\\\"nullable\\\":true,\\\"metadata\\\":{}},{\\\"name\\\":\\\"fruits\\\",\\\"type\\\":\\\"string\\\",\\\"nullable\\\":true,\\\"metadata\\\":{}},{\\\"name\\\":\\\"B\\\",\\\"type\\\":\\\"long\\\",\\\"nullable\\\":true,\\\"metadata\\\":{}},{\\\"name\\\":\\\"cars\\\",\\\"type\\\":\\\"string\\\",\\\"nullable\\\":true,\\\"metadata\\\":{}}]}\"}","mode":"ErrorIfExists"},"clientVersion":"delta-rs.0.17.1"}} |
This file contains 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
This file contains 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
Binary file not shown.
This file contains 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 |
---|---|---|
|
@@ -54,7 +54,7 @@ | |
"precommit": "yarn lint && yarn test" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.6.1", | ||
"@biomejs/biome": "^1.6.2", | ||
"@napi-rs/cli": "^2.18.0", | ||
"@types/chance": "^1.1.6", | ||
"@types/jest": "^29.5.12", | ||
|
@@ -65,7 +65,7 @@ | |
"ts-jest": "^29.1.2", | ||
"ts-node": "^10.9.2", | ||
"typedoc": "^0.25.12", | ||
"typescript": "5.4.2" | ||
"typescript": "5.4.3" | ||
}, | ||
"packageManager": "[email protected]", | ||
"workspaces": [ | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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,52 @@ | ||
use polars_core::prelude::DataFrame; | ||
use polars_io::{parquet::ParquetReader, SerReader}; | ||
use polars_lazy::{dsl::UnionArgs, frame::{IntoLazy, LazyFrame}}; | ||
use polars::prelude::concat; | ||
use deltalake::{DeltaTableBuilder, DeltaTableError}; | ||
use crate::dataframe::ReadDeltaOptions; | ||
|
||
pub async fn read_delta_table(path: &str, | ||
options: ReadDeltaOptions, | ||
) -> Result<LazyFrame, DeltaTableError> { | ||
let mut db = DeltaTableBuilder::from_uri(path) | ||
.with_allow_http(false); | ||
|
||
// if version specified, add it | ||
if options.version.is_some() { | ||
db = db.with_version(options.version.unwrap()); | ||
} | ||
|
||
let dt = db.load().await?; | ||
|
||
// show all active files in the table | ||
let files: Vec<_> = dt.get_file_uris()?.collect(); | ||
|
||
let mut df_collection: Vec<DataFrame> = vec![]; | ||
|
||
for file in files.into_iter() { | ||
let base = std::path::Path::new(path); | ||
let file_path = std::path::Path::new(&file); | ||
let full_path = base.join(file_path); | ||
let mut file = std::fs::File::open(full_path).unwrap(); | ||
|
||
let columns = options.columns.clone(); | ||
let parallel = options.parallel.0; | ||
|
||
let df = ParquetReader::new(&mut file) | ||
.with_columns(columns) | ||
.read_parallel(parallel) | ||
.finish().unwrap(); | ||
|
||
df_collection.push(df); | ||
} | ||
|
||
let empty_head = df_collection[0].clone().lazy().limit(0); | ||
|
||
Ok(df_collection.into_iter().fold(empty_head, |acc, df| concat([acc, df.lazy()], | ||
UnionArgs { | ||
rechunk: false, | ||
parallel: false, | ||
..Default::default() | ||
}).unwrap())) | ||
|
||
} |
This file contains 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 |
---|---|---|
|
@@ -28,6 +28,7 @@ pub mod series; | |
pub mod set; | ||
pub mod utils; | ||
pub mod sql; | ||
pub mod delta; | ||
|
||
pub use polars_core; | ||
|
||
|
This file contains 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 |
---|---|---|
|
@@ -408,18 +408,18 @@ __metadata: | |
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/biome@npm:^1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/biome@npm:1.6.1" | ||
dependencies: | ||
"@biomejs/cli-darwin-arm64": 1.6.1 | ||
"@biomejs/cli-darwin-x64": 1.6.1 | ||
"@biomejs/cli-linux-arm64": 1.6.1 | ||
"@biomejs/cli-linux-arm64-musl": 1.6.1 | ||
"@biomejs/cli-linux-x64": 1.6.1 | ||
"@biomejs/cli-linux-x64-musl": 1.6.1 | ||
"@biomejs/cli-win32-arm64": 1.6.1 | ||
"@biomejs/cli-win32-x64": 1.6.1 | ||
"@biomejs/biome@npm:^1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/biome@npm:1.6.2" | ||
dependencies: | ||
"@biomejs/cli-darwin-arm64": 1.6.2 | ||
"@biomejs/cli-darwin-x64": 1.6.2 | ||
"@biomejs/cli-linux-arm64": 1.6.2 | ||
"@biomejs/cli-linux-arm64-musl": 1.6.2 | ||
"@biomejs/cli-linux-x64": 1.6.2 | ||
"@biomejs/cli-linux-x64-musl": 1.6.2 | ||
"@biomejs/cli-win32-arm64": 1.6.2 | ||
"@biomejs/cli-win32-x64": 1.6.2 | ||
dependenciesMeta: | ||
"@biomejs/cli-darwin-arm64": | ||
optional: true | ||
|
@@ -439,62 +439,62 @@ __metadata: | |
optional: true | ||
bin: | ||
biome: bin/biome | ||
checksum: 4d012438d5ce52418ce7af4cb2285180afe767b8df2465cf7890fb2f8b01920bf29d7a8d78c5c4379b589f6e735db8f0ad7502b78ec943b65efd0e74eea5abb2 | ||
checksum: 3e2d1b5d54aa3ebac1f758bd7ad524d7e45f95f82436900da592ff8b3a3398863a28b098e6a6799f9af33cb7367c15ef4af10399cd9d28587d0f817e977ed994 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/cli-darwin-arm64@npm:1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/cli-darwin-arm64@npm:1.6.1" | ||
"@biomejs/cli-darwin-arm64@npm:1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/cli-darwin-arm64@npm:1.6.2" | ||
conditions: os=darwin & cpu=arm64 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/cli-darwin-x64@npm:1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/cli-darwin-x64@npm:1.6.1" | ||
"@biomejs/cli-darwin-x64@npm:1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/cli-darwin-x64@npm:1.6.2" | ||
conditions: os=darwin & cpu=x64 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/cli-linux-arm64-musl@npm:1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/cli-linux-arm64-musl@npm:1.6.1" | ||
"@biomejs/cli-linux-arm64-musl@npm:1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/cli-linux-arm64-musl@npm:1.6.2" | ||
conditions: os=linux & cpu=arm64 & libc=musl | ||
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/cli-linux-arm64@npm:1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/cli-linux-arm64@npm:1.6.1" | ||
"@biomejs/cli-linux-arm64@npm:1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/cli-linux-arm64@npm:1.6.2" | ||
conditions: os=linux & cpu=arm64 & libc=glibc | ||
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/cli-linux-x64-musl@npm:1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/cli-linux-x64-musl@npm:1.6.1" | ||
"@biomejs/cli-linux-x64-musl@npm:1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/cli-linux-x64-musl@npm:1.6.2" | ||
conditions: os=linux & cpu=x64 & libc=musl | ||
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/cli-linux-x64@npm:1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/cli-linux-x64@npm:1.6.1" | ||
"@biomejs/cli-linux-x64@npm:1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/cli-linux-x64@npm:1.6.2" | ||
conditions: os=linux & cpu=x64 & libc=glibc | ||
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/cli-win32-arm64@npm:1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/cli-win32-arm64@npm:1.6.1" | ||
"@biomejs/cli-win32-arm64@npm:1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/cli-win32-arm64@npm:1.6.2" | ||
conditions: os=win32 & cpu=arm64 | ||
languageName: node | ||
linkType: hard | ||
|
||
"@biomejs/cli-win32-x64@npm:1.6.1": | ||
version: 1.6.1 | ||
resolution: "@biomejs/cli-win32-x64@npm:1.6.1" | ||
"@biomejs/cli-win32-x64@npm:1.6.2": | ||
version: 1.6.2 | ||
resolution: "@biomejs/cli-win32-x64@npm:1.6.2" | ||
conditions: os=win32 & cpu=x64 | ||
languageName: node | ||
linkType: hard | ||
|
@@ -3004,7 +3004,7 @@ __metadata: | |
version: 0.0.0-use.local | ||
resolution: "nodejs-polars@workspace:." | ||
dependencies: | ||
"@biomejs/biome": ^1.6.1 | ||
"@biomejs/biome": ^1.6.2 | ||
"@napi-rs/cli": ^2.18.0 | ||
"@types/chance": ^1.1.6 | ||
"@types/jest": ^29.5.12 | ||
|
@@ -3015,7 +3015,7 @@ __metadata: | |
ts-jest: ^29.1.2 | ||
ts-node: ^10.9.2 | ||
typedoc: ^0.25.12 | ||
typescript: 5.4.2 | ||
typescript: 5.4.3 | ||
languageName: unknown | ||
linkType: soft | ||
|
||
|
@@ -3733,23 +3733,23 @@ __metadata: | |
languageName: node | ||
linkType: hard | ||
|
||
"typescript@npm:5.4.2": | ||
version: 5.4.2 | ||
resolution: "typescript@npm:5.4.2" | ||
"typescript@npm:5.4.3": | ||
version: 5.4.3 | ||
resolution: "typescript@npm:5.4.3" | ||
bin: | ||
tsc: bin/tsc | ||
tsserver: bin/tsserver | ||
checksum: 96d80fde25a09bcb04d399082fb27a808a9e17c2111e43849d2aafbd642d835e4f4ef0de09b0ba795ec2a700be6c4c2c3f62bf4660c05404c948727b5bbfb32a | ||
checksum: d74d731527e35e64d8d2dcf2f897cf8cfbc3428be0ad7c48434218ba4ae41239f53be7c90714089db1068c05cae22436af2ecba71fd36ecc5e7a9118af060198 | ||
languageName: node | ||
linkType: hard | ||
|
||
"typescript@patch:[email protected].2#~builtin<compat/typescript>": | ||
version: 5.4.2 | ||
resolution: "typescript@patch:typescript@npm%3A5.4.2#~builtin<compat/typescript>::version=5.4.2&hash=14eedb" | ||
"typescript@patch:[email protected].3#~builtin<compat/typescript>": | ||
version: 5.4.3 | ||
resolution: "typescript@patch:typescript@npm%3A5.4.3#~builtin<compat/typescript>::version=5.4.3&hash=14eedb" | ||
bin: | ||
tsc: bin/tsc | ||
tsserver: bin/tsserver | ||
checksum: c1b669146bca5529873aae60870e243fa8140c85f57ca32c42f898f586d73ce4a6b4f6bb02ae312729e214d7f5859a0c70da3e527a116fdf5ad00c9fc733ecc6 | ||
checksum: 3a62fe90aa79d68c9ce38ea5edb2957e62801c733b99f0e5a2b8b50922761f68f7d9a40d28c544b449866e81185cddb93cba2496d0ff3fa52ef5b1f8bcace38c | ||
languageName: node | ||
linkType: hard | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit hesitant to add this in as a dependency.
this pulls in the entire arrow-rs project as well as many other heavy dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense, I will keep looking for alternatives. Thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I think the "ideal" approach would be first to upstream some work to delta-rs and expose a javascript library. Then we could use the JS library directly like py-polars does, and do a bunch of the logic on the JS side using
apache-arrow
as an optional dependency.If the
apache-arrow
npm package becomes a point of contention, we could likely bypass it by dynamically linking to the delta js bindings directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delta-rs
team is busy with C# implementation now. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was effort to use delta-sharing using JS and Danfo.js.