rroonga 9.0.3 → 9.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +30 -0
- data/ext/groonga/rb-grn-context.c +27 -0
- data/ext/groonga/rb-grn-flushable.c +7 -0
- data/ext/groonga/rb-grn-index-column.c +28 -0
- data/ext/groonga/rb-grn-index-cursor.c +19 -0
- data/ext/groonga/rb-grn-logger.c +17 -3
- data/ext/groonga/rb-grn-object.c +236 -22
- data/ext/groonga/rb-grn-table.c +68 -42
- data/ext/groonga/rb-grn.h +1 -1
- data/lib/groonga/dumper.rb +3 -0
- data/lib/groonga/record.rb +2 -2
- data/test/groonga-test-utils.rb +28 -5
- data/test/run-test.rb +0 -2
- data/test/test-accessor.rb +63 -7
- data/test/test-context.rb +25 -0
- data/test/test-exception.rb +5 -0
- data/test/test-flushable.rb +51 -6
- data/test/test-index-column.rb +67 -6
- data/test/test-index-cursor.rb +26 -0
- data/test/test-logger.rb +56 -11
- data/test/test-plugin.rb +1 -0
- data/test/test-query-logger.rb +4 -3
- data/test/test-record.rb +2 -1
- data/test/test-remote.rb +40 -10
- data/test/test-schema-dumper.rb +13 -0
- data/test/test-table.rb +21 -1
- data/test/test-variable.rb +23 -7
- metadata +59 -59
data/ext/groonga/rb-grn-table.c
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
/*
|
3
3
|
Copyright (C) 2009-2017 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
Copyright (C) 2014-2016 Masafumi Yokoyama <yokoyama@clear-code.com>
|
5
|
+
Copyright (C) 2019 Horimoto Yasuhiro <horimoto@clear-code.com>
|
5
6
|
|
6
7
|
This library is free software; you can redistribute it and/or
|
7
8
|
modify it under the terms of the GNU Lesser General Public
|
@@ -29,9 +30,9 @@ static ID id_array_set;
|
|
29
30
|
/*
|
30
31
|
* Document-class: Groonga::Table < Groonga::Object
|
31
32
|
*
|
32
|
-
* Rroonga
|
33
|
-
*
|
34
|
-
*
|
33
|
+
* This class is base class which represents Rroonga's table.
|
34
|
+
* {Groonga::Array} , {Groonga::Hash} , {Groonga::PatriciaTrie}
|
35
|
+
* are extended from this class.
|
35
36
|
*/
|
36
37
|
|
37
38
|
grn_obj *
|
@@ -183,7 +184,8 @@ rb_grn_table_inspect_content (VALUE self, VALUE inspected)
|
|
183
184
|
}
|
184
185
|
|
185
186
|
/*
|
186
|
-
*
|
187
|
+
* This function return contents of a table as a string.
|
188
|
+
* It's easy to understand for human.
|
187
189
|
*
|
188
190
|
* @overload inspect
|
189
191
|
* @return [String]
|
@@ -203,31 +205,33 @@ rb_grn_table_inspect (VALUE self)
|
|
203
205
|
}
|
204
206
|
|
205
207
|
/*
|
206
|
-
*
|
207
|
-
*
|
208
|
+
* Defines a column that name is `name` and type is `value_type`. It
|
209
|
+
* returns the newly defined column.
|
208
210
|
*
|
209
211
|
* @overload define_column(name, value_type, options={})
|
210
212
|
* @param options [::Hash] The name and value
|
211
213
|
* pairs. Omitted names are initialized as the default value.
|
212
|
-
* @option options :path
|
213
|
-
*
|
214
|
-
*
|
215
|
-
*
|
216
|
-
*
|
217
|
-
*
|
214
|
+
* @option options :path [String, nil] (nil)
|
215
|
+
* The path to store the content of the column.
|
216
|
+
* If this is omitted, path is generated automatically.
|
217
|
+
* @option options :persistent [Boolean] (true)
|
218
|
+
* Whether the column is a persistent column or not.
|
219
|
+
* If this is `true` and `:path` is omitted, path is generated
|
220
|
+
* automatically.
|
218
221
|
* @option options :type (:scalar)
|
219
|
-
*
|
220
|
-
* +:scalar+
|
222
|
+
* This option specifies how to store a value of a column.
|
223
|
+
* If this option is omitted, +:scalar+ is used.
|
221
224
|
*
|
222
|
-
* - +:scalar+ :=
|
223
|
-
* - +:vector+ :=
|
225
|
+
* - +:scalar+ := Store scalar value.
|
226
|
+
* - +:vector+ := Store array value.
|
224
227
|
* @option options [Boolean] :with_weight (false)
|
225
228
|
* It specifies whether making the column weight vector column or not.
|
226
229
|
* Weight vector column can store weight for each element.
|
227
230
|
*
|
228
231
|
* You can't use this option for scalar column.
|
229
232
|
* @option options :compress
|
230
|
-
*
|
233
|
+
* This option specifies how to compress values.
|
234
|
+
* If we omit this option, values are not compressed.
|
231
235
|
*
|
232
236
|
* * `:zlib`: Compressed by zlib.
|
233
237
|
* * `:lz4`: Compressed by LZ4.
|
@@ -345,32 +349,37 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
|
|
345
349
|
}
|
346
350
|
|
347
351
|
/*
|
348
|
-
*
|
349
|
-
*
|
352
|
+
* Defines an index column that name is `name` and type is
|
353
|
+
* `value_type`. It returns the newly defined index column.
|
350
354
|
*
|
351
355
|
* @overload define_index_column(name, value_type, options={})
|
352
356
|
* @param options [::Hash] The name and value
|
353
357
|
* pairs. Omitted names are initialized as the default value.
|
354
|
-
* @option options :path
|
355
|
-
*
|
356
|
-
*
|
357
|
-
*
|
358
|
-
*
|
359
|
-
*
|
360
|
-
*
|
361
|
-
*
|
362
|
-
*
|
363
|
-
*
|
364
|
-
*
|
365
|
-
*
|
366
|
-
*
|
367
|
-
*
|
368
|
-
*
|
369
|
-
*
|
370
|
-
*
|
371
|
-
*
|
372
|
-
*
|
373
|
-
*
|
358
|
+
* @option options :path [String, nil] (nil)
|
359
|
+
* The path to store the content of the index column.
|
360
|
+
* If this is omitted, path is generated automatically.
|
361
|
+
* @option options :persistent [Boolean] (true)
|
362
|
+
* Whether the index column is a persistent indent column or not.
|
363
|
+
* If this is `true` and `:path` is omitted, path is generated
|
364
|
+
* automatically.
|
365
|
+
* @option options :with_section [Boolean] (false)
|
366
|
+
* Whether section information is stored to the index column or not.
|
367
|
+
* @option options :with_weight [Boolean] (false)
|
368
|
+
* Whether weight information is stored to the index column or not.
|
369
|
+
* @option options :with_position [Boolean] (false)
|
370
|
+
* Whether position information is stored to the index column or not.
|
371
|
+
* @option options :size [Symbol, nil] (nil)
|
372
|
+
* The size of index column. It must be `nil`, `:small`,
|
373
|
+
* `:medium` or `:large`. `nil` means the default size.
|
374
|
+
* `:small` means small size. `:medium` means medium size. Medium size
|
375
|
+
* is smaller than the default size. `:large` means large size.
|
376
|
+
* Large size is larger than the default size.
|
377
|
+
* @option options :source [Groonga::Column, nil] (nil)
|
378
|
+
* Specifies the source column of the index column.
|
379
|
+
* This option can't be used with `:sources`.
|
380
|
+
* @option options :sources [::Array<Groonga::Column>, nil] (nil)
|
381
|
+
* Specifies the source columns of the index column.
|
382
|
+
* This option can't be used with `:source`.
|
374
383
|
*
|
375
384
|
* @return [Groonga::IndexColumn]
|
376
385
|
*/
|
@@ -461,9 +470,11 @@ rb_grn_table_define_index_column (int argc, VALUE *argv, VALUE self)
|
|
461
470
|
flags |= GRN_OBJ_INDEX_SMALL;
|
462
471
|
} else if (rb_grn_equal_option(rb_size, "medium")) {
|
463
472
|
flags |= GRN_OBJ_INDEX_MEDIUM;
|
473
|
+
} else if (rb_grn_equal_option(rb_size, "large")) {
|
474
|
+
flags |= GRN_OBJ_INDEX_LARGE;
|
464
475
|
} else {
|
465
476
|
rb_raise(rb_eArgError,
|
466
|
-
":size must be nil, :small or :
|
477
|
+
":size must be nil, :small, :medium or :large: <%" PRIsVALUE ">",
|
467
478
|
rb_size);
|
468
479
|
}
|
469
480
|
|
@@ -2482,8 +2493,8 @@ rb_grn_table_support_key_p (VALUE self)
|
|
2482
2493
|
/*
|
2483
2494
|
* @overload support_value?
|
2484
2495
|
*
|
2485
|
-
* @return
|
2486
|
-
*
|
2496
|
+
* @return [Boolean] `true` if the table is created with value type,
|
2497
|
+
* `false` otherwise.
|
2487
2498
|
*/
|
2488
2499
|
static VALUE
|
2489
2500
|
rb_grn_table_support_value_p (VALUE self)
|
@@ -2517,6 +2528,19 @@ rb_grn_table_support_sub_records_p (VALUE self)
|
|
2517
2528
|
return CBOOL2RVAL(grn_table_is_grouped(context, table));
|
2518
2529
|
}
|
2519
2530
|
|
2531
|
+
/*
|
2532
|
+
* @overload support_score?
|
2533
|
+
*
|
2534
|
+
* @return [Boolean] `true` if the table has `_score` column,
|
2535
|
+
* `false` otherwise.
|
2536
|
+
*/
|
2537
|
+
static VALUE
|
2538
|
+
rb_grn_table_support_score_p (VALUE self)
|
2539
|
+
{
|
2540
|
+
return CBOOL2RVAL(rb_grn_table_have_column(self,
|
2541
|
+
rb_str_new_literal("_score")));
|
2542
|
+
}
|
2543
|
+
|
2520
2544
|
/*
|
2521
2545
|
* {Groonga::Table#group} returns a table that contains grouped
|
2522
2546
|
* records. If grouped table has a space to store the number of
|
@@ -2890,6 +2914,8 @@ rb_grn_init_table (VALUE mGrn)
|
|
2890
2914
|
rb_grn_table_support_value_p, 0);
|
2891
2915
|
rb_define_method(rb_cGrnTable, "support_sub_records?",
|
2892
2916
|
rb_grn_table_support_sub_records_p, 0);
|
2917
|
+
rb_define_method(rb_cGrnTable, "support_score?",
|
2918
|
+
rb_grn_table_support_score_p, 0);
|
2893
2919
|
rb_define_method(rb_cGrnTable, "have_n_sub_records_space?",
|
2894
2920
|
rb_grn_table_have_n_sub_records_space_p, 0);
|
2895
2921
|
|
data/ext/groonga/rb-grn.h
CHANGED
@@ -99,7 +99,7 @@ RB_GRN_BEGIN_DECLS
|
|
99
99
|
|
100
100
|
#define RB_GRN_MAJOR_VERSION 9
|
101
101
|
#define RB_GRN_MINOR_VERSION 0
|
102
|
-
#define RB_GRN_MICRO_VERSION
|
102
|
+
#define RB_GRN_MICRO_VERSION 7
|
103
103
|
|
104
104
|
#define RB_GRN_OBJECT(object) ((RbGrnObject *)(object))
|
105
105
|
#define RB_GRN_NAMED_OBJECT(object) ((RbGrnNamedObject *)(object))
|
data/lib/groonga/dumper.rb
CHANGED
@@ -491,6 +491,8 @@ module Groonga
|
|
491
491
|
options[:size] = :small
|
492
492
|
elsif column.medium?
|
493
493
|
options[:size] = :medium
|
494
|
+
elsif column.large?
|
495
|
+
options[:size] = :large
|
494
496
|
end
|
495
497
|
arguments = [
|
496
498
|
dump_object(target_table_name),
|
@@ -652,6 +654,7 @@ module Groonga
|
|
652
654
|
flags << "WITH_POSITION" if column.with_position?
|
653
655
|
flags << "INDEX_SMALL" if column.small?
|
654
656
|
flags << "INDEX_MEDIUM" if column.medium?
|
657
|
+
flags << "INDEX_LARGE" if column.large?
|
655
658
|
parameters << "#{flags.join('|')}"
|
656
659
|
parameters << "#{column.range.name}"
|
657
660
|
source_names = column.sources.collect do |source|
|
data/lib/groonga/record.rb
CHANGED
@@ -205,10 +205,10 @@ module Groonga
|
|
205
205
|
self["_score"] = new_score
|
206
206
|
end
|
207
207
|
|
208
|
-
# {Groonga::Record#score} が利用できる場合は
|
208
|
+
# {Groonga::Record#score} が利用できる場合は `true` を
|
209
209
|
# 返す。
|
210
210
|
def support_score?
|
211
|
-
@table.
|
211
|
+
@table.support_score?
|
212
212
|
end
|
213
213
|
|
214
214
|
# 主キーの値が同一であったレコードの件数を返す。検索結果とし
|
data/test/groonga-test-utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (C) 2015 Masafumi Yokoyama <yokoyama@clear-code.com>
|
2
|
-
# Copyright (C) 2009-
|
2
|
+
# Copyright (C) 2009-2019 Kouhei Sutou <kou@clear-code.com>
|
3
3
|
#
|
4
4
|
# This library is free software; you can redistribute it and/or
|
5
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -14,13 +14,16 @@
|
|
14
14
|
# License along with this library; if not, write to the Free Software
|
15
15
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
16
|
|
17
|
+
require "erb"
|
17
18
|
require "fileutils"
|
19
|
+
require "json"
|
18
20
|
require "pathname"
|
21
|
+
require "stringio"
|
19
22
|
require "tempfile"
|
20
23
|
require "time"
|
21
|
-
require "
|
22
|
-
|
23
|
-
require "
|
24
|
+
require "timeout"
|
25
|
+
|
26
|
+
require "groonga/client"
|
24
27
|
require "pkg-config"
|
25
28
|
|
26
29
|
require "groonga"
|
@@ -44,7 +47,7 @@ module GroongaTestUtils
|
|
44
47
|
setup_context
|
45
48
|
|
46
49
|
@database = nil
|
47
|
-
name_for_path = name
|
50
|
+
name_for_path = escape_path(name)
|
48
51
|
@database_path = @tmp_dir + "#{name_for_path}.db"
|
49
52
|
end
|
50
53
|
|
@@ -69,9 +72,11 @@ module GroongaTestUtils
|
|
69
72
|
|
70
73
|
@log_path = @tmp_dir + "groonga.log"
|
71
74
|
Groonga::Logger.path = @log_path.to_s
|
75
|
+
Groonga::Logger.reopen
|
72
76
|
|
73
77
|
@query_log_path = @tmp_dir + "groonga-query.log"
|
74
78
|
Groonga::QueryLogger.path = @query_log_path.to_s
|
79
|
+
Groonga::QueryLogger.reopen
|
75
80
|
end
|
76
81
|
|
77
82
|
def setup_tables_directory
|
@@ -107,6 +112,14 @@ module GroongaTestUtils
|
|
107
112
|
end
|
108
113
|
end
|
109
114
|
|
115
|
+
def collect_query_log
|
116
|
+
@query_log_path.open do |file|
|
117
|
+
file.seek(0, IO::SEEK_END)
|
118
|
+
yield
|
119
|
+
file.read
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
110
123
|
def setup_database
|
111
124
|
@database = Groonga::Database.create(:path => @database_path.to_s)
|
112
125
|
end
|
@@ -155,6 +168,12 @@ module GroongaTestUtils
|
|
155
168
|
actual.expression.inspect)
|
156
169
|
end
|
157
170
|
|
171
|
+
def escape_path(path)
|
172
|
+
path.gsub(/[: ?!\(\)\[\]]/) do
|
173
|
+
"_"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
158
177
|
def linux?
|
159
178
|
/linux/ =~ RUBY_PLATFORM
|
160
179
|
end
|
@@ -167,6 +186,10 @@ module GroongaTestUtils
|
|
167
186
|
/cygwin|mingw|mswin/ === RUBY_PLATFORM
|
168
187
|
end
|
169
188
|
|
189
|
+
def only_not_windows
|
190
|
+
omit("This test is only for non Windows system.") if windows?
|
191
|
+
end
|
192
|
+
|
170
193
|
def support_self_recursive_equal?
|
171
194
|
self_recursive_hash1 = {}
|
172
195
|
self_recursive_hash1["next"] = self_recursive_hash1
|
data/test/run-test.rb
CHANGED
data/test/test-accessor.rb
CHANGED
@@ -19,12 +19,13 @@ class AccessorTest < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
def setup
|
21
21
|
setup_database
|
22
|
-
@posts = Groonga::Hash.create(:name => "Posts",
|
22
|
+
@posts = Groonga::Hash.create(:name => "Posts",
|
23
|
+
:key_type => "ShortText",
|
24
|
+
:value_type => "UInt32")
|
25
|
+
@grouped_posts = @posts.group("_key")
|
23
26
|
@id = @posts.column("_id")
|
24
|
-
|
25
|
-
|
26
|
-
def teardown
|
27
|
-
@id = nil
|
27
|
+
@key = @posts.column("_key")
|
28
|
+
@value = @posts.column("_value")
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_name
|
@@ -51,9 +52,8 @@ class AccessorTest < Test::Unit::TestCase
|
|
51
52
|
|
52
53
|
sub_test_case "#key_accessor?" do
|
53
54
|
test "true" do
|
54
|
-
key = @posts.column("_key")
|
55
55
|
assert do
|
56
|
-
key.key_accessor?
|
56
|
+
@key.key_accessor?
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -63,4 +63,60 @@ class AccessorTest < Test::Unit::TestCase
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
sub_test_case "#id_accessor?" do
|
68
|
+
test "true" do
|
69
|
+
assert do
|
70
|
+
@id.id_accessor?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test "false" do
|
75
|
+
assert do
|
76
|
+
not @key.id_accessor?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
sub_test_case "#value_accessor?" do
|
82
|
+
test "true" do
|
83
|
+
assert do
|
84
|
+
@value.value_accessor?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
test "false" do
|
89
|
+
assert do
|
90
|
+
not @key.value_accessor?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
sub_test_case "#score_accessor?" do
|
96
|
+
test "true" do
|
97
|
+
assert do
|
98
|
+
@posts.select.column("_score").score_accessor?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
test "false" do
|
103
|
+
assert do
|
104
|
+
not @key.score_accessor?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
sub_test_case "#n_sub_records_accessor?" do
|
110
|
+
test "true" do
|
111
|
+
assert do
|
112
|
+
@grouped_posts.column("_nsubrecs").n_sub_records_accessor?
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
test "false" do
|
117
|
+
assert do
|
118
|
+
not @key.n_sub_records_accessor?
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
66
122
|
end
|
data/test/test-context.rb
CHANGED
@@ -132,6 +132,31 @@ class ContextTest < Test::Unit::TestCase
|
|
132
132
|
assert_equal(-1, context.match_escalation_threshold)
|
133
133
|
end
|
134
134
|
|
135
|
+
sub_test_case("#force_match_escalation?") do
|
136
|
+
def setup
|
137
|
+
default_force_match_escalation = context.force_match_escalation?
|
138
|
+
begin
|
139
|
+
yield
|
140
|
+
ensure
|
141
|
+
context.force_match_escalation = default_force_match_escalation
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_true
|
146
|
+
context.force_match_escalation = true
|
147
|
+
assert do
|
148
|
+
context.force_match_escalation?
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_false
|
153
|
+
context.force_match_escalation = false
|
154
|
+
assert do
|
155
|
+
not context.force_match_escalation?
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
135
160
|
def test_close
|
136
161
|
context = Groonga::Context.new
|
137
162
|
assert_false(context.closed?)
|
data/test/test-exception.rb
CHANGED
@@ -108,11 +108,16 @@ class TooManyOpenFilesTest < Test::Unit::TestCase
|
|
108
108
|
include GroongaTestUtils
|
109
109
|
|
110
110
|
def setup
|
111
|
+
@sub_context = nil
|
112
|
+
unless Process.const_defined?(:RLIMIT_NOFILE)
|
113
|
+
omit("No Process::RLIMIT_NOFILE")
|
114
|
+
end
|
111
115
|
setup_database
|
112
116
|
@sub_context = create_sub_context
|
113
117
|
end
|
114
118
|
|
115
119
|
def teardown
|
120
|
+
return if @sub_context.nil?
|
116
121
|
@sub_context.database.close
|
117
122
|
@sub_context.close
|
118
123
|
end
|