merge
The merge operator produces a result array by merging the data from two other arrays.
Synopsis
merge(left_array,right_array);
Summary
The following table shows the relationship between input and output cells.
The merge operator requires that the left_array and right_array have the same number of attributes.
The attribute names in the left_array and right_array need not match as attribute names are irrelevant to the merge operator. Instead, the first attribute of the left_array corresponds to the first attribute of the right_array; the second to the second, and so on.
- In the ordering of attributes in each array, each pair of corresponding attributes requires the same datatype and the same null/not null setting.
The left_array and right_array require the same number of dimensions.
Here too, the names are irrelevant. Dimensions of the operand arrays correspond based on the left-to-right order of dimensions.
- In the ordering of dimensions in each array, each pair of corresponding dimensions must have the same chunk overlap and dimension starting index.
- Corresponding dimensions may have different chunk sizes, and if so then SciDB reconciles them by inserting a redimension operator. This has a performance cost.
For each cell, merge combines elements from the input arrays as follows:
- If the cell of the first array is not empty, the attributes from that cell are selected and placed in the output.
- If the cell in the first array is empty, the attributes of the corresponding cell in the second array are taken.
- If the cell is empty in both input arrays, the output cell is set to empty.
If the dimensions are not the same size, merge returns an output array the same size as the larger input array.
Examples
Using the Operator
To demonstrate merge operator, do the following:
Enter:
AFL% store(filter(build(<attr1:double>[i=0:3; j=0:3],i+j),i=j),A);
The output is:{i,j} attr1 {0,0} 0 {1,1} 2 {2,2} 4 {3,3} 6
Enter:
AFL% store(filter(build(<attr2:double>[i=0:3; j=0:3],100),i=0),B);Â
The output is:{i,j} attr2 {0,0} 100 {0,1} 100 {0,2} 100 {0,3} 100
Merge them by entering:
AFL% merge(A, B);Â
The output is:{i,j} attr1 {0,0} 0 {0,1} 100 {1,1} 2 {0,2} 100 {0,3} 100 {2,2} 4 {3,3} 6
Remove the arrays by entering:
AFL% remove(A); remove(B);