Class: AerospikeNative::Scan

Inherits:
Object
  • Object
show all
Defined in:
ext/aerospike_native/scan.c

Constant Summary collapse

STATUS_UNDEFINED =
INT2FIX(AS_SCAN_STATUS_UNDEF)
STATUS_INPROGRESS =
INT2FIX(AS_SCAN_STATUS_INPROGRESS)
STATUS_ABORTED =
INT2FIX(AS_SCAN_STATUS_ABORTED)
STATUS_COMPLETED =
INT2FIX(AS_SCAN_STATUS_COMPLETED)
PRIORITY_AUTO =
INT2FIX(AS_SCAN_PRIORITY_AUTO)
PRIORITY_HIGH =
INT2FIX(AS_SCAN_PRIORITY_HIGH)
PRIORITY_MEDIUM =
INT2FIX(AS_SCAN_PRIORITY_MEDIUM)
PRIORITY_LOW =
INT2FIX(AS_SCAN_PRIORITY_LOW)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vClient, vNamespace, vSet) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'ext/aerospike_native/scan.c', line 8

VALUE scan_initialize(VALUE vSelf, VALUE vClient, VALUE vNamespace, VALUE vSet)
{
    Check_Type(vNamespace, T_STRING);
    Check_Type(vSet, T_STRING);
    check_aerospike_client(vClient);

    rb_iv_set(vSelf, "@client", vClient);
    rb_iv_set(vSelf, "@namespace", vNamespace);
    rb_iv_set(vSelf, "@set", vSet);

    return vSelf;
}

Instance Attribute Details

#clientObject (readonly)

#concurrentObject (readonly)

#no_binsObject (readonly)

#percentObject (readonly)

#priorityObject (readonly)

#select_binsObject (readonly)

Class Method Details

.info(, vSelf) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'ext/aerospike_native/scan.c', line 218

VALUE scan_info(int argc, VALUE* vArgs, VALUE vSelf)
{
    VALUE vClient, vHash;
    as_scan_info info;
    as_policy_scan policy;
    as_error err;
    aerospike* ptr;
    uint64_t scan_id;

    if (argc > 3 || argc < 2) {  // there should only be 2 or 3 arguments
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
    }

    vClient = vArgs[0];
    check_aerospike_client(vClient);

//    Check_Type(vArgs[1], T_BIGNUM);
    scan_id = NUM2ULONG(vArgs[1]);

    as_policy_scan_init(&policy);
    if(argc == 3 && TYPE(vArgs[2]) != T_NIL) {
        SET_SCAN_POLICY(policy, vArgs[2]);
    }

    Data_Get_Struct(vClient, aerospike, ptr);

    if (aerospike_scan_info(ptr, &err, &policy, scan_id, &info) != AEROSPIKE_OK) {
        raise_aerospike_exception(err.code, err.message);
    }

    vHash = rb_hash_new();
    rb_hash_aset(vHash, rb_str_new2("progress_percent"), ULONG2NUM(info.progress_pct));
    rb_hash_aset(vHash, rb_str_new2("records_scanned"), ULONG2NUM(info.records_scanned));
    rb_hash_aset(vHash, rb_str_new2("status"), INT2NUM(info.status));

    return vHash;
}

Instance Method Details

#apply(, vSelf) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/aerospike_native/scan.c', line 87

VALUE scan_apply(int argc, VALUE* vArgs, VALUE vSelf)
{
    if (argc < 2 || argc > 3) {  // there should only be 2 or 3 arguments
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
    }

    Check_Type(vArgs[0], T_STRING);
    Check_Type(vArgs[1], T_STRING);
    rb_iv_set(vSelf, "@udf_module", vArgs[0]);
    rb_iv_set(vSelf, "@udf_function", vArgs[1]);

    if (argc == 3 && TYPE(vArgs[2]) != T_NIL) {
        Check_Type(vArgs[2], T_ARRAY);
    }

    return vSelf;
}

#exec(, vSelf) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'ext/aerospike_native/scan.c', line 114

VALUE scan_exec(int argc, VALUE* vArgs, VALUE vSelf)
{
    VALUE vClient, vNamespace, vSet;
    VALUE vArray;
    VALUE vConcurrent, vPercent, vPriority, vBins, vNoBins, vUdfModule;
    as_scan scan;
    as_policy_scan policy;
    as_error err;
    aerospike* ptr;

    int n, idx = 0;
    bool is_background = false;

    if (argc > 1) {  // there should only be 0 or 1 argument
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
    }

    as_policy_scan_init(&policy);
    if(argc == 1) {
        SET_SCAN_POLICY(policy, vArgs[0]);
    }

    vClient = rb_iv_get(vSelf, "@client");
    vNamespace = rb_iv_get(vSelf, "@namespace");
    vSet = rb_iv_get(vSelf, "@set");
    vConcurrent = rb_iv_get(vSelf, "@concurrent");
    vPercent = rb_iv_get(vSelf, "@percent");
    vPriority = rb_iv_get(vSelf, "@priority");
    vNoBins = rb_iv_get(vSelf, "@no_bins");
    vBins = rb_iv_get(vSelf, "@select_bins");
    as_scan_init(&scan, StringValueCStr(vNamespace), StringValueCStr(vSet));

    if (TYPE(vPercent) == T_FIXNUM) {
        as_scan_set_percent(&scan, FIX2INT(vPercent));
    }

    if (TYPE(vPriority) == T_FIXNUM) {
        as_scan_set_priority(&scan, FIX2INT(vPriority));
    }

    if (TYPE(vConcurrent) != T_NIL) {
        as_scan_set_priority(&scan, RTEST(vConcurrent));
    }

    if (TYPE(vNoBins) != T_NIL) {
        as_scan_set_nobins(&scan, RTEST(vNoBins));
    }

    if (TYPE(vBins) == T_ARRAY && (idx = RARRAY_LEN(vBins)) > 0) {
        as_scan_select_inita(&scan, idx);
        for(n = 0; n < idx; n++) {
            VALUE vEntry = rb_ary_entry(vBins, n);
            as_scan_select(&scan, StringValueCStr(vEntry));
        }
    }

    vUdfModule = rb_iv_get(vSelf, "@udf_module");
    switch(TYPE(vUdfModule)) {
    case T_NIL:
        break;
    case T_STRING: {
        VALUE vUdfFunction = rb_iv_get(vSelf, "@udf_function");
        as_scan_apply_each(&scan, StringValueCStr(vUdfModule), StringValueCStr(vUdfFunction), NULL);
        is_background = true;
        break;
    }
    default:
        rb_raise(rb_eTypeError, "wrong argument type for udf module (expected String or Nil)");
    }

    Data_Get_Struct(vClient, aerospike, ptr);

    vArray = rb_ary_new();
    if(is_background) {
        uint64_t scan_id = 0;
        if (aerospike_scan_background(ptr, &err, &policy, &scan, &scan_id) != AEROSPIKE_OK) {
            as_scan_destroy(&scan);
            raise_aerospike_exception(err.code, err.message);
        }
        as_scan_destroy(&scan);
        return ULONG2NUM(scan_id);
    }

    if (aerospike_scan_foreach(ptr, &err, &policy, &scan, query_callback, &vArray) != AEROSPIKE_OK) {
        as_scan_destroy(&scan);
        raise_aerospike_exception(err.code, err.message);
    }

    as_scan_destroy(&scan);
    if ( rb_block_given_p() ) {
        return Qnil;
    }

    return vArray;
}

#select(, vSelf) ⇒ Object



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
# File 'ext/aerospike_native/scan.c', line 28

VALUE scan_select(int argc, VALUE* vArgs, VALUE vSelf)
{
    VALUE vBins;
    int i;

    if (argc == 0) {  // there should be greater than 0
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..n)", argc);
    }

    vBins = rb_iv_get(vSelf, "@select_bins");
    if(TYPE(vBins) == T_NIL) {
        vBins = rb_ary_new();
    }
    if (argc == 1) {
        int idx;
        VALUE vArray = vArgs[0];
        Check_Type(vArray, T_ARRAY);
        idx = RARRAY_LEN(vArray);
        for(i = 0; i < idx; i++) {
            VALUE vString = rb_ary_entry(vArray, i);
            GET_STRING(vString);
            rb_ary_push(vBins, vString);
        }
    } else {
        for(i = 0; i < argc; i++) {
            VALUE vString = vArgs[i];
            GET_STRING(vString);
            rb_ary_push(vBins, vString);
        }
    }

    rb_iv_set(vSelf, "@select_bins", vBins);
    return vSelf;
}

#set_concurrent(vValue) ⇒ Object



63
64
65
66
67
# File 'ext/aerospike_native/scan.c', line 63

VALUE scan_concurrent(VALUE vSelf, VALUE vValue)
{
    rb_iv_set(vSelf, "@concurrent", vValue);
    return vSelf;
}

#set_no_bins(vValue) ⇒ Object



81
82
83
84
85
# File 'ext/aerospike_native/scan.c', line 81

VALUE scan_no_bins(VALUE vSelf, VALUE vValue)
{
    rb_iv_set(vSelf, "@no_bins", vValue);
    return vSelf;
}

#set_percent(vValue) ⇒ Object



69
70
71
72
73
# File 'ext/aerospike_native/scan.c', line 69

VALUE scan_percent(VALUE vSelf, VALUE vValue)
{
    rb_iv_set(vSelf, "@percent", vValue);
    return vSelf;
}

#set_priority(vValue) ⇒ Object



75
76
77
78
79
# File 'ext/aerospike_native/scan.c', line 75

VALUE scan_priority(VALUE vSelf, VALUE vValue)
{
    rb_iv_set(vSelf, "@priority", vValue);
    return vSelf;
}