Created
April 4, 2024 20:11
-
-
Save sjrusso8/2b4e43af462367a15f91db5a33627449 to your computer and use it in GitHub Desktop.
connect_readwrite.rs
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
use spark_connect_rs; | |
use spark_connect_rs::dataframe::SaveMode; | |
use spark_connect_rs::{SparkSession, SparkSessionBuilder}; | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let spark: SparkSession = | |
SparkSessionBuilder::remote("sc://127.0.0.1:15002/;user_id=example_rs") | |
.build() | |
.await?; | |
let df = spark | |
.clone() | |
.sql("select 'apple' as word, 123 as count") | |
.await?; | |
df.write() | |
.mode(SaveMode::Overwrite) | |
.format("parquet") | |
.save("file:///tmp/spark-connect-write-example-output.parquet") | |
.await?; | |
let df = spark | |
.read() | |
.format("parquet") | |
.load(["file:///tmp/spark-connect-write-example-output.parquet"])?; | |
df.show(Some(100), None, None).await?; | |
// +---------------+ | |
// | show_string | | |
// +---------------+ | |
// | +-----+-----+ | | |
// | |word |count| | | |
// | +-----+-----+ | | |
// | |apple|123 | | | |
// | +-----+-----+ | | |
// | | | |
// +---------------+ | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment