-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogicalcu.cpp
More file actions
80 lines (75 loc) · 2.36 KB
/
Logicalcu.cpp
File metadata and controls
80 lines (75 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @file Logicalcu.cpp
*
* @brief chunkwise unique
*
* @par Synopsis: cu(A).
*
* @par Summary:
* something
* <br>
*
* @par Input:
* A is an array with one string attribute
* <br>
*
* @par Output array:
* Has same schema as A, but is sparse with only within-chunk unique elements
* <br>
*
* @par Examples:
* See help('cu')
* <br>
*
* @author B. W. Lewis <blewis@paradigm4.com>
*/
#include "query/Operator.h"
namespace scidb
{
class Logicalcu : public LogicalOperator
{
public:
Logicalcu(const string& logicalName, const string& alias):
LogicalOperator(logicalName, alias)
{
ADD_PARAM_INPUT()
_usage = "cu(A)\n"
"filter chunk-wise unique elements\n"
"where:\n"
" - A is an array with one string attribute\n\n"
"cu(A) returns a sparse array with schema identical to A whose entries contain\n"
"unique elements within each chunk by marking repeated entries empty. The array\n"
"A may be multi-dimensional and chunked arbitrarily. The cu filter is applied\n"
"independently within each chunk. It is intended to help speed up the SciDB uniq\n"
"and sort operators by cutting down on the amount of data to be sorted. Note\n"
"that the order of returned elements may differ from the input array although\n"
"the schema will be the same.\n"
"BASIC EXAMPLE:\n"
"iquery -aq \"load_library('cu')\"\n"
"iquery -aq \"cu(build(<s:string>[i=1:4,4,0],'{1}[(x),(y),(x),(a)]',true))\"\n"
"{i} s \n"
"{1} 'x' \n"
"{2} 'y' \n"
"{3} 'a' \n"
"{4} 'x' \n\n"
"iquery -aq \"cu(build(<s:string>[i=1:4,4,0],'{1}[(x),(y),(x),(a)]',true))\"\n"
"{i} s \n"
"{1} 'a'\n"
"{2} 'x'\n"
"{4} 'y'\n\n";
}
/* inferSchema helps the query planner decide on the shape of
* the output array. All operators must define this function.
*/
ArrayDesc inferSchema(vector< ArrayDesc> schemas, shared_ptr< Query> query)
{
ArrayDesc const& matrix = schemas[0];
if(matrix.getAttributes(true)[0].getType() != TID_STRING)
throw SYSTEM_EXCEPTION(SCIDB_SE_INTERNAL, SCIDB_LE_ILLEGAL_OPERATION) << "cu requires a single string-valued attribute";
Attributes outputAttributes(matrix.getAttributes());
Dimensions outputDimensions(matrix.getDimensions());
return ArrayDesc(matrix.getName(), outputAttributes, outputDimensions);
}
};
REGISTER_LOGICAL_OPERATOR_FACTORY(Logicalcu, "cu");
}