Struct spark_connect_rs::column::Column
source · pub struct Column {
pub expression: Expression,
}Expand description
A Column is composed of a expressions which is used as input into
a Plan object
Fields§
§expression: ExpressionAn expression is an unresolved value to be leveraged in a Spark Plan
Implementations§
source§impl Column
impl Column
sourcepub fn alias(&mut self, value: &str) -> Column
pub fn alias(&mut self, value: &str) -> Column
Returns the column with a new name
§Example:
let cols = vec![
col("name").alias("new_name"),
col("age").alias("new_age")
];
df.select(cols);Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let spark: SparkSession = SparkSessionBuilder::default().build().await?;
let path = ["/opt/spark/examples/src/main/resources/people.csv"];
let mut df = spark
.read()
.format("csv")
.option("header", "True")
.option("delimiter", ";")
.load(path);
df.select([
F::col("name"),
F::col("age").cast("int").alias("age_int"),
(F::lit(3.0) + F::col("age").cast("int")).alias("addition"),
])
.sort(vec![F::col("name").desc()])
.show(Some(5), None, None)
.await?;
// print results
// +--------------------------+
// | show_string |
// +--------------------------+
// | +-----+-------+--------+ |
// | |name |age_int|addition| |
// | +-----+-------+--------+ |
// | |Jorge|30 |33.0 | |
// | |Bob |32 |35.0 | |
// | +-----+-------+--------+ |
// | |
// +--------------------------+
Ok(())
}More examples
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let spark: SparkSession = SparkSessionBuilder::default().build().await?;
let df = spark
.clone()
.range(None, 1000, 1, Some(16))
.select(col("id").alias("range_id"));
let path = "/opt/spark/examples/src/main/rust/employees/";
df.write()
.format("csv")
.mode(SaveMode::Overwrite)
.option("header", "true")
.save(path)
.await?;
let mut df = spark
.clone()
.read()
.format("csv")
.option("header", "true")
.load([path]);
df.show(Some(10), None, None).await?;
// print results may slighty vary but should be close to the below
// +--------------------------+
// | show_string |
// +--------------------------+
// | +--------+ |
// | |range_id| |
// | +--------+ |
// | |312 | |
// | |313 | |
// | |314 | |
// | |315 | |
// | |316 | |
// | |317 | |
// | |318 | |
// | |319 | |
// | |320 | |
// | |321 | |
// | +--------+ |
// | only showing top 10 rows |
// | |
// +--------------------------+
Ok(())
}sourcepub fn asc(&mut self) -> Column
pub fn asc(&mut self) -> Column
Returns a sorted expression based on the ascending order of the column
§Example:
let mut df: DataFrame = df.sort(col("id").asc());
let mut df: DataFrame = df.sort(asc(col("id")));pub fn asc_nulls_first(&mut self) -> Column
pub fn asc_nulls_last(&mut self) -> Column
sourcepub fn desc(&mut self) -> Column
pub fn desc(&mut self) -> Column
Returns a sorted expression based on the ascending order of the column
§Example:
let mut df: DataFrame = df.sort(col("id").desc());
let mut df: DataFrame = df.sort(desc(col("id")));Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let spark: SparkSession = SparkSessionBuilder::default().build().await?;
let path = ["/opt/spark/examples/src/main/resources/people.csv"];
let mut df = spark
.read()
.format("csv")
.option("header", "True")
.option("delimiter", ";")
.load(path);
df.select([
F::col("name"),
F::col("age").cast("int").alias("age_int"),
(F::lit(3.0) + F::col("age").cast("int")).alias("addition"),
])
.sort(vec![F::col("name").desc()])
.show(Some(5), None, None)
.await?;
// print results
// +--------------------------+
// | show_string |
// +--------------------------+
// | +-----+-------+--------+ |
// | |name |age_int|addition| |
// | +-----+-------+--------+ |
// | |Jorge|30 |33.0 | |
// | |Bob |32 |35.0 | |
// | +-----+-------+--------+ |
// | |
// +--------------------------+
Ok(())
}pub fn desc_nulls_first(&mut self) -> Column
pub fn desc_nulls_last(&mut self) -> Column
sourcepub fn cast(&mut self, to_type: &str) -> Column
pub fn cast(&mut self, to_type: &str) -> Column
Casts the column into the Spark type represented as a &str
§Arguments:
to_typeis the string representation of the datatype
§Example:
let mut df = df.select(vec![
col("age").cast("int"),
col("name").cast("string")
])
.collect()
.await?;Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let spark: SparkSession = SparkSessionBuilder::default().build().await?;
let path = ["/opt/spark/examples/src/main/resources/people.csv"];
let mut df = spark
.read()
.format("csv")
.option("header", "True")
.option("delimiter", ";")
.load(path);
df.select([
F::col("name"),
F::col("age").cast("int").alias("age_int"),
(F::lit(3.0) + F::col("age").cast("int")).alias("addition"),
])
.sort(vec![F::col("name").desc()])
.show(Some(5), None, None)
.await?;
// print results
// +--------------------------+
// | show_string |
// +--------------------------+
// | +-----+-------+--------+ |
// | |name |age_int|addition| |
// | +-----+-------+--------+ |
// | |Jorge|30 |33.0 | |
// | |Bob |32 |35.0 | |
// | +-----+-------+--------+ |
// | |
// +--------------------------+
Ok(())
}sourcepub fn isin<T: ToLiteralExpr>(&self, cols: Vec<T>) -> Column
pub fn isin<T: ToLiteralExpr>(&self, cols: Vec<T>) -> Column
A boolean expression that is evaluated to true if the value of the expression is
contained by the evaluated values of the arguments
§Arguments:
colsa value that implements the [ToLiteralExpr] trait
§Example:
let paths = vec!["/opt/spark/examples/src/main/resources/people.csv".to_string()];
let mut df = spark
.read()
.format("csv")
.option("header", "True")
.option("delimiter", ";")
.load(paths);
let row = df
.filter(col("name").isin(vec!["Jorge", "Bob"]))
.select("name");sourcepub fn contains<T: ToLiteralExpr>(&self, other: T) -> Column
pub fn contains<T: ToLiteralExpr>(&self, other: T) -> Column
A boolean expression that is evaluated to true if the value is in the Column
§Arguments:
cols: a col reference that is translated into an spark::Expression
§Example:
let paths = vec!["/opt/spark/examples/src/main/resources/people.csv".to_string()];
let mut df = spark
.read()
.format("csv")
.option("header", "True")
.option("delimiter", ";")
.load(paths);
let row = df
.filter(col("name").contains("ge"))
.select("name");sourcepub fn startswith<T: ToLiteralExpr>(&self, other: T) -> Column
pub fn startswith<T: ToLiteralExpr>(&self, other: T) -> Column
A filter expression that evaluates if the column startswith a string literal
sourcepub fn endswith<T: ToLiteralExpr>(&self, other: T) -> Column
pub fn endswith<T: ToLiteralExpr>(&self, other: T) -> Column
A filter expression that evaluates if the column endswith a string literal
sourcepub fn like<T: ToLiteralExpr>(&self, other: T) -> Column
pub fn like<T: ToLiteralExpr>(&self, other: T) -> Column
A SQL LIKE filter expression that evaluates the column based on a case sensitive match
sourcepub fn ilike<T: ToLiteralExpr>(&self, other: T) -> Column
pub fn ilike<T: ToLiteralExpr>(&self, other: T) -> Column
A SQL ILIKE filter expression that evaluates the column based on a case insensitive match
sourcepub fn rlike<T: ToLiteralExpr>(&self, other: T) -> Column
pub fn rlike<T: ToLiteralExpr>(&self, other: T) -> Column
A SQL RLIKE filter expression that evaluates the column based on a regex match
sourcepub fn eq<T: ToLiteralExpr>(&self, other: T) -> Column
pub fn eq<T: ToLiteralExpr>(&self, other: T) -> Column
Equality comparion. Cannot overload the ‘==’ and return something other than a bool
sourcepub fn isNull(&self) -> Column
pub fn isNull(&self) -> Column
A filter expression that evaluates to true is the expression is null
sourcepub fn isNotNull(&self) -> Column
pub fn isNotNull(&self) -> Column
A filter expression that evaluates to true is the expression is NOT null
pub fn isNaN(&self) -> Column
Trait Implementations§
source§impl From<Expression> for Column
impl From<Expression> for Column
source§fn from(expression: Expression) -> Self
fn from(expression: Expression) -> Self
Auto Trait Implementations§
impl Freeze for Column
impl RefUnwindSafe for Column
impl Send for Column
impl Sync for Column
impl Unpin for Column
impl UnwindSafe for Column
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request