-
Notifications
You must be signed in to change notification settings - Fork 309
feat: add extension to support DataFrame::checkpoint()
#1993
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
Open
sandugood
wants to merge
9
commits into
apache:main
Choose a base branch
from
sandugood:feat/df-checkpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
20907b8
Refactored code parts + added lazy checkpointing to trait
sandugood d88bb6c
fixed formatting
sandugood 92c11f5
Merge remote-tracking branch 'upstream/main' into feat/df-checkpoint
sandugood 47099ef
Job splitter + unit test for the .checkpoint() and lazy_checkpoint() …
sandugood 419d89a
Formatting fixed
sandugood 794875c
Merged main into branch
sandugood afd78cb
cargo lock fixed
sandugood 98e8f16
Added license info to the test
sandugood bd4e247
Added checkpointing docs entry
sandugood 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,164 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| mod common; | ||
|
|
||
| use ballista::prelude::DataFrameExt; | ||
| use datafusion::assert_batches_eq; | ||
| use datafusion::logical_expr::LogicalPlan; | ||
| use tempfile::TempDir; | ||
|
|
||
| #[tokio::test] | ||
| async fn should_checkpoint_dataframe() -> datafusion::error::Result<()> { | ||
| let checkpoint_dir = TempDir::new().unwrap(); | ||
| let checkpoint_path = checkpoint_dir.path().to_str().unwrap().to_string(); | ||
|
|
||
| let ctx = common::standalone_context_with_checkpoint_dir(&checkpoint_path).await; | ||
|
|
||
| let test_data = common::example_test_data(); | ||
| ctx.register_parquet( | ||
| "test", | ||
| &format!("{test_data}/alltypes_plain.parquet"), | ||
| Default::default(), | ||
| ) | ||
| .await?; | ||
|
|
||
| let df = ctx | ||
| .sql("select string_col, timestamp_col from test where id > 4") | ||
| .await?; | ||
|
|
||
| let expected = [ | ||
| "+------------+---------------------+", | ||
| "| string_col | timestamp_col |", | ||
| "+------------+---------------------+", | ||
| "| 31 | 2009-03-01T00:01:00 |", | ||
| "| 30 | 2009-04-01T00:00:00 |", | ||
| "| 31 | 2009-04-01T00:01:00 |", | ||
| "+------------+---------------------+", | ||
| ]; | ||
|
|
||
| // sanity check the plan pre-checkpoint isn't already a bare TableScan | ||
| assert!(!matches!(df.logical_plan(), LogicalPlan::TableScan(_))); | ||
|
|
||
| let checkpointed = df.checkpoint().await?; | ||
|
|
||
| // lineage is broken: the new DataFrame is a scan over the checkpoint files, | ||
| // not the filter/projection chain that produced them | ||
| assert!(matches!( | ||
| checkpointed.logical_plan(), | ||
| LogicalPlan::TableScan(_) | ||
| )); | ||
|
|
||
| let result = checkpointed.collect().await?; | ||
| assert_batches_eq!(expected, &result); | ||
|
|
||
| // the checkpoint actually landed on the configured storage | ||
| let written_any_files = std::fs::read_dir(checkpoint_dir.path()) | ||
| .unwrap() | ||
| .next() | ||
| .is_some(); | ||
| assert!(written_any_files, "expected checkpoint files to be written"); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn checkpoint_without_configured_dir_errors() -> datafusion::error::Result<()> { | ||
| // no with_ballista_checkpoint_dir() call | ||
| let ctx = common::standalone_context_with_state().await; | ||
|
|
||
| let test_data = common::example_test_data(); | ||
| ctx.register_parquet( | ||
| "test", | ||
| &format!("{test_data}/alltypes_plain.parquet"), | ||
| Default::default(), | ||
| ) | ||
| .await?; | ||
|
|
||
| let df = ctx.sql("select * from test").await?; | ||
|
|
||
| let err = df.checkpoint().await.unwrap_err(); | ||
| assert!(err.to_string().contains("ballista.checkpoint.dir")); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn should_insert_checkpoint_node_without_executing() -> datafusion::error::Result<()> | ||
|
Contributor
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.
|
||
| { | ||
| let checkpoint_dir = TempDir::new().unwrap(); | ||
| let checkpoint_path = checkpoint_dir.path().to_str().unwrap().to_string(); | ||
|
|
||
| let ctx = common::standalone_context_with_checkpoint_dir(&checkpoint_path).await; | ||
|
|
||
| let test_data = common::example_test_data(); | ||
| ctx.register_parquet( | ||
| "test", | ||
| &format!("{test_data}/alltypes_plain.parquet"), | ||
| Default::default(), | ||
| ) | ||
| .await?; | ||
|
|
||
| let df = ctx | ||
| .sql("select string_col, timestamp_col from test where id > 4") | ||
| .await?; | ||
| let schema_before = df.schema().clone(); | ||
|
|
||
| let checkpointed = df.checkpoint_lazy()?; | ||
|
Contributor
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. should we have test to check execution of |
||
|
|
||
| // The marker sits at the root and the schema is unchanged: the node is a | ||
| // pass through until the scheduler materialises it. | ||
| assert!(matches!( | ||
| checkpointed.logical_plan(), | ||
| LogicalPlan::Extension(_) | ||
| )); | ||
| assert_eq!(checkpointed.schema(), &schema_before); | ||
| assert!( | ||
| format!("{}", checkpointed.logical_plan().display_indent()) | ||
| .contains("BallistaCheckpointNode") | ||
| ); | ||
|
|
||
| // Nothing has been materialised: a lazy checkpoint performs no I/O. | ||
| let written_any_files = std::fs::read_dir(checkpoint_dir.path()) | ||
| .unwrap() | ||
| .next() | ||
| .is_some(); | ||
| assert!(!written_any_files, "lazy checkpoint must not write eagerly"); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn lazy_checkpoint_without_configured_dir_errors() -> datafusion::error::Result<()> | ||
| { | ||
| let ctx = common::standalone_context_with_state().await; | ||
|
|
||
| let test_data = common::example_test_data(); | ||
| ctx.register_parquet( | ||
| "test", | ||
| &format!("{test_data}/alltypes_plain.parquet"), | ||
| Default::default(), | ||
| ) | ||
| .await?; | ||
|
|
||
| let df = ctx.sql("select * from test").await?; | ||
|
|
||
| let err = df.checkpoint_lazy().unwrap_err(); | ||
| assert!(err.to_string().contains("ballista.checkpoint.dir")); | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.