Skip to content
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

chore: Remove references from SessionState from physical_plan #5455

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Mar 2, 2023

Which issue does this PR close?

Part of #1754

Rationale for this change

I am trying to extract the physical_plan code into its own crate; SessionState is in datafusion-core which means physical_plan can't have references back there.

See more details in #1754 (comment)

What changes are included in this PR?

Change some code to use TaskContext rather than SessionState (that is simply used to make a TaskContext)

Are these changes tested?

Covered by existing tests

Are there any user-facing changes?

I don't think anyone uses these APIs (they are helpers from SessionContext) but I think they are technically public

@alamb alamb added the api change Changes the API exposed to users of the crate label Mar 2, 2023
@github-actions github-actions bot added the core Core DataFusion crate label Mar 2, 2023
@@ -280,7 +280,7 @@ impl FileOpener for CsvOpener {
}

pub async fn plan_to_csv(
state: &SessionState,
task_ctx: Arc<TaskContext>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of the pR is to remove the use of SessionState and hoist the creation of TaskContext into SessionContext

@@ -300,8 +300,7 @@ pub async fn plan_to_csv(
let path = fs_path.join(filename);
let file = fs::File::create(path)?;
let mut writer = csv::Writer::new(file);
let task_ctx = Arc::new(TaskContext::from(state));
let stream = plan.execute(i, task_ctx)?;
let stream = plan.execute(i, task_ctx.clone())?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that TaskContext is simply a clone of the state on SessionState: https://github.com/apache/arrow-datafusion/blob/a95e0ec2fd929aae1c2f67148243eb4825d81a3b/datafusion/core/src/execution/context.rs#L2157-L2173

so making it once and cloning is probably better than making multiple TaskContexts (each that have a bunch of Arcs)

@@ -803,6 +802,7 @@ mod tests {
use crate::datasource::file_format::test_util::scan_format;
use crate::datasource::listing::{FileRange, PartitionedFile};
use crate::datasource::object_store::ObjectStoreUrl;
use crate::execution::context::SessionState;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for tests, which I think is ok to depend on datafusion core

@alamb
Copy link
Contributor Author

alamb commented Mar 4, 2023

@metesynnada / @mustafasrepo might you have time to review this change? I also think this may be be on code that @metesynnada is working on for INSERT / COPY TO.

@mustafasrepo
Copy link
Contributor

LGTM!. Thanks for this PR.

@alamb alamb merged commit 928662b into apache:main Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants