rowMergeAndSort

Syntax

rowMergeAndSort(sortVec, asc, args...)

Details

Merges multiple rows of array vectors or columnar tuples into a single row, and sorts the merged result.

Elements in sortVec and args are positionally correlated, and the merging and sorting of args are performed in synchronization with the order of sortVec.

Parameters

sortVec is an array vector or columnar tuple representing the column used for sorting after merging. sortVec can also be a tuple containing up to 2 columns of array vectors or columnar tuples.

asc is a Boolean scalar or Boolean vector indicating whether the merged result is sorted in ascending order. The default value is true. If sortVec is a tuple, asc can be a Boolean vector with the same length as the number of columns in sortVec .

args... (optional) can be array vectors or columnar tuples representing additional columns to be merged and reordered together with sortVec using the same sorting order.

Returns

  • When args is specified, returns a tuple with the number of elements equal to the length of args plus 1, each element being a vector.

  • When args is not specified, returns a vector.

Examples

Example 1. Merge an array vector and sort elements in ascending order. The return value is a vector.

askPrices = array(INT[], 0, 10).append!([900 900 900 901 901, 800 800 802 802 802 803 803])
rowMergeAndSort(askPrices, true)
//output: ([800,800,802,802,802,803,803,900,900,900,901,901])

Example 2. Merge columnar tuples, with multiple sorting columns arranged in different orders: best ask prices in askPrices corresponds to different times, different order volumes, and different channels srcs . Now the data is merged and sorted in descending order of askPrices and ascending order of quoteTimes . The return value is a tuple.

srcs = [`SRC1`SRC1`SRC3`SRC3`SRC3, `SRC3`SRC3`SRC1`SRC2`SRC3`SRC1`SRC2].setColumnarTuple!(true)
askPrices = array(INT[], 0, 10).append!([900 900 900 901 901, 800 800 802 802 802 803 803])
quoteTimes = array(SECOND[], 0, 10).append!([09:30:00 09:30:00 09:30:00 09:30:01 09:30:02, 
	09:30:00 09:30:00 09:30:00 09:30:00 09:30:00 09:30:00 09:30:00])
askVols = array(INT[], 0, 10).append!([10 15 20 15 20, 20 15 30 40 20 15 30])
rowMergeAndSort([askPrices,quoteTimes], false true, srcs, askVols)
/*
output: 
([901,901,900,900,900,803,803,802,802,802,800,800],
[09:30:01,09:30:02,09:30:00,09:30:00,09:30:00,09:30:00,09:30:00,09:30:00,09:30:00,09:30:00,09:30:00,09:30:00],
["SRC3","SRC3","SRC1","SRC1","SRC3","SRC1","SRC2","SRC1","SRC2","SRC3","SRC3","SRC3"],
[15,20,10,15,20,15,30,30,40,20,20,15])
*/

Related Functions: rowFilterAndSort