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
VastFrameto use during merging. For example,CASE WHEN "column" > 3 THEN 2 ELSE NULL ENDandPOWER("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 ENDandPOWER("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:
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 fromvastorbitare used as intended without interfering with functions from other libraries.Let us create two
VastFramewhich 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
VastFramewith the second one:vdf.append(vdf_2)
123scoreIntegerAbccatVarchar(1)1 12 A 2 1 B 3 13 A 4 11 A 5 23 B 6 11 B Rows: 1-6 | Columns: 2We can also apply some SQL expressions on the append using
expr1andexpr2. Let us try to limit the maximum value of the secondVastFrameto 20.vdf.append( vdf_2, expr1 = [ 'CASE WHEN "score" > 20 THEN 20 ELSE "score" END AS "score"', '"cat"', ], )
123scoreIntegerAbccatVarchar(1)1 13 A 2 11 A 3 11 B 4 1 B 5 20 B 6 12 A Rows: 1-6 | Columns: 2Note
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_allfor more information.