-
Notifications
You must be signed in to change notification settings - Fork 58
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
Implement row group skipping for the default engine parquet readers #362
Merged
Merged
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
715f233
WIP - first pass at the code
ryan-johnson-databricks ef71f1a
split out a trait, add more type support
ryan-johnson-databricks 39b8927
support short circuit junction eval
ryan-johnson-databricks b5c3a52
Merge remote-tracking branch 'oss/main' into row-group-skipping
scovich e71571e
add tests, fix bugs
scovich cbca3b3
support SQL WHERE semantics, finished adding tests for skipping logic
scovich e7d87eb
Mark block text as not rust code doctest should run
scovich beeb6e8
add missing tests identified by codecov
scovich 519acbd
Wire up row group skipping
scovich 18b33cf
delete for split - parquet reader uses row group skipping
scovich 6c98441
parquet reader now uses row group skipping
scovich 0fdaf0a
add stats-getter test; review comments
scovich 8ac33f8
Merge remote-tracking branch 'oss/main' into use-row-group-skipping
scovich 1cf03dc
improve test coverage; clippy
scovich bc8b344
yet more test coverage
scovich 0971002
improve test coverage even more
scovich 375a380
Add a query level test as well
scovich 6236874
Fix broken sync json parsing and harmonize file reading
scovich 9efcbf7
fmt
scovich 46d19e3
remove spurious TODO
scovich 7666512
Revert "Fix broken sync json parsing and harmonize file reading"
scovich f3865d0
Merge remote-tracking branch 'oss/main' into use-row-group-skipping
scovich a4dc3da
review comments
scovich 40131db
Merge remote-tracking branch 'oss/main' into use-row-group-skipping
scovich bf65904
Infer null count stat for missing columns; add more tests
scovich cce762d
One last test
scovich c7d6bb0
test cleanup
scovich 4f92ed7
code comment tweak
scovich 08a305b
remove unneeded test
scovich e8a947e
Merge remote-tracking branch 'oss' into use-row-group-skipping
scovich bf1e3a8
fix two nullcount stat bugs
scovich 9d632e7
Merge remote-tracking branch 'oss/main' into use-row-group-skipping
scovich 4a77f3a
review nits
scovich 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
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 |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
//! | ||
|
||
use std::cmp::Ordering; | ||
use std::ops::Not; | ||
use std::sync::Arc; | ||
|
||
use itertools::Itertools; | ||
|
@@ -78,15 +77,7 @@ impl LogSegment { | |
} | ||
|
||
fn read_metadata(&self, engine: &dyn Engine) -> DeltaResult<Option<(Metadata, Protocol)>> { | ||
let schema = get_log_schema().project(&[PROTOCOL_NAME, METADATA_NAME])?; | ||
// filter out log files that do not contain metadata or protocol information | ||
use Expression as Expr; | ||
let meta_predicate = Some(Expr::or( | ||
Expr::not(Expr::is_null(Expr::column("metaData.id"))), | ||
Expr::not(Expr::is_null(Expr::column("protocol.minReaderVersion"))), | ||
)); | ||
// read the same protocol and metadata schema for both commits and checkpoints | ||
let data_batches = self.replay(engine, schema.clone(), schema, meta_predicate)?; | ||
let data_batches = self.replay_for_metadata(engine)?; | ||
let mut metadata_opt: Option<Metadata> = None; | ||
let mut protocol_opt: Option<Protocol> = None; | ||
for batch in data_batches { | ||
|
@@ -109,6 +100,22 @@ impl LogSegment { | |
_ => Err(Error::MissingMetadataAndProtocol), | ||
} | ||
} | ||
|
||
// Factored out to facilitate testing | ||
fn replay_for_metadata( | ||
&self, | ||
engine: &dyn Engine, | ||
) -> DeltaResult<impl Iterator<Item = DeltaResult<(Box<dyn EngineData>, bool)>> + Send> { | ||
let schema = get_log_schema().project(&[PROTOCOL_NAME, METADATA_NAME])?; | ||
// filter out log files that do not contain metadata or protocol information | ||
use Expression as Expr; | ||
let meta_predicate = Some(Expr::or( | ||
Expr::column("metaData.id").is_not_null(), | ||
Expr::column("protocol.minReaderVersion").is_not_null(), | ||
)); | ||
// read the same protocol and metadata schema for both commits and checkpoints | ||
self.replay(engine, schema.clone(), schema, meta_predicate) | ||
} | ||
} | ||
|
||
// TODO expose methods for accessing the files of a table (with file pruning). | ||
|
@@ -175,6 +182,10 @@ impl Snapshot { | |
if let Some(version) = version { | ||
commit_files.retain(|log_path| log_path.version <= version); | ||
} | ||
// only keep commit files above the checkpoint we found | ||
if let Some(checkpoint_file) = checkpoint_files.first() { | ||
scovich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
commit_files.retain(|log_path| checkpoint_file.version < log_path.version); | ||
} | ||
|
||
// get the effective version from chosen files | ||
let version_eff = commit_files | ||
|
@@ -452,6 +463,7 @@ mod tests { | |
use crate::engine::default::filesystem::ObjectStoreFileSystemClient; | ||
use crate::engine::sync::SyncEngine; | ||
use crate::schema::StructType; | ||
use crate::Table; | ||
|
||
#[test] | ||
fn test_snapshot_read_metadata() { | ||
|
@@ -623,6 +635,37 @@ mod tests { | |
assert!(invalid.is_none()) | ||
} | ||
|
||
// NOTE: In addition to testing the meta-predicate for metadata replay, this test also verifies | ||
// that the parquet reader properly infers nullcount = rowcount for missing columns. The two | ||
// checkpoint part files that contain transaction app ids have truncated schemas that would | ||
// otherwise fail skipping due to their missing nullcount stat: | ||
// | ||
// Row group 0: count: 1 total(compressed): 111 B total(uncompressed):107 B | ||
// -------------------------------------------------------------------------------- | ||
// type nulls min / max | ||
// txn.appId BINARY 0 "3ae45b72-24e1-865a-a211-3..." / "3ae45b72-24e1-865a-a211-3..." | ||
// txn.version INT64 0 "4390" / "4390" | ||
#[test] | ||
fn test_replay_for_metadata() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An accidentally clever test :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
let path = std::fs::canonicalize(PathBuf::from("./tests/data/parquet_row_group_skipping/")); | ||
let url = url::Url::from_directory_path(path.unwrap()).unwrap(); | ||
let engine = SyncEngine::new(); | ||
|
||
let table = Table::new(url); | ||
let snapshot = table.snapshot(&engine, None).unwrap(); | ||
let data: Vec<_> = snapshot | ||
.log_segment | ||
.replay_for_metadata(&engine) | ||
.unwrap() | ||
.try_collect() | ||
.unwrap(); | ||
// The checkpoint has five parts, each containing one action. The P&M come from first and | ||
// third parts, respectively. The parquet reader skips the second part; it would also skip | ||
// the last two parts, but the actual `read_metadata` will anyway skip them because it | ||
// terminates the iteration immediately after finding both P&M. | ||
assert_eq!(data.len(), 2); | ||
} | ||
|
||
#[test_log::test] | ||
fn test_read_table_with_checkpoint() { | ||
let path = std::fs::canonicalize(PathBuf::from( | ||
|
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added
BIN
+1.04 KB
...w_group_skipping/_delta_log/00000000000000000001.checkpoint.0000000004.0000000005.parquet
Binary file not shown.
Binary file added
BIN
+1.04 KB
...w_group_skipping/_delta_log/00000000000000000001.checkpoint.0000000005.0000000005.parquet
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
kernel/tests/data/parquet_row_group_skipping/_delta_log/00000000000000000001.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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
{"commitInfo":{"timestamp":1728065844007,"operation":"WRITE","operationParameters":{"mode":"Append","partitionBy":"[]"},"readVersion":0,"isolationLevel":"Serializable","isBlindAppend":true,"operationMetrics":{"numFiles":"1","numOutputRows":"5","numOutputBytes":"4959"},"engineInfo":"Apache-Spark/3.5.3 Delta-Lake/3.2.1","txnId":"d46d4bca-ab50-4075-977f-80a5b3844afa"}} | ||
{"add":{"path":"part-00000-b92e017a-50ba-4676-8322-48fc371c2b59-c000.snappy.parquet","partitionValues":{},"size":4959,"modificationTime":1728065843972,"dataChange":true,"stats":"{\"numRecords\":5}"}} | ||
{"txn":{"appId":"3ae45b72-24e1-865a-a211-34987ae02f2a","version":4390}} | ||
{"txn":{"appId":"b42b951f-f5d1-4f6e-be2a-0d11d1543029","version":1235}} |
Oops, something went wrong.
Oops, something went wrong.
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.
This is a new find, exposed on accident by me hacking two more parts into the checkpoint so we could test transaction app id filtering (the "checkpoint" schema was truncated, which prevented the P&M query from skipping those parts)
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.
If the
statistics()
method onColumnChunkMetadata
returnsNone
, that just means that there are no stats for that column, but doesn't necessarily imply that all values arenull
does it?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.
Oh, good catch. I didn't put the check deep enough. There are three levels of
None
here:To make things even more "fun", we have the following warning in Statistics::null_count_opt 🤦:
So I have two problems to work around 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.
Both fixed.