Snowpark Scala API Reference1.21.0 < Back


# Packages

-  package root
  Definition Classes
    root
-  package com
  Definition Classes
    root
-  package snowflake
  Definition Classes
    com
-  package snowpark
  Definition Classes
    snowflake
-  package types

  This package contains all Snowpark logical types.

  This package contains all Snowpark logical types.

  Definition Classes
    snowpark
  Since

    0.1.0

-  package udaf
  Definition Classes
    snowpark
-  package udtf
  Definition Classes
    snowpark
- AggregateFunction
- AsyncJob
- CaseExpr
- Column
- CopyableDataFrame
- CopyableDataFrameAsyncActor
- DataFrame
- DataFrameAsyncActor
- DataFrameNaFunctions
- DataFrameReader
- DataFrameStatFunctions
- DataFrameWriter
- DataFrameWriterAsyncActor
- DeleteResult
- FileOperation
- GetResult
- GroupingSets
- HasCachedResult
- MatchedClauseBuilder
- MergeBuilder
- MergeBuilderAsyncActor
- MergeResult
- MergeTypedAsyncJob
- NotMatchedClauseBuilder
- PublicPreview
- PutResult
- RelationalGroupedDataFrame
- Row
- SProcRegistration
- SaveMode
- Session
- SnowparkClientException
- StoredProcedure
- TableFunction
- TypedAsyncJob
- UDAFRegistration
- UDFRegistration
- UDTFRegistration
- Updatable
- UpdatableAsyncActor
- UpdateResult
- UserDefinedFunction
- Window
- WindowSpec
- WriteFileResult
- functions
- tableFunctions

c

com.snowflake.snowpark

# CaseExpr

###

#### class CaseExpr extends Column

Represents a CASE expression.

To construct this object for a CASE expression, call the functions.when. specifying a condition and the corresponding result for that condition. Then, call the when and otherwise methods to specify additional conditions and results.

For example:

    import com.snowflake.snowpark.functions._
    df.select(
      when(col("col").is_null, lit(1))
        .when(col("col") === 1, lit(2))
        .otherwise(lit(3))
    )

Since

  0.2.0

Linear Supertypes
Column, Serializable, Product, Equals, Logging, AnyRef, Any

Ordering

1. Alphabetic
2. By Inheritance

Inherited

1. CaseExpr
2. Column
3. Serializable
4. Product
5. Equals
6. Logging
7. AnyRef
8. Any

1. Hide All
2. Show All

Visibility

1. Public
2. Protected

### Value Members

1.  final def !=(arg0: Any): Boolean
   Definition Classes
     AnyRef → Any
2.  final def ##: Int
   Definition Classes
     AnyRef → Any
3.  def %(other: Any): Column

   Remainder.

   Remainder. Alias for mod.

   Definition Classes
     Column
   Since

     0.1.0

4.  def &&(other: Any): Column

   And.

   And. Alias for and.

   Definition Classes
     Column
   Since

     0.1.0

5.  def *(other: Any): Column

   Multiply.

   Multiply. Alias for multiply.

   Definition Classes
     Column
   Since

     0.1.0

6.  def +(other: Any): Column

   Plus.

   Plus. Alias for plus.

   Definition Classes
     Column
   Since

     0.1.0

7.  def -(other: Any): Column

   Minus.

   Minus. Alias for minus.

   Definition Classes
     Column
   Since

     0.1.0

8.  def /(other: Any): Column

   Divide.

   Divide. Alias for divide.

   Definition Classes
     Column
   Since

     0.1.0

9.  def <(other: Any): Column

   Less than.

   Less than. Alias for lt.

   Definition Classes
     Column
   Since

     0.1.0

10.  def <=(other: Any): Column

    Less than or equal to.

    Less than or equal to. Alias for leq.

    Definition Classes
      Column
    Since

      0.1.0

11.  def <=>(other: Any): Column

    Equal to.

    Equal to. You can use this for comparisons against a null value. Alias for equal_null.

    Definition Classes
      Column
    Since

      0.1.0

12.  def =!=(other: Any): Column

    Not equal to.

    Not equal to. Alias for not_equal.

    Definition Classes
      Column
    Since

      0.1.0

13.  final def ==(arg0: Any): Boolean
    Definition Classes
      AnyRef → Any
14.  def ===(other: Any): Column

    Equal to.

    Equal to. Alias for equal_to. Use this instead of `==` to perform an equality check in an expression. For example:

        lhs.filter(col("a") === 10).join(rhs, rhs("id") === lhs("id"))

    Definition Classes
      Column
    Since

      0.1.0

15.  def >(other: Any): Column

    Greater than.

    Greater than. Alias for gt.

    Definition Classes
      Column
    Since

      0.1.0

16.  def >=(other: Any): Column

    Greater than or equal to.

    Greater than or equal to. Alias for geq.

    Definition Classes
      Column
    Since

      0.1.0

17.  def alias(alias: String): Column

    Returns a new renamed Column.

    Returns a new renamed Column. Alias for name.

    Definition Classes
      Column
    Since

      0.1.0

18.  def and(other: Column): Column

    And.

    And.

    Definition Classes
      Column
    Since

      0.1.0

19.  def apply(idx: Int): Column

    Returns the element (field) at the specified index in a column that contains semi-structured data.

    Returns the element (field) at the specified index in a column that contains semi-structured data.

    The method applies case-sensitive matching to the names of the specified elements.

    This is equivalent to using bracket notation in SQL (`column[index]`).

    - If the column is an ARRAY value, this function extracts the VARIANT value of the array element at the specified index.
    - If the index points outside of the array boundaries or if an element does not exist at the specified index (e.g. if the array is sparsely populated), the method returns NULL.
    - If the column is a VARIANT value, this function first checks if the VARIANT value contains an ARRAY value.
    - If the VARIANT value does not contain an ARRAY value, the method returns NULL.
    - Otherwise, the method works as described above.

    For example:

        import com.snowflake.snowpark.functions.col
        df.select(col("src")(1)(0)("name")(0))

    idx

      index of the subfield to be extracted

    Definition Classes
      Column
    Since

      0.2.0

20.  def apply(field: String): Column

    Returns the specified element (field) in a column that contains semi-structured data.

    Returns the specified element (field) in a column that contains semi-structured data.

    The method applies case-sensitive matching to the names of the specified elements.

    This is equivalent to using bracket notation in SQL (`column['element']`).

    - If the column is an OBJECT value, this function extracts the VARIANT value of the element with the specified name from the OBJECT value.
    - If the element is not found, the method returns NULL.
    - You must not specify an empty string for the element name.
    - If the column is a VARIANT value, this function first checks if the VARIANT value contains an OBJECT value.
    - If the VARIANT value does not contain an OBJECT value, the method returns NULL.
    - Otherwise, the method works as described above.

    For example:

        import com.snowflake.snowpark.functions.col
        df.select(col("src")("salesperson")("emails")(0))

    field

      field name of the subfield to be extracted. You cannot specify a path.

    Definition Classes
      Column
    Since

      0.2.0

21.  def as(alias: String): Column

    Returns a new renamed Column.

    Returns a new renamed Column. Alias for name.

    Definition Classes
      Column
    Since

      0.1.0

22.  final def asInstanceOf[T0]: T0
    Definition Classes
      Any
23.  def asc: Column

    Returns a Column expression with values sorted in ascending order.

    Returns a Column expression with values sorted in ascending order.

    Definition Classes
      Column
    Since

      0.1.0

24.  def asc_nulls_first: Column

    Returns a Column expression with values sorted in ascending order (null values sorted before non-null values).

    Returns a Column expression with values sorted in ascending order (null values sorted before non-null values).

    Definition Classes
      Column
    Since

      0.1.0

25.  def asc_nulls_last: Column

    Returns a Column expression with values sorted in ascending order (null values sorted after non-null values).

    Returns a Column expression with values sorted in ascending order (null values sorted after non-null values).

    Definition Classes
      Column
    Since

      0.1.0

26.  def between(lowerBound: Column, upperBound: Column): Column

    Between lower bound and upper bound.

    Between lower bound and upper bound.

    Definition Classes
      Column
    Since

      0.1.0

27.  def bitand(other: Column): Column

    Bitwise and.

    Bitwise and.

    Definition Classes
      Column
    Since

      0.1.0

28.  def bitor(other: Column): Column

    Bitwise or.

    Bitwise or.

    Definition Classes
      Column
    Since

      0.1.0

29.  def bitxor(other: Column): Column

    Bitwise xor.

    Bitwise xor.

    Definition Classes
      Column
    Since

      0.1.0

30.  def cast(to: String): Column

    Casts the values in the Column to the specified data type.

    Casts the values in the Column to the specified data type.

    Examples

        val df = Seq(123, 456, 789).toDF("a")
        df.select(col("a").cast("string").as("casted")).schema.toString
        // res: String = "StructType[StructField(CASTED, String, Nullable = false)]"

    to

      A string representing the target data type.

    returns

      A new Column with values cast to the specified data type.

    Definition Classes
      Column
    Since

      1.18.0

    Exceptions thrown

      `IllegalArgumentException` If the provided string does not represent a valid data type.

31.  def cast(to: DataType): Column

    Casts the values in the Column to the specified data type.

    Casts the values in the Column to the specified data type.

    Definition Classes
      Column
    Since

      0.1.0

32.  def clone(): AnyRef
    Attributes
      protected[lang]
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
33.  def collate(collateSpec: String): Column

    Returns a copy of the original Column with the specified `collationSpec` property, rather than the original collation specification property.

    Returns a copy of the original Column with the specified `collationSpec` property, rather than the original collation specification property.

    For details, see the Snowflake documentation on collation specifications.

    Definition Classes
      Column
    Since

      0.1.0

34.  def desc: Column

    Returns a Column expression with values sorted in descending order.

    Returns a Column expression with values sorted in descending order.

    Definition Classes
      Column
    Since

      0.1.0

35.  def desc_nulls_first: Column

    Returns a Column expression with values sorted in descending order (null values sorted before non-null values).

    Returns a Column expression with values sorted in descending order (null values sorted before non-null values).

    Definition Classes
      Column
    Since

      0.1.0

36.  def desc_nulls_last: Column

    Returns a Column expression with values sorted in descending order (null values sorted after non-null values).

    Returns a Column expression with values sorted in descending order (null values sorted after non-null values).

    Definition Classes
      Column
    Since

      0.1.0

37.  def divide(other: Any): Column

    Divide.

    Divide.

    Definition Classes
      Column
    Since

      0.1.0

38.  def else(value: Any): Column

    Sets the default result for this CASE expression.

    Sets the default result for this CASE expression. Alias for otherwise.

    Since

      0.2.0

39.  final def eq(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
40.  def equal_nan: Column

    Is NaN.

    Is NaN.

    Definition Classes
      Column
    Since

      0.1.0

41.  def equal_null(other: Any): Column

    Equal to.

    Equal to. You can use this for comparisons against a null value.

    Definition Classes
      Column
    Since

      0.1.0

42.  def equal_to(other: Any): Column

    Equal to.

    Equal to. Same as `===`.

    Definition Classes
      Column
    Since

      0.1.0

43.  def geq(other: Any): Column

    Greater than or equal to.

    Greater than or equal to.

    Definition Classes
      Column
    Since

      0.1.0

44.  final def getClass(): Class[_ <: AnyRef]
    Definition Classes
      AnyRef → Any
    Annotations
      @HotSpotIntrinsicCandidate() @native()
45.  def getName: Option[String]

    Returns the column name (if the column has a name).

    Returns the column name (if the column has a name).

    Definition Classes
      Column
    Since

      0.2.0

46.  def gt(other: Any): Column

    Greater than.

    Greater than.

    Definition Classes
      Column
    Since

      0.1.0

47.  def in(df: DataFrame): Column

    Returns a conditional expression that you can pass to the filter or where method to perform a WHERE ...

    Returns a conditional expression that you can pass to the filter or where method to perform a WHERE ... IN query with a specified subquery.

    The expression evaluates to true if the value in the column is one of the values in the column of the same name in a specified DataFrame.

    For example, the following code returns a DataFrame that contains the rows where the column "a" of `df2` contains one of the values from column "a" in `df1`. This is equivalent to SELECT * FROM table2 WHERE a IN (SELECT a FROM table1).

        val df1 = session.table(table1)
        val df2 = session.table(table2)
        df2.filter(col("a").in(df1))

    Definition Classes
      Column
    Since

      0.10.0

48.  def in(values: Seq[Any]): Column

    Returns a conditional expression that you can pass to the filter or where method to perform the equivalent of a WHERE ...

    Returns a conditional expression that you can pass to the filter or where method to perform the equivalent of a WHERE ... IN query with a specified list of values.

    The expression evaluates to true if the value in the column is one of the values in a specified sequence.

    For example, the following code returns a DataFrame that contains the rows where the column "a" contains the value 1, 2, or 3. This is equivalent to SELECT * FROM table WHERE a IN (1, 2, 3).

        df.filter(df("a").in(Seq(1, 2, 3)))

    Definition Classes
      Column
    Since

      0.10.0

49.  final def isInstanceOf[T0]: Boolean
    Definition Classes
      Any
50.  def isNull: Column

    Wrapper for is_null function.

    Wrapper for is_null function.

    Definition Classes
      Column
    Since

      1.10.0

51.  def is_not_null: Column

    Is not null.

    Is not null.

    Definition Classes
      Column
    Since

      0.1.0

52.  def is_null: Column

    Is null.

    Is null.

    Definition Classes
      Column
    Since

      0.1.0

53.  def leq(other: Any): Column

    Less than or equal to.

    Less than or equal to.

    Definition Classes
      Column
    Since

      0.1.0

54.  def like(pattern: Column): Column

    Allows case-sensitive matching of strings based on comparison with a pattern.

    Allows case-sensitive matching of strings based on comparison with a pattern.

    For details, see the Snowflake documentation on LIKE.

    Definition Classes
      Column
    Since

      0.1.0

55.  def log(): Logger
    Attributes
      protected[internal]
    Definition Classes
      Logging
56.  def logDebug(msg: String, throwable: Throwable): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
57.  def logDebug(msg: String): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
58.  def logError(msg: String, throwable: Throwable): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
59.  def logError(msg: String): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
60.  def logInfo(msg: String, throwable: Throwable): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
61.  def logInfo(msg: String): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
62.  def logTrace(msg: String, throwable: Throwable): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
63.  def logTrace(msg: String): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
64.  def logWarning(msg: String, throwable: Throwable): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
65.  def logWarning(msg: String): Unit
    Attributes
      protected[internal]
    Definition Classes
      Logging
66.  def lt(other: Any): Column

    Less than.

    Less than.

    Definition Classes
      Column
    Since

      0.1.0

67.  def minus(other: Any): Column

    Minus.

    Minus.

    Definition Classes
      Column
    Since

      0.1.0

68.  def mod(other: Any): Column

    Remainder.

    Remainder.

    Definition Classes
      Column
    Since

      0.1.0

69.  def multiply(other: Any): Column

    Multiply.

    Multiply.

    Definition Classes
      Column
    Since

      0.1.0

70.  def name(alias: String): Column

    Returns a new renamed Column.

    Returns a new renamed Column.

    Definition Classes
      Column
    Since

      0.1.0

71.  final def ne(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
72.  def not_equal(other: Any): Column

    Not equal to.

    Not equal to.

    Definition Classes
      Column
    Since

      0.1.0

73.  final def notify(): Unit
    Definition Classes
      AnyRef
    Annotations
      @HotSpotIntrinsicCandidate() @native()
74.  final def notifyAll(): Unit
    Definition Classes
      AnyRef
    Annotations
      @HotSpotIntrinsicCandidate() @native()
75.  def or(other: Column): Column

    Or.

    Or.

    Definition Classes
      Column
    Since

      0.1.0

76.  def otherwise(value: Any): Column

    Sets the default result for this CASE expression.

    Sets the default result for this CASE expression.

    This method handles any literal value and converts it into a `Column` using `lit()`.

    ##### Example

        val df = session.sql("SELECT * FROM values (10), (25), (65), (70) as T(age)")
        val result = df.select(
          when(col("age") < lit(18), "Minor")
            .when(col("age") < lit(65), lit("Adult"))
            .otherwise("Senior")
        )
        // The age_category column will be "Senior" for rows where age >= 65

    value

      The default value, which can be any literal (e.g., String, Int, Boolean) or a `Column`.

    returns

      The result column.

    Since

      0.2.0

77.  def over(): Column

    Returns a windows frame, based on an empty WindowSpec expression.

    Returns a windows frame, based on an empty WindowSpec expression.

    Definition Classes
      Column
    Since

      0.1.0

78.  def over(window: WindowSpec): Column

    Returns a windows frame, based on the specified WindowSpec.

    Returns a windows frame, based on the specified WindowSpec.

    Definition Classes
      Column
    Since

      0.1.0

79.  def plus(other: Any): Column

    Plus.

    Plus.

    Definition Classes
      Column
    Since

      0.1.0

80.  def productElementNames: Iterator[String]
    Definition Classes
      Product
81.  def regexp(pattern: Column): Column

    Returns true if this Column matches the specified regular expression.

    Returns true if this Column matches the specified regular expression.

    For details, see the Snowflake documentation on regular expressions.

    Definition Classes
      Column
    Since

      0.1.0

82.  final def synchronized[T0](arg0: => T0): T0
    Definition Classes
      AnyRef
83.  def toString(): String

    Returns a string representation of the expression corresponding to this Column instance.

    Returns a string representation of the expression corresponding to this Column instance.

    Definition Classes
      Column → AnyRef → Any
    Since

      0.1.0

84.  def unary_!: Column

    Unary not.

    Unary not.

    Definition Classes
      Column
    Since

      0.1.0

85.  def unary_-: Column

    Unary minus.

    Unary minus.

    Definition Classes
      Column
    Since

      0.1.0

86.  final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.InterruptedException])
87.  final def wait(arg0: Long): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.InterruptedException]) @native()
88.  final def wait(): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws(classOf[java.lang.InterruptedException])
89.  def when(condition: Column, value: Any): CaseExpr

    Appends one more WHEN condition to the CASE expression.

    Appends one more WHEN condition to the CASE expression.

    This method handles any literal value and converts it into a `Column`.

    ##### Example

        val df = session.sql("SELECT * FROM values (10), (25), (65), (70) as T(age)")
        val result = df.select(
          when(col("age") < lit(18), "Minor")
            .when(col("age") < lit(65), lit("Adult"))
            .otherwise("Senior")
        )
        // The second when condition will be "Adult" for rows where age >= 18 and age < 65

    condition

      The case condition.

    value

      The result value, which can be any literal (e.g., String, Int, Boolean) or a `Column`.

    returns

      The result case expression.

    Since

      0.2.0

90.  def withExpr(newExpr: Expression): Column
    Attributes
      protected
    Definition Classes
      Column
91.  def withinGroup(cols: Seq[Column]): Column

    Returns a Column expression that adds a WITHIN GROUP clause to sort the rows by the specified sequence of columns.

    Returns a Column expression that adds a WITHIN GROUP clause to sort the rows by the specified sequence of columns.

    This method is supported on Column expressions returned by some of the aggregate functions, including functions.array_agg, LISTAGG(), PERCENTILE_CONT(), and PERCENTILE_DISC().

    For example:

        import com.snowflake.snowpark.functions._
        import session.implicits._
        // Create a DataFrame from a sequence.
        val df = Seq((3, "v1"), (1, "v3"), (2, "v2")).toDF("a", "b")
        // Create a DataFrame containing the values in "a" sorted by "b".
        df.select(array_agg(col("a")).withinGroup(Seq(col("b"))))
        // Create a DataFrame containing the values in "a" grouped by "b"
        // and sorted by "a" in descending order.
        df.select(
          array_agg(Seq(col("a")))
          .withinGroup(col("a").desc)
          .over(Window.partitionBy(col("b")))
        )

    For details, see the Snowflake documentation for the aggregate function that you are using (e.g. ARRAY_AGG).

    Definition Classes
      Column
    Since

      0.6.0

92.  def withinGroup(first: Column, remaining: Column*): Column

    Returns a Column expression that adds a WITHIN GROUP clause to sort the rows by the specified columns.

    Returns a Column expression that adds a WITHIN GROUP clause to sort the rows by the specified columns.

    This method is supported on Column expressions returned by some of the aggregate functions, including functions.array_agg, LISTAGG(), PERCENTILE_CONT(), and PERCENTILE_DISC().

    For example:

        import com.snowflake.snowpark.functions._
        import session.implicits._
        // Create a DataFrame from a sequence.
        val df = Seq((3, "v1"), (1, "v3"), (2, "v2")).toDF("a", "b")
        // Create a DataFrame containing the values in "a" sorted by "b".
        val dfArrayAgg = df.select(array_agg(col("a")).withinGroup(col("b")))
        // Create a DataFrame containing the values in "a" grouped by "b"
        // and sorted by "a" in descending order.
        var dfArrayAggWindow = df.select(
          array_agg(col("a"))
          .withinGroup(col("a").desc)
          .over(Window.partitionBy(col("b")))
        )

    For details, see the Snowflake documentation for the aggregate function that you are using (e.g. ARRAY_AGG).

    Definition Classes
      Column
    Since

      0.6.0

93.  def ||(other: Any): Column

    Or.

    Or. Alias for or.

    Definition Classes
      Column
    Since

      0.1.0

### Deprecated Value Members

1.  def finalize(): Unit
   Attributes
     protected[lang]
   Definition Classes
     AnyRef
   Annotations
     @throws(classOf[java.lang.Throwable]) @Deprecated
   Deprecated

     (Since version 9)

### Inherited from Column

### Inherited from Serializable

### Inherited from Product

### Inherited from Equals

### Inherited from Logging

### Inherited from AnyRef

### Inherited from Any

### Expression Operation Functions

### Utility Functions

### Ungrouped