store
The store operator stores query output into a SciDB array.
Synopsis
store(operator(operator_args), target_array [, distribution: hashed/replicated/row_cyclic/col_cyclic]);
store(source_array, target_array[, distribution:
hashed/replicated/row_cyclic/col_cyclic
]
);
Summary
The store() operator lets you:
- Save the resultant array from operator(operator_args) into an existing or new array.
- Duplicate an array.
- Reclaim storage space on a Linux file system by duplicating an array, removing the original array, and renaming the duplicated array.
If the target array already exists, the source array schema must match the target's schema. A new version of the target array is created containing only data from the source. Previously stored data is still available by accessing older array versions. Use insert or append to add new data to an array without discarding existing data.
The store() operator is a write operator (an AFL operation that can update an array). Each store execution creates a new version of the named_array. As you update an array, newly-created versions use more disk space to store the array versions. When you remove an array, SciDB removes all of its versions as well. To keep an array, but not the previous versions, copy the array, and then delete the original. See remove_versions.
The store() operator accepts an optional keyword distribution. When target_array does not yet exist, you may use this keyword to specify the distribution for target_array. For more information see Array Distribution.
The AFL store operator provides the same functionality as the AQL SELECT * INTO ... FROM ... statement.
The store() operator must not be embedded in other SciDB operators.
Examples
Store a 2-Dimensional, 1-Attribute Array using build operator
Build and store a 2-dimensional, 1-attribute array with each value equal to
AFL% store(build(<val:double>[i=0:2; j=0:2], i + double(j)/10), store_example);
Scan the stored array:
AFL% scan(store_example); {i,j} val {0,0} 0 {0,1} 0.1 {0,2} 0.2 {1,0} 1 {1,1} 1.1 {1,2} 1.2 {2,0} 2 {2,1} 2.1 {2,2} 2.2
Duplicate an Array
Copy the array, store_example, to the new array store_example_copy.
AFL% store(store_example, store_example_copy);
Scan the copied array:
AFL% scan(store_example_copy); {i,j} val {0,0} 0 {0,1} 0.1 {0,2} 0.2 {1,0} 1 {1,1} 1.1 {1,2} 1.2 {2,0} 2 {2,1} 2.1 {2,2} 2.2
Reclaim Storage Space
This example assumes the array, store_reclaim_example, has more than one version.
To create the example, enter the following:
AFL% store(build(<val:double>[i=0:1], i), store_reclaim_example); --create first version AFL% store(build(<val:double>[i=0:1], double(i)/2), store_reclaim_example); --create second version
Confirm array has multiple versions by running:
AFL% aggregate(versions(store_reclaim_example),count(*));
The output is:{i} count {0} 2
Reclaim storage space on file system by removing all versions of an array, except for the current version:
AFL% store(store_reclaim_example, temp_reclaim); --copy original to temporary array AFL% remove(store_reclaim_example); --remove the the original array with multiple versions AFL% rename(temp_reclaim, store_reclaim_example); --rename the temporary array to the original name
Confirm that now there is only one version of the array:
AFL% aggregate(versions(store_reclaim_example),count(*));
The output is:{i} count {0} 1
Remove the example arrays by running:
AFL% remove(store_example); remove(store_example_copy); remove(store_reclaim_example);