Class: Groonga::ColumnCache

Inherits:
Data
  • Object
show all
Defined in:
ext/groonga/rb-grn-column-cache.c,
ext/groonga/rb-grn-column-cache.c

Overview

This is a class for accelerating column value read.

FixSizeColumn is only supported for now.

Since:

  • 7.1.1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column) ⇒ Groonga::ColumnCache

Returns Create a new column cache.

Parameters:

Since:

  • 7.1.1



110
111
112
113
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
# File 'ext/groonga/rb-grn-column-cache.c', line 110

static VALUE
rb_grn_column_cache_initialize (VALUE self, VALUE rb_column)
{
    RbGrnColumnCache *rb_grn_column_cache;
    grn_ctx *context;
    grn_obj *column;
    grn_id range_id;

    rb_grn_column_cache = ALLOC(RbGrnColumnCache);
    rb_grn_column_cache->self = self;
    rb_grn_column_cache->context = NULL;
    rb_grn_column_cache->rb_column = rb_column;
    rb_grn_column_cache->column_cache = NULL;
    DATA_PTR(self) = rb_grn_column_cache;

    column = RVAL2GRNCOLUMN(rb_column, &(rb_grn_column_cache->context));
    context = rb_grn_column_cache->context;
    rb_grn_column_cache->column_cache = grn_column_cache_open(context, column);
    if (!rb_grn_column_cache->column_cache) {
        rb_raise(rb_eArgError,
                 "failed to create column cache: %s%s%" PRIsVALUE,
                 context->rc == GRN_SUCCESS ? "" : context->errbuf,
                 context->rc == GRN_SUCCESS ? "" : ": ",
                 rb_column);
    }

    range_id = grn_obj_get_range(context, column);
    GRN_VALUE_FIX_SIZE_INIT(&(rb_grn_column_cache->buffer),
                            GRN_OBJ_DO_SHALLOW_COPY,
                            range_id);
    rb_grn_column_cache->range = grn_ctx_at(context, range_id);
    rb_grn_column_cache->table = grn_ctx_at(context, column->header.domain);

    return Qnil;
}

Class Method Details

.open(column) {|The| ... } ⇒ Object

Opens a new column cache and passes to the given block. The opened column cache is closed after the given block is finished.

Returns The object returned by the given block.

Parameters:

Yield Parameters:

Returns:

  • (Object)

    The object returned by the given block.

Since:

  • 7.1.1



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'ext/groonga/rb-grn-column-cache.c', line 90

static VALUE
rb_grn_column_cache_s_open (VALUE klass, VALUE rb_column)
{
    VALUE rb_column_cache;

    rb_column_cache = rb_funcall(klass, rb_intern("new"), 1, rb_column);
    if (rb_block_given_p()) {
        return rb_ensure(rb_yield, rb_column_cache,
                         rb_grn_column_cache_close, rb_column_cache);
    } else {
        return rb_column_cache;
    }
}

Instance Method Details

#[](id) ⇒ Object

Returns The value for the record ID.

Parameters:

Returns:

  • (Object)

    The value for the record ID.

Since:

  • 7.1.1



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
# File 'ext/groonga/rb-grn-column-cache.c', line 153

static VALUE
rb_grn_column_cache_array_reference (VALUE self, VALUE rb_id)
{
    RbGrnColumnCache *rb_grn_column_cache;
    grn_id id;
    void *value;
    size_t value_size = 0;

    TypedData_Get_Struct(self,
                         RbGrnColumnCache,
                         &data_type,
                         rb_grn_column_cache);

    if (!rb_grn_column_cache->column_cache) {
        return Qnil;
    }

    id = rb_grn_id_from_ruby_object(rb_id,
                                    rb_grn_column_cache->context,
                                    rb_grn_column_cache->table,
                                    self);
    value = grn_column_cache_ref(rb_grn_column_cache->context,
                                 rb_grn_column_cache->column_cache,
                                 id,
                                 &value_size);
    rb_grn_context_check(rb_grn_column_cache->context, self);
    GRN_TEXT_SET_REF(&(rb_grn_column_cache->buffer),
                     value,
                     value_size);

    return GRNBULK2RVAL(rb_grn_column_cache->context,
                        &(rb_grn_column_cache->buffer),
                        rb_grn_column_cache->range,
                        self);
}

#closevoid

This method returns an undefined value.

Returns Close the column cache.

Since:

  • 7.1.1



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'ext/groonga/rb-grn-column-cache.c', line 193

static VALUE
rb_grn_column_cache_close (VALUE self)
{
    RbGrnColumnCache *rb_grn_column_cache;

    TypedData_Get_Struct(self,
                         RbGrnColumnCache,
                         &data_type,
                         rb_grn_column_cache);

    if (rb_grn_column_cache->column_cache) {
        GRN_OBJ_FIN(rb_grn_column_cache->context,
                    &(rb_grn_column_cache->buffer));
        grn_column_cache_close(rb_grn_column_cache->context,
                               rb_grn_column_cache->column_cache);
        rb_grn_column_cache->column_cache = NULL;
        rb_grn_context_check(rb_grn_column_cache->context, self);
    }

    return Qnil;
}