groonga 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.ja.rdoc +11 -0
- data/NEWS.rdoc +11 -0
- data/README.ja.rdoc +4 -3
- data/README.rdoc +4 -3
- data/Rakefile +1 -1
- data/TUTORIAL.ja.rdoc +168 -44
- data/benchmark/common.rb +49 -0
- data/benchmark/read-write-small-many-items.rb +156 -0
- data/benchmark/write-small-many-items.rb +145 -0
- data/example/bookmark.rb +68 -20
- data/ext/rb-grn-array-cursor.c +8 -0
- data/ext/rb-grn-array.c +40 -11
- data/ext/rb-grn-column.c +38 -209
- data/ext/rb-grn-context.c +203 -56
- data/ext/rb-grn-database.c +119 -5
- data/ext/rb-grn-encoding-support.c +64 -0
- data/ext/rb-grn-encoding.c +58 -1
- data/ext/rb-grn-fix-size-column.c +220 -0
- data/ext/rb-grn-hash-cursor.c +8 -0
- data/ext/rb-grn-hash.c +244 -2
- data/ext/rb-grn-index-column.c +474 -0
- data/ext/rb-grn-object.c +143 -265
- data/ext/rb-grn-patricia-trie.c +148 -2
- data/ext/rb-grn-query.c +5 -3
- data/ext/rb-grn-record.c +3 -2
- data/ext/rb-grn-snippet.c +5 -3
- data/ext/rb-grn-table-cursor-key-support.c +3 -3
- data/ext/rb-grn-table-cursor.c +106 -112
- data/ext/rb-grn-table-key-support.c +220 -118
- data/ext/rb-grn-table.c +336 -80
- data/ext/rb-grn-type.c +5 -4
- data/ext/rb-grn-utils.c +62 -63
- data/ext/rb-grn.h +215 -14
- data/ext/rb-groonga.c +7 -16
- data/extconf.rb +3 -1
- data/html/favicon.ico +0 -0
- data/html/favicon.xcf +0 -0
- data/html/index.html +1 -7
- data/lib/groonga/record.rb +6 -1
- data/test/groonga-test-utils.rb +1 -0
- data/test/test-array.rb +81 -0
- data/test/test-column.rb +22 -12
- data/test/test-context.rb +1 -29
- data/test/test-database.rb +30 -0
- data/test/test-hash.rb +194 -0
- data/test/test-index-column.rb +57 -0
- data/test/test-patricia-trie.rb +82 -0
- data/test/test-record.rb +10 -10
- data/test/test-table.rb +37 -130
- data/test/test-type.rb +4 -3
- metadata +15 -4
- data/benchmark/small-many-items.rb +0 -175
data/ext/rb-grn-table.c
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
#include "rb-grn.h"
|
20
20
|
|
21
|
-
#define SELF(object
|
21
|
+
#define SELF(object) ((RbGrnTable *)DATA_PTR(object))
|
22
22
|
|
23
23
|
VALUE rb_cGrnTable;
|
24
24
|
|
@@ -39,6 +39,85 @@ rb_grn_table_to_ruby_object (grn_ctx *context, grn_obj *table,
|
|
39
39
|
return GRNOBJECT2RVAL(rb_cGrnTable, context, table, owner);
|
40
40
|
}
|
41
41
|
|
42
|
+
void
|
43
|
+
rb_grn_table_unbind (RbGrnTable *rb_grn_table)
|
44
|
+
{
|
45
|
+
RbGrnObject *rb_grn_object;
|
46
|
+
grn_ctx *context;
|
47
|
+
|
48
|
+
rb_grn_object = RB_GRN_OBJECT(rb_grn_table);
|
49
|
+
context = rb_grn_object->context;
|
50
|
+
|
51
|
+
if (context)
|
52
|
+
grn_obj_close(context, rb_grn_table->value);
|
53
|
+
|
54
|
+
rb_grn_object_unbind(rb_grn_object);
|
55
|
+
}
|
56
|
+
|
57
|
+
static void
|
58
|
+
rb_grn_table_free (void *object)
|
59
|
+
{
|
60
|
+
RbGrnTable *rb_grn_table = object;
|
61
|
+
|
62
|
+
rb_grn_table_unbind(rb_grn_table);
|
63
|
+
xfree(rb_grn_table);
|
64
|
+
}
|
65
|
+
|
66
|
+
VALUE
|
67
|
+
rb_grn_table_alloc (VALUE klass)
|
68
|
+
{
|
69
|
+
return Data_Wrap_Struct(klass, NULL, rb_grn_table_free, NULL);
|
70
|
+
}
|
71
|
+
|
72
|
+
void
|
73
|
+
rb_grn_table_bind (RbGrnTable *rb_grn_table,
|
74
|
+
grn_ctx *context, grn_obj *table, rb_grn_boolean owner)
|
75
|
+
{
|
76
|
+
RbGrnObject *rb_grn_object;
|
77
|
+
|
78
|
+
rb_grn_object = RB_GRN_OBJECT(rb_grn_table);
|
79
|
+
rb_grn_object_bind(rb_grn_object, context, table, owner);
|
80
|
+
rb_grn_object->unbind = RB_GRN_UNBIND_FUNCTION(rb_grn_table_unbind);
|
81
|
+
|
82
|
+
rb_grn_table->value = grn_obj_open(context, GRN_BULK, 0,
|
83
|
+
rb_grn_object->range_id);
|
84
|
+
}
|
85
|
+
|
86
|
+
void
|
87
|
+
rb_grn_table_assign (VALUE self, VALUE rb_context,
|
88
|
+
grn_ctx *context, grn_obj *table,
|
89
|
+
rb_grn_boolean owner)
|
90
|
+
{
|
91
|
+
RbGrnTable *rb_grn_table;
|
92
|
+
|
93
|
+
rb_grn_table = ALLOC(RbGrnTable);
|
94
|
+
DATA_PTR(self) = rb_grn_table;
|
95
|
+
rb_grn_table_bind(rb_grn_table, context, table, owner);
|
96
|
+
|
97
|
+
rb_iv_set(self, "context", rb_context);
|
98
|
+
}
|
99
|
+
|
100
|
+
void
|
101
|
+
rb_grn_table_deconstruct (RbGrnTable *rb_grn_table,
|
102
|
+
grn_obj **table,
|
103
|
+
grn_ctx **context,
|
104
|
+
grn_id *domain_id,
|
105
|
+
grn_obj **domain,
|
106
|
+
grn_obj **value,
|
107
|
+
grn_id *range_id,
|
108
|
+
grn_obj **range)
|
109
|
+
{
|
110
|
+
RbGrnObject *rb_grn_object;
|
111
|
+
|
112
|
+
rb_grn_object = RB_GRN_OBJECT(rb_grn_table);
|
113
|
+
rb_grn_object_deconstruct(rb_grn_object, table, context,
|
114
|
+
domain_id, domain,
|
115
|
+
range_id, range);
|
116
|
+
|
117
|
+
if (value)
|
118
|
+
*value = rb_grn_table->value;
|
119
|
+
}
|
120
|
+
|
42
121
|
VALUE
|
43
122
|
rb_grn_table_s_create (int argc, VALUE *argv, VALUE klass,
|
44
123
|
grn_obj_flags key_store)
|
@@ -66,7 +145,7 @@ rb_grn_table_s_create (int argc, VALUE *argv, VALUE klass,
|
|
66
145
|
"value_size", &rb_value_size,
|
67
146
|
NULL);
|
68
147
|
|
69
|
-
context = rb_grn_context_ensure(rb_context);
|
148
|
+
context = rb_grn_context_ensure(&rb_context);
|
70
149
|
|
71
150
|
if (!NIL_P(rb_name)) {
|
72
151
|
name = StringValuePtr(rb_name);
|
@@ -98,7 +177,8 @@ rb_grn_table_s_create (int argc, VALUE *argv, VALUE klass,
|
|
98
177
|
|
99
178
|
table = grn_table_create(context, name, name_size, path,
|
100
179
|
flags, key_type, value_size);
|
101
|
-
rb_table =
|
180
|
+
rb_table = rb_grn_table_alloc(klass);
|
181
|
+
rb_grn_table_assign(rb_table, rb_context, context, table, RB_GRN_TRUE);
|
102
182
|
rb_grn_context_check(context, rb_table);
|
103
183
|
|
104
184
|
if (rb_block_given_p())
|
@@ -107,18 +187,19 @@ rb_grn_table_s_create (int argc, VALUE *argv, VALUE klass,
|
|
107
187
|
return rb_table;
|
108
188
|
}
|
109
189
|
|
110
|
-
|
111
|
-
|
190
|
+
grn_obj *
|
191
|
+
rb_grn_table_open_raw (int argc, VALUE *argv,
|
192
|
+
grn_ctx **context, VALUE *rb_context)
|
112
193
|
{
|
113
194
|
grn_obj *table;
|
114
195
|
char *name = NULL, *path = NULL;
|
115
196
|
unsigned name_size = 0;
|
116
|
-
VALUE rb_path, options,
|
197
|
+
VALUE rb_path, options, rb_name;
|
117
198
|
|
118
199
|
rb_scan_args(argc, argv, "01", &options);
|
119
200
|
|
120
201
|
rb_grn_scan_options(options,
|
121
|
-
"context",
|
202
|
+
"context", rb_context,
|
122
203
|
"name", &rb_name,
|
123
204
|
"path", &rb_path,
|
124
205
|
NULL);
|
@@ -142,9 +223,16 @@ rb_grn_table_initialize (int argc, VALUE *argv, VALUE self)
|
|
142
223
|
{
|
143
224
|
grn_ctx *context = NULL;
|
144
225
|
grn_obj *table;
|
226
|
+
VALUE rb_context;
|
145
227
|
|
146
|
-
table =
|
147
|
-
|
228
|
+
table = rb_grn_table_open_raw(argc, argv, &context, &rb_context);
|
229
|
+
/* FIXME!!!! */
|
230
|
+
if (self == rb_cGrnArray) {
|
231
|
+
rb_grn_table_assign(self, rb_context, context, table, RB_GRN_TRUE);
|
232
|
+
} else {
|
233
|
+
rb_grn_table_key_support_assign(self, rb_context, context,
|
234
|
+
table, RB_GRN_TRUE);
|
235
|
+
}
|
148
236
|
rb_grn_context_check(context, self);
|
149
237
|
|
150
238
|
return Qnil;
|
@@ -153,23 +241,44 @@ rb_grn_table_initialize (int argc, VALUE *argv, VALUE self)
|
|
153
241
|
static VALUE
|
154
242
|
rb_grn_table_s_open (int argc, VALUE *argv, VALUE klass)
|
155
243
|
{
|
156
|
-
|
244
|
+
VALUE rb_table;
|
157
245
|
grn_obj *table;
|
158
|
-
|
246
|
+
grn_ctx *context = NULL;
|
247
|
+
VALUE rb_context;
|
159
248
|
|
160
|
-
table =
|
249
|
+
table = rb_grn_table_open_raw(argc, argv, &context, &rb_context);
|
161
250
|
rb_grn_context_check(context, rb_ary_new4(argc, argv));
|
162
|
-
|
251
|
+
|
252
|
+
if (!table)
|
253
|
+
rb_raise(rb_eGrnError,
|
254
|
+
"unable to open table: %s: %s",
|
255
|
+
rb_grn_inspect(klass),
|
256
|
+
rb_grn_inspect(rb_ary_new4(argc, argv)));
|
257
|
+
|
258
|
+
if (klass == rb_cGrnTable) {
|
259
|
+
klass = GRNOBJECT2RCLASS(table);
|
260
|
+
} else {
|
261
|
+
VALUE rb_class;
|
262
|
+
|
163
263
|
rb_class = GRNOBJECT2RCLASS(table);
|
164
|
-
if (
|
264
|
+
if (rb_class != klass) {
|
165
265
|
rb_raise(rb_eTypeError,
|
166
266
|
"unexpected existing table type: %s: expected %s",
|
167
267
|
rb_grn_inspect(rb_class),
|
168
268
|
rb_grn_inspect(klass));
|
269
|
+
}
|
270
|
+
}
|
271
|
+
|
272
|
+
/* FIXME!!!! */
|
273
|
+
if (klass == rb_cGrnArray) {
|
274
|
+
rb_table = rb_grn_table_alloc(klass);
|
275
|
+
rb_grn_table_assign(rb_table, rb_context, context, table, RB_GRN_TRUE);
|
276
|
+
} else {
|
277
|
+
rb_table = rb_grn_table_key_support_alloc(klass);
|
278
|
+
rb_grn_table_key_support_assign(rb_table, rb_context, context,
|
279
|
+
table, RB_GRN_TRUE);
|
169
280
|
}
|
170
281
|
|
171
|
-
rb_table = rb_grn_object_alloc(klass);
|
172
|
-
rb_grn_table_initialize(argc, argv, rb_table);
|
173
282
|
if (rb_block_given_p())
|
174
283
|
return rb_ensure(rb_yield, rb_table, rb_grn_object_close, rb_table);
|
175
284
|
else
|
@@ -182,10 +291,14 @@ rb_grn_table_inspect_content (VALUE self, VALUE inspected)
|
|
182
291
|
grn_ctx *context = NULL;
|
183
292
|
grn_obj *table;
|
184
293
|
|
185
|
-
|
294
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
295
|
+
NULL, NULL,
|
296
|
+
NULL, NULL, NULL);
|
186
297
|
|
187
298
|
if (!table)
|
188
299
|
return inspected;
|
300
|
+
if (!context)
|
301
|
+
return inspected;
|
189
302
|
|
190
303
|
if (table->header.type != GRN_TABLE_NO_KEY) {
|
191
304
|
grn_obj value;
|
@@ -193,7 +306,7 @@ rb_grn_table_inspect_content (VALUE self, VALUE inspected)
|
|
193
306
|
|
194
307
|
rb_str_cat2(inspected, ", ");
|
195
308
|
rb_str_cat2(inspected, "encoding: <");
|
196
|
-
GRN_OBJ_INIT(&value, GRN_BULK, 0);
|
309
|
+
GRN_OBJ_INIT(&value, GRN_BULK, 0, GRN_ID_NIL);
|
197
310
|
grn_obj_get_info(context, table, GRN_INFO_ENCODING, &value);
|
198
311
|
encoding = *((grn_encoding *)GRN_BULK_HEAD(&value));
|
199
312
|
grn_obj_close(context, &value);
|
@@ -241,12 +354,12 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
|
|
241
354
|
char *name = NULL, *path = NULL;
|
242
355
|
unsigned name_size = 0;
|
243
356
|
grn_obj_flags flags = 0;
|
244
|
-
rb_grn_boolean use_default_type = RB_GRN_FALSE;
|
245
357
|
VALUE rb_name, rb_value_type;
|
246
358
|
VALUE options, rb_path, rb_persistent, rb_type;
|
247
|
-
VALUE rb_compress, rb_with_section, rb_with_weight, rb_with_position;
|
248
359
|
|
249
|
-
|
360
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
361
|
+
NULL, NULL,
|
362
|
+
NULL, NULL, NULL);
|
250
363
|
|
251
364
|
rb_scan_args(argc, argv, "21", &rb_name, &rb_value_type, &options);
|
252
365
|
|
@@ -257,10 +370,6 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
|
|
257
370
|
"path", &rb_path,
|
258
371
|
"persistent", &rb_persistent,
|
259
372
|
"type", &rb_type,
|
260
|
-
"compress", &rb_compress,
|
261
|
-
"with_section", &rb_with_section,
|
262
|
-
"with_weight", &rb_with_weight,
|
263
|
-
"with_position", &rb_with_position,
|
264
373
|
NULL);
|
265
374
|
|
266
375
|
value_type = RVAL2GRNOBJECT(rb_value_type, &context);
|
@@ -273,21 +382,69 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
|
|
273
382
|
if (RVAL2CBOOL(rb_persistent))
|
274
383
|
flags |= GRN_OBJ_PERSISTENT;
|
275
384
|
|
276
|
-
if (NIL_P(rb_type)
|
277
|
-
|
278
|
-
} else if (rb_grn_equal_option(rb_type, "index")) {
|
279
|
-
flags |= GRN_OBJ_COLUMN_INDEX;
|
280
|
-
} else if (rb_grn_equal_option(rb_type, "scalar")) {
|
385
|
+
if (NIL_P(rb_type) ||
|
386
|
+
(rb_grn_equal_option(rb_type, "scalar"))) {
|
281
387
|
flags |= GRN_OBJ_COLUMN_SCALAR;
|
282
388
|
} else if (rb_grn_equal_option(rb_type, "vector")) {
|
283
389
|
flags |= GRN_OBJ_COLUMN_VECTOR;
|
284
390
|
} else {
|
285
391
|
rb_raise(rb_eArgError,
|
286
392
|
"invalid column type: %s: "
|
287
|
-
"available types: [:
|
393
|
+
"available types: [:scalar, :vector, nil]",
|
288
394
|
rb_grn_inspect(rb_type));
|
289
395
|
}
|
290
396
|
|
397
|
+
column = grn_column_create(context, table, name, name_size,
|
398
|
+
path, flags, value_type);
|
399
|
+
rb_grn_context_check(context, self);
|
400
|
+
|
401
|
+
return GRNCOLUMN2RVAL(Qnil, context, column, RB_GRN_TRUE);
|
402
|
+
}
|
403
|
+
|
404
|
+
static VALUE
|
405
|
+
rb_grn_table_define_index_column (int argc, VALUE *argv, VALUE self)
|
406
|
+
{
|
407
|
+
grn_ctx *context = NULL;
|
408
|
+
grn_obj *table;
|
409
|
+
grn_obj *value_type, *column;
|
410
|
+
char *name = NULL, *path = NULL;
|
411
|
+
unsigned name_size = 0;
|
412
|
+
grn_obj_flags flags = GRN_OBJ_COLUMN_INDEX;
|
413
|
+
VALUE rb_name, rb_value_type;
|
414
|
+
VALUE options, rb_path, rb_persistent;
|
415
|
+
VALUE rb_compress, rb_with_section, rb_with_weight, rb_with_position;
|
416
|
+
VALUE rb_column, rb_source, rb_sources;
|
417
|
+
|
418
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
419
|
+
NULL, NULL,
|
420
|
+
NULL, NULL, NULL);
|
421
|
+
|
422
|
+
rb_scan_args(argc, argv, "21", &rb_name, &rb_value_type, &options);
|
423
|
+
|
424
|
+
name = StringValuePtr(rb_name);
|
425
|
+
name_size = RSTRING_LEN(rb_name);
|
426
|
+
|
427
|
+
rb_grn_scan_options(options,
|
428
|
+
"path", &rb_path,
|
429
|
+
"persistent", &rb_persistent,
|
430
|
+
"compress", &rb_compress,
|
431
|
+
"with_section", &rb_with_section,
|
432
|
+
"with_weight", &rb_with_weight,
|
433
|
+
"with_position", &rb_with_position,
|
434
|
+
"source", &rb_source,
|
435
|
+
"sources", &rb_sources,
|
436
|
+
NULL);
|
437
|
+
|
438
|
+
value_type = RVAL2GRNOBJECT(rb_value_type, &context);
|
439
|
+
|
440
|
+
if (!NIL_P(rb_path)) {
|
441
|
+
path = StringValueCStr(rb_path);
|
442
|
+
flags |= GRN_OBJ_PERSISTENT;
|
443
|
+
}
|
444
|
+
|
445
|
+
if (RVAL2CBOOL(rb_persistent))
|
446
|
+
flags |= GRN_OBJ_PERSISTENT;
|
447
|
+
|
291
448
|
if (NIL_P(rb_compress)) {
|
292
449
|
} else if (rb_grn_equal_option(rb_compress, "zlib")) {
|
293
450
|
flags |= GRN_OBJ_COMPRESS_ZLIB;
|
@@ -300,44 +457,45 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
|
|
300
457
|
rb_grn_inspect(rb_compress));
|
301
458
|
}
|
302
459
|
|
303
|
-
if (RVAL2CBOOL(rb_with_section))
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
460
|
+
if (RVAL2CBOOL(rb_with_section))
|
461
|
+
flags |= GRN_OBJ_WITH_SECTION;
|
462
|
+
|
463
|
+
if (RVAL2CBOOL(rb_with_weight))
|
464
|
+
flags |= GRN_OBJ_WITH_WEIGHT;
|
465
|
+
|
466
|
+
if (NIL_P(rb_with_position) &&
|
467
|
+
(table->header.type == GRN_TABLE_HASH_KEY ||
|
468
|
+
table->header.type == GRN_TABLE_PAT_KEY)) {
|
469
|
+
grn_id tokenizer_id;
|
470
|
+
grn_obj *tokenizer;
|
471
|
+
|
472
|
+
tokenizer = grn_obj_get_info(context, table,
|
473
|
+
GRN_INFO_DEFAULT_TOKENIZER,
|
474
|
+
NULL);
|
475
|
+
tokenizer_id = grn_obj_id(context, tokenizer);
|
476
|
+
if ((tokenizer_id == GRN_DB_UNIGRAM) ||
|
477
|
+
(tokenizer_id == GRN_DB_BIGRAM) ||
|
478
|
+
(tokenizer_id == GRN_DB_TRIGRAM)) {
|
479
|
+
rb_with_position = Qtrue;
|
480
|
+
}
|
323
481
|
}
|
482
|
+
if (RVAL2CBOOL(rb_with_position))
|
483
|
+
flags |= GRN_OBJ_WITH_POSITION;
|
324
484
|
|
325
|
-
if (
|
326
|
-
|
327
|
-
flags |= GRN_OBJ_COLUMN_INDEX;
|
328
|
-
if (flags & GRN_OBJ_COLUMN_INDEX)
|
329
|
-
flags |= GRN_OBJ_WITH_POSITION;
|
330
|
-
else
|
331
|
-
rb_raise(rb_eArgError,
|
332
|
-
"{:with_position => true} requires "
|
333
|
-
"{:type => :index} option.");
|
334
|
-
}
|
485
|
+
if (!NIL_P(rb_source) && !NIL_P(rb_sources))
|
486
|
+
rb_raise(rb_eArgError, "should not pass both of :source and :sources.");
|
335
487
|
|
336
488
|
column = grn_column_create(context, table, name, name_size,
|
337
489
|
path, flags, value_type);
|
338
490
|
rb_grn_context_check(context, self);
|
339
491
|
|
340
|
-
|
492
|
+
rb_column = GRNCOLUMN2RVAL(Qnil, context, column, RB_GRN_TRUE);
|
493
|
+
if (!NIL_P(rb_source))
|
494
|
+
rb_funcall(rb_column, rb_intern("source="), 1, rb_source);
|
495
|
+
if (!NIL_P(rb_sources))
|
496
|
+
rb_funcall(rb_column, rb_intern("sources="), 1, rb_sources);
|
497
|
+
|
498
|
+
return rb_column;
|
341
499
|
}
|
342
500
|
|
343
501
|
static VALUE
|
@@ -349,8 +507,11 @@ rb_grn_table_add_column (VALUE self, VALUE rb_name, VALUE rb_value_type,
|
|
349
507
|
grn_obj *value_type, *column;
|
350
508
|
char *name = NULL, *path = NULL;
|
351
509
|
unsigned name_size = 0;
|
510
|
+
VALUE rb_column;
|
352
511
|
|
353
|
-
|
512
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
513
|
+
NULL, NULL,
|
514
|
+
NULL, NULL, NULL);
|
354
515
|
|
355
516
|
name = StringValuePtr(rb_name);
|
356
517
|
name_size = RSTRING_LEN(rb_name);
|
@@ -363,7 +524,9 @@ rb_grn_table_add_column (VALUE self, VALUE rb_name, VALUE rb_value_type,
|
|
363
524
|
path, value_type);
|
364
525
|
rb_grn_context_check(context, self);
|
365
526
|
|
366
|
-
|
527
|
+
rb_column = GRNCOLUMN2RVAL(Qnil, context, column, RB_GRN_TRUE);
|
528
|
+
rb_iv_set(rb_column, "table", self);
|
529
|
+
return rb_column;
|
367
530
|
}
|
368
531
|
|
369
532
|
static VALUE
|
@@ -375,17 +538,23 @@ rb_grn_table_get_column (VALUE self, VALUE rb_name)
|
|
375
538
|
char *name = NULL;
|
376
539
|
unsigned name_size = 0;
|
377
540
|
rb_grn_boolean owner;
|
541
|
+
VALUE rb_column;
|
378
542
|
|
379
|
-
|
543
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
544
|
+
NULL, NULL,
|
545
|
+
NULL, NULL, NULL);
|
380
546
|
|
381
547
|
name = StringValuePtr(rb_name);
|
382
548
|
name_size = RSTRING_LEN(rb_name);
|
383
549
|
|
384
|
-
column =
|
550
|
+
column = grn_obj_column(context, table, name, name_size);
|
385
551
|
rb_grn_context_check(context, self);
|
386
552
|
|
387
553
|
owner = (column && column->header.type == GRN_ACCESSOR);
|
388
|
-
|
554
|
+
rb_column = GRNCOLUMN2RVAL(Qnil, context, column, owner);
|
555
|
+
if (owner)
|
556
|
+
rb_iv_set(rb_column, "table", self);
|
557
|
+
return rb_column;
|
389
558
|
}
|
390
559
|
|
391
560
|
static VALUE
|
@@ -401,7 +570,9 @@ rb_grn_table_get_columns (int argc, VALUE *argv, VALUE self)
|
|
401
570
|
char *name = NULL;
|
402
571
|
unsigned name_size = 0;
|
403
572
|
|
404
|
-
|
573
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
574
|
+
NULL, NULL,
|
575
|
+
NULL, NULL, NULL);
|
405
576
|
|
406
577
|
rb_scan_args(argc, argv, "01", &rb_name);
|
407
578
|
|
@@ -430,7 +601,7 @@ rb_grn_table_get_columns (int argc, VALUE *argv, VALUE self)
|
|
430
601
|
|
431
602
|
grn_table_cursor_get_key(context, cursor, &key);
|
432
603
|
column_id = key;
|
433
|
-
column =
|
604
|
+
column = grn_ctx_at(context, *column_id);
|
434
605
|
rb_column = GRNOBJECT2RVAL(Qnil, context, column, RB_GRN_FALSE);
|
435
606
|
rb_ary_push(rb_columns, rb_column);
|
436
607
|
}
|
@@ -454,7 +625,9 @@ rb_grn_table_open_grn_cursor (int argc, VALUE *argv, VALUE self,
|
|
454
625
|
int flags = 0;
|
455
626
|
VALUE options, rb_min, rb_max, rb_order, rb_greater_than, rb_less_than;
|
456
627
|
|
457
|
-
|
628
|
+
rb_grn_table_deconstruct(SELF(self), &table, context,
|
629
|
+
NULL, NULL,
|
630
|
+
NULL, NULL, NULL);
|
458
631
|
|
459
632
|
rb_scan_args(argc, argv, "01", &options);
|
460
633
|
|
@@ -531,7 +704,7 @@ rb_grn_table_get_records (int argc, VALUE *argv, VALUE self)
|
|
531
704
|
cursor = rb_grn_table_open_grn_cursor(argc, argv, self, &context);
|
532
705
|
records = rb_ary_new();
|
533
706
|
while ((record_id = grn_table_cursor_next(context, cursor))) {
|
534
|
-
rb_ary_push(records, rb_grn_record_new(self, record_id));
|
707
|
+
rb_ary_push(records, rb_grn_record_new(self, record_id, Qnil));
|
535
708
|
}
|
536
709
|
grn_table_cursor_close(context, cursor);
|
537
710
|
|
@@ -545,7 +718,9 @@ rb_grn_table_get_size (VALUE self)
|
|
545
718
|
grn_obj *table;
|
546
719
|
unsigned int size;
|
547
720
|
|
548
|
-
|
721
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
722
|
+
NULL, NULL,
|
723
|
+
NULL, NULL, NULL);
|
549
724
|
size = grn_table_size(context, table);
|
550
725
|
return UINT2NUM(size);
|
551
726
|
}
|
@@ -557,7 +732,9 @@ rb_grn_table_truncate (VALUE self)
|
|
557
732
|
grn_obj *table;
|
558
733
|
grn_rc rc;
|
559
734
|
|
560
|
-
|
735
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
736
|
+
NULL, NULL,
|
737
|
+
NULL, NULL, NULL);
|
561
738
|
rc = grn_table_truncate(context, table);
|
562
739
|
rb_grn_rc_check(rc, self);
|
563
740
|
|
@@ -570,21 +747,25 @@ rb_grn_table_each (VALUE self)
|
|
570
747
|
grn_ctx *context = NULL;
|
571
748
|
grn_obj *table;
|
572
749
|
grn_table_cursor *cursor;
|
750
|
+
VALUE rb_cursor;
|
573
751
|
grn_id id;
|
574
752
|
|
575
|
-
|
753
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
754
|
+
NULL, NULL,
|
755
|
+
NULL, NULL, NULL);
|
576
756
|
cursor = grn_table_cursor_open(context, table, NULL, 0, NULL, 0, 0);
|
577
|
-
|
757
|
+
rb_cursor = GRNTABLECURSOR2RVAL(Qnil, context, cursor);
|
758
|
+
rb_iv_set(self, "cursor", rb_cursor);
|
578
759
|
while ((id = grn_table_cursor_next(context, cursor)) != GRN_ID_NIL) {
|
579
|
-
rb_yield(rb_grn_record_new(self, id));
|
760
|
+
rb_yield(rb_grn_record_new(self, id, Qnil));
|
580
761
|
}
|
581
|
-
|
762
|
+
rb_grn_table_cursor_close(rb_cursor);
|
582
763
|
rb_iv_set(self, "cursor", Qnil);
|
583
764
|
|
584
765
|
return Qnil;
|
585
766
|
}
|
586
767
|
|
587
|
-
|
768
|
+
VALUE
|
588
769
|
rb_grn_table_delete (VALUE self, VALUE rb_id)
|
589
770
|
{
|
590
771
|
grn_ctx *context = NULL;
|
@@ -592,7 +773,9 @@ rb_grn_table_delete (VALUE self, VALUE rb_id)
|
|
592
773
|
grn_id id;
|
593
774
|
grn_rc rc;
|
594
775
|
|
595
|
-
|
776
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
777
|
+
NULL, NULL,
|
778
|
+
NULL, NULL, NULL);
|
596
779
|
|
597
780
|
id = NUM2UINT(rb_id);
|
598
781
|
rc = grn_table_delete_by_id(context, table, id);
|
@@ -614,7 +797,9 @@ rb_grn_table_sort (int argc, VALUE *argv, VALUE self)
|
|
614
797
|
VALUE rb_limit;
|
615
798
|
VALUE *rb_sort_keys;
|
616
799
|
|
617
|
-
|
800
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
801
|
+
NULL, NULL,
|
802
|
+
NULL, NULL, NULL);
|
618
803
|
|
619
804
|
rb_scan_args(argc, argv, "11", &rb_keys, &options);
|
620
805
|
rb_grn_scan_options(options,
|
@@ -664,10 +849,76 @@ rb_grn_table_sort (int argc, VALUE *argv, VALUE self)
|
|
664
849
|
return GRNOBJECT2RVAL(Qnil, context, result, RB_GRN_TRUE);
|
665
850
|
}
|
666
851
|
|
852
|
+
/*
|
853
|
+
* Document-method: []
|
854
|
+
*
|
855
|
+
* call-seq:
|
856
|
+
* table[id] -> 値
|
857
|
+
*
|
858
|
+
* _table_の_id_に対応する値を返す。
|
859
|
+
*/
|
860
|
+
VALUE
|
861
|
+
rb_grn_table_array_reference (VALUE self, VALUE rb_id)
|
862
|
+
{
|
863
|
+
grn_id id;
|
864
|
+
grn_ctx *context;
|
865
|
+
grn_obj *table;
|
866
|
+
grn_obj *range;
|
867
|
+
grn_obj *value;
|
868
|
+
|
869
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
870
|
+
NULL, NULL,
|
871
|
+
&value, NULL, &range);
|
872
|
+
|
873
|
+
id = NUM2UINT(rb_id);
|
874
|
+
GRN_BULK_REWIND(value);
|
875
|
+
grn_obj_get_value(context, table, id, value);
|
876
|
+
rb_grn_context_check(context, self);
|
877
|
+
|
878
|
+
if (GRN_BULK_EMPTYP(value))
|
879
|
+
return Qnil;
|
880
|
+
else
|
881
|
+
return rb_str_new(GRN_BULK_HEAD(value), GRN_BULK_VSIZE(value));
|
882
|
+
}
|
883
|
+
|
884
|
+
/*
|
885
|
+
* Document-method: []=
|
886
|
+
*
|
887
|
+
* call-seq:
|
888
|
+
* table[id] = value
|
889
|
+
*
|
890
|
+
* _table_の_id_に対応する値を設定する。既存の値は上書きさ
|
891
|
+
* れる。
|
892
|
+
*/
|
893
|
+
VALUE
|
894
|
+
rb_grn_table_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
|
895
|
+
{
|
896
|
+
grn_id id;
|
897
|
+
grn_ctx *context;
|
898
|
+
grn_obj *table;
|
899
|
+
grn_obj *range;
|
900
|
+
grn_obj *value;
|
901
|
+
grn_rc rc;
|
902
|
+
|
903
|
+
rb_grn_table_deconstruct(SELF(self), &table, &context,
|
904
|
+
NULL, NULL,
|
905
|
+
&value, NULL, &range);
|
906
|
+
|
907
|
+
id = NUM2UINT(rb_id);
|
908
|
+
GRN_BULK_REWIND(value);
|
909
|
+
RVAL2GRNBULK(rb_value, context, value);
|
910
|
+
rc = grn_obj_set_value(context, table, id, value, GRN_OBJ_SET);
|
911
|
+
rb_grn_context_check(context, self);
|
912
|
+
rb_grn_rc_check(rc, self);
|
913
|
+
|
914
|
+
return Qnil;
|
915
|
+
}
|
916
|
+
|
667
917
|
void
|
668
918
|
rb_grn_init_table (VALUE mGrn)
|
669
919
|
{
|
670
920
|
rb_cGrnTable = rb_define_class_under(mGrn, "Table", rb_cGrnObject);
|
921
|
+
rb_define_alloc_func(rb_cGrnTable, rb_grn_table_alloc);
|
671
922
|
|
672
923
|
rb_include_module(rb_cGrnTable, rb_mEnumerable);
|
673
924
|
|
@@ -680,6 +931,8 @@ rb_grn_init_table (VALUE mGrn)
|
|
680
931
|
|
681
932
|
rb_define_method(rb_cGrnTable, "define_column",
|
682
933
|
rb_grn_table_define_column, -1);
|
934
|
+
rb_define_method(rb_cGrnTable, "define_index_column",
|
935
|
+
rb_grn_table_define_index_column, -1);
|
683
936
|
rb_define_method(rb_cGrnTable, "add_column",
|
684
937
|
rb_grn_table_add_column, 3);
|
685
938
|
rb_define_method(rb_cGrnTable, "column",
|
@@ -699,6 +952,9 @@ rb_grn_init_table (VALUE mGrn)
|
|
699
952
|
|
700
953
|
rb_define_method(rb_cGrnTable, "sort", rb_grn_table_sort, -1);
|
701
954
|
|
955
|
+
rb_define_method(rb_cGrnTable, "[]", rb_grn_table_array_reference, 1);
|
956
|
+
rb_define_method(rb_cGrnTable, "[]=", rb_grn_table_array_set, 2);
|
957
|
+
|
702
958
|
rb_grn_init_table_key_support(mGrn);
|
703
959
|
rb_grn_init_array(mGrn);
|
704
960
|
rb_grn_init_hash(mGrn);
|
data/ext/rb-grn-type.c
CHANGED
@@ -60,7 +60,7 @@ rb_grn_type_initialize (int argc, VALUE *argv, VALUE self)
|
|
60
60
|
name = StringValuePtr(rb_name);
|
61
61
|
name_size = RSTRING_LEN(rb_name);
|
62
62
|
|
63
|
-
context = rb_grn_context_ensure(rb_context);
|
63
|
+
context = rb_grn_context_ensure(&rb_context);
|
64
64
|
|
65
65
|
if (NIL_P(rb_key_type)) {
|
66
66
|
flags = GRN_OBJ_KEY_VAR_SIZE;
|
@@ -85,7 +85,7 @@ rb_grn_type_initialize (int argc, VALUE *argv, VALUE self)
|
|
85
85
|
}
|
86
86
|
|
87
87
|
type = grn_type_create(context, name, name_size, flags, size);
|
88
|
-
|
88
|
+
rb_grn_object_assign(self, rb_context, context, type, RB_GRN_TRUE);
|
89
89
|
rb_grn_context_check(context, rb_ary_new4(argc, argv));
|
90
90
|
|
91
91
|
return Qnil;
|
@@ -98,9 +98,10 @@ rb_grn_init_type (VALUE mGrn)
|
|
98
98
|
|
99
99
|
rb_define_method(rb_cGrnType, "initialize", rb_grn_type_initialize, -1);
|
100
100
|
|
101
|
-
rb_define_const(rb_cGrnType, "
|
102
|
-
rb_define_const(rb_cGrnType, "
|
101
|
+
rb_define_const(rb_cGrnType, "INT32", INT2NUM(GRN_DB_INT32));
|
102
|
+
rb_define_const(rb_cGrnType, "UINT32", INT2NUM(GRN_DB_UINT32));
|
103
103
|
rb_define_const(rb_cGrnType, "INT64", INT2NUM(GRN_DB_INT64));
|
104
|
+
rb_define_const(rb_cGrnType, "UINT64", INT2NUM(GRN_DB_UINT64));
|
104
105
|
rb_define_const(rb_cGrnType, "FLOAT", INT2NUM(GRN_DB_FLOAT));
|
105
106
|
rb_define_const(rb_cGrnType, "TIME", INT2NUM(GRN_DB_TIME));
|
106
107
|
rb_define_const(rb_cGrnType, "SHORT_TEXT", INT2NUM(GRN_DB_SHORTTEXT));
|