mergeSorted
mergeSorted combines two or more tables into one sorted, aggregate table. This essentially stacks the tables one on top of the other and sorts the result. Null tables are ignored. mergeSorted is more efficient than using merge followed by sort.
Syntax
mergeSorted(keyColumn, tables...)
Parameters
| Parameter | Type | Description |
|---|---|---|
| keyColumn | String | The column by which to sort the merged table. |
| tables | Table... | Source tables to be merged.
|
| tables | Collection<Table> | Source tables to be merged.
|
Returns
A new table with the source tables stacked one on top of the other and sorted by the specified column.
Examples
In the following example, source1 is stacked on top of source2, and the result is sorted based on the Number column.
source1 = newTable(col("Letter", "A", "D", "E"), col("Number", 3, 4, 7))
source2 = newTable(col("Letter", "B", "C", "D"), col("Number", 1, 2, 5))
result = mergeSorted("Letter", source1, source2)
In the following example, three tables are merged and sorted based on the Number column.
source1 = newTable(col("Letter", "A", "C", "G"), col("Number", 1, 6, 9))
source2 = newTable(col("Letter", "B", "D", "G"), col("Number", 3, 5, 8))
source3 = newTable(col("Letter", "D", "E", "F"), col("Number", 2, 4, 7))
result = mergeSorted("Number", source1, source2, source3)