Skip to content

Making Spark Connect Rust more thread-safe friendly #13

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
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

edmondop
Copy link

Description

Enabling send_guard and using ARC makes the crate much more friendly to usage in multi-threaded environment, making the session Send and Sync

@sjrusso8
Copy link
Owner

Thanks for creating this PR! I played around with something similar when I was rewriting the client implementation. I just didn't like having the user wrap the SparkSession with Arc to create the session. It felt clunky, but that is probably me over thinking the interface.

Do you know of way to allow for friendlier Send and Sync without requiring the user to create Arc? I was loosely mirroring the SessionContext from DataFusion as for how users of a similar DataFrame library interact with a session object. The SessionContext does not get wrapped in Arc.

@edmondop
Copy link
Author

edmondop commented Apr 16, 2024 via email

@@ -56,6 +56,34 @@ impl SparkSession {
DataFrame::new(self, LogicalPlanBuilder::from(range_relation))
}

pub fn setCatalog(self: Arc<Self>, catalog: &str) -> DataFrame {
Copy link
Owner

Choose a reason for hiding this comment

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

So for both setCatalog and setDatabase, these should be implemented on the spark.catalog object as setCurrentCatalog and setCurrentDatabasesince we want to mirror the existing Spark API.

For these actions to take effect on the existing session, the plan has to be submitted to the server via client.execute_and_fetch and receive a successful response. Both of these execution plans return nothing from the server. The code might look like this below

pub async fn setCurrentCatalog(self, catalog: &str) -> Result<(), SparkError> {
       let cat_type = Some(spark::catalog::CatType::SetCurrentCatalog(
            spark::SetCurrentCatalog { catalog_name: catalog.to_string() },
        ));

        let rel_type = spark::relation::RelType::Catalog(spark::Catalog { cat_type });

        let plan = LogicalPlanBuilder::plan_root(LogicalPlanBuilder::from(rel_type));

        self.spark_session.client().execute_and_fetch(plan).await
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants