rroonga 1.2.9 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -0
- data/Rakefile +1 -0
- data/bin/grntest-log-analyze +123 -0
- data/bin/groonga-query-log-extract +117 -0
- data/ext/groonga/rb-grn-accessor.c +7 -5
- data/ext/groonga/rb-grn-array-cursor.c +1 -1
- data/ext/groonga/rb-grn-array.c +34 -44
- data/ext/groonga/rb-grn-column.c +74 -38
- data/ext/groonga/rb-grn-context.c +19 -15
- data/ext/groonga/rb-grn-database.c +47 -42
- data/ext/groonga/rb-grn-double-array-trie-cursor.c +40 -0
- data/ext/groonga/rb-grn-double-array-trie.c +530 -0
- data/ext/groonga/rb-grn-encoding-support.c +1 -1
- data/ext/groonga/rb-grn-encoding.c +1 -1
- data/ext/groonga/rb-grn-exception.c +1 -1
- data/ext/groonga/rb-grn-expression-builder.c +1 -1
- data/ext/groonga/rb-grn-expression.c +63 -51
- data/ext/groonga/rb-grn-fix-size-column.c +7 -7
- data/ext/groonga/rb-grn-hash-cursor.c +1 -1
- data/ext/groonga/rb-grn-hash.c +42 -39
- data/ext/groonga/rb-grn-index-column.c +35 -31
- data/ext/groonga/rb-grn-index-cursor.c +1 -1
- data/ext/groonga/rb-grn-logger.c +23 -18
- data/ext/groonga/rb-grn-object.c +40 -27
- data/ext/groonga/rb-grn-operator.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie-cursor.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie.c +122 -90
- data/ext/groonga/rb-grn-plugin.c +8 -7
- data/ext/groonga/rb-grn-posting.c +1 -1
- data/ext/groonga/rb-grn-procedure.c +1 -1
- data/ext/groonga/rb-grn-query.c +12 -12
- data/ext/groonga/rb-grn-record.c +1 -1
- data/ext/groonga/rb-grn-snippet.c +26 -19
- data/ext/groonga/rb-grn-table-cursor-key-support.c +1 -1
- data/ext/groonga/rb-grn-table-cursor.c +4 -3
- data/ext/groonga/rb-grn-table-key-support.c +23 -23
- data/ext/groonga/rb-grn-table.c +268 -153
- data/ext/groonga/rb-grn-type.c +11 -7
- data/ext/groonga/rb-grn-utils.c +4 -1
- data/ext/groonga/rb-grn-variable-size-column.c +1 -1
- data/ext/groonga/rb-grn-variable.c +2 -2
- data/ext/groonga/rb-grn-view-accessor.c +1 -1
- data/ext/groonga/rb-grn-view-cursor.c +1 -1
- data/ext/groonga/rb-grn-view-record.c +1 -1
- data/ext/groonga/rb-grn-view.c +43 -34
- data/ext/groonga/rb-grn.h +6 -2
- data/ext/groonga/rb-groonga.c +1 -1
- data/lib/groonga.rb +4 -2
- data/lib/groonga/context.rb +16 -41
- data/lib/groonga/dumper.rb +6 -4
- data/lib/groonga/expression-builder.rb +52 -26
- data/lib/groonga/grntest-log.rb +206 -0
- data/lib/groonga/pagination.rb +21 -19
- data/lib/groonga/patricia-trie.rb +7 -10
- data/lib/groonga/posting.rb +1 -1
- data/lib/groonga/query-log.rb +348 -0
- data/lib/groonga/record.rb +47 -143
- data/lib/groonga/schema.rb +679 -406
- data/lib/groonga/view-record.rb +4 -10
- data/rroonga-build.rb +1 -1
- data/test/test-array.rb +25 -4
- data/test/test-column.rb +8 -8
- data/test/test-database.rb +2 -3
- data/test/test-double-array-trie.rb +164 -0
- data/test/test-expression-builder.rb +2 -2
- data/test/test-expression.rb +10 -9
- data/test/test-gqtp.rb +2 -2
- data/test/test-hash.rb +32 -8
- data/test/test-patricia-trie.rb +34 -10
- data/test/test-query-log.rb +258 -0
- data/test/test-record.rb +6 -5
- data/test/test-schema-create-table.rb +8 -0
- data/test/test-schema.rb +491 -234
- data/test/test-table.rb +17 -24
- metadata +123 -100
- data/ext/groonga/Makefile +0 -233
data/test/test-patricia-trie.rb
CHANGED
@@ -42,11 +42,11 @@ class PatriciaTrieTest < Test::Unit::TestCase
|
|
42
42
|
|
43
43
|
def test_search
|
44
44
|
users = Groonga::Array.create(:name => "Users")
|
45
|
-
|
45
|
+
users.define_column("name", "ShortText")
|
46
46
|
|
47
47
|
bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks",
|
48
48
|
:key_type => "ShortText")
|
49
|
-
|
49
|
+
bookmarks.define_column("user_id", users)
|
50
50
|
|
51
51
|
daijiro = users.add
|
52
52
|
daijiro["name"] = "daijiro"
|
@@ -187,10 +187,10 @@ class PatriciaTrieTest < Test::Unit::TestCase
|
|
187
187
|
def test_prefix_search
|
188
188
|
paths = Groonga::PatriciaTrie.create(:name => "Paths",
|
189
189
|
:key_type => 'ShortText')
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
190
|
+
paths.add('/')
|
191
|
+
paths.add('/tmp')
|
192
|
+
paths.add('/usr/bin')
|
193
|
+
paths.add('/usr/local/bin')
|
194
194
|
|
195
195
|
records = paths.prefix_search('/')
|
196
196
|
assert_equal(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
|
@@ -213,10 +213,10 @@ class PatriciaTrieTest < Test::Unit::TestCase
|
|
213
213
|
def test_prefix_cursor
|
214
214
|
paths = Groonga::PatriciaTrie.create(:name => "Paths",
|
215
215
|
:key_type => 'ShortText')
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
216
|
+
paths.add('/')
|
217
|
+
paths.add('/tmp')
|
218
|
+
paths.add('/usr/bin')
|
219
|
+
paths.add('/usr/local/bin')
|
220
220
|
|
221
221
|
assert_prefix_cursor(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
|
222
222
|
paths, "/", {:order => :desc})
|
@@ -388,4 +388,28 @@ class PatriciaTrieTest < Test::Unit::TestCase
|
|
388
388
|
bob_again = users.add("bob")
|
389
389
|
assert_not_predicate(bob_again, :added?)
|
390
390
|
end
|
391
|
+
|
392
|
+
def test_defrag
|
393
|
+
users = Groonga::PatriciaTrie.create(:name => "Users",
|
394
|
+
:key_type => "ShortText")
|
395
|
+
users.define_column("name", "ShortText")
|
396
|
+
users.define_column("address", "ShortText")
|
397
|
+
1000.times do |i|
|
398
|
+
users.add("user #{i}",
|
399
|
+
:name => "user #{i}" * 1000,
|
400
|
+
:address => "address #{i}" * 1000)
|
401
|
+
end
|
402
|
+
assert_equal(7, users.defrag)
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_rename
|
406
|
+
users = Groonga::PatriciaTrie.create(:name => "Users",
|
407
|
+
:key_type => "ShortText")
|
408
|
+
name = users.define_column("name", "ShortText")
|
409
|
+
address = users.define_column("address", "ShortText")
|
410
|
+
|
411
|
+
users.rename("People")
|
412
|
+
assert_equal(["People", "People.name", "People.address"],
|
413
|
+
[users.name, name.name, address.name])
|
414
|
+
end
|
391
415
|
end
|
@@ -0,0 +1,258 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) 2011 Kouhei Sutou <kou@clear-code.com>
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License version 2.1 as published by the Free Software Foundation.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
16
|
+
|
17
|
+
require "cgi"
|
18
|
+
|
19
|
+
module QueryLogTest
|
20
|
+
module CommandParseTestUtils
|
21
|
+
private
|
22
|
+
def command(name, parameters)
|
23
|
+
Groonga::QueryLog::Command.new(name, parameters)
|
24
|
+
end
|
25
|
+
|
26
|
+
def parse_http_path(command, parameters)
|
27
|
+
path = "/d/#{command}.json"
|
28
|
+
unless parameters.empty?
|
29
|
+
uri_parameters = parameters.collect do |key, value|
|
30
|
+
[CGI.escape(key.to_s), CGI.escape(value.to_s)].join("=")
|
31
|
+
end
|
32
|
+
path << "?"
|
33
|
+
path << uri_parameters.join("&")
|
34
|
+
end
|
35
|
+
Groonga::QueryLog::Command.parse(path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_command_line(command, parameters)
|
39
|
+
command_line = "#{command} --output_type json"
|
40
|
+
parameters.each do |key, value|
|
41
|
+
if /"| / =~ value
|
42
|
+
escaped_value = '"' + value.gsub(/"/, '\"') + '"'
|
43
|
+
else
|
44
|
+
escaped_value = value
|
45
|
+
end
|
46
|
+
command_line << " --#{key} #{escaped_value}"
|
47
|
+
end
|
48
|
+
Groonga::QueryLog::Command.parse(command_line)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
module HTTPCommandParseTestUtils
|
53
|
+
private
|
54
|
+
def parse(command, parameters={})
|
55
|
+
parse_http_path(command, parameters)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module CommandLineCommandParseTestUtils
|
60
|
+
private
|
61
|
+
def parse(command, parameters={})
|
62
|
+
parse_command_line(command, parameters)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module SelectCommandParseTests
|
67
|
+
include CommandParseTestUtils
|
68
|
+
|
69
|
+
def test_parameters
|
70
|
+
select = parse("select",
|
71
|
+
:table => "Users",
|
72
|
+
:filter => "age<=30")
|
73
|
+
assert_equal(command("select",
|
74
|
+
"table" => "Users",
|
75
|
+
"filter" => "age<=30",
|
76
|
+
"output_type" => "json"),
|
77
|
+
select)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_scorer
|
81
|
+
select = parse("select",
|
82
|
+
:table => "Users",
|
83
|
+
:filter => "age<=30",
|
84
|
+
:scorer => "_score = random()")
|
85
|
+
assert_equal("_score = random()", select.scorer)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_to_uri_format
|
89
|
+
select = parse("select",
|
90
|
+
:table => "Users",
|
91
|
+
:filter => "age<=30")
|
92
|
+
assert_equal("/d/select.json?filter=age%3C%3D30&table=Users",
|
93
|
+
select.to_uri_format)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_to_command_format
|
97
|
+
select = parse("select",
|
98
|
+
:table => "Users",
|
99
|
+
:filter => "age<=30")
|
100
|
+
assert_equal("select --filter \"age<=30\" " +
|
101
|
+
"--output_type \"json\" --table \"Users\"",
|
102
|
+
select.to_command_format)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
module SelectCommandParseFilterTests
|
107
|
+
include CommandParseTestUtils
|
108
|
+
|
109
|
+
def test_parenthesis
|
110
|
+
filter = 'geo_in_rectangle(location,' +
|
111
|
+
'"35.73360x139.7394","62614x139.7714") && ' +
|
112
|
+
'((type == "たいやき" || type == "和菓子")) && ' +
|
113
|
+
'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
|
114
|
+
select = parse("select",
|
115
|
+
:table => "Users",
|
116
|
+
:filter => filter)
|
117
|
+
assert_equal(['geo_in_rectangle(location,' +
|
118
|
+
'"35.73360x139.7394","62614x139.7714")',
|
119
|
+
'type == "たいやき"',
|
120
|
+
'type == "和菓子"',
|
121
|
+
'keyword @ "たいやき"',
|
122
|
+
'keyword @ "白"',
|
123
|
+
'keyword @ "養殖"'],
|
124
|
+
select.conditions)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_to_uri_format
|
128
|
+
filter = 'geo_in_rectangle(location,' +
|
129
|
+
'"35.73360x139.7394","62614x139.7714") && ' +
|
130
|
+
'((type == "たいやき" || type == "和菓子")) && ' +
|
131
|
+
'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
|
132
|
+
select = parse("select",
|
133
|
+
:table => "Users",
|
134
|
+
:filter => filter)
|
135
|
+
assert_equal("/d/select.json?filter=geo_in_rectangle%28location%2C" +
|
136
|
+
"%2235.73360x139.7394%22%2C%2262614x139.7714%22%29+" +
|
137
|
+
"%26%26+%28%28type+" +
|
138
|
+
"%3D%3D+%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+" +
|
139
|
+
"%7C%7C+type+%3D%3D+" +
|
140
|
+
"%22%E5%92%8C%E8%8F%93%E5%AD%90%22%29%29+" +
|
141
|
+
"%26%26+keyword+%40+" +
|
142
|
+
"%22%E3%81%9F%E3%81%84%E3%82%84%E3%81%8D%22+%26%21+" +
|
143
|
+
"keyword+%40+%22%E7%99%BD%22+%26%21+" +
|
144
|
+
"keyword+%40+%22%E9%A4%8A%E6%AE%96%22&table=Users",
|
145
|
+
select.to_uri_format)
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_to_command_format
|
149
|
+
filter = 'geo_in_rectangle(location,' +
|
150
|
+
'"35.73360x139.7394","62614x139.7714") && ' +
|
151
|
+
'((type == "たいやき" || type == "和菓子")) && ' +
|
152
|
+
'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
|
153
|
+
select = parse("select",
|
154
|
+
:table => "Users",
|
155
|
+
:filter => filter)
|
156
|
+
assert_equal("select " +
|
157
|
+
"--filter " +
|
158
|
+
"\"geo_in_rectangle(location," +
|
159
|
+
"\\\"35.73360x139.7394\\\",\\\"62614x139.7714\\\") && " +
|
160
|
+
"((type == \\\"たいやき\\\" || " +
|
161
|
+
"type == \\\"和菓子\\\")) && " +
|
162
|
+
"keyword @ \\\"たいやき\\\" &! keyword @ \\\"白\\\" &! " +
|
163
|
+
"keyword @ \\\"養殖\\\"\" " +
|
164
|
+
"--output_type \"json\" --table \"Users\"",
|
165
|
+
select.to_command_format)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
class HTTPSelectCommandParseTest < Test::Unit::TestCase
|
170
|
+
include SelectCommandParseTests
|
171
|
+
include SelectCommandParseFilterTests
|
172
|
+
include HTTPCommandParseTestUtils
|
173
|
+
|
174
|
+
def test_uri_format?
|
175
|
+
command = parse("status")
|
176
|
+
assert_predicate(command, :uri_format?)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_command_format?
|
180
|
+
command = parse("status")
|
181
|
+
assert_not_predicate(command, :command_format?)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
class CommandLineSelecCommandParseTest < Test::Unit::TestCase
|
186
|
+
include SelectCommandParseTests
|
187
|
+
include SelectCommandParseFilterTests
|
188
|
+
include CommandLineCommandParseTestUtils
|
189
|
+
|
190
|
+
def test_uri_format?
|
191
|
+
command = parse("status")
|
192
|
+
assert_not_predicate(command, :uri_format?)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_command_format?
|
196
|
+
command = parse("status")
|
197
|
+
assert_predicate(command, :command_format?)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class StatisticOperationParseTest < Test::Unit::TestCase
|
202
|
+
def test_context
|
203
|
+
operations = statistics.first.operations.collect do |operation|
|
204
|
+
[operation[:name], operation[:context]]
|
205
|
+
end
|
206
|
+
expected = [
|
207
|
+
["filter", "local_name @ \"gsub\""],
|
208
|
+
["filter", "description @ \"string\""],
|
209
|
+
["select", nil],
|
210
|
+
["sort", "_score"],
|
211
|
+
["output", "_key"],
|
212
|
+
["drilldown", "name"],
|
213
|
+
["drilldown", "class"],
|
214
|
+
]
|
215
|
+
assert_equal(expected, operations)
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_n_records
|
219
|
+
operations = statistics.first.operations.collect do |operation|
|
220
|
+
[operation[:name], operation[:n_records]]
|
221
|
+
end
|
222
|
+
expected = [
|
223
|
+
["filter", 15],
|
224
|
+
["filter", 13],
|
225
|
+
["select", 13],
|
226
|
+
["sort", 10],
|
227
|
+
["output", 10],
|
228
|
+
["drilldown", 3],
|
229
|
+
["drilldown", 2],
|
230
|
+
]
|
231
|
+
assert_equal(expected, operations)
|
232
|
+
end
|
233
|
+
|
234
|
+
private
|
235
|
+
def log
|
236
|
+
<<-EOL
|
237
|
+
2011-06-02 16:27:04.731685|5091e5c0|>/d/select.join?table=Entries&filter=local_name+%40+%22gsub%22+%26%26+description+%40+%22string%22&sortby=_score&output_columns=_key&drilldown=name,class
|
238
|
+
2011-06-02 16:27:04.733539|5091e5c0|:000000001849451 filter(15)
|
239
|
+
2011-06-02 16:27:04.734978|5091e5c0|:000000003293459 filter(13)
|
240
|
+
2011-06-02 16:27:04.735012|5091e5c0|:000000003327415 select(13)
|
241
|
+
2011-06-02 16:27:04.735096|5091e5c0|:000000003411824 sort(10)
|
242
|
+
2011-06-02 16:27:04.735232|5091e5c0|:000000003547265 output(10)
|
243
|
+
2011-06-02 16:27:04.735606|5091e5c0|:000000003921419 drilldown(3)
|
244
|
+
2011-06-02 16:27:04.735762|5091e5c0|:000000004077552 drilldown(2)
|
245
|
+
2011-06-02 16:27:04.735808|5091e5c0|<000000004123726 rc=0
|
246
|
+
EOL
|
247
|
+
end
|
248
|
+
|
249
|
+
def statistics
|
250
|
+
statistics = []
|
251
|
+
parser = Groonga::QueryLog::Parser.new
|
252
|
+
parser.parse(StringIO.new(log)) do |statistic|
|
253
|
+
statistics << statistic
|
254
|
+
end
|
255
|
+
statistics
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
data/test/test-record.rb
CHANGED
@@ -168,12 +168,13 @@ class RecordTest < Test::Unit::TestCase
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def test_delete
|
171
|
-
|
172
|
-
|
173
|
-
|
171
|
+
bookmark_records = []
|
172
|
+
bookmark_records << @bookmarks.add
|
173
|
+
bookmark_records << @bookmarks.add
|
174
|
+
bookmark_records << @bookmarks.add
|
174
175
|
|
175
176
|
assert_equal(3, @bookmarks.size)
|
176
|
-
|
177
|
+
bookmark_records[1].delete
|
177
178
|
assert_equal(2, @bookmarks.size)
|
178
179
|
end
|
179
180
|
|
@@ -375,7 +376,7 @@ class RecordTest < Test::Unit::TestCase
|
|
375
376
|
end
|
376
377
|
|
377
378
|
def test_select_result_attributes
|
378
|
-
|
379
|
+
@bookmarks.add(top_page)
|
379
380
|
select_result = @bookmarks.select
|
380
381
|
select_result_result = select_result.first
|
381
382
|
|
@@ -102,6 +102,14 @@ module SchemaCreateTableTests
|
|
102
102
|
def test_default_path
|
103
103
|
Groonga::Schema.create_table("Posts", options) do |table|
|
104
104
|
end
|
105
|
+
assert_equal("#{@database_path}.0000100",
|
106
|
+
context["Posts"].path)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_default_named_path
|
110
|
+
options_with_named_path = options.merge(:named_path => true)
|
111
|
+
Groonga::Schema.create_table("Posts", options_with_named_path) do |table|
|
112
|
+
end
|
105
113
|
assert_equal("#{@database_path}.tables/Posts",
|
106
114
|
context["Posts"].path)
|
107
115
|
end
|
data/test/test-schema.rb
CHANGED
@@ -70,120 +70,277 @@ class SchemaTest < Test::Unit::TestCase
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
class DefineHashTest < self
|
74
|
+
def test_default
|
75
|
+
Groonga::Schema.create_table("Posts", :type => :hash) do |table|
|
76
|
+
end
|
77
|
+
posts = context["Posts"]
|
78
|
+
assert_kind_of(Groonga::Hash, posts)
|
79
|
+
assert_equal("#{@database_path}.0000100", posts.path)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_named_path
|
83
|
+
Groonga::Schema.create_table("Posts",
|
84
|
+
:type => :hash,
|
85
|
+
:named_path => true) do |table|
|
86
|
+
end
|
87
|
+
posts = context["Posts"]
|
88
|
+
assert_kind_of(Groonga::Hash, posts)
|
89
|
+
assert_equal("#{@database_path}.tables/Posts", posts.path)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_full_option
|
93
|
+
path = @tmp_dir + "hash.groonga"
|
94
|
+
tokenizer = context["TokenTrigram"]
|
95
|
+
Groonga::Schema.create_table("Posts",
|
96
|
+
:type => :hash,
|
97
|
+
:key_type => "integer",
|
98
|
+
:path => path.to_s,
|
99
|
+
:value_type => "UInt32",
|
100
|
+
:default_tokenizer => tokenizer,
|
101
|
+
:named_path => true) do |table|
|
102
|
+
end
|
103
|
+
table = context["Posts"]
|
104
|
+
assert_equal("#<Groonga::Hash " +
|
105
|
+
"id: <#{table.id}>, " +
|
106
|
+
"name: <Posts>, " +
|
107
|
+
"path: <#{path}>, " +
|
108
|
+
"domain: <Int32>, " +
|
109
|
+
"range: <UInt32>, " +
|
110
|
+
"flags: <>, " +
|
111
|
+
"encoding: <#{Groonga::Encoding.default.inspect}>, " +
|
112
|
+
"size: <0>>",
|
113
|
+
table.inspect)
|
114
|
+
assert_equal(tokenizer, table.default_tokenizer)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_rename
|
118
|
+
Groonga::Schema.create_table("Posts", :type => :hash) do |table|
|
119
|
+
end
|
120
|
+
posts = context["Posts"]
|
121
|
+
assert_kind_of(Groonga::Hash, posts)
|
122
|
+
Groonga::Schema.rename_table("Posts", "Entries") do |table|
|
123
|
+
end
|
124
|
+
entries = context["Entries"]
|
125
|
+
assert_kind_of(Groonga::Hash, entries)
|
126
|
+
assert_equal("Entries", posts.name)
|
75
127
|
end
|
76
|
-
posts = context["Posts"]
|
77
|
-
assert_kind_of(Groonga::Hash, posts)
|
78
|
-
assert_equal("#{@database_path}.tables/Posts", posts.path)
|
79
128
|
end
|
80
129
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
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
|
-
|
130
|
+
class DefinePatriciaTrieTest < self
|
131
|
+
def test_default
|
132
|
+
Groonga::Schema.create_table("Posts", :type => :patricia_trie) do |table|
|
133
|
+
end
|
134
|
+
posts = context["Posts"]
|
135
|
+
assert_kind_of(Groonga::PatriciaTrie, posts)
|
136
|
+
assert_equal("#{@database_path}.0000100", posts.path)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_named_path
|
140
|
+
Groonga::Schema.create_table("Posts",
|
141
|
+
:type => :patricia_trie,
|
142
|
+
:named_path => true) do |table|
|
143
|
+
end
|
144
|
+
posts = context["Posts"]
|
145
|
+
assert_kind_of(Groonga::PatriciaTrie, posts)
|
146
|
+
assert_equal("#{@database_path}.tables/Posts", posts.path)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_full_option
|
150
|
+
path = @tmp_dir + "patricia-trie.groonga"
|
151
|
+
Groonga::Schema.create_table("Posts",
|
152
|
+
:type => :patricia_trie,
|
153
|
+
:key_type => "integer",
|
154
|
+
:path => path.to_s,
|
155
|
+
:value_type => "Float",
|
156
|
+
:default_tokenizer => "TokenBigram",
|
157
|
+
:key_normalize => true,
|
158
|
+
:key_with_sis => true,
|
159
|
+
:named_path => true) do |table|
|
160
|
+
end
|
161
|
+
table = context["Posts"]
|
162
|
+
assert_equal("#<Groonga::PatriciaTrie " +
|
163
|
+
"id: <#{table.id}>, " +
|
164
|
+
"name: <Posts>, " +
|
165
|
+
"path: <#{path}>, " +
|
166
|
+
"domain: <Int32>, " +
|
167
|
+
"range: <Float>, " +
|
168
|
+
"flags: <KEY_WITH_SIS|KEY_NORMALIZE|WITH_SECTION>, " +
|
169
|
+
"encoding: <#{Groonga::Encoding.default.inspect}>, " +
|
170
|
+
"size: <0>>",
|
171
|
+
table.inspect)
|
172
|
+
assert_equal(context["TokenBigram"], table.default_tokenizer)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_rename
|
176
|
+
Groonga::Schema.create_table("Posts", :type => :patricia_trie) do |table|
|
177
|
+
end
|
178
|
+
posts = context["Posts"]
|
179
|
+
assert_kind_of(Groonga::PatriciaTrie, posts)
|
180
|
+
Groonga::Schema.rename_table("Posts", "Entries") do |table|
|
181
|
+
end
|
182
|
+
entries = context["Entries"]
|
183
|
+
assert_kind_of(Groonga::PatriciaTrie, entries)
|
184
|
+
assert_equal("Entries", posts.name)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
class DefineDoubleArrayTrieTest < self
|
189
|
+
def test_default
|
190
|
+
Groonga::Schema.create_table("Posts",
|
191
|
+
:type => :double_array_trie) do |table|
|
192
|
+
end
|
193
|
+
posts = context["Posts"]
|
194
|
+
assert_kind_of(Groonga::DoubleArrayTrie, posts)
|
195
|
+
assert_equal("#{@database_path}.0000100", posts.path)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_named_path
|
199
|
+
Groonga::Schema.create_table("Posts",
|
200
|
+
:type => :double_array_trie,
|
201
|
+
:named_path => true) do |table|
|
202
|
+
end
|
203
|
+
posts = context["Posts"]
|
204
|
+
assert_kind_of(Groonga::DoubleArrayTrie, posts)
|
205
|
+
assert_equal("#{@database_path}.tables/Posts", posts.path)
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_full_option
|
209
|
+
path = @tmp_dir + "patricia-trie.groonga"
|
210
|
+
Groonga::Schema.create_table("Posts",
|
211
|
+
:type => :double_array_trie,
|
212
|
+
:key_type => "integer",
|
213
|
+
:path => path.to_s,
|
214
|
+
:value_type => "Float",
|
215
|
+
:default_tokenizer => "TokenBigram",
|
216
|
+
:key_normalize => true,
|
217
|
+
:named_path => true) do |table|
|
218
|
+
end
|
219
|
+
table = context["Posts"]
|
220
|
+
assert_equal("#<Groonga::DoubleArrayTrie " +
|
221
|
+
"id: <#{table.id}>, " +
|
222
|
+
"name: <Posts>, " +
|
223
|
+
"path: <#{path}>, " +
|
224
|
+
"domain: <Int32>, " +
|
225
|
+
"range: <Float>, " +
|
226
|
+
"flags: <KEY_NORMALIZE|WITH_SECTION>, " +
|
227
|
+
"encoding: <#{Groonga::Encoding.default.inspect}>, " +
|
228
|
+
"size: <0>>",
|
229
|
+
table.inspect)
|
230
|
+
assert_equal(context["TokenBigram"], table.default_tokenizer)
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_rename
|
234
|
+
Groonga::Schema.create_table("Posts", :type => :double_array_trie) do |table|
|
235
|
+
end
|
236
|
+
posts = context["Posts"]
|
237
|
+
assert_kind_of(Groonga::DoubleArrayTrie, posts)
|
238
|
+
Groonga::Schema.rename_table("Posts", "Entries") do |table|
|
239
|
+
end
|
240
|
+
entries = context["Entries"]
|
241
|
+
assert_kind_of(Groonga::DoubleArrayTrie, entries)
|
242
|
+
assert_equal("Entries", posts.name)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
class DefineArrayTest < self
|
247
|
+
def test_default
|
248
|
+
Groonga::Schema.create_table("Posts", :type => :array) do |table|
|
249
|
+
end
|
250
|
+
posts = context["Posts"]
|
251
|
+
assert_kind_of(Groonga::Array, posts)
|
252
|
+
assert_equal("#{@database_path}.0000100", posts.path)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_named_path
|
256
|
+
Groonga::Schema.create_table("Posts",
|
257
|
+
:type => :array,
|
258
|
+
:named_path => true) do |table|
|
259
|
+
end
|
260
|
+
posts = context["Posts"]
|
261
|
+
assert_kind_of(Groonga::Array, posts)
|
262
|
+
assert_equal("#{@database_path}.tables/Posts", posts.path)
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_full_option
|
266
|
+
path = @tmp_dir + "array.groonga"
|
267
|
+
Groonga::Schema.create_table("Posts",
|
268
|
+
:type => :array,
|
269
|
+
:path => path.to_s,
|
270
|
+
:value_type => "Int32",
|
271
|
+
:named_path => true) do |table|
|
272
|
+
end
|
273
|
+
table = context["Posts"]
|
274
|
+
assert_equal("#<Groonga::Array " +
|
275
|
+
"id: <#{table.id}>, " +
|
276
|
+
"name: <Posts>, " +
|
277
|
+
"path: <#{path}>, " +
|
278
|
+
"domain: <Int32>, " +
|
279
|
+
"range: <Int32>, " +
|
280
|
+
"flags: <>, " +
|
281
|
+
"size: <0>>",
|
282
|
+
table.inspect)
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_rename
|
286
|
+
Groonga::Schema.create_table("Posts", :type => :array) do |table|
|
287
|
+
end
|
288
|
+
posts = context["Posts"]
|
289
|
+
assert_kind_of(Groonga::Array, posts)
|
290
|
+
Groonga::Schema.rename_table("Posts", "Entries") do |table|
|
291
|
+
end
|
292
|
+
entries = context["Entries"]
|
293
|
+
assert_kind_of(Groonga::Array, entries)
|
294
|
+
assert_equal("Entries", posts.name)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
class DefineColumnTest < self
|
299
|
+
def test_default
|
300
|
+
Groonga::Schema.create_table("Posts") do |table|
|
301
|
+
table.column("rate", :int)
|
302
|
+
end
|
303
|
+
|
304
|
+
column_name = "Posts.rate"
|
305
|
+
column = context[column_name]
|
306
|
+
assert_kind_of(Groonga::FixSizeColumn, column)
|
307
|
+
assert_equal("#{@database_path}.0000101", column.path)
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_named_path
|
311
|
+
Groonga::Schema.create_table("Posts") do |table|
|
312
|
+
table.column("rate", :int, :named_path => true)
|
313
|
+
end
|
314
|
+
|
315
|
+
column_name = "Posts.rate"
|
316
|
+
column = context[column_name]
|
317
|
+
assert_kind_of(Groonga::FixSizeColumn, column)
|
318
|
+
assert_equal("#{@database_path}.0000100.columns/rate", column.path)
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_full_option
|
322
|
+
path = @tmp_dir + "column.groonga"
|
323
|
+
type = Groonga::Type.new("Niku", :size => 29)
|
324
|
+
Groonga::Schema.create_table("Posts") do |table|
|
325
|
+
table.column("rate",
|
326
|
+
type,
|
327
|
+
:path => path.to_s,
|
328
|
+
:persistent => true,
|
329
|
+
:type => :vector,
|
330
|
+
:compress => :lzo)
|
331
|
+
end
|
332
|
+
|
333
|
+
column_name = "Posts.rate"
|
334
|
+
column = context[column_name]
|
335
|
+
assert_equal("#<Groonga::VariableSizeColumn " +
|
336
|
+
"id: <#{column.id}>, " +
|
337
|
+
"name: <#{column_name}>, " +
|
338
|
+
"path: <#{path}>, " +
|
339
|
+
"domain: <Posts>, " +
|
340
|
+
"range: <Niku>, " +
|
341
|
+
"flags: <COMPRESS_LZO>>",
|
342
|
+
column.inspect)
|
343
|
+
end
|
187
344
|
end
|
188
345
|
|
189
346
|
def test_integer32_column
|
@@ -286,6 +443,19 @@ class SchemaTest < Test::Unit::TestCase
|
|
286
443
|
assert_nil(context["Posts.content"])
|
287
444
|
end
|
288
445
|
|
446
|
+
def test_rename_column
|
447
|
+
Groonga::Schema.create_table("Posts") do |table|
|
448
|
+
table.long_text :content
|
449
|
+
end
|
450
|
+
content = context["Posts.content"]
|
451
|
+
assert_equal("Posts.content", content.name)
|
452
|
+
|
453
|
+
Groonga::Schema.rename_column("Posts", "content", "body")
|
454
|
+
body = context["Posts.body"]
|
455
|
+
assert_equal("Posts.body", body.name)
|
456
|
+
assert_equal("Posts.body", content.name)
|
457
|
+
end
|
458
|
+
|
289
459
|
def test_column_again
|
290
460
|
Groonga::Schema.create_table("Posts") do |table|
|
291
461
|
table.text :content
|
@@ -310,131 +480,167 @@ class SchemaTest < Test::Unit::TestCase
|
|
310
480
|
end
|
311
481
|
end
|
312
482
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
483
|
+
class DefineIndexColumnTest < self
|
484
|
+
def test_default
|
485
|
+
assert_nil(context["Terms.content"])
|
486
|
+
Groonga::Schema.create_table("Posts") do |table|
|
487
|
+
table.long_text :content
|
488
|
+
end
|
489
|
+
Groonga::Schema.create_table("Terms") do |table|
|
490
|
+
table.index "Posts.content"
|
491
|
+
end
|
492
|
+
index_column = context["Terms.Posts_content"]
|
493
|
+
assert_equal([context["Posts.content"]],
|
494
|
+
index_column.sources)
|
495
|
+
assert_equal("#{@database_path}.0000103", index_column.path)
|
317
496
|
end
|
318
|
-
|
319
|
-
|
497
|
+
|
498
|
+
def test_named_path
|
499
|
+
assert_nil(context["Terms.content"])
|
500
|
+
Groonga::Schema.create_table("Posts") do |table|
|
501
|
+
table.long_text :content
|
502
|
+
end
|
503
|
+
Groonga::Schema.create_table("Terms") do |table|
|
504
|
+
table.index "Posts.content", :named_path => true
|
505
|
+
end
|
506
|
+
index_column = context["Terms.Posts_content"]
|
507
|
+
assert_equal([context["Posts.content"]],
|
508
|
+
index_column.sources)
|
509
|
+
assert_equal("#{@database_path}.0000102.columns/Posts_content",
|
510
|
+
index_column.path)
|
320
511
|
end
|
321
|
-
assert_equal([context["Posts.content"]],
|
322
|
-
context["Terms.Posts_content"].sources)
|
323
|
-
end
|
324
512
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
513
|
+
def test_full_option
|
514
|
+
path = @tmp_dir + "index-column.groonga"
|
515
|
+
assert_nil(context["Terms.content"])
|
516
|
+
index_column_name = "Posts_index"
|
329
517
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
index_column.inspect)
|
355
|
-
end
|
356
|
-
|
357
|
-
def test_index_again
|
358
|
-
Groonga::Schema.create_table("Posts") do |table|
|
359
|
-
table.long_text :content
|
360
|
-
end
|
361
|
-
Groonga::Schema.create_table("Terms") do |table|
|
362
|
-
table.index "Posts.content"
|
518
|
+
Groonga::Schema.create_table("Posts") do |table|
|
519
|
+
table.long_text :content
|
520
|
+
end
|
521
|
+
Groonga::Schema.create_table("Terms") do |table|
|
522
|
+
table.index("Posts.content",
|
523
|
+
:name => index_column_name,
|
524
|
+
:path => path.to_s,
|
525
|
+
:persistent => true,
|
526
|
+
:with_section => true,
|
527
|
+
:with_weight => true,
|
528
|
+
:with_position => true,
|
529
|
+
:named_path => true)
|
530
|
+
end
|
531
|
+
|
532
|
+
full_index_column_name = "Terms.#{index_column_name}"
|
533
|
+
index_column = context[full_index_column_name]
|
534
|
+
assert_equal("#<Groonga::IndexColumn " +
|
535
|
+
"id: <#{index_column.id}>, " +
|
536
|
+
"name: <#{full_index_column_name}>, " +
|
537
|
+
"path: <#{path}>, " +
|
538
|
+
"domain: <Terms>, " +
|
539
|
+
"range: <Posts>, " +
|
540
|
+
"flags: <WITH_SECTION|WITH_WEIGHT|WITH_POSITION>>",
|
541
|
+
index_column.inspect)
|
363
542
|
end
|
364
543
|
|
365
|
-
|
544
|
+
def test_again
|
545
|
+
Groonga::Schema.create_table("Posts") do |table|
|
546
|
+
table.long_text :content
|
547
|
+
end
|
366
548
|
Groonga::Schema.create_table("Terms") do |table|
|
367
549
|
table.index "Posts.content"
|
368
550
|
end
|
369
|
-
end
|
370
|
-
end
|
371
551
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
Groonga::Schema.create_table("Terms") do |table|
|
378
|
-
table.index "Posts.content"
|
552
|
+
assert_nothing_raised do
|
553
|
+
Groonga::Schema.create_table("Terms") do |table|
|
554
|
+
table.index "Posts.content"
|
555
|
+
end
|
556
|
+
end
|
379
557
|
end
|
380
558
|
|
381
|
-
|
559
|
+
def test_again_with_difference_source
|
560
|
+
Groonga::Schema.create_table("Posts") do |table|
|
561
|
+
table.long_text :content
|
562
|
+
table.short_text :name
|
563
|
+
end
|
382
564
|
Groonga::Schema.create_table("Terms") do |table|
|
383
|
-
table.index "Posts.
|
565
|
+
table.index "Posts.content"
|
384
566
|
end
|
385
|
-
end
|
386
|
-
end
|
387
567
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
Groonga::Schema.create_table("Terms") do |table|
|
394
|
-
table.index "Posts._key", :with_position => true
|
568
|
+
assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
|
569
|
+
Groonga::Schema.create_table("Terms") do |table|
|
570
|
+
table.index "Posts.name", :name => "Posts_content"
|
571
|
+
end
|
572
|
+
end
|
395
573
|
end
|
396
574
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
"flags: <WITH_POSITION>>",
|
406
|
-
index_column.inspect)
|
407
|
-
end
|
575
|
+
def test_key
|
576
|
+
Groonga::Schema.create_table("Posts",
|
577
|
+
:type => :hash,
|
578
|
+
:key_type => "ShortText") do |table|
|
579
|
+
end
|
580
|
+
Groonga::Schema.create_table("Terms") do |table|
|
581
|
+
table.index "Posts._key", :with_position => true
|
582
|
+
end
|
408
583
|
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
584
|
+
full_index_column_name = "Terms.Posts__key"
|
585
|
+
index_column = context[full_index_column_name]
|
586
|
+
assert_equal("#<Groonga::IndexColumn " +
|
587
|
+
"id: <#{index_column.id}>, " +
|
588
|
+
"name: <#{full_index_column_name}>, " +
|
589
|
+
"path: <#{index_column.path}>, " +
|
590
|
+
"domain: <Terms>, " +
|
591
|
+
"range: <Posts>, " +
|
592
|
+
"flags: <WITH_POSITION>>",
|
593
|
+
index_column.inspect)
|
416
594
|
end
|
417
595
|
|
418
|
-
|
596
|
+
def test_key_again
|
597
|
+
Groonga::Schema.create_table("Posts",
|
598
|
+
:type => :hash,
|
599
|
+
:key_type => "ShortText") do |table|
|
600
|
+
end
|
419
601
|
Groonga::Schema.create_table("Terms") do |table|
|
420
|
-
table.index "Posts._key"
|
602
|
+
table.index "Posts._key", :with_position => true
|
421
603
|
end
|
422
|
-
end
|
423
|
-
end
|
424
604
|
|
425
|
-
|
426
|
-
|
427
|
-
|
605
|
+
assert_nothing_raised do
|
606
|
+
Groonga::Schema.create_table("Terms") do |table|
|
607
|
+
table.index "Posts._key"
|
608
|
+
end
|
609
|
+
end
|
428
610
|
end
|
429
|
-
|
430
|
-
|
611
|
+
|
612
|
+
def test_remove
|
613
|
+
Groonga::Schema.create_table("Posts") do |table|
|
614
|
+
table.long_text :content
|
615
|
+
end
|
616
|
+
Groonga::Schema.create_table("Terms") do |table|
|
617
|
+
table.index "Posts.content"
|
618
|
+
end
|
619
|
+
assert_equal([context["Posts.content"]],
|
620
|
+
context["Terms.Posts_content"].sources)
|
621
|
+
Groonga::Schema.change_table("Terms") do |table|
|
622
|
+
table.remove_index("Posts.content")
|
623
|
+
end
|
624
|
+
assert_nil(context["Terms.Posts_content"])
|
431
625
|
end
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
626
|
+
|
627
|
+
def test_rename
|
628
|
+
Groonga::Schema.create_table("Posts") do |table|
|
629
|
+
table.long_text :content
|
630
|
+
end
|
631
|
+
Groonga::Schema.create_table("Terms") do |table|
|
632
|
+
table.index "Posts.content"
|
633
|
+
end
|
634
|
+
index = context["Terms.Posts_content"]
|
635
|
+
assert_equal([context["Posts.content"]], index.sources)
|
636
|
+
Groonga::Schema.change_table("Terms") do |table|
|
637
|
+
table.rename_column("Posts_content", "posts_content_index")
|
638
|
+
end
|
639
|
+
renamed_index = context["Terms.posts_content_index"]
|
640
|
+
assert_equal("Terms.posts_content_index", renamed_index.name)
|
641
|
+
assert_equal("Terms.posts_content_index", index.name)
|
642
|
+
assert_equal([context["Posts.content"]], renamed_index.sources)
|
436
643
|
end
|
437
|
-
assert_nil(context["Terms.Posts_content"])
|
438
644
|
end
|
439
645
|
|
440
646
|
def test_reference_guess
|
@@ -486,26 +692,6 @@ class SchemaTest < Test::Unit::TestCase
|
|
486
692
|
assert_nil(Groonga::Context.default["TermsText.Items_text"])
|
487
693
|
end
|
488
694
|
|
489
|
-
def test_columns_directory_removed
|
490
|
-
table = "Posts"
|
491
|
-
dir = create_table_with_column(table)
|
492
|
-
|
493
|
-
Groonga::Schema.remove_table(table)
|
494
|
-
|
495
|
-
assert_table_removed(table)
|
496
|
-
assert_directory_removed(dir)
|
497
|
-
end
|
498
|
-
|
499
|
-
def test_columns_directory_not_removed
|
500
|
-
table = "Posts"
|
501
|
-
dir = create_table_with_column(table)
|
502
|
-
|
503
|
-
Groonga::Context.default[table].remove
|
504
|
-
|
505
|
-
assert_table_removed(table)
|
506
|
-
assert_directory_not_removed(dir)
|
507
|
-
end
|
508
|
-
|
509
695
|
def test_default_tokenizer_name_shortcut
|
510
696
|
Groonga::Schema.define do |schema|
|
511
697
|
schema.create_table("Terms",
|
@@ -531,13 +717,84 @@ class SchemaTest < Test::Unit::TestCase
|
|
531
717
|
assert_equal(short_text, Groonga["Users"].domain)
|
532
718
|
end
|
533
719
|
|
720
|
+
class RemoveTest < self
|
721
|
+
def test_tables_directory_removed_on_last_table_remove
|
722
|
+
table_name = "Posts"
|
723
|
+
Groonga::Schema.create_table(table_name, :named_path => true)
|
724
|
+
table = Groonga[table_name]
|
725
|
+
tables_directory = Pathname.new(table.path).dirname
|
726
|
+
|
727
|
+
assert_directory_not_removed(tables_directory)
|
728
|
+
Groonga::Schema.remove_table(table_name)
|
729
|
+
assert_directory_removed(tables_directory)
|
730
|
+
end
|
731
|
+
|
732
|
+
def test_tables_directory_not_removed_on_not_last_table_remove
|
733
|
+
table_name = "Posts"
|
734
|
+
Groonga::Schema.define(:named_path => true) do |schema|
|
735
|
+
schema.create_table(table_name)
|
736
|
+
schema.create_table("Users")
|
737
|
+
end
|
738
|
+
|
739
|
+
table = Groonga[table_name]
|
740
|
+
tables_directory = Pathname.new(table.path).dirname
|
741
|
+
|
742
|
+
assert_directory_not_removed(tables_directory)
|
743
|
+
Groonga::Schema.remove_table(table_name)
|
744
|
+
assert_directory_not_removed(tables_directory)
|
745
|
+
end
|
746
|
+
|
747
|
+
def test_columns_directory_removed
|
748
|
+
table = "Posts"
|
749
|
+
dir = create_table_with_column(table, :named_path => true)
|
750
|
+
|
751
|
+
Groonga::Schema.remove_table(table)
|
752
|
+
|
753
|
+
assert_table_removed(table)
|
754
|
+
assert_directory_removed(dir)
|
755
|
+
end
|
756
|
+
end
|
757
|
+
|
758
|
+
class ColumnRemoveTest < self
|
759
|
+
def test_columns_directory_removed_on_last_column_remove
|
760
|
+
Groonga::Schema.define(:named_path => true) do |schema|
|
761
|
+
schema.create_table("Posts") do |table|
|
762
|
+
table.short_text("title")
|
763
|
+
end
|
764
|
+
end
|
765
|
+
|
766
|
+
columns_directory = columns_directory_path(Groonga["Posts"])
|
767
|
+
assert_directory_not_removed(columns_directory)
|
768
|
+
Groonga::Schema.change_table("Posts") do |table|
|
769
|
+
table.remove_column("title")
|
770
|
+
end
|
771
|
+
assert_directory_removed(columns_directory)
|
772
|
+
end
|
773
|
+
|
774
|
+
def test_columns_directory_not_removed_on_not_last_column_remove
|
775
|
+
Groonga::Schema.define(:named_path => true) do |schema|
|
776
|
+
schema.create_table("Posts") do |table|
|
777
|
+
table.short_text("title")
|
778
|
+
table.short_text("body")
|
779
|
+
end
|
780
|
+
end
|
781
|
+
|
782
|
+
columns_directory = columns_directory_path(Groonga["Posts"])
|
783
|
+
assert_directory_not_removed(columns_directory)
|
784
|
+
Groonga::Schema.change_table("Posts") do |table|
|
785
|
+
table.remove_column("title")
|
786
|
+
end
|
787
|
+
assert_directory_not_removed(columns_directory)
|
788
|
+
end
|
789
|
+
end
|
790
|
+
|
534
791
|
private
|
535
792
|
def columns_directory_path(table)
|
536
793
|
"#{table.path}.columns"
|
537
794
|
end
|
538
795
|
|
539
|
-
def create_table_with_column(name)
|
540
|
-
Groonga::Schema.create_table(name) do |table|
|
796
|
+
def create_table_with_column(name, options={})
|
797
|
+
Groonga::Schema.create_table(name, options) do |table|
|
541
798
|
table.integer64 :rate
|
542
799
|
end
|
543
800
|
context = Groonga::Context.default
|
@@ -545,11 +802,11 @@ class SchemaTest < Test::Unit::TestCase
|
|
545
802
|
end
|
546
803
|
|
547
804
|
def assert_directory_removed(dir)
|
548
|
-
|
805
|
+
assert_not_predicate(Pathname.new(dir), :exist?)
|
549
806
|
end
|
550
807
|
|
551
808
|
def assert_directory_not_removed(dir)
|
552
|
-
|
809
|
+
assert_predicate(Pathname.new(dir), :exist?)
|
553
810
|
end
|
554
811
|
|
555
812
|
def assert_table_removed(name)
|