Loading...

vastorbit.sql.functions.case_when

vastorbit.sql.functions.case_when(*args) StringSQL

Returns the conditional statement of the input arguments.

Parameters:

args (SQLExpression) –

Infinite number of Expressions. The expression generated will look like:

even:

CASE … WHEN args[2 * i] THEN args[2 * i + 1] … END

odd :

CASE … WHEN args[2 * i] THEN args[2 * i + 1] … ELSE args[n] END

Returns:

SQL string.

Return type:

StringSQL

Examples

First, let’s import the VastFrame in order to create a dummy dataset.

from vastorbit import VastFrame

Now, let’s import the vastorbit SQL functions.

import vastorbit.sql.functions as vof

We can now build a dummy dataset.

df = VastFrame({"x": [0.8, -1, 0, -2, 0.5]})

Now, let’s go ahead and apply the function.

df["x_pos"] = vof.case_when(
    df["x"] > 0, 1,
    df["x"] == 0, 0,
    -1,
)
display(df)
123
x
Decimal(11,1)
100%
123
x_pos
Integer
100%
10.51
2-2.0-1
30.00
4-1.0-1
50.81

Note

It’s crucial to utilize vastorbit SQL functions in coding, as they can be updated over time with new syntax. While SQL functions typically remain stable, they may vary across platforms or versions. vastorbit effectively manages these changes, a task not achievable with pure SQL.

See also

VastFrame.eval() : Evaluates the expression.