implicit class ColumnMethods extends AnyRef
- Alphabetic
- By Inheritance
- ColumnMethods
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new ColumnMethods(col: Column)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
chain(colMethod: (Column) ⇒ Column): Column
Chains column functions //The chain method takes a org.apache.spark.sql.functions function as an argument and can be used as follows:
Chains column functions //The chain method takes a org.apache.spark.sql.functions function as an argument and can be used as follows:
val wordsDf = Seq( ("Batman "), (" CATWOMAN"), (" pikachu ") ).toDF("word") val actualDf = wordsDf.withColumn( "cleaned_word", col("word").chain(lower).chain(trim) ) actualDf.show() +----------+------------+ | word|cleaned_word| +----------+------------+ | Batman | batman| | CATWOMAN| catwoman| | pikachu | pikachu| +----------+------------+
-
def
chainUDF(udfName: String, cols: Column*): Column
Chains UDFs
Chains UDFs
def appendZ(s: String): String = { s + "Z" } spark.udf.register("appendZUdf", appendZ _) def prependA(s: String): String = { "A" + s } spark.udf.register("prependAUdf", prependA _) val hobbiesDf = Seq( ("dance"), ("sing") ).toDF("word") val actualDf = hobbiesDf.withColumn( "fun", col("word").chainUDF("appendZUdf").chainUDF("prependAUdf") ) actualDf.show() +-----+-------+ | word| fun| +-----+-------+ |dance|AdanceZ| | sing| AsingZ| +-----+-------+
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def evalString(): String
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
isFalse: Column
Returns true if the col is false Returns false if the current expression is false
-
def
isFalsy: Column
Returns true if the col is false or null
isFalsyreturnstrueif a column isnullorfalseandfalseotherwise.Returns true if the col is false or null
isFalsyreturnstrueif a column isnullorfalseandfalseotherwise.Suppose you start with the following
sourceDF:+------+ |is_fun| +------+ | true| | false| | null| +------+
Run the
isFalsymethod:val actualDF = sourceDF.withColumn("is_fun_falsy", col("is_fun").isFalsy)
Here are the contents of
actualDF:+------+------------+ |is_fun|is_fun_falsy| +------+------------+ | true| false| | false| true| | null| true| +------+------------+
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isNotIn(list: Any*): Column
Returns true if the col is not in a list of elements The
isNotInmethod returnstrueif a column element is not in a list andfalseotherwise.Returns true if the col is not in a list of elements The
isNotInmethod returnstrueif a column element is not in a list andfalseotherwise. It's the opposite of theisinmethod.Suppose you start with the following
sourceDF:+-----+ |stuff| +-----+ | dog| |shoes| |laces| | null| +-----+Run the
isNotInmethod:val footwearRelated = Seq("laces", "shoes") val actualDF = sourceDF.withColumn( "is_not_footwear_related", col("stuff").isNotIn(footwearRelated: _*) )
Here are the contents of
actualDF:+-----+-----------------------+ |stuff|is_not_footwear_related| +-----+-----------------------+ | dog| true| |shoes| false| |laces| false| | null| null| +-----+-----------------------+
-
def
isNotNullOrBlank: Column
Returns true if the col is not null or a blank string
Returns true if the col is not null or a blank string
The
isNotNullOrBlankmethod returnstrueif a column is notnullorblankandfalseotherwise. Suppose you start with the followingsourceDF:+-------------+
employee_name
+-------------+
John
""
" "
+-------------+
Run the
isNotNullOrBlankmethod:val actualDF = sourceDF.withColumn( "employee_name_is_not_null_or_blank", col("employee_name").isNotNullOrBlank )
Here are the contents of
actualDF:+-------------+----------------------------------+
employee_name
employee_name_is_not_null_or_blank
+-------------+----------------------------------+
John
true
""
false
" "
false
+-------------+----------------------------------+
-
def
isNullOrBlank: Column
Returns true if the col is null or a blank string The
isNullOrBlankmethod returnstrueif a column isnullorblankandfalseotherwise.Returns true if the col is null or a blank string The
isNullOrBlankmethod returnstrueif a column isnullorblankandfalseotherwise.Suppose you start with the following
sourceDF:+-----------+ |animal_type| +-----------+ | dog| | null| | ""| | " "| +-----------+
Run the
isNullOrBlankmethod:val actualDF = sourceDF.withColumn( "animal_type_is_null_or_blank", col("animal_type").isNullOrBlank )
Here are the contents of
actualDF:+-----------+----------------------------+ |animal_type|animal_type_is_null_or_blank| +-----------+----------------------------+ | dog| false| | null| true| | ""| true| | " "| true| +-----------+----------------------------+
-
def
isTrue: Column
Returns true if the current expression is true Returns false if the current expression is null
-
def
isTruthy: Column
Returns true if the col is not false or null
isTruthyreturnsfalseif a column isnullorfalseandtrueotherwise.Returns true if the col is not false or null
isTruthyreturnsfalseif a column isnullorfalseandtrueotherwise.Suppose you start with the following
sourceDF:+------+ |is_fun| +------+ | true| | false| | null| +------+
Run the
isTruthymethod:val actualDF = sourceDF.withColumn("is_fun_truthy", col("is_fun").isTruthy)
Here are the contents of
actualDF:+------+-------------+ |is_fun|is_fun_truthy| +------+-------------+ | true| true| | false| false| | null| false| +------+-------------+
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
nullBetween(lowerCol: Column, upperCol: Column): Column
Like between, but geq when upper bound is null and leq when lower bound is null The built in
betweendoesn't work well when one of the bounds is undefined.Like between, but geq when upper bound is null and leq when lower bound is null The built in
betweendoesn't work well when one of the bounds is undefined.nullBetweenis more useful when you have "less than or equal to" or "greater than or equal to" logic embedded in your upper and lower bounds. For example, if the lower bound isnulland the upper bound is15,nullBetweenwill interpret that as "all values below 15".Let's compare the
betweenandnullBetweenmethods with a code snipped and the outputted DataFrame.val actualDF = sourceDF.withColumn( "between", col("age").between(col("lower_bound"), col("upper_bound")) ).withColumn( "nullBetween", col("age").nullBetween(col("lower_bound"), col("upper_bound")) ) +-----------+-----------+---+-------+-----------+ |lower_bound|upper_bound|age|between|nullBetween| +-----------+-----------+---+-------+-----------+ | 10| 15| 11| true| true| | 17| null| 94| null| true| | null| 10| 5| null| true| +-----------+-----------+---+-------+-----------+
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
Deprecated Value Members
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] ) @Deprecated
- Deprecated