when(col(
"col"
).is_null, lit(
1
))
.when(col(
"col"
) ===
1
, lit(
2
))
.otherwise(lit(
3
))
Since
0.2.0
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.
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.
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).
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).
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).
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).
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
contains one of the values from column "a" in
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
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
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
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