public class Column
extends java.lang.Object
DataFrame
.
A new column is constructed based on the input columns present in a dataframe:
df("columnName") // On a specific DataFrame.
col("columnName") // A generic column no yet associated with a DataFrame.
col("columnName.field") // Extracting a struct field
col("`a.column.with.dots`") // Escape `.` in column names.
$"columnName" // Scala short hand for a named column.
expr("a + 1") // A column that is constructed from a parsed SQL Expression.
lit("abc") // A column that produces a literal (constant) value.
Column
objects can be composed to form complex expressions:
$"a" + 1
$"a" === $"b"
Constructor and Description |
---|
Column(org.apache.spark.sql.catalyst.expressions.Expression expr) |
Column(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
Column |
alias(java.lang.String alias)
Gives the column an alias.
|
Column |
and(Column other)
Boolean AND.
|
Column |
apply(java.lang.Object extraction)
Extracts a value or values from a complex type.
|
<U> TypedColumn<java.lang.Object,U> |
as(Encoder<U> evidence$1)
Provides a type hint about the expected return value of this column.
|
Column |
as(scala.collection.Seq<java.lang.String> aliases)
(Scala-specific) Assigns the given aliases to the results of a table generating function.
|
Column |
as(java.lang.String alias)
Gives the column an alias.
|
Column |
as(java.lang.String[] aliases)
Assigns the given aliases to the results of a table generating function.
|
Column |
as(java.lang.String alias,
Metadata metadata)
Gives the column an alias with metadata.
|
Column |
as(scala.Symbol alias)
Gives the column an alias.
|
Column |
asc()
Returns an ordering used in sorting.
|
Column |
between(java.lang.Object lowerBound,
java.lang.Object upperBound)
True if the current column is between the lower bound and upper bound, inclusive.
|
Column |
bitwiseAND(java.lang.Object other)
Compute bitwise AND of this expression with another expression.
|
Column |
bitwiseOR(java.lang.Object other)
Compute bitwise OR of this expression with another expression.
|
Column |
bitwiseXOR(java.lang.Object other)
Compute bitwise XOR of this expression with another expression.
|
Column |
cast(DataType to)
Casts the column to a different data type.
|
Column |
cast(java.lang.String to)
Casts the column to a different data type, using the canonical string representation
of the type.
|
Column |
contains(java.lang.Object other)
Contains the other element.
|
Column |
desc()
Returns an ordering used in sorting.
|
Column |
divide(java.lang.Object other)
Division this expression by another expression.
|
Column |
endsWith(Column other)
String ends with.
|
Column |
endsWith(java.lang.String literal)
String ends with another string literal.
|
Column |
eqNullSafe(java.lang.Object other)
Equality test that is safe for null values.
|
boolean |
equals(java.lang.Object that) |
Column |
equalTo(java.lang.Object other)
Equality test.
|
void |
explain(boolean extended)
Prints the expression to the console for debugging purpose.
|
protected org.apache.spark.sql.catalyst.expressions.Expression |
expr() |
Column |
geq(java.lang.Object other)
Greater than or equal to an expression.
|
Column |
getField(java.lang.String fieldName)
An expression that gets a field by name in a
StructType . |
Column |
getItem(java.lang.Object key)
An expression that gets an item at position
ordinal out of an array,
or gets a value by key key in a MapType . |
Column |
gt(java.lang.Object other)
Greater than.
|
int |
hashCode() |
protected static void |
initializeLogIfNecessary(boolean isInterpreter) |
Column |
isin(java.lang.Object... list)
A boolean expression that is evaluated to true if the value of this expression is contained
by the evaluated values of the arguments.
|
Column |
isin(scala.collection.Seq<java.lang.Object> list)
A boolean expression that is evaluated to true if the value of this expression is contained
by the evaluated values of the arguments.
|
Column |
isNaN()
True if the current expression is NaN.
|
Column |
isNotNull()
True if the current expression is NOT null.
|
Column |
isNull()
True if the current expression is null.
|
protected static boolean |
isTraceEnabled() |
Column |
leq(java.lang.Object other)
Less than or equal to.
|
Column |
like(java.lang.String literal)
SQL like expression.
|
protected static org.slf4j.Logger |
log() |
protected static void |
logDebug(scala.Function0<java.lang.String> msg) |
protected static void |
logDebug(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logError(scala.Function0<java.lang.String> msg) |
protected static void |
logError(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logInfo(scala.Function0<java.lang.String> msg) |
protected static void |
logInfo(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static java.lang.String |
logName() |
protected static void |
logTrace(scala.Function0<java.lang.String> msg) |
protected static void |
logTrace(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logWarning(scala.Function0<java.lang.String> msg) |
protected static void |
logWarning(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
Column |
lt(java.lang.Object other)
Less than.
|
Column |
minus(java.lang.Object other)
Subtraction.
|
Column |
mod(java.lang.Object other)
Modulo (a.k.a.
|
Column |
multiply(java.lang.Object other)
Multiplication of this expression and another expression.
|
Column |
name(java.lang.String alias)
Gives the column a name (alias).
|
Column |
notEqual(java.lang.Object other)
Inequality test.
|
Column |
or(Column other)
Boolean OR.
|
Column |
otherwise(java.lang.Object value)
Evaluates a list of conditions and returns one of multiple possible result expressions.
|
Column |
over(WindowSpec window)
Define a windowing column.
|
Column |
plus(java.lang.Object other)
Sum of this expression and another expression.
|
Column |
rlike(java.lang.String literal)
SQL RLIKE expression (LIKE with Regex).
|
Column |
startsWith(Column other)
String starts with.
|
Column |
startsWith(java.lang.String literal)
String starts with another string literal.
|
Column |
substr(Column startPos,
Column len)
An expression that returns a substring.
|
Column |
substr(int startPos,
int len)
An expression that returns a substring.
|
java.lang.String |
toString() |
static scala.Option<org.apache.spark.sql.catalyst.expressions.Expression> |
unapply(Column col) |
Column |
when(Column condition,
java.lang.Object value)
Evaluates a list of conditions and returns one of multiple possible result expressions.
|
public Column(org.apache.spark.sql.catalyst.expressions.Expression expr)
public Column(java.lang.String name)
public static scala.Option<org.apache.spark.sql.catalyst.expressions.Expression> unapply(Column col)
protected static java.lang.String logName()
protected static org.slf4j.Logger log()
protected static void logInfo(scala.Function0<java.lang.String> msg)
protected static void logDebug(scala.Function0<java.lang.String> msg)
protected static void logTrace(scala.Function0<java.lang.String> msg)
protected static void logWarning(scala.Function0<java.lang.String> msg)
protected static void logError(scala.Function0<java.lang.String> msg)
protected static void logInfo(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logDebug(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logTrace(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logWarning(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logError(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static boolean isTraceEnabled()
protected static void initializeLogIfNecessary(boolean isInterpreter)
public Column isin(java.lang.Object... list)
list
- (undocumented)protected org.apache.spark.sql.catalyst.expressions.Expression expr()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object that)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public <U> TypedColumn<java.lang.Object,U> as(Encoder<U> evidence$1)
select
on a Dataset
to automatically convert the
results into the correct JVM types.evidence$1
- (undocumented)public Column apply(java.lang.Object extraction)
- Given an Array, an integer ordinal can be used to retrieve a single value. - Given a Map, a key of the correct type can be used to retrieve an individual value. - Given a Struct, a string fieldName can be used to extract that field. - Given an Array of Structs, a string fieldName can be used to extract filed of every struct in that array, and return an Array of fields
extraction
- (undocumented)public Column equalTo(java.lang.Object other)
// Scala:
df.filter( df("colA") === df("colB") )
// Java
import static org.apache.spark.sql.functions.*;
df.filter( col("colA").equalTo(col("colB")) );
other
- (undocumented)public Column notEqual(java.lang.Object other)
// Scala:
df.select( df("colA") !== df("colB") )
df.select( !(df("colA") === df("colB")) )
// Java:
import static org.apache.spark.sql.functions.*;
df.filter( col("colA").notEqual(col("colB")) );
other
- (undocumented)public Column gt(java.lang.Object other)
// Scala: The following selects people older than 21.
people.select( people("age") > lit(21) )
// Java:
import static org.apache.spark.sql.functions.*;
people.select( people("age").gt(21) );
other
- (undocumented)public Column lt(java.lang.Object other)
// Scala: The following selects people younger than 21.
people.select( people("age") < 21 )
// Java:
people.select( people("age").lt(21) );
other
- (undocumented)public Column leq(java.lang.Object other)
// Scala: The following selects people age 21 or younger than 21.
people.select( people("age") <= 21 )
// Java:
people.select( people("age").leq(21) );
other
- (undocumented)public Column geq(java.lang.Object other)
// Scala: The following selects people age 21 or older than 21.
people.select( people("age") >= 21 )
// Java:
people.select( people("age").geq(21) )
other
- (undocumented)public Column eqNullSafe(java.lang.Object other)
other
- (undocumented)public Column when(Column condition, java.lang.Object value)
// Example: encoding gender string column into integer.
// Scala:
people.select(when(people("gender") === "male", 0)
.when(people("gender") === "female", 1)
.otherwise(2))
// Java:
people.select(when(col("gender").equalTo("male"), 0)
.when(col("gender").equalTo("female"), 1)
.otherwise(2))
condition
- (undocumented)value
- (undocumented)public Column otherwise(java.lang.Object value)
// Example: encoding gender string column into integer.
// Scala:
people.select(when(people("gender") === "male", 0)
.when(people("gender") === "female", 1)
.otherwise(2))
// Java:
people.select(when(col("gender").equalTo("male"), 0)
.when(col("gender").equalTo("female"), 1)
.otherwise(2))
value
- (undocumented)public Column between(java.lang.Object lowerBound, java.lang.Object upperBound)
lowerBound
- (undocumented)upperBound
- (undocumented)public Column isNaN()
public Column isNull()
public Column isNotNull()
public Column or(Column other)
// Scala: The following selects people that are in school or employed.
people.filter( people("inSchool") || people("isEmployed") )
// Java:
people.filter( people("inSchool").or(people("isEmployed")) );
other
- (undocumented)public Column and(Column other)
// Scala: The following selects people that are in school and employed at the same time.
people.select( people("inSchool") && people("isEmployed") )
// Java:
people.select( people("inSchool").and(people("isEmployed")) );
other
- (undocumented)public Column plus(java.lang.Object other)
// Scala: The following selects the sum of a person's height and weight.
people.select( people("height") + people("weight") )
// Java:
people.select( people("height").plus(people("weight")) );
other
- (undocumented)public Column minus(java.lang.Object other)
// Scala: The following selects the difference between people's height and their weight.
people.select( people("height") - people("weight") )
// Java:
people.select( people("height").minus(people("weight")) );
other
- (undocumented)public Column multiply(java.lang.Object other)
// Scala: The following multiplies a person's height by their weight.
people.select( people("height") * people("weight") )
// Java:
people.select( people("height").multiply(people("weight")) );
other
- (undocumented)public Column divide(java.lang.Object other)
// Scala: The following divides a person's height by their weight.
people.select( people("height") / people("weight") )
// Java:
people.select( people("height").divide(people("weight")) );
other
- (undocumented)public Column mod(java.lang.Object other)
other
- (undocumented)public Column isin(scala.collection.Seq<java.lang.Object> list)
list
- (undocumented)public Column like(java.lang.String literal)
literal
- (undocumented)public Column rlike(java.lang.String literal)
literal
- (undocumented)public Column getItem(java.lang.Object key)
ordinal
out of an array,
or gets a value by key key
in a MapType
.
key
- (undocumented)public Column getField(java.lang.String fieldName)
StructType
.
fieldName
- (undocumented)public Column substr(Column startPos, Column len)
startPos
- expression for the starting position.len
- expression for the length of the substring.
public Column substr(int startPos, int len)
startPos
- starting position.len
- length of the substring.
public Column contains(java.lang.Object other)
other
- (undocumented)public Column startsWith(Column other)
other
- (undocumented)public Column startsWith(java.lang.String literal)
literal
- (undocumented)public Column endsWith(Column other)
other
- (undocumented)public Column endsWith(java.lang.String literal)
literal
- (undocumented)public Column alias(java.lang.String alias)
as
.
// Renames colA to colB in select output.
df.select($"colA".alias("colB"))
alias
- (undocumented)public Column as(java.lang.String alias)
// Renames colA to colB in select output.
df.select($"colA".as("colB"))
If the current column has metadata associated with it, this metadata will be propagated
to the new column. If this not desired, use as
with explicitly empty metadata.
alias
- (undocumented)public Column as(scala.collection.Seq<java.lang.String> aliases)
// Renames colA to colB in select output.
df.select(explode($"myMap").as("key" :: "value" :: Nil))
aliases
- (undocumented)public Column as(java.lang.String[] aliases)
// Renames colA to colB in select output.
df.select(explode($"myMap").as("key" :: "value" :: Nil))
aliases
- (undocumented)public Column as(scala.Symbol alias)
// Renames colA to colB in select output.
df.select($"colA".as('colB))
If the current column has metadata associated with it, this metadata will be propagated
to the new column. If this not desired, use as
with explicitly empty metadata.
alias
- (undocumented)public Column as(java.lang.String alias, Metadata metadata)
val metadata: Metadata = ...
df.select($"colA".as("colB", metadata))
alias
- (undocumented)metadata
- (undocumented)public Column name(java.lang.String alias)
// Renames colA to colB in select output.
df.select($"colA".name("colB"))
If the current column has metadata associated with it, this metadata will be propagated
to the new column. If this not desired, use as
with explicitly empty metadata.
alias
- (undocumented)public Column cast(DataType to)
// Casts colA to IntegerType.
import org.apache.spark.sql.types.IntegerType
df.select(df("colA").cast(IntegerType))
// equivalent to
df.select(df("colA").cast("int"))
to
- (undocumented)public Column cast(java.lang.String to)
string
, boolean
, byte
, short
, int
, long
,
float
, double
, decimal
, date
, timestamp
.
// Casts colA to integer.
df.select(df("colA").cast("int"))
to
- (undocumented)public Column desc()
// Scala: sort a DataFrame by age column in descending order.
df.sort(df("age").desc)
// Java
df.sort(df.col("age").desc());
public Column asc()
// Scala: sort a DataFrame by age column in ascending order.
df.sort(df("age").asc)
// Java
df.sort(df.col("age").asc());
public void explain(boolean extended)
extended
- (undocumented)public Column bitwiseOR(java.lang.Object other)
df.select($"colA".bitwiseOR($"colB"))
other
- (undocumented)public Column bitwiseAND(java.lang.Object other)
df.select($"colA".bitwiseAND($"colB"))
other
- (undocumented)public Column bitwiseXOR(java.lang.Object other)
df.select($"colA".bitwiseXOR($"colB"))
other
- (undocumented)public Column over(WindowSpec window)
val w = Window.partitionBy("name").orderBy("id")
df.select(
sum("price").over(w.rangeBetween(Long.MinValue, 2)),
avg("price").over(w.rowsBetween(0, 4))
)
window
- (undocumented)