Loading...

vastorbit.sql.functions.decode

vastorbit.sql.functions.decode(expr: Annotated[str | list[str] | StringSQL | list[StringSQL], ''], *args) StringSQL

Compares the expressions to each search value.

Parameters:
  • expr (SQLExpression) – Expression.

  • args (SQLExpression) –

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

    even:

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

    odd:

    CASE … WHEN expr = 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": ['banana', 'apple', 'onion', 'potato']})

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

df["type_x"] = vof.decode(
    df["x"],
    'banana', 'fruit',
    'apple', 'fruit',
    'vegetable',
)
display(df)
Abc
x
Varchar(6)
100%
Abc
type_x
Varchar(9)
100%
1bananafruit
2applefruit
3onionvegetable
4potatovegetable

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.