rroonga 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/Rakefile +21 -2
  2. data/bin/grndump +3 -2
  3. data/ext/groonga/extconf.rb +1 -6
  4. data/ext/groonga/rb-grn-array.c +58 -31
  5. data/ext/groonga/rb-grn-column.c +220 -148
  6. data/ext/groonga/rb-grn-context.c +46 -32
  7. data/ext/groonga/rb-grn-database.c +102 -90
  8. data/ext/groonga/rb-grn-double-array-trie.c +205 -163
  9. data/ext/groonga/rb-grn-encoding-support.c +2 -3
  10. data/ext/groonga/rb-grn-encoding.c +13 -8
  11. data/ext/groonga/rb-grn-exception.c +1 -1
  12. data/ext/groonga/rb-grn-expression.c +110 -133
  13. data/ext/groonga/rb-grn-fix-size-column.c +5 -4
  14. data/ext/groonga/rb-grn-geo-point.c +55 -0
  15. data/ext/groonga/rb-grn-hash.c +120 -82
  16. data/ext/groonga/rb-grn-index-column.c +66 -70
  17. data/ext/groonga/rb-grn-index-cursor.c +3 -0
  18. data/ext/groonga/rb-grn-logger.c +33 -51
  19. data/ext/groonga/rb-grn-object.c +2 -0
  20. data/ext/groonga/rb-grn-operator.c +1 -1
  21. data/ext/groonga/rb-grn-patricia-trie.c +287 -232
  22. data/ext/groonga/rb-grn-plugin.c +11 -14
  23. data/ext/groonga/rb-grn-snippet.c +37 -54
  24. data/ext/groonga/rb-grn-table-cursor-key-support.c +3 -3
  25. data/ext/groonga/rb-grn-table-cursor.c +8 -6
  26. data/ext/groonga/rb-grn-table-key-support.c +22 -29
  27. data/ext/groonga/rb-grn-table.c +355 -279
  28. data/ext/groonga/rb-grn-type.c +18 -25
  29. data/ext/groonga/rb-grn-utils.c +77 -7
  30. data/ext/groonga/rb-grn-variable-size-column.c +12 -20
  31. data/ext/groonga/rb-grn-view.c +56 -51
  32. data/ext/groonga/rb-grn.h +28 -1
  33. data/ext/groonga/rb-groonga.c +1 -0
  34. data/lib/groonga.rb +2 -0
  35. data/lib/groonga/command.rb +3 -1
  36. data/lib/groonga/database.rb +27 -0
  37. data/lib/groonga/dumper.rb +96 -17
  38. data/lib/groonga/geo-point.rb +216 -0
  39. data/lib/groonga/schema.rb +29 -46
  40. data/rroonga-build.rb +1 -1
  41. data/rroonga.gemspec +90 -0
  42. data/test/groonga-test-utils.rb +168 -0
  43. data/test/run-test.rb +60 -0
  44. data/test/test-accessor.rb +36 -0
  45. data/test/test-array.rb +146 -0
  46. data/test/test-column.rb +350 -0
  47. data/test/test-command-select.rb +181 -0
  48. data/test/test-context.rb +130 -0
  49. data/test/test-database-dumper.rb +259 -0
  50. data/test/test-database.rb +173 -0
  51. data/test/test-double-array-trie.rb +189 -0
  52. data/test/test-encoding.rb +33 -0
  53. data/test/test-exception.rb +230 -0
  54. data/test/test-expression-builder.rb +602 -0
  55. data/test/test-expression.rb +134 -0
  56. data/test/test-fix-size-column.rb +77 -0
  57. data/test/test-geo-point.rb +190 -0
  58. data/test/test-gqtp.rb +70 -0
  59. data/test/test-hash.rb +367 -0
  60. data/test/test-index-column.rb +180 -0
  61. data/test/test-index-cursor.rb +123 -0
  62. data/test/test-logger.rb +37 -0
  63. data/test/test-pagination.rb +249 -0
  64. data/test/test-patricia-trie.rb +440 -0
  65. data/test/test-plugin.rb +35 -0
  66. data/test/test-procedure.rb +37 -0
  67. data/test/test-query-log.rb +258 -0
  68. data/test/test-record.rb +577 -0
  69. data/test/test-remote.rb +63 -0
  70. data/test/test-schema-create-table.rb +267 -0
  71. data/test/test-schema-dumper.rb +235 -0
  72. data/test/test-schema-type.rb +208 -0
  73. data/test/test-schema-view.rb +90 -0
  74. data/test/test-schema.rb +886 -0
  75. data/test/test-snippet.rb +130 -0
  76. data/test/test-table-dumper.rb +353 -0
  77. data/test/test-table-offset-and-limit.rb +100 -0
  78. data/test/test-table-select-mecab.rb +80 -0
  79. data/test/test-table-select-normalize.rb +57 -0
  80. data/test/test-table-select-weight.rb +123 -0
  81. data/test/test-table-select.rb +191 -0
  82. data/test/test-table-traverse.rb +304 -0
  83. data/test/test-table.rb +711 -0
  84. data/test/test-type.rb +79 -0
  85. data/test/test-variable-size-column.rb +147 -0
  86. data/test/test-variable.rb +28 -0
  87. data/test/test-vector-column.rb +76 -0
  88. data/test/test-version.rb +61 -0
  89. data/test/test-view.rb +72 -0
  90. metadata +330 -202
data/test/test-type.rb ADDED
@@ -0,0 +1,79 @@
1
+ # Copyright (C) 2009-2012 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 TypeTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_new
22
+ type = Groonga::Type.new("user_id", :type => :integer)
23
+ assert_equal("user_id", type.name)
24
+ end
25
+
26
+ def test_new_with_space_name
27
+ exception = assert_raise(Groonga::InvalidArgument) do
28
+ Groonga::Type.new("user id", :type => :integer)
29
+ end
30
+ message =
31
+ "name can't start with '_' and contains only 0-9, A-Z, a-z, #, @, - or _"
32
+ assert_match(/#{Regexp.escape(message)}/,
33
+ exception.message)
34
+ end
35
+
36
+ def test_builtins
37
+ assert_equal_type("Object", Groonga::Type::OBJECT) # FIXME!!!
38
+ assert_equal_type("Bool", Groonga::Type::BOOLEAN)
39
+ assert_equal_type("Bool", Groonga::Type::BOOL)
40
+ assert_equal_type("Int8", Groonga::Type::INT8)
41
+ assert_equal_type("UInt8", Groonga::Type::UINT8)
42
+ assert_equal_type("Int16", Groonga::Type::INT16)
43
+ assert_equal_type("UInt16", Groonga::Type::UINT16)
44
+ assert_equal_type("Int32", Groonga::Type::INT32)
45
+ assert_equal_type("UInt32", Groonga::Type::UINT32)
46
+ assert_equal_type("Int64", Groonga::Type::INT64)
47
+ assert_equal_type("UInt64", Groonga::Type::UINT64)
48
+ assert_equal_type("Float", Groonga::Type::FLOAT)
49
+ assert_equal_type("Time", Groonga::Type::TIME)
50
+ assert_equal_type("ShortText", Groonga::Type::SHORT_TEXT)
51
+ assert_equal_type("Text", Groonga::Type::TEXT)
52
+ assert_equal_type("LongText", Groonga::Type::LONG_TEXT)
53
+ end
54
+
55
+ def test_inspect
56
+ assert_equal("#<Groonga::Type id: <#{Groonga::Type::LONG_TEXT}>, " +
57
+ "name: <LongText>, " +
58
+ "path: (temporary), " +
59
+ "domain: (nil), " +
60
+ "range: <2147483648>, " +
61
+ "flags: <>>",
62
+ context["<longtext>"].inspect)
63
+ end
64
+
65
+ data("builtin - Int32" => "Int32",
66
+ "builtin - ShortText" => "ShortText",
67
+ "builtin - Time" => "Time")
68
+ def test_builtin?(name)
69
+ type = Groonga[name]
70
+ assert_predicate(type, :builtin?)
71
+ end
72
+
73
+ private
74
+ def assert_equal_type(expected_name, id)
75
+ type = Groonga[id]
76
+ assert_equal(expected_name,
77
+ type ? type.name : type)
78
+ end
79
+ end
@@ -0,0 +1,147 @@
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 VariableSizeColumnTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+
22
+ setup_users_table
23
+ setup_users
24
+ end
25
+
26
+ def setup_users_table
27
+ @users_path = @tables_dir + "users"
28
+ @users = Groonga::Array.create(:name => "Users",
29
+ :path => @users_path.to_s)
30
+
31
+ @users_name_column_path = @columns_dir + "name"
32
+ @name = @users.define_column("name", "ShortText",
33
+ :path => @users_name_column_path.to_s)
34
+
35
+ @users_friends_column_path = @columns_dir + "friends"
36
+ @friends = @users.define_column("friends", @users,
37
+ :type => :vector,
38
+ :path => @users_friends_column_path.to_s)
39
+
40
+ @users_nick_names_column_path = @columns_dir + "nick_names"
41
+ @nick_names =
42
+ @users.define_column("nick_names", "ShortText",
43
+ :type => :vector,
44
+ :path => @users_nick_names_column_path.to_s)
45
+ end
46
+
47
+ def setup_users
48
+ @morita = @users.add(:name => "mori daijiro")
49
+ @gunyara_kun = @users.add(:name => "Tasuku SUENAGA")
50
+ @yu = @users.add(:name => "Yutaro Shimamura")
51
+ end
52
+
53
+ def test_index?
54
+ assert_not_predicate(@nick_names, :index?)
55
+ end
56
+
57
+ def test_vector?
58
+ assert_predicate(@nick_names, :vector?)
59
+ end
60
+
61
+ def test_scalar?
62
+ assert_not_predicate(@nick_names, :scalar?)
63
+ end
64
+
65
+ def test_compressed?
66
+ description = @users.define_column("description", "ShortText",
67
+ :compress => :zlib)
68
+ if context.support_zlib?
69
+ assert_predicate(description, :compressed?)
70
+ else
71
+ assert_not_predicate(description, :compressed?)
72
+ end
73
+ end
74
+
75
+ def test_compressed_zlib?
76
+ description = @users.define_column("description", "ShortText",
77
+ :compress => :zlib)
78
+ if context.support_zlib?
79
+ assert_send([description, :compressed?, :zlib])
80
+ else
81
+ assert_not_send([description, :compressed?, :zlib])
82
+ end
83
+ end
84
+
85
+ def test_compressed_lzo?
86
+ description = @users.define_column("description", "ShortText",
87
+ :compress => :lzo)
88
+ if context.support_lzo?
89
+ assert_send([description, :compressed?, :lzo])
90
+ else
91
+ assert_not_send([description, :compressed?, :lzo])
92
+ end
93
+ end
94
+
95
+ def test_inspect
96
+ assert_equal("#<Groonga::VariableSizeColumn " +
97
+ "id: <#{@name.id}>, " +
98
+ "name: <Users.name>, " +
99
+ "path: <#{@users_name_column_path}>, " +
100
+ "domain: <Users>, " +
101
+ "range: <ShortText>, " +
102
+ "flags: <>" +
103
+ ">",
104
+ @name.inspect)
105
+ end
106
+
107
+ def test_domain
108
+ assert_equal(@users, @name.domain)
109
+ end
110
+
111
+ def test_table
112
+ assert_equal(@users, @name.table)
113
+ end
114
+
115
+ def test_vector_append
116
+ assert_equal([], @morita["friends"])
117
+ @morita.append("friends", @yu)
118
+ assert_equal([@yu], @morita["friends"])
119
+ @morita.append("friends", @gunyara_kun)
120
+ assert_equal([@yu, @gunyara_kun], @morita["friends"])
121
+ end
122
+
123
+ def test_vector_prepend
124
+ assert_equal([], @morita["friends"])
125
+ @morita.prepend("friends", @yu)
126
+ assert_equal([@yu], @morita["friends"])
127
+ @morita.prepend("friends", @gunyara_kun)
128
+ assert_equal([@gunyara_kun, @yu], @morita["friends"])
129
+ end
130
+
131
+ def test_string_vector
132
+ omit("append/prepend for non table domain column " +
133
+ "isn't supported by groonga.")
134
+ assert_equal([], @morita["nick_names"])
135
+ @morita.append("nick_names", "morita")
136
+ assert_equal(["morita"], @morita["nick_names"])
137
+ @morita.prepend("nick_names", "moritapo")
138
+ assert_equal(["moritapo", "morita"], @morita["nick_names"])
139
+ end
140
+
141
+ def test_defrag
142
+ 1000.times do |i|
143
+ @users.add(:name => "user #{i}" * 1000)
144
+ end
145
+ assert_equal(3, @name.defrag)
146
+ end
147
+ end
@@ -0,0 +1,28 @@
1
+ # Copyright (C) 2009 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 VariableTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_value
22
+ expression = Groonga::Expression.new
23
+ variable = expression.define_variable
24
+ assert_nil(variable.value)
25
+ variable.value = "morita"
26
+ assert_equal("morita", variable.value)
27
+ end
28
+ end
@@ -0,0 +1,76 @@
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 VectorColumnTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+ setup_tables
22
+ end
23
+
24
+ def setup_tables
25
+ Groonga::Schema.define do |schema|
26
+ schema.create_table("Users",
27
+ :type => :hash,
28
+ :key_type => "UInt32") do |table|
29
+ end
30
+
31
+ schema.create_table("Communities",
32
+ :type => :hash,
33
+ :key_type => "ShortText") do |table|
34
+ table.reference("users", "Users", :type => :vector)
35
+ end
36
+
37
+ schema.create_table("Areas",
38
+ :type => :hash,
39
+ :key_type => "ShortText") do |table|
40
+ table.reference("communities", "Communities", :type => :vector)
41
+ end
42
+ end
43
+
44
+ @users = Groonga::Context.default["Users"]
45
+ @communities = Groonga::Context.default["Communities"]
46
+ @areas = Groonga::Context.default["Areas"]
47
+ end
48
+
49
+ def test_set_records
50
+ groonga = @communities.add("groonga")
51
+ morita = @users.add(29)
52
+ groonga["users"] = [morita]
53
+
54
+ assert_equal([29], @users.collect {|record| record.key})
55
+ assert_equal([29], groonga["users"].collect {|record| record.key})
56
+ end
57
+
58
+ def test_set_nonexistent_keys
59
+ shinjuku = @areas.add("Shinjuku")
60
+ shinjuku["communities"] = ["groonga", "Senna"]
61
+
62
+ assert_equal(["groonga", "Senna"],
63
+ @communities.collect {|record| record.key})
64
+ assert_equal(["groonga", "Senna"],
65
+ shinjuku["communities"].collect {|record| record.key})
66
+ end
67
+
68
+ def test_set_nil
69
+ groonga = @communities.add("groonga")
70
+ assert_equal([], groonga["users"])
71
+ groonga["users"] = nil
72
+ assert_equal([], groonga["users"]) # should return nil?
73
+ # Can groonga tell us
74
+ # that the value is empty?
75
+ end
76
+ end
@@ -0,0 +1,61 @@
1
+ # Copyright (C) 2009-2012 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 VersionTest < Test::Unit::TestCase
17
+ def test_build_version_format
18
+ assert_equal("X.X.X", normalize(Groonga.build_version))
19
+ end
20
+
21
+ def test_build_version_value
22
+ assert_equal(Groonga.build_version, Groonga::BUILD_VERSION.join("."))
23
+ end
24
+
25
+ def test_version_format
26
+ if /-/ =~ Groonga.version
27
+ assert_equal("X.X.X-XXX", normalize(Groonga.version))
28
+ else
29
+ assert_equal("X.X.X", normalize(Groonga.version))
30
+ end
31
+ end
32
+
33
+ def test_version_value
34
+ major, minor, micro, tag = Groonga::VERSION
35
+ versions = [major, minor, micro]
36
+ assert_equal(Groonga.version, [versions.join("."), tag].compact.join("-"))
37
+ end
38
+
39
+ def test_bindings_version_format
40
+ assert_equal("X.X.X", normalize(Groonga.bindings_version))
41
+ end
42
+
43
+ def test_bindings_version_value
44
+ assert_equal(Groonga.bindings_version, Groonga::BINDINGS_VERSION.join("."))
45
+ end
46
+
47
+ private
48
+ def normalize(version)
49
+ versions_component, tag_component = version.split(/-/, 2)
50
+ versions = versions_component.split(/\./)
51
+ normalized_versions = versions.collect do |component|
52
+ component.gsub(/\d+/, "X")
53
+ end
54
+ if tag_component
55
+ normalized_tag = "XXX"
56
+ else
57
+ normalized_tag = nil
58
+ end
59
+ [normalized_versions.join("."), normalized_tag].compact.join("-")
60
+ end
61
+ end
data/test/test-view.rb ADDED
@@ -0,0 +1,72 @@
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 ViewTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_inspect
22
+ path = @tables_dir + "users.groonga"
23
+ view = Groonga::View.create(:name => "Users", :path => path.to_s)
24
+ assert_equal("#<Groonga::View " +
25
+ "id: <#{view.id}>, " +
26
+ "name: <Users>, " +
27
+ "path: <#{path}>, " +
28
+ "domain: (nil), " +
29
+ "range: (nil), " +
30
+ "flags: <>, " +
31
+ "encoding: <:default>, " +
32
+ "size: <0>>",
33
+ view.inspect)
34
+ end
35
+
36
+ def test_encoding
37
+ view = Groonga::View.create
38
+ assert_false(view.respond_to?(:encoding))
39
+ end
40
+
41
+ def test_add_table
42
+ users = Groonga::Array.create(:name => "Users")
43
+ dogs = Groonga::Array.create(:name => "Dogs")
44
+ entries = Groonga::View.create(:name => "Entries")
45
+ entries.add_table(users)
46
+ entries.add_table(dogs)
47
+
48
+ assert_equal(0, entries.size)
49
+ users.add
50
+ assert_equal(1, entries.size)
51
+ dogs.add
52
+ assert_equal(2, entries.size)
53
+ end
54
+
55
+ def test_sort
56
+ users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
57
+ dogs = Groonga::Hash.create(:name => "Dogs", :key_type => "ShortText")
58
+ entries = Groonga::View.create(:name => "Entries")
59
+ entries.add_table(users)
60
+ entries.add_table(dogs)
61
+
62
+ users.add("morita")
63
+ users.add("tasuku")
64
+ users.add("yu")
65
+ dogs.add("pochi")
66
+ dogs.add("bob")
67
+ dogs.add("fuga")
68
+ omit("View#sort is broken!!!")
69
+ assert_equal(["XXX"],
70
+ entries.sort(["_key"], :limit => 2).collect {|entry| entry["_key"]})
71
+ end
72
+ end