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
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

let catalog_relation = spark::relation::RelType::Catalog(spark::Catalog {
cat_type: Some(spark::catalog::CatType::SetCurrentCatalog(
spark::SetCurrentCatalog {
catalog_name: catalog.to_string(),
},
)),
});

let logical_plan = LogicalPlanBuilder::from(catalog_relation);

DataFrame::new(self, logical_plan)
}

pub fn setDatabase(self: Arc<Self>, database: &str) -> DataFrame {
let catalog_relation = spark::relation::RelType::Catalog(spark::Catalog {
cat_type: Some(spark::catalog::CatType::SetCurrentDatabase(
spark::SetCurrentDatabase {
db_name: database.to_string(),
},
)),
});

let logical_plan = LogicalPlanBuilder::from(catalog_relation);

DataFrame::new(self, logical_plan)
}

/// Returns a [DataFrameReader] that can be used to read datra in as a [DataFrame]
pub fn read(self: Arc<Self>) -> DataFrameReader {
DataFrameReader::new(self)
Expand Down