Loading...

vastorbit.VastFrame.append

VastFrame.append(input_relation: Annotated[str | VastFrame, ''], expr1: Annotated[str | list[str] | StringSQL | list[StringSQL], ''] | None = None, expr2: Annotated[str | list[str] | StringSQL | list[StringSQL], ''] | None = None, union_all: bool = True) VastFrame

Merges the VastFrame with another VastFrame or an input relation, and returns a new VastFrame.

Warning

Appending datasets can potentially increase the structural weight; exercise caution when performing this operation.

Parameters:
  • input_relation (SQLRelation) – Relation to merge with.

  • expr1 (SQLExpression, optional) – List of pure-SQL expressions from the current VastFrame to use during merging. For example, CASE WHEN "column" > 3 THEN 2 ELSE NULL END and POWER("column", 2) will work. If empty, all VastFrame VastColumns are used. Aliases are recommended to avoid auto-naming.

  • expr2 (SQLExpression, optional) – List of pure-SQL expressions from the input relation to use during the merging. For example, CASE WHEN "column" > 3 THEN 2 ELSE NULL END and POWER("column", 2) will work. If empty, all input relation columns are used. Aliases are recommended to avoid auto-naming.

  • union_all (bool, optional) – If set to True, the VastFrame is merged with the input relation using an ‘UNION ALL’ instead of an ‘UNION’.

Returns:

VastFrame of the Union

Return type:

VastFrame

Examples

Let’s begin by importing vastorbit.

import vastorbit as vo

Hint

By assigning an alias to vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from vastorbit are used as intended without interfering with functions from other libraries.

Let us create two VastFrame which we can merge for this example:

vdf = vo.VastFrame(
    {
        "score": [12, 11, 13],
        "cat": ['A', 'B', 'A'],
    }
)

vdf_2 = vo.VastFrame(
    {
        "score": [11, 1, 23],
        "cat": ['A', 'B', 'B'],
    }
)

We can conveniently append the the first VastFrame with the second one:

vdf.append(vdf_2)
123
score
Integer
Abc
cat
Varchar(1)
112A
21B
313A
411A
523B
611B
Rows: 1-6 | Columns: 2

We can also apply some SQL expressions on the append using expr1 and expr2. Let us try to limit the maximum value of the second VastFrame to 20.

vdf.append(
    vdf_2,
    expr1 = [
        'CASE WHEN "score" > 20 THEN 20 ELSE "score" END AS "score"',
        '"cat"',
    ],
)
123
score
Integer
Abc
cat
Varchar(1)
113A
211A
311B
41B
520B
612A
Rows: 1-6 | Columns: 2

Note

vastorbit offers the flexibility to use UNION ALL or simple UNION based on your specific use case. The former includes duplicates, while the latter handles them. Refer to union_all for more information.

See also

VastFrame.join() : Joins the VastFrame with another one or an input_relation.