rroonga 2.0.2 → 2.0.3
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/AUTHORS +5 -0
- data/Gemfile +1 -12
- data/Rakefile +4 -57
- data/bin/grndump +11 -1
- data/ext/groonga/extconf.rb +125 -54
- data/ext/groonga/rb-grn-context.c +25 -7
- data/ext/groonga/rb-grn-database.c +25 -0
- data/ext/groonga/rb-grn-object.c +19 -7
- data/ext/groonga/rb-grn-table.c +8 -10
- data/ext/groonga/rb-grn.h +9 -2
- data/lib/groonga/dumper.rb +2 -2
- data/lib/groonga/expression-builder.rb +33 -18
- data/rroonga-build.rb +1 -1
- metadata +97 -180
- data/TODO +0 -0
- data/test/groonga-test-utils.rb +0 -139
- data/test/run-test.rb +0 -60
- data/test/test-accessor.rb +0 -36
- data/test/test-array.rb +0 -123
- data/test/test-column.rb +0 -350
- data/test/test-command-select.rb +0 -147
- data/test/test-context.rb +0 -130
- data/test/test-database-dumper.rb +0 -259
- data/test/test-database.rb +0 -148
- data/test/test-double-array-trie.rb +0 -164
- data/test/test-encoding.rb +0 -33
- data/test/test-exception.rb +0 -96
- data/test/test-expression-builder.rb +0 -269
- data/test/test-expression.rb +0 -134
- data/test/test-fix-size-column.rb +0 -77
- data/test/test-gqtp.rb +0 -70
- data/test/test-hash.rb +0 -344
- data/test/test-index-column.rb +0 -180
- data/test/test-index-cursor.rb +0 -93
- data/test/test-logger.rb +0 -37
- data/test/test-pagination.rb +0 -249
- data/test/test-patricia-trie.rb +0 -415
- data/test/test-plugin.rb +0 -35
- data/test/test-procedure.rb +0 -37
- data/test/test-query-log.rb +0 -258
- data/test/test-record.rb +0 -569
- data/test/test-remote.rb +0 -63
- data/test/test-schema-create-table.rb +0 -267
- data/test/test-schema-dumper.rb +0 -235
- data/test/test-schema-type.rb +0 -208
- data/test/test-schema-view.rb +0 -90
- data/test/test-schema.rb +0 -886
- data/test/test-snippet.rb +0 -130
- data/test/test-table-cursor.rb +0 -187
- data/test/test-table-dumper.rb +0 -83
- data/test/test-table-offset-and-limit.rb +0 -100
- data/test/test-table-select-mecab.rb +0 -80
- data/test/test-table-select-normalize.rb +0 -57
- data/test/test-table-select-weight.rb +0 -123
- data/test/test-table-select.rb +0 -191
- data/test/test-table.rb +0 -675
- data/test/test-type.rb +0 -79
- data/test/test-variable-size-column.rb +0 -147
- data/test/test-variable.rb +0 -28
- data/test/test-vector-column.rb +0 -76
- data/test/test-version.rb +0 -61
- data/test/test-view.rb +0 -72
data/test/test-schema-type.rb
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
# Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
|
2
|
-
#
|
3
|
-
# This library is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the GNU Lesser General Public
|
5
|
-
# License version 2.1 as published by the Free Software Foundation.
|
6
|
-
#
|
7
|
-
# This library is distributed in the hope that it will be useful,
|
8
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
-
# Lesser General Public License for more details.
|
11
|
-
#
|
12
|
-
# You should have received a copy of the GNU Lesser General Public
|
13
|
-
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
-
|
16
|
-
class SchemaTypeTest < Test::Unit::TestCase
|
17
|
-
include GroongaTestUtils
|
18
|
-
|
19
|
-
def test_normalize_short_text
|
20
|
-
assert_normalize_type("ShortText", "short_text")
|
21
|
-
assert_normalize_type("ShortText", "string")
|
22
|
-
assert_normalize_type("ShortText", "ShortText")
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_normalize_text
|
26
|
-
assert_normalize_type("Text", "text")
|
27
|
-
assert_normalize_type("Text", "Text")
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_normalize_long_text
|
31
|
-
assert_normalize_type("LongText", "binary")
|
32
|
-
assert_normalize_type("LongText", "long_text")
|
33
|
-
assert_normalize_type("LongText", "LongText")
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_normalize_integer8
|
37
|
-
assert_normalize_type("Int8", "int8")
|
38
|
-
assert_normalize_type("Int8", "integer8")
|
39
|
-
assert_normalize_type("Int8", "Int8")
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_normalize_integer16
|
43
|
-
assert_normalize_type("Int16", "int16")
|
44
|
-
assert_normalize_type("Int16", "integer16")
|
45
|
-
assert_normalize_type("Int16", "Int16")
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_normalize_integer32
|
49
|
-
assert_normalize_type("Int32", "int")
|
50
|
-
assert_normalize_type("Int32", "integer")
|
51
|
-
assert_normalize_type("Int32", "int32")
|
52
|
-
assert_normalize_type("Int32", "integer32")
|
53
|
-
assert_normalize_type("Int32", "Int32")
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_normalize_integer64
|
57
|
-
assert_normalize_type("Int64", "int64")
|
58
|
-
assert_normalize_type("Int64", "integer64")
|
59
|
-
assert_normalize_type("Int64", "Int64")
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_normalize_unsigned_integer8
|
63
|
-
assert_normalize_type("UInt8", "uint8")
|
64
|
-
assert_normalize_type("UInt8", "unsigned_integer8")
|
65
|
-
assert_normalize_type("UInt8", "UInt8")
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_normalize_unsigned_integer16
|
69
|
-
assert_normalize_type("UInt16", "uint16")
|
70
|
-
assert_normalize_type("UInt16", "unsigned_integer16")
|
71
|
-
assert_normalize_type("UInt16", "UInt16")
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_normalize_unsigned_integer32
|
75
|
-
assert_normalize_type("UInt32", "uint")
|
76
|
-
assert_normalize_type("UInt32", "unsigned_integer")
|
77
|
-
assert_normalize_type("UInt32", "uint32")
|
78
|
-
assert_normalize_type("UInt32", "unsigned_integer32")
|
79
|
-
assert_normalize_type("UInt32", "UInt32")
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_normalize_unsigned_integer64
|
83
|
-
assert_normalize_type("UInt64", "uint64")
|
84
|
-
assert_normalize_type("UInt64", "unsigned_integer64")
|
85
|
-
assert_normalize_type("UInt64", "UInt64")
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_normalize_float
|
89
|
-
assert_normalize_type("Float", "float")
|
90
|
-
assert_normalize_type("Float", "Float")
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_normalize_time
|
94
|
-
assert_normalize_type("Time", "datetime")
|
95
|
-
assert_normalize_type("Time", "timestamp")
|
96
|
-
assert_normalize_type("Time", "time")
|
97
|
-
assert_normalize_type("Time", "date")
|
98
|
-
assert_normalize_type("Time", "Time")
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_normalize_boolean
|
102
|
-
assert_normalize_type("Bool", "boolean")
|
103
|
-
assert_normalize_type("Bool", "Bool")
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_normalize_tokyo_geo_point
|
107
|
-
assert_normalize_type("TokyoGeoPoint", "tokyo_geo_point")
|
108
|
-
assert_normalize_type("TokyoGeoPoint", "TokyoGeoPoint")
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_normalize_wgs84_geo_point
|
112
|
-
assert_normalize_type("WGS84GeoPoint", "geo_point")
|
113
|
-
assert_normalize_type("WGS84GeoPoint", "wgs84_geo_point")
|
114
|
-
assert_normalize_type("WGS84GeoPoint", "WGS84GeoPoint")
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_normalize_delimit
|
118
|
-
assert_normalize_type("TokenDelimit", "delimit")
|
119
|
-
assert_normalize_type("TokenDelimit", "token_delimit")
|
120
|
-
assert_normalize_type("TokenDelimit", "TokenDelimit")
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_normalize_unigram
|
124
|
-
assert_normalize_type("TokenUnigram", "unigram")
|
125
|
-
assert_normalize_type("TokenUnigram", "token_unigram")
|
126
|
-
assert_normalize_type("TokenUnigram", "TokenUnigram")
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_normalize_bigram
|
130
|
-
assert_normalize_type("TokenBigram", "bigram")
|
131
|
-
assert_normalize_type("TokenBigram", "token_bigram")
|
132
|
-
assert_normalize_type("TokenBigram", "TokenBigram")
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_normalize_bigram_split_symbol
|
136
|
-
assert_normalize_type("TokenBigramSplitSymbol", "bigram_split_symbol")
|
137
|
-
assert_normalize_type("TokenBigramSplitSymbol", "token_bigram_split_symbol")
|
138
|
-
assert_normalize_type("TokenBigramSplitSymbol", "TokenBigramSplitSymbol")
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_normalize_bigram_split_symbol_alpha
|
142
|
-
assert_normalize_type("TokenBigramSplitSymbolAlpha",
|
143
|
-
"bigram_split_symbol_alpha")
|
144
|
-
assert_normalize_type("TokenBigramSplitSymbolAlpha",
|
145
|
-
"token_bigram_split_symbol_alpha")
|
146
|
-
assert_normalize_type("TokenBigramSplitSymbolAlpha",
|
147
|
-
"TokenBigramSplitSymbolAlpha")
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_normalize_bigram_split_symbol_alpha_digit
|
151
|
-
assert_normalize_type("TokenBigramSplitSymbolAlphaDigit",
|
152
|
-
"bigram_split_symbol_alpha_digit")
|
153
|
-
assert_normalize_type("TokenBigramSplitSymbolAlphaDigit",
|
154
|
-
"token_bigram_split_symbol_alpha_digit")
|
155
|
-
assert_normalize_type("TokenBigramSplitSymbolAlphaDigit",
|
156
|
-
"TokenBigramSplitSymbolAlphaDigit")
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_normalize_bigram_ignore_blank
|
160
|
-
assert_normalize_type("TokenBigramIgnoreBlank", "bigram_ignore_blank")
|
161
|
-
assert_normalize_type("TokenBigramIgnoreBlank", "token_bigram_ignore_blank")
|
162
|
-
assert_normalize_type("TokenBigramIgnoreBlank", "TokenBigramIgnoreBlank")
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_normalize_bigram_ignore_blank_split_symbol
|
166
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbol",
|
167
|
-
"bigram_ignore_blank_split_symbol")
|
168
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbol",
|
169
|
-
"token_bigram_ignore_blank_split_symbol")
|
170
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbol",
|
171
|
-
"TokenBigramIgnoreBlankSplitSymbol")
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_normalize_bigram_ignore_blank_split_symbol_alpha
|
175
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbolAlpha",
|
176
|
-
"bigram_ignore_blank_split_symbol_alpha")
|
177
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbolAlpha",
|
178
|
-
"token_bigram_ignore_blank_split_symbol_alpha")
|
179
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbolAlpha",
|
180
|
-
"TokenBigramIgnoreBlankSplitSymbolAlpha")
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_normalize_bigram_ignore_blank_split_symbol_alpha_digit
|
184
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbolAlphaDigit",
|
185
|
-
"bigram_ignore_blank_split_symbol_alpha_digit")
|
186
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbolAlphaDigit",
|
187
|
-
"token_bigram_ignore_blank_split_symbol_alpha_digit")
|
188
|
-
assert_normalize_type("TokenBigramIgnoreBlankSplitSymbolAlphaDigit",
|
189
|
-
"TokenBigramIgnoreBlankSplitSymbolAlphaDigit")
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_normalize_trigram
|
193
|
-
assert_normalize_type("TokenTrigram", "trigram")
|
194
|
-
assert_normalize_type("TokenTrigram", "token_trigram")
|
195
|
-
assert_normalize_type("TokenTrigram", "TokenTrigram")
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_normalize_mecab
|
199
|
-
assert_normalize_type("TokenMecab", "mecab")
|
200
|
-
assert_normalize_type("TokenMecab", "token_mecab")
|
201
|
-
assert_normalize_type("TokenMecab", "TokenMecab")
|
202
|
-
end
|
203
|
-
|
204
|
-
private
|
205
|
-
def assert_normalize_type(expected, type)
|
206
|
-
assert_equal(expected, Groonga::Schema.normalize_type(type))
|
207
|
-
end
|
208
|
-
end
|
data/test/test-schema-view.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
# Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
|
2
|
-
#
|
3
|
-
# This library is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the GNU Lesser General Public
|
5
|
-
# License version 2.1 as published by the Free Software Foundation.
|
6
|
-
#
|
7
|
-
# This library is distributed in the hope that it will be useful,
|
8
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
-
# Lesser General Public License for more details.
|
11
|
-
#
|
12
|
-
# You should have received a copy of the GNU Lesser General Public
|
13
|
-
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
-
|
16
|
-
class SchemaViewTest < Test::Unit::TestCase
|
17
|
-
include GroongaTestUtils
|
18
|
-
|
19
|
-
setup :setup_database
|
20
|
-
|
21
|
-
def test_create_view
|
22
|
-
assert_nil(context["Entries"])
|
23
|
-
Groonga::Schema.create_view("Entries") do |view|
|
24
|
-
end
|
25
|
-
assert_not_nil(context["Entries"])
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_create_view_force
|
29
|
-
Groonga::Schema.create_table("People") do |table|
|
30
|
-
table.string("name")
|
31
|
-
end
|
32
|
-
context["People"].add(:name => "morita")
|
33
|
-
|
34
|
-
Groonga::Schema.create_view("Entries") do |view|
|
35
|
-
view.add("People")
|
36
|
-
end
|
37
|
-
assert_equal(["morita"],
|
38
|
-
context["Entries"].collect {|entry| entry["name"]})
|
39
|
-
|
40
|
-
Groonga::Schema.create_view("People") do |view|
|
41
|
-
end
|
42
|
-
assert_equal(["morita"],
|
43
|
-
context["Entries"].collect {|entry| entry["name"]})
|
44
|
-
|
45
|
-
Groonga::Schema.create_view("Entries", :force => true) do |view|
|
46
|
-
end
|
47
|
-
assert_equal([],
|
48
|
-
context["Entries"].collect {|entry| entry["name"]})
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_remove_view
|
52
|
-
Groonga::View.create(:name => "Entries")
|
53
|
-
assert_not_nil(context["Entries"])
|
54
|
-
Groonga::Schema.remove_view("Entries")
|
55
|
-
assert_nil(context["Entries"])
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_add
|
59
|
-
Groonga::Schema.create_table("People") do |table|
|
60
|
-
table.string("name")
|
61
|
-
end
|
62
|
-
context["People"].add(:name => "morita")
|
63
|
-
|
64
|
-
Groonga::Schema.create_table("Dogs") do |table|
|
65
|
-
table.string("name")
|
66
|
-
end
|
67
|
-
context["Dogs"].add(:name => "pochi")
|
68
|
-
|
69
|
-
Groonga::Schema.create_view("Entries") do |view|
|
70
|
-
view.add("People")
|
71
|
-
view.add("Dogs")
|
72
|
-
end
|
73
|
-
assert_equal(["morita", "pochi"],
|
74
|
-
context["Entries"].collect {|entry| entry["name"]})
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_define_lazy
|
78
|
-
assert_nothing_raised do
|
79
|
-
Groonga::Schema.define do |schema|
|
80
|
-
schema.create_table("People") do |table|
|
81
|
-
table.string("name")
|
82
|
-
end
|
83
|
-
|
84
|
-
schema.create_view("Entries") do |view|
|
85
|
-
view.add("People")
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
data/test/test-schema.rb
DELETED
@@ -1,886 +0,0 @@
|
|
1
|
-
# Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
|
2
|
-
#
|
3
|
-
# This library is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the GNU Lesser General Public
|
5
|
-
# License version 2.1 as published by the Free Software Foundation.
|
6
|
-
#
|
7
|
-
# This library is distributed in the hope that it will be useful,
|
8
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
-
# Lesser General Public License for more details.
|
11
|
-
#
|
12
|
-
# You should have received a copy of the GNU Lesser General Public
|
13
|
-
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
-
|
16
|
-
class SchemaTest < Test::Unit::TestCase
|
17
|
-
include GroongaTestUtils
|
18
|
-
|
19
|
-
setup :setup_database
|
20
|
-
|
21
|
-
def test_remove_table
|
22
|
-
Groonga::Array.create(:name => "Posts")
|
23
|
-
assert_not_nil(context["Posts"])
|
24
|
-
Groonga::Schema.remove_table("Posts")
|
25
|
-
assert_nil(context["Posts"])
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_remove_not_existing_table
|
29
|
-
assert_raise(Groonga::Schema::TableNotExists) do
|
30
|
-
Groonga::Schema.remove_table("NotExistingTable")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_remove_not_existing_column
|
35
|
-
create_table = Proc.new do |&block|
|
36
|
-
Groonga::Schema.create_table("Posts", :type => :hash) do |table|
|
37
|
-
block.call(table)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
create_table.call do |table|
|
42
|
-
end
|
43
|
-
|
44
|
-
assert_raise(Groonga::Schema::ColumnNotExists) do
|
45
|
-
create_table.call do |table|
|
46
|
-
table.remove_column("not_existing_column")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_path_canonicalization
|
52
|
-
directory = @tmp_dir.to_s
|
53
|
-
table_filename = "hash.groonga"
|
54
|
-
|
55
|
-
canonical_path = directory + "/#{table_filename}"
|
56
|
-
uncanonical_path = directory + "/./#{table_filename}"
|
57
|
-
|
58
|
-
Groonga::Schema.create_table("Posts",
|
59
|
-
:type => :hash,
|
60
|
-
:key_type => "integer",
|
61
|
-
:path => canonical_path) do |table|
|
62
|
-
end
|
63
|
-
|
64
|
-
assert_nothing_raised do
|
65
|
-
Groonga::Schema.create_table("Posts",
|
66
|
-
:type => :hash,
|
67
|
-
:key_type => "integer",
|
68
|
-
:path => uncanonical_path) do |table|
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
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)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
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
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_integer8_column
|
347
|
-
assert_nil(context["Posts.rate"])
|
348
|
-
Groonga::Schema.create_table("Posts") do |table|
|
349
|
-
table.integer8 :rate
|
350
|
-
end
|
351
|
-
assert_equal(context["Int8"], context["Posts.rate"].range)
|
352
|
-
end
|
353
|
-
|
354
|
-
def test_integer16_column
|
355
|
-
assert_nil(context["Posts.rate"])
|
356
|
-
Groonga::Schema.create_table("Posts") do |table|
|
357
|
-
table.integer16 :rate
|
358
|
-
end
|
359
|
-
assert_equal(context["Int16"], context["Posts.rate"].range)
|
360
|
-
end
|
361
|
-
|
362
|
-
def test_integer32_column
|
363
|
-
assert_nil(context["Posts.rate"])
|
364
|
-
Groonga::Schema.create_table("Posts") do |table|
|
365
|
-
table.integer32 :rate
|
366
|
-
end
|
367
|
-
assert_equal(context["Int32"], context["Posts.rate"].range)
|
368
|
-
end
|
369
|
-
|
370
|
-
def test_integer64_column
|
371
|
-
assert_nil(context["Posts.rate"])
|
372
|
-
Groonga::Schema.create_table("Posts") do |table|
|
373
|
-
table.integer64 :rate
|
374
|
-
end
|
375
|
-
assert_equal(context["Int64"], context["Posts.rate"].range)
|
376
|
-
end
|
377
|
-
|
378
|
-
def test_unsigned_integer8_column
|
379
|
-
assert_nil(context["Posts.n_viewed"])
|
380
|
-
Groonga::Schema.create_table("Posts") do |table|
|
381
|
-
table.unsigned_integer8 :n_viewed
|
382
|
-
end
|
383
|
-
assert_equal(context["UInt8"], context["Posts.n_viewed"].range)
|
384
|
-
end
|
385
|
-
|
386
|
-
def test_unsigned_integer16_column
|
387
|
-
assert_nil(context["Posts.n_viewed"])
|
388
|
-
Groonga::Schema.create_table("Posts") do |table|
|
389
|
-
table.unsigned_integer16 :n_viewed
|
390
|
-
end
|
391
|
-
assert_equal(context["UInt16"], context["Posts.n_viewed"].range)
|
392
|
-
end
|
393
|
-
|
394
|
-
def test_unsigned_integer32_column
|
395
|
-
assert_nil(context["Posts.n_viewed"])
|
396
|
-
Groonga::Schema.create_table("Posts") do |table|
|
397
|
-
table.unsigned_integer32 :n_viewed
|
398
|
-
end
|
399
|
-
assert_equal(context["UInt32"], context["Posts.n_viewed"].range)
|
400
|
-
end
|
401
|
-
|
402
|
-
def test_unsigned_integer64_column
|
403
|
-
assert_nil(context["Posts.n_viewed"])
|
404
|
-
Groonga::Schema.create_table("Posts") do |table|
|
405
|
-
table.unsigned_integer64 :n_viewed
|
406
|
-
end
|
407
|
-
assert_equal(context["UInt64"], context["Posts.n_viewed"].range)
|
408
|
-
end
|
409
|
-
|
410
|
-
def test_float_column
|
411
|
-
assert_nil(context["Posts.rate"])
|
412
|
-
Groonga::Schema.create_table("Posts") do |table|
|
413
|
-
table.float :rate
|
414
|
-
end
|
415
|
-
assert_equal(context["Float"], context["Posts.rate"].range)
|
416
|
-
end
|
417
|
-
|
418
|
-
def test_time_column
|
419
|
-
assert_nil(context["Posts.last_modified"])
|
420
|
-
Groonga::Schema.create_table("Posts") do |table|
|
421
|
-
table.time :last_modified
|
422
|
-
end
|
423
|
-
assert_equal(context["Time"], context["Posts.last_modified"].range)
|
424
|
-
end
|
425
|
-
|
426
|
-
def test_timestamps
|
427
|
-
assert_nil(context["Posts.created_at"])
|
428
|
-
assert_nil(context["Posts.updated_at"])
|
429
|
-
Groonga::Schema.create_table("Posts") do |table|
|
430
|
-
table.timestamps
|
431
|
-
end
|
432
|
-
assert_equal(context["Time"], context["Posts.created_at"].range)
|
433
|
-
assert_equal(context["Time"], context["Posts.updated_at"].range)
|
434
|
-
end
|
435
|
-
|
436
|
-
def test_short_text_column
|
437
|
-
assert_nil(context["Posts.title"])
|
438
|
-
Groonga::Schema.create_table("Posts") do |table|
|
439
|
-
table.short_text :title
|
440
|
-
end
|
441
|
-
assert_equal(context["ShortText"], context["Posts.title"].range)
|
442
|
-
end
|
443
|
-
|
444
|
-
def test_text_column
|
445
|
-
assert_nil(context["Posts.comment"])
|
446
|
-
Groonga::Schema.create_table("Posts") do |table|
|
447
|
-
table.text :comment
|
448
|
-
end
|
449
|
-
assert_equal(context["Text"], context["Posts.comment"].range)
|
450
|
-
end
|
451
|
-
|
452
|
-
def test_long_text_column
|
453
|
-
assert_nil(context["Posts.content"])
|
454
|
-
Groonga::Schema.create_table("Posts") do |table|
|
455
|
-
table.long_text :content
|
456
|
-
end
|
457
|
-
assert_equal(context["LongText"], context["Posts.content"].range)
|
458
|
-
end
|
459
|
-
|
460
|
-
def test_boolean_column
|
461
|
-
assert_nil(context["Posts.public"])
|
462
|
-
Groonga::Schema.create_table("Posts") do |table|
|
463
|
-
table.boolean :public
|
464
|
-
end
|
465
|
-
assert_equal(context["Bool"], context["Posts.public"].range)
|
466
|
-
end
|
467
|
-
|
468
|
-
def test_tokyo_geo_point_column
|
469
|
-
assert_nil(context["Posts.location"])
|
470
|
-
Groonga::Schema.create_table("Posts") do |table|
|
471
|
-
table.tokyo_geo_point :location
|
472
|
-
end
|
473
|
-
assert_equal(context["TokyoGeoPoint"], context["Posts.location"].range)
|
474
|
-
end
|
475
|
-
|
476
|
-
def test_wgs84_geo_point_column
|
477
|
-
assert_nil(context["Posts.location"])
|
478
|
-
Groonga::Schema.create_table("Posts") do |table|
|
479
|
-
table.wgs84_geo_point :location
|
480
|
-
end
|
481
|
-
assert_equal(context["WGS84GeoPoint"], context["Posts.location"].range)
|
482
|
-
end
|
483
|
-
|
484
|
-
def test_geo_point_column
|
485
|
-
assert_nil(context["Posts.location"])
|
486
|
-
Groonga::Schema.create_table("Posts") do |table|
|
487
|
-
table.geo_point :location
|
488
|
-
end
|
489
|
-
assert_equal(context["WGS84GeoPoint"], context["Posts.location"].range)
|
490
|
-
end
|
491
|
-
|
492
|
-
def test_remove_column
|
493
|
-
Groonga::Schema.create_table("Posts") do |table|
|
494
|
-
table.long_text :content
|
495
|
-
end
|
496
|
-
assert_not_nil(context["Posts.content"])
|
497
|
-
|
498
|
-
Groonga::Schema.remove_column("Posts", "content")
|
499
|
-
assert_nil(context["Posts.content"])
|
500
|
-
end
|
501
|
-
|
502
|
-
def test_rename_column
|
503
|
-
Groonga::Schema.create_table("Posts") do |table|
|
504
|
-
table.long_text :content
|
505
|
-
end
|
506
|
-
content = context["Posts.content"]
|
507
|
-
assert_equal("Posts.content", content.name)
|
508
|
-
|
509
|
-
Groonga::Schema.rename_column("Posts", "content", "body")
|
510
|
-
body = context["Posts.body"]
|
511
|
-
assert_equal("Posts.body", body.name)
|
512
|
-
assert_equal("Posts.body", content.name)
|
513
|
-
end
|
514
|
-
|
515
|
-
class DefineColumnAgainTest < self
|
516
|
-
def test_same_option
|
517
|
-
Groonga::Schema.create_table("Posts") do |table|
|
518
|
-
table.text :content
|
519
|
-
end
|
520
|
-
|
521
|
-
assert_nothing_raised do
|
522
|
-
Groonga::Schema.create_table("Posts") do |table|
|
523
|
-
table.text :content
|
524
|
-
end
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
|
-
def test_difference_type
|
529
|
-
Groonga::Schema.create_table("Posts") do |table|
|
530
|
-
table.text :content
|
531
|
-
end
|
532
|
-
|
533
|
-
assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
|
534
|
-
Groonga::Schema.create_table("Posts") do |table|
|
535
|
-
table.integer :content
|
536
|
-
end
|
537
|
-
end
|
538
|
-
end
|
539
|
-
|
540
|
-
def test_same_option_by_groonga_object
|
541
|
-
Groonga::Schema.create_table("Posts") do |table|
|
542
|
-
table.text :content
|
543
|
-
end
|
544
|
-
|
545
|
-
assert_nothing_raised do
|
546
|
-
Groonga::Schema.create_table("Posts") do |table|
|
547
|
-
table.column(:content, Groonga["Text"])
|
548
|
-
end
|
549
|
-
end
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
class DefineIndexColumnTest < self
|
554
|
-
def test_default
|
555
|
-
assert_nil(context["Terms.content"])
|
556
|
-
Groonga::Schema.create_table("Posts") do |table|
|
557
|
-
table.long_text :content
|
558
|
-
end
|
559
|
-
Groonga::Schema.create_table("Terms") do |table|
|
560
|
-
table.index "Posts.content"
|
561
|
-
end
|
562
|
-
index_column = context["Terms.Posts_content"]
|
563
|
-
assert_equal([context["Posts.content"]],
|
564
|
-
index_column.sources)
|
565
|
-
assert_equal("#{@database_path}.0000103", index_column.path)
|
566
|
-
end
|
567
|
-
|
568
|
-
def test_named_path
|
569
|
-
assert_nil(context["Terms.content"])
|
570
|
-
Groonga::Schema.create_table("Posts") do |table|
|
571
|
-
table.long_text :content
|
572
|
-
end
|
573
|
-
Groonga::Schema.create_table("Terms") do |table|
|
574
|
-
table.index "Posts.content", :named_path => true
|
575
|
-
end
|
576
|
-
index_column = context["Terms.Posts_content"]
|
577
|
-
assert_equal([context["Posts.content"]],
|
578
|
-
index_column.sources)
|
579
|
-
assert_equal("#{@database_path}.0000102.columns/Posts_content",
|
580
|
-
index_column.path)
|
581
|
-
end
|
582
|
-
|
583
|
-
def test_full_option
|
584
|
-
path = @tmp_dir + "index-column.groonga"
|
585
|
-
assert_nil(context["Terms.content"])
|
586
|
-
index_column_name = "Posts_index"
|
587
|
-
|
588
|
-
Groonga::Schema.create_table("Posts") do |table|
|
589
|
-
table.long_text :content
|
590
|
-
end
|
591
|
-
Groonga::Schema.create_table("Terms") do |table|
|
592
|
-
table.index("Posts.content",
|
593
|
-
:name => index_column_name,
|
594
|
-
:path => path.to_s,
|
595
|
-
:persistent => true,
|
596
|
-
:with_section => true,
|
597
|
-
:with_weight => true,
|
598
|
-
:with_position => true,
|
599
|
-
:named_path => true)
|
600
|
-
end
|
601
|
-
|
602
|
-
full_index_column_name = "Terms.#{index_column_name}"
|
603
|
-
index_column = context[full_index_column_name]
|
604
|
-
assert_equal("#<Groonga::IndexColumn " +
|
605
|
-
"id: <#{index_column.id}>, " +
|
606
|
-
"name: <#{full_index_column_name}>, " +
|
607
|
-
"path: <#{path}>, " +
|
608
|
-
"domain: <Terms>, " +
|
609
|
-
"range: <Posts>, " +
|
610
|
-
"flags: <WITH_SECTION|WITH_WEIGHT|WITH_POSITION>>",
|
611
|
-
index_column.inspect)
|
612
|
-
end
|
613
|
-
|
614
|
-
def test_again
|
615
|
-
Groonga::Schema.create_table("Posts") do |table|
|
616
|
-
table.long_text :content
|
617
|
-
end
|
618
|
-
Groonga::Schema.create_table("Terms") do |table|
|
619
|
-
table.index "Posts.content"
|
620
|
-
end
|
621
|
-
|
622
|
-
assert_nothing_raised do
|
623
|
-
Groonga::Schema.create_table("Terms") do |table|
|
624
|
-
table.index "Posts.content"
|
625
|
-
end
|
626
|
-
end
|
627
|
-
end
|
628
|
-
|
629
|
-
def test_again_with_difference_source
|
630
|
-
Groonga::Schema.create_table("Posts") do |table|
|
631
|
-
table.long_text :content
|
632
|
-
table.short_text :name
|
633
|
-
end
|
634
|
-
Groonga::Schema.create_table("Terms") do |table|
|
635
|
-
table.index "Posts.content"
|
636
|
-
end
|
637
|
-
|
638
|
-
assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do
|
639
|
-
Groonga::Schema.create_table("Terms") do |table|
|
640
|
-
table.index "Posts.name", :name => "Posts_content"
|
641
|
-
end
|
642
|
-
end
|
643
|
-
end
|
644
|
-
|
645
|
-
def test_key
|
646
|
-
Groonga::Schema.create_table("Posts",
|
647
|
-
:type => :hash,
|
648
|
-
:key_type => "ShortText") do |table|
|
649
|
-
end
|
650
|
-
Groonga::Schema.create_table("Terms") do |table|
|
651
|
-
table.index "Posts._key", :with_position => true
|
652
|
-
end
|
653
|
-
|
654
|
-
full_index_column_name = "Terms.Posts__key"
|
655
|
-
index_column = context[full_index_column_name]
|
656
|
-
assert_equal("#<Groonga::IndexColumn " +
|
657
|
-
"id: <#{index_column.id}>, " +
|
658
|
-
"name: <#{full_index_column_name}>, " +
|
659
|
-
"path: <#{index_column.path}>, " +
|
660
|
-
"domain: <Terms>, " +
|
661
|
-
"range: <Posts>, " +
|
662
|
-
"flags: <WITH_POSITION>>",
|
663
|
-
index_column.inspect)
|
664
|
-
end
|
665
|
-
|
666
|
-
def test_key_again
|
667
|
-
Groonga::Schema.create_table("Posts",
|
668
|
-
:type => :hash,
|
669
|
-
:key_type => "ShortText") do |table|
|
670
|
-
end
|
671
|
-
Groonga::Schema.create_table("Terms") do |table|
|
672
|
-
table.index "Posts._key", :with_position => true
|
673
|
-
end
|
674
|
-
|
675
|
-
assert_nothing_raised do
|
676
|
-
Groonga::Schema.create_table("Terms") do |table|
|
677
|
-
table.index "Posts._key"
|
678
|
-
end
|
679
|
-
end
|
680
|
-
end
|
681
|
-
|
682
|
-
def test_remove
|
683
|
-
Groonga::Schema.create_table("Posts") do |table|
|
684
|
-
table.long_text :content
|
685
|
-
end
|
686
|
-
Groonga::Schema.create_table("Terms") do |table|
|
687
|
-
table.index "Posts.content"
|
688
|
-
end
|
689
|
-
assert_equal([context["Posts.content"]],
|
690
|
-
context["Terms.Posts_content"].sources)
|
691
|
-
Groonga::Schema.change_table("Terms") do |table|
|
692
|
-
table.remove_index("Posts.content")
|
693
|
-
end
|
694
|
-
assert_nil(context["Terms.Posts_content"])
|
695
|
-
end
|
696
|
-
|
697
|
-
def test_rename
|
698
|
-
Groonga::Schema.create_table("Posts") do |table|
|
699
|
-
table.long_text :content
|
700
|
-
end
|
701
|
-
Groonga::Schema.create_table("Terms") do |table|
|
702
|
-
table.index "Posts.content"
|
703
|
-
end
|
704
|
-
index = context["Terms.Posts_content"]
|
705
|
-
assert_equal([context["Posts.content"]], index.sources)
|
706
|
-
Groonga::Schema.change_table("Terms") do |table|
|
707
|
-
table.rename_column("Posts_content", "posts_content_index")
|
708
|
-
end
|
709
|
-
renamed_index = context["Terms.posts_content_index"]
|
710
|
-
assert_equal("Terms.posts_content_index", renamed_index.name)
|
711
|
-
assert_equal("Terms.posts_content_index", index.name)
|
712
|
-
assert_equal([context["Posts.content"]], renamed_index.sources)
|
713
|
-
end
|
714
|
-
end
|
715
|
-
|
716
|
-
def test_reference_guess
|
717
|
-
Groonga::Schema.define do |schema|
|
718
|
-
schema.create_table("Items", :type => :hash) do |table|
|
719
|
-
table.short_text("title")
|
720
|
-
end
|
721
|
-
|
722
|
-
schema.create_table("Users", :type => :hash) do |table|
|
723
|
-
table.reference("item")
|
724
|
-
end
|
725
|
-
end
|
726
|
-
|
727
|
-
assert_equal(context["Items"], context["Users.item"].range)
|
728
|
-
end
|
729
|
-
|
730
|
-
def test_reference_ungeussable
|
731
|
-
candidates = ["item", "items", "Items"]
|
732
|
-
exception =
|
733
|
-
Groonga::Schema::UnguessableReferenceTable.new("item", candidates)
|
734
|
-
assert_raise(exception) do
|
735
|
-
Groonga::Schema.define do |schema|
|
736
|
-
schema.create_table("Users", :type => :hash) do |table|
|
737
|
-
table.reference("item")
|
738
|
-
end
|
739
|
-
end
|
740
|
-
end
|
741
|
-
end
|
742
|
-
|
743
|
-
def test_explicit_context_create_table
|
744
|
-
context = Groonga::Context.default
|
745
|
-
Groonga::Context.default = nil
|
746
|
-
|
747
|
-
Groonga::Schema.define(:context => context) do |schema|
|
748
|
-
schema.create_table('Items', :type => :hash) do |table|
|
749
|
-
table.text("text")
|
750
|
-
end
|
751
|
-
schema.create_table("TermsText",
|
752
|
-
:type => :patricia_trie,
|
753
|
-
:key_normalize => true,
|
754
|
-
:default_tokenizer => "TokenBigram") do |table|
|
755
|
-
table.index('Items.text')
|
756
|
-
end
|
757
|
-
end
|
758
|
-
|
759
|
-
assert_not_nil(context["Items.text"])
|
760
|
-
assert_not_nil(context["TermsText.Items_text"])
|
761
|
-
assert_nil(Groonga::Context.default["Items.text"])
|
762
|
-
assert_nil(Groonga::Context.default["TermsText.Items_text"])
|
763
|
-
end
|
764
|
-
|
765
|
-
def test_default_tokenizer_name_shortcut
|
766
|
-
Groonga::Schema.define do |schema|
|
767
|
-
schema.create_table("Terms",
|
768
|
-
:type => :patricia_trie,
|
769
|
-
:key_normalize => true,
|
770
|
-
:default_tokenizer => :bigram) do |table|
|
771
|
-
end
|
772
|
-
end
|
773
|
-
|
774
|
-
assert_equal(Groonga["TokenBigram"], Groonga["Terms"].default_tokenizer)
|
775
|
-
end
|
776
|
-
|
777
|
-
def test_duplicated_shortcut_name
|
778
|
-
short_text = Groonga::Type.new("short_text", :size => 1024)
|
779
|
-
Groonga::Schema.define do |schema|
|
780
|
-
schema.create_table("Users",
|
781
|
-
:type => :patricia_trie,
|
782
|
-
:key_normalize => true,
|
783
|
-
:key_type => :short_text) do |table|
|
784
|
-
end
|
785
|
-
end
|
786
|
-
|
787
|
-
assert_equal(short_text, Groonga["Users"].domain)
|
788
|
-
end
|
789
|
-
|
790
|
-
class RemoveTest < self
|
791
|
-
def test_tables_directory_removed_on_last_table_remove
|
792
|
-
table_name = "Posts"
|
793
|
-
Groonga::Schema.create_table(table_name, :named_path => true)
|
794
|
-
table = Groonga[table_name]
|
795
|
-
tables_directory = Pathname.new(table.path).dirname
|
796
|
-
|
797
|
-
assert_directory_not_removed(tables_directory)
|
798
|
-
Groonga::Schema.remove_table(table_name)
|
799
|
-
assert_directory_removed(tables_directory)
|
800
|
-
end
|
801
|
-
|
802
|
-
def test_tables_directory_not_removed_on_not_last_table_remove
|
803
|
-
table_name = "Posts"
|
804
|
-
Groonga::Schema.define(:named_path => true) do |schema|
|
805
|
-
schema.create_table(table_name)
|
806
|
-
schema.create_table("Users")
|
807
|
-
end
|
808
|
-
|
809
|
-
table = Groonga[table_name]
|
810
|
-
tables_directory = Pathname.new(table.path).dirname
|
811
|
-
|
812
|
-
assert_directory_not_removed(tables_directory)
|
813
|
-
Groonga::Schema.remove_table(table_name)
|
814
|
-
assert_directory_not_removed(tables_directory)
|
815
|
-
end
|
816
|
-
|
817
|
-
def test_columns_directory_removed
|
818
|
-
table = "Posts"
|
819
|
-
dir = create_table_with_column(table, :named_path => true)
|
820
|
-
|
821
|
-
Groonga::Schema.remove_table(table)
|
822
|
-
|
823
|
-
assert_table_removed(table)
|
824
|
-
assert_directory_removed(dir)
|
825
|
-
end
|
826
|
-
end
|
827
|
-
|
828
|
-
class ColumnRemoveTest < self
|
829
|
-
def test_columns_directory_removed_on_last_column_remove
|
830
|
-
Groonga::Schema.define(:named_path => true) do |schema|
|
831
|
-
schema.create_table("Posts") do |table|
|
832
|
-
table.short_text("title")
|
833
|
-
end
|
834
|
-
end
|
835
|
-
|
836
|
-
columns_directory = columns_directory_path(Groonga["Posts"])
|
837
|
-
assert_directory_not_removed(columns_directory)
|
838
|
-
Groonga::Schema.change_table("Posts") do |table|
|
839
|
-
table.remove_column("title")
|
840
|
-
end
|
841
|
-
assert_directory_removed(columns_directory)
|
842
|
-
end
|
843
|
-
|
844
|
-
def test_columns_directory_not_removed_on_not_last_column_remove
|
845
|
-
Groonga::Schema.define(:named_path => true) do |schema|
|
846
|
-
schema.create_table("Posts") do |table|
|
847
|
-
table.short_text("title")
|
848
|
-
table.short_text("body")
|
849
|
-
end
|
850
|
-
end
|
851
|
-
|
852
|
-
columns_directory = columns_directory_path(Groonga["Posts"])
|
853
|
-
assert_directory_not_removed(columns_directory)
|
854
|
-
Groonga::Schema.change_table("Posts") do |table|
|
855
|
-
table.remove_column("title")
|
856
|
-
end
|
857
|
-
assert_directory_not_removed(columns_directory)
|
858
|
-
end
|
859
|
-
end
|
860
|
-
|
861
|
-
private
|
862
|
-
def columns_directory_path(table)
|
863
|
-
"#{table.path}.columns"
|
864
|
-
end
|
865
|
-
|
866
|
-
def create_table_with_column(name, options={})
|
867
|
-
Groonga::Schema.create_table(name, options) do |table|
|
868
|
-
table.integer64 :rate
|
869
|
-
end
|
870
|
-
context = Groonga::Context.default
|
871
|
-
columns_directory_path(context[name])
|
872
|
-
end
|
873
|
-
|
874
|
-
def assert_directory_removed(dir)
|
875
|
-
assert_not_predicate(Pathname.new(dir), :exist?)
|
876
|
-
end
|
877
|
-
|
878
|
-
def assert_directory_not_removed(dir)
|
879
|
-
assert_predicate(Pathname.new(dir), :exist?)
|
880
|
-
end
|
881
|
-
|
882
|
-
def assert_table_removed(name)
|
883
|
-
context = Groonga::Context.default
|
884
|
-
assert_nil(context[name])
|
885
|
-
end
|
886
|
-
end
|