org.apache.spark.sql

Column

class Column extends Logging

:: Experimental :: A column in a DataFrame.

Annotations
@Experimental()
Since

1.3.0

Linear Supertypes
Logging, AnyRef, Any
Known Subclasses
Ordering
  1. Grouped
  2. Alphabetic
  3. By inheritance
Inherited
  1. Column
  2. Logging
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Column(name: String)

  2. new Column(expr: Expression)

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. def !==(other: Any): Column

    Inequality test.

    Inequality test.

    // 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")) );
    Since

    1.3.0

  4. final def ##(): Int

    Definition Classes
    AnyRef → Any
  5. def %(other: Any): Column

    Modulo (a.

    Modulo (a.k.a. remainder) expression.

    Since

    1.3.0

  6. def &&(other: Any): Column

    Boolean AND.

    Boolean AND.

    // 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")) );
    Since

    1.3.0

  7. def *(other: Any): Column

    Multiplication of this expression and another expression.

    Multiplication of this expression and another expression.

    // 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")) );
    Since

    1.3.0

  8. def +(other: Any): Column

    Sum of this expression and another expression.

    Sum of this expression and another expression.

    // 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")) );
    Since

    1.3.0

  9. def -(other: Any): Column

    Subtraction.

    Subtraction. Subtract the other expression from this expression.

    // 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")) );
    Since

    1.3.0

  10. def /(other: Any): Column

    Division this expression by another expression.

    Division this expression by another expression.

    // 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")) );
    Since

    1.3.0

  11. def <(other: Any): Column

    Less than.

    Less than.

    // Scala: The following selects people younger than 21.
    people.select( people("age") < 21 )
    
    // Java:
    people.select( people("age").lt(21) );
    Since

    1.3.0

  12. def <=(other: Any): Column

    Less than or equal to.

    Less than or equal to.

    // Scala: The following selects people age 21 or younger than 21.
    people.select( people("age") <= 21 )
    
    // Java:
    people.select( people("age").leq(21) );
    Since

    1.3.0

  13. def <=>(other: Any): Column

    Equality test that is safe for null values.

    Equality test that is safe for null values.

    Since

    1.3.0

  14. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  16. def ===(other: Any): Column

    Equality test.

    Equality test.

    // Scala:
    df.filter( df("colA") === df("colB") )
    
    // Java
    import static org.apache.spark.sql.functions.*;
    df.filter( col("colA").equalTo(col("colB")) );
    Since

    1.3.0

  17. def >(other: Any): Column

    Greater than.

    Greater than.

    // Scala: The following selects people older than 21.
    people.select( people("age") > 21 )
    
    // Java:
    import static org.apache.spark.sql.functions.*;
    people.select( people("age").gt(21) );
    Since

    1.3.0

  18. def >=(other: Any): Column

    Greater than or equal to an expression.

    Greater than or equal to an expression.

    // Scala: The following selects people age 21 or older than 21.
    people.select( people("age") >= 21 )
    
    // Java:
    people.select( people("age").geq(21) )
    Since

    1.3.0

  19. def alias(alias: String): Column

    Gives the column an alias.

    Gives the column an alias. Same as as.

    // Renames colA to colB in select output.
    df.select($"colA".alias("colB"))
    Since

    1.4.0

  20. def and(other: Column): Column

    Boolean AND.

    Boolean AND.

    // 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")) );
    Since

    1.3.0

  21. def apply(extraction: Any): Column

    Extracts a value or values from a complex type.

    Extracts a value or values from a complex type. The following types of extraction are supported: - 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

    Since

    1.4.0

  22. def as(alias: String, metadata: Metadata): Column

    Gives the column an alias with metadata.

    Gives the column an alias with metadata.

    val metadata: Metadata = ...
    df.select($"colA".as("colB", metadata))
    Since

    1.3.0

  23. def as(alias: Symbol): Column

    Gives the column an alias.

    Gives the column an alias.

    // Renames colA to colB in select output.
    df.select($"colA".as('colB))
    Since

    1.3.0

  24. def as(aliases: Array[String]): Column

    Assigns the given aliases to the results of a table generating function.

    Assigns the given aliases to the results of a table generating function.

    // Renames colA to colB in select output.
    df.select(explode($"myMap").as("key" :: "value" :: Nil))
    Since

    1.4.0

  25. def as(aliases: Seq[String]): Column

    (Scala-specific) Assigns the given aliases to the results of a table generating function.

    (Scala-specific) Assigns the given aliases to the results of a table generating function.

    // Renames colA to colB in select output.
    df.select(explode($"myMap").as("key" :: "value" :: Nil))
    Since

    1.4.0

  26. def as(alias: String): Column

    Gives the column an alias.

    Gives the column an alias.

    // Renames colA to colB in select output.
    df.select($"colA".as("colB"))
    Since

    1.3.0

  27. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  28. def asc: Column

    Returns an ordering used in sorting.

    Returns an ordering used in sorting.

    // Scala: sort a DataFrame by age column in ascending order.
    df.sort(df("age").asc)
    
    // Java
    df.sort(df.col("age").asc());
    Since

    1.3.0

  29. def between(lowerBound: Any, upperBound: Any): Column

    True if the current column is between the lower bound and upper bound, inclusive.

    True if the current column is between the lower bound and upper bound, inclusive.

    Since

    1.4.0

  30. def bitwiseAND(other: Any): Column

    Compute bitwise AND of this expression with another expression.

    Compute bitwise AND of this expression with another expression.

    df.select($"colA".bitwiseAND($"colB"))
    Since

    1.4.0

  31. def bitwiseOR(other: Any): Column

    Compute bitwise OR of this expression with another expression.

    Compute bitwise OR of this expression with another expression.

    df.select($"colA".bitwiseOR($"colB"))
    Since

    1.4.0

  32. def bitwiseXOR(other: Any): Column

    Compute bitwise XOR of this expression with another expression.

    Compute bitwise XOR of this expression with another expression.

    df.select($"colA".bitwiseXOR($"colB"))
    Since

    1.4.0

  33. def cast(to: String): Column

    Casts the column to a different data type, using the canonical string representation of the type.

    Casts the column to a different data type, using the canonical string representation of the type. The supported types are: string, boolean, byte, short, int, long, float, double, decimal, date, timestamp.

    // Casts colA to integer.
    df.select(df("colA").cast("int"))
    Since

    1.3.0

  34. def cast(to: DataType): Column

    Casts the column to a different data type.

    Casts the column to a different data type.

    // 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"))
    Since

    1.3.0

  35. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. def contains(other: Any): Column

    Contains the other element.

    Contains the other element.

    Since

    1.3.0

  37. def desc: Column

    Returns an ordering used in sorting.

    Returns an ordering used in sorting.

    // Scala: sort a DataFrame by age column in descending order.
    df.sort(df("age").desc)
    
    // Java
    df.sort(df.col("age").desc());
    Since

    1.3.0

  38. def divide(other: Any): Column

    Division this expression by another expression.

    Division this expression by another expression.

    // 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")) );
    Since

    1.3.0

  39. def endsWith(literal: String): Column

    String ends with another string literal.

    String ends with another string literal.

    Since

    1.3.0

  40. def endsWith(other: Column): Column

    String ends with.

    String ends with.

    Since

    1.3.0

  41. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  42. def eqNullSafe(other: Any): Column

    Equality test that is safe for null values.

    Equality test that is safe for null values.

    Since

    1.3.0

  43. def equalTo(other: Any): Column

    Equality test.

    Equality test.

    // Scala:
    df.filter( df("colA") === df("colB") )
    
    // Java
    import static org.apache.spark.sql.functions.*;
    df.filter( col("colA").equalTo(col("colB")) );
    Since

    1.3.0

  44. def equals(that: Any): Boolean

    Definition Classes
    Column → AnyRef → Any
  45. def explain(extended: Boolean): Unit

    Prints the expression to the console for debugging purpose.

    Prints the expression to the console for debugging purpose.

    Since

    1.3.0

  46. val expr: Expression

    Attributes
    protected[org.apache.spark.sql]
  47. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  48. def geq(other: Any): Column

    Greater than or equal to an expression.

    Greater than or equal to an expression.

    // Scala: The following selects people age 21 or older than 21.
    people.select( people("age") >= 21 )
    
    // Java:
    people.select( people("age").geq(21) )
    Since

    1.3.0

  49. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  50. def getField(fieldName: String): Column

    An expression that gets a field by name in a StructType.

    An expression that gets a field by name in a StructType.

    Since

    1.3.0

  51. def getItem(key: Any): Column

    An expression that gets an item at position ordinal out of an array, or gets a value by key key in a MapType.

    An expression that gets an item at position ordinal out of an array, or gets a value by key key in a MapType.

    Since

    1.3.0

  52. def gt(other: Any): Column

    Greater than.

    Greater than.

    // 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) );
    Since

    1.3.0

  53. def hashCode(): Int

    Definition Classes
    Column → AnyRef → Any
  54. def in(list: Column*): Column

    A boolean expression that is evaluated to true if the value of this expression is contained by the evaluated values of the arguments.

    A boolean expression that is evaluated to true if the value of this expression is contained by the evaluated values of the arguments.

    Annotations
    @varargs()
    Since

    1.3.0

  55. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  56. def isNotNull: Column

    True if the current expression is NOT null.

    True if the current expression is NOT null.

    Since

    1.3.0

  57. def isNull: Column

    True if the current expression is null.

    True if the current expression is null.

    Since

    1.3.0

  58. def isTraceEnabled(): Boolean

    Attributes
    protected
    Definition Classes
    Logging
  59. def leq(other: Any): Column

    Less than or equal to.

    Less than or equal to.

    // Scala: The following selects people age 21 or younger than 21.
    people.select( people("age") <= 21 )
    
    // Java:
    people.select( people("age").leq(21) );
    Since

    1.3.0

  60. def like(literal: String): Column

    SQL like expression.

    SQL like expression.

    Since

    1.3.0

  61. def log: Logger

    Attributes
    protected
    Definition Classes
    Logging
  62. def logDebug(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  63. def logDebug(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  64. def logError(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  65. def logError(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  66. def logInfo(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  67. def logInfo(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  68. def logName: String

    Attributes
    protected
    Definition Classes
    Logging
  69. def logTrace(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  70. def logTrace(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  71. def logWarning(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  72. def logWarning(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  73. def lt(other: Any): Column

    Less than.

    Less than.

    // Scala: The following selects people younger than 21.
    people.select( people("age") < 21 )
    
    // Java:
    people.select( people("age").lt(21) );
    Since

    1.3.0

  74. def minus(other: Any): Column

    Subtraction.

    Subtraction. Subtract the other expression from this expression.

    // 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")) );
    Since

    1.3.0

  75. def mod(other: Any): Column

    Modulo (a.

    Modulo (a.k.a. remainder) expression.

    Since

    1.3.0

  76. def multiply(other: Any): Column

    Multiplication of this expression and another expression.

    Multiplication of this expression and another expression.

    // 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")) );
    Since

    1.3.0

  77. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  78. def notEqual(other: Any): Column

    Inequality test.

    Inequality test.

    // 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")) );
    Since

    1.3.0

  79. final def notify(): Unit

    Definition Classes
    AnyRef
  80. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  81. def or(other: Column): Column

    Boolean OR.

    Boolean OR.

    // 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")) );
    Since

    1.3.0

  82. def otherwise(value: Any): Column

    Evaluates a list of conditions and returns one of multiple possible result expressions.

    Evaluates a list of conditions and returns one of multiple possible result expressions. If otherwise is not defined at the end, null is returned for unmatched conditions.

    // 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))
    Since

    1.4.0

  83. def over(window: WindowSpec): Column

    Define a windowing column.

    Define a windowing column.

    val w = Window.partitionBy("name").orderBy("id")
    df.select(
      sum("price").over(w.rangeBetween(Long.MinValue, 2)),
      avg("price").over(w.rowsBetween(0, 4))
    )
    Since

    1.4.0

  84. def plus(other: Any): Column

    Sum of this expression and another expression.

    Sum of this expression and another expression.

    // 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")) );
    Since

    1.3.0

  85. def rlike(literal: String): Column

    SQL RLIKE expression (LIKE with Regex).

    SQL RLIKE expression (LIKE with Regex).

    Since

    1.3.0

  86. def startsWith(literal: String): Column

    String starts with another string literal.

    String starts with another string literal.

    Since

    1.3.0

  87. def startsWith(other: Column): Column

    String starts with.

    String starts with.

    Since

    1.3.0

  88. def substr(startPos: Int, len: Int): Column

    An expression that returns a substring.

    An expression that returns a substring.

    startPos

    starting position.

    len

    length of the substring.

    Since

    1.3.0

  89. def substr(startPos: Column, len: Column): Column

    An expression that returns a substring.

    An expression that returns a substring.

    startPos

    expression for the starting position.

    len

    expression for the length of the substring.

    Since

    1.3.0

  90. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  91. def toString(): String

    Definition Classes
    Column → AnyRef → Any
  92. def unary_!: Column

    Inversion of boolean expression, i.

    Inversion of boolean expression, i.e. NOT.

    // Scala: select rows that are not active (isActive === false)
    df.filter( !df("isActive") )
    
    // Java:
    import static org.apache.spark.sql.functions.*;
    df.filter( not(df.col("isActive")) );
    Since

    1.3.0

  93. def unary_-: Column

    Unary minus, i.

    Unary minus, i.e. negate the expression.

    // Scala: select the amount column and negates all values.
    df.select( -df("amount") )
    
    // Java:
    import static org.apache.spark.sql.functions.*;
    df.select( negate(col("amount") );
    Since

    1.3.0

  94. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  95. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  96. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  97. def when(condition: Column, value: Any): Column

    Evaluates a list of conditions and returns one of multiple possible result expressions.

    Evaluates a list of conditions and returns one of multiple possible result expressions. If otherwise is not defined at the end, null is returned for unmatched conditions.

    // 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))
    Since

    1.4.0

  98. def ||(other: Any): Column

    Boolean OR.

    Boolean OR.

    // 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")) );
    Since

    1.3.0

Inherited from Logging

Inherited from AnyRef

Inherited from Any

df_ops

expr_ops

java_expr_ops

Ungrouped