rroonga 9.0.2 → 10.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Rakefile +9 -142
  4. data/doc/text/news.md +73 -1
  5. data/doc/text/tutorial.md +1 -1
  6. data/ext/groonga/extconf.rb +9 -74
  7. data/ext/groonga/rb-grn-context.c +27 -0
  8. data/ext/groonga/rb-grn-expression-builder.c +3 -3
  9. data/ext/groonga/rb-grn-flushable.c +7 -0
  10. data/ext/groonga/rb-grn-index-column.c +28 -0
  11. data/ext/groonga/rb-grn-index-cursor.c +19 -0
  12. data/ext/groonga/rb-grn-logger.c +17 -3
  13. data/ext/groonga/rb-grn-object.c +236 -22
  14. data/ext/groonga/rb-grn-table-key-support.c +26 -7
  15. data/ext/groonga/rb-grn-table.c +119 -87
  16. data/ext/groonga/rb-grn-type.c +5 -1
  17. data/ext/groonga/rb-grn-utils.c +17 -1
  18. data/ext/groonga/rb-grn.h +7 -13
  19. data/ext/groonga/rb-groonga.c +2 -2
  20. data/lib/groonga.rb +3 -7
  21. data/lib/groonga/dumper.rb +3 -0
  22. data/lib/groonga/record.rb +2 -2
  23. data/rroonga.gemspec +4 -5
  24. data/test/groonga-test-utils.rb +34 -5
  25. data/test/run-test.rb +1 -3
  26. data/test/test-accessor.rb +63 -7
  27. data/test/test-column.rb +12 -1
  28. data/test/test-context.rb +25 -0
  29. data/test/test-exception.rb +5 -0
  30. data/test/test-flushable.rb +51 -6
  31. data/test/test-index-column.rb +67 -6
  32. data/test/test-index-cursor.rb +26 -0
  33. data/test/test-logger.rb +56 -11
  34. data/test/test-plugin.rb +1 -0
  35. data/test/test-query-logger.rb +4 -3
  36. data/test/test-record.rb +2 -1
  37. data/test/test-remote.rb +56 -10
  38. data/test/test-schema-dumper.rb +13 -0
  39. data/test/test-schema.rb +9 -1
  40. data/test/test-table-arrow.rb +1 -1
  41. data/test/test-table.rb +21 -1
  42. data/test/test-variable.rb +23 -7
  43. metadata +65 -106
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2009-2016 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2020 Sutou Kouhei <kou@clear-code.com>
4
4
 
5
5
  This library is free software; you can redistribute it and/or
6
6
  modify it under the terms of the GNU Lesser General Public
@@ -304,6 +304,10 @@ rb_grn_init_type (VALUE mGrn)
304
304
  rb_define_const(rb_cGrnType, "INT64", INT2NUM(GRN_DB_INT64));
305
305
  /* 64bit符号なし整数。 */
306
306
  rb_define_const(rb_cGrnType, "UINT64", INT2NUM(GRN_DB_UINT64));
307
+ #if RB_GRN_HAVE_FLOAT32
308
+ /* 32bit floating pointer number in IEEE754 format. */
309
+ rb_define_const(rb_cGrnType, "FLOAT32", INT2NUM(GRN_DB_FLOAT32));
310
+ #endif
307
311
  /* ieee754形式の64bit浮動小数点数。 */
308
312
  rb_define_const(rb_cGrnType, "FLOAT", INT2NUM(GRN_DB_FLOAT));
309
313
  /* 1970年1月1日0時0分0秒からの経過マイクロ秒数を64bit符
@@ -1,7 +1,7 @@
1
1
  /* -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /* vim: set sts=4 sw=4 ts=8 noet: */
3
3
  /*
4
- Copyright (C) 2009-2017 Kouhei Sutou <kou@clear-code.com>
4
+ Copyright (C) 2009-2020 Sutou Kouhei <kou@clear-code.com>
5
5
 
6
6
  This library is free software; you can redistribute it and/or
7
7
  modify it under the terms of the GNU Lesser General Public
@@ -201,6 +201,11 @@ rb_grn_bulk_to_ruby_object_by_range_id (grn_ctx *context, grn_obj *bulk,
201
201
  case GRN_DB_UINT64:
202
202
  *rb_value = ULL2NUM(GRN_UINT64_VALUE(bulk));
203
203
  break;
204
+ #if RB_GRN_HAVE_FLOAT32
205
+ case GRN_DB_FLOAT32:
206
+ *rb_value = rb_float_new(GRN_FLOAT32_VALUE(bulk));
207
+ break;
208
+ #endif
204
209
  case GRN_DB_FLOAT:
205
210
  *rb_value = rb_float_new(GRN_FLOAT_VALUE(bulk));
206
211
  break;
@@ -447,6 +452,7 @@ rb_grn_bulk_from_ruby_object_with_type (VALUE object, grn_ctx *context,
447
452
  int64_t int64_value;
448
453
  uint64_t uint64_value;
449
454
  int64_t time_value;
455
+ float float_value;
450
456
  double double_value;
451
457
  grn_geo_point geo_point_value;
452
458
  grn_id record_id;
@@ -525,6 +531,16 @@ rb_grn_bulk_from_ruby_object_with_type (VALUE object, grn_ctx *context,
525
531
  string = (const char *)&(value.uint64_value);
526
532
  size = sizeof(value.uint64_value);
527
533
  break;
534
+ #if RB_GRN_HAVE_FLOAT32
535
+ case GRN_DB_FLOAT32:
536
+ if (string_p) {
537
+ object = rb_Float(object);
538
+ }
539
+ value.float_value = NUM2DBL(object);
540
+ string = (const char *)&(value.float_value);
541
+ size = sizeof(value.float_value);
542
+ break;
543
+ #endif
528
544
  case GRN_DB_FLOAT:
529
545
  if (string_p) {
530
546
  object = rb_Float(object);
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2009-2018 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2020 Sutou Kouhei <kou@clear-code.com>
4
4
  Copyright (C) 2015-2017 Masafumi Yokoyama <yokoyama@clear-code.com>
5
5
 
6
6
  This library is free software; you can redistribute it and/or
@@ -73,17 +73,9 @@ RB_GRN_BEGIN_DECLS
73
73
  # define RB_GRN_GNUC_NULL_TERMINATED
74
74
  #endif
75
75
 
76
- #if defined(RUBY_GRN_PLATFORM_WIN32) && !defined(RB_GRN_PLATFORM_WIN32)
77
- # define RB_GRN_PLATFORM_WIN32 RUBY_GRN_PLATFORM_WIN32
78
- #endif
79
-
80
- #if defined(RUBY_GRN_STATIC_COMPILATION) && !defined(RB_GRN_STATIC_COMPILATION)
81
- # define RB_GRN_STATIC_COMPILATION RUBY_GRN_STATIC_COMPILATION
82
- #endif
83
-
84
- #if defined(RB_GRN_PLATFORM_WIN32) && !defined(RB_GRN_STATIC_COMPILATION)
76
+ #ifdef __WIN32__
85
77
  # ifdef RB_GRN_COMPILATION
86
- # define RB_GRN_VAR __declspec(dllexport)
78
+ # define RB_GRN_VAR extern __declspec(dllexport)
87
79
  # else
88
80
  # define RB_GRN_VAR extern __declspec(dllimport)
89
81
  # endif
@@ -97,9 +89,11 @@ RB_GRN_BEGIN_DECLS
97
89
  # define debug(...)
98
90
  #endif
99
91
 
100
- #define RB_GRN_MAJOR_VERSION 9
92
+ #define RB_GRN_HAVE_FLOAT32 GRN_VERSION_OR_LATER(10, 0, 2)
93
+
94
+ #define RB_GRN_MAJOR_VERSION 10
101
95
  #define RB_GRN_MINOR_VERSION 0
102
- #define RB_GRN_MICRO_VERSION 2
96
+ #define RB_GRN_MICRO_VERSION 6
103
97
 
104
98
  #define RB_GRN_OBJECT(object) ((RbGrnObject *)(object))
105
99
  #define RB_GRN_NAMED_OBJECT(object) ((RbGrnNamedObject *)(object))
@@ -1,6 +1,6 @@
1
1
  /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
2
  /*
3
- Copyright (C) 2009-2018 Kouhei Sutou <kou@clear-code.com>
3
+ Copyright (C) 2009-2020 Sutou Kouhei <kou@clear-code.com>
4
4
  Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
5
5
 
6
6
  This library is free software; you can redistribute it and/or
@@ -22,7 +22,7 @@
22
22
  grn_bool rb_grn_exited = GRN_FALSE;
23
23
 
24
24
  static VALUE
25
- finish_groonga (VALUE data)
25
+ finish_groonga (RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
26
26
  {
27
27
  debug("finish\n");
28
28
  grn_fin();
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2018 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2009-2020 Sutou Kouhei <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -44,12 +44,8 @@ require "groonga/record"
44
44
  require "groonga/expression-builder"
45
45
  require "groonga/posting"
46
46
  require "groonga/index"
47
- begin
48
- major, minor, _ = RUBY_VERSION.split(/\./)
49
- require "#{major}.#{minor}/groonga.so"
50
- rescue LoadError
51
- require "groonga.so"
52
- end
47
+
48
+ require "groonga.so"
53
49
 
54
50
  ##
55
51
  # rroonga用のネームスペース。rroongaのクラスやメソッ
@@ -491,6 +491,8 @@ module Groonga
491
491
  options[:size] = :small
492
492
  elsif column.medium?
493
493
  options[:size] = :medium
494
+ elsif column.large?
495
+ options[:size] = :large
494
496
  end
495
497
  arguments = [
496
498
  dump_object(target_table_name),
@@ -652,6 +654,7 @@ module Groonga
652
654
  flags << "WITH_POSITION" if column.with_position?
653
655
  flags << "INDEX_SMALL" if column.small?
654
656
  flags << "INDEX_MEDIUM" if column.medium?
657
+ flags << "INDEX_LARGE" if column.large?
655
658
  parameters << "#{flags.join('|')}"
656
659
  parameters << "#{column.range.name}"
657
660
  source_names = column.sources.collect do |source|
@@ -205,10 +205,10 @@ module Groonga
205
205
  self["_score"] = new_score
206
206
  end
207
207
 
208
- # {Groonga::Record#score} が利用できる場合は +true+
208
+ # {Groonga::Record#score} が利用できる場合は `true`
209
209
  # 返す。
210
210
  def support_score?
211
- @table.have_column?("_score") # TODO delegate to Table
211
+ @table.support_score?
212
212
  end
213
213
 
214
214
  # 主キーの値が同一であったレコードの件数を返す。検索結果とし
@@ -1,6 +1,6 @@
1
- # -*- mode: ruby; coding: utf-8 -*-
1
+ # -*- ruby -*-
2
2
  #
3
- # Copyright (C) 2012-2016 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2020 Sutou Kouhei <kou@clear-code.com>
4
4
  # Copyright (C) 2017 Masafumi Yokoyama <yokoyama@clear-code.com>
5
5
  #
6
6
  # This library is free software; you can redistribute it and/or
@@ -85,14 +85,13 @@ Gem::Specification.new do |s|
85
85
  s.add_runtime_dependency("pkg-config")
86
86
  s.add_runtime_dependency("groonga-client", ">= 0.0.3")
87
87
  s.add_runtime_dependency("json")
88
- s.add_runtime_dependency("archive-zip")
89
88
  s.add_development_dependency("test-unit", [">= 3.0.0"])
90
89
  s.add_development_dependency("rake")
91
- s.add_development_dependency("rake-compiler", [">= 0.9.5"])
92
- s.add_development_dependency("rake-compiler-dock", [">= 0.6.2"])
93
90
  s.add_development_dependency("bundler")
94
91
  s.add_development_dependency("yard")
95
92
  s.add_development_dependency("packnga", [">= 1.0.0"])
96
93
  s.add_development_dependency("kramdown")
94
+
95
+ s.metadata["msys2_mingw_dependencies"] = "groonga>=10.0.1"
97
96
  end
98
97
 
@@ -1,5 +1,5 @@
1
1
  # Copyright (C) 2015 Masafumi Yokoyama <yokoyama@clear-code.com>
2
- # Copyright (C) 2009-2015 Kouhei Sutou <kou@clear-code.com>
2
+ # Copyright (C) 2009-2019 Kouhei Sutou <kou@clear-code.com>
3
3
  #
4
4
  # This library is free software; you can redistribute it and/or
5
5
  # modify it under the terms of the GNU Lesser General Public
@@ -14,13 +14,16 @@
14
14
  # License along with this library; if not, write to the Free Software
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
+ require "erb"
17
18
  require "fileutils"
19
+ require "json"
18
20
  require "pathname"
21
+ require "stringio"
19
22
  require "tempfile"
20
23
  require "time"
21
- require "erb"
22
- require "stringio"
23
- require "json"
24
+ require "timeout"
25
+
26
+ require "groonga/client"
24
27
  require "pkg-config"
25
28
 
26
29
  require "groonga"
@@ -44,7 +47,7 @@ module GroongaTestUtils
44
47
  setup_context
45
48
 
46
49
  @database = nil
47
- name_for_path = name.gsub(/[\(\)\[\] ]/, "-")
50
+ name_for_path = escape_path(name)
48
51
  @database_path = @tmp_dir + "#{name_for_path}.db"
49
52
  end
50
53
 
@@ -69,9 +72,11 @@ module GroongaTestUtils
69
72
 
70
73
  @log_path = @tmp_dir + "groonga.log"
71
74
  Groonga::Logger.path = @log_path.to_s
75
+ Groonga::Logger.reopen
72
76
 
73
77
  @query_log_path = @tmp_dir + "groonga-query.log"
74
78
  Groonga::QueryLogger.path = @query_log_path.to_s
79
+ Groonga::QueryLogger.reopen
75
80
  end
76
81
 
77
82
  def setup_tables_directory
@@ -107,6 +112,14 @@ module GroongaTestUtils
107
112
  end
108
113
  end
109
114
 
115
+ def collect_query_log
116
+ @query_log_path.open do |file|
117
+ file.seek(0, IO::SEEK_END)
118
+ yield
119
+ file.read
120
+ end
121
+ end
122
+
110
123
  def setup_database
111
124
  @database = Groonga::Database.create(:path => @database_path.to_s)
112
125
  end
@@ -155,6 +168,12 @@ module GroongaTestUtils
155
168
  actual.expression.inspect)
156
169
  end
157
170
 
171
+ def escape_path(path)
172
+ path.gsub(/[: ?!\(\)\[\]]/) do
173
+ "_"
174
+ end
175
+ end
176
+
158
177
  def linux?
159
178
  /linux/ =~ RUBY_PLATFORM
160
179
  end
@@ -167,6 +186,10 @@ module GroongaTestUtils
167
186
  /cygwin|mingw|mswin/ === RUBY_PLATFORM
168
187
  end
169
188
 
189
+ def only_not_windows
190
+ omit("This test is only for non Windows system.") if windows?
191
+ end
192
+
170
193
  def support_self_recursive_equal?
171
194
  self_recursive_hash1 = {}
172
195
  self_recursive_hash1["next"] = self_recursive_hash1
@@ -186,4 +209,10 @@ module GroongaTestUtils
186
209
  def check_mecab_availability
187
210
  omit("MeCab isn't available") if context["TokenMecab"].nil?
188
211
  end
212
+
213
+ def need_groonga(major, minor, micro)
214
+ if (Groonga::BUILD_VERSION[0, 3] <=> [major, minor, micro]) < 0
215
+ omit("Groonga #{major}.#{minor}.#{micro} or later is required")
216
+ end
217
+ end
189
218
  end
@@ -17,8 +17,6 @@
17
17
 
18
18
  $VERBOSE = true
19
19
 
20
- $KCODE = "u" if RUBY_VERSION < "1.9"
21
-
22
20
  base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
23
21
  ext_dir = File.join(base_dir, "ext", "groonga")
24
22
  lib_dir = File.join(base_dir, "lib")
@@ -39,7 +37,7 @@ end
39
37
  require "test-unit"
40
38
  require "test/unit/priority"
41
39
 
42
- Test::Unit::Priority.enable
40
+ Test::Unit::Priority.enable unless ENV["CI"]
43
41
 
44
42
 
45
43
  groonga_command_dir = File.join(base_dir, "..", "groonga-command")
@@ -19,12 +19,13 @@ class AccessorTest < Test::Unit::TestCase
19
19
 
20
20
  def setup
21
21
  setup_database
22
- @posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
22
+ @posts = Groonga::Hash.create(:name => "Posts",
23
+ :key_type => "ShortText",
24
+ :value_type => "UInt32")
25
+ @grouped_posts = @posts.group("_key")
23
26
  @id = @posts.column("_id")
24
- end
25
-
26
- def teardown
27
- @id = nil
27
+ @key = @posts.column("_key")
28
+ @value = @posts.column("_value")
28
29
  end
29
30
 
30
31
  def test_name
@@ -51,9 +52,8 @@ class AccessorTest < Test::Unit::TestCase
51
52
 
52
53
  sub_test_case "#key_accessor?" do
53
54
  test "true" do
54
- key = @posts.column("_key")
55
55
  assert do
56
- key.key_accessor?
56
+ @key.key_accessor?
57
57
  end
58
58
  end
59
59
 
@@ -63,4 +63,60 @@ class AccessorTest < Test::Unit::TestCase
63
63
  end
64
64
  end
65
65
  end
66
+
67
+ sub_test_case "#id_accessor?" do
68
+ test "true" do
69
+ assert do
70
+ @id.id_accessor?
71
+ end
72
+ end
73
+
74
+ test "false" do
75
+ assert do
76
+ not @key.id_accessor?
77
+ end
78
+ end
79
+ end
80
+
81
+ sub_test_case "#value_accessor?" do
82
+ test "true" do
83
+ assert do
84
+ @value.value_accessor?
85
+ end
86
+ end
87
+
88
+ test "false" do
89
+ assert do
90
+ not @key.value_accessor?
91
+ end
92
+ end
93
+ end
94
+
95
+ sub_test_case "#score_accessor?" do
96
+ test "true" do
97
+ assert do
98
+ @posts.select.column("_score").score_accessor?
99
+ end
100
+ end
101
+
102
+ test "false" do
103
+ assert do
104
+ not @key.score_accessor?
105
+ end
106
+ end
107
+ end
108
+
109
+ sub_test_case "#n_sub_records_accessor?" do
110
+ test "true" do
111
+ assert do
112
+ @grouped_posts.column("_nsubrecs").n_sub_records_accessor?
113
+ end
114
+ end
115
+
116
+ test "false" do
117
+ assert do
118
+ not @key.n_sub_records_accessor?
119
+ end
120
+ end
121
+ end
66
122
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2016 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2009-2020 Sutou Kouhei <kou@clear-code.com>
2
2
  # Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
3
3
  #
4
4
  # This library is free software; you can redistribute it and/or
@@ -307,6 +307,17 @@ class ColumnTest < Test::Unit::TestCase
307
307
  assert_false(post["hidden"])
308
308
  end
309
309
 
310
+ def test_float32
311
+ need_groonga(10, 0, 2)
312
+
313
+ numbers = Groonga::Array.create(:name => "Numbers")
314
+ numbers.define_column("data", "Float32")
315
+
316
+ number = numbers.add
317
+ number["data"] = 1.1
318
+ assert_in_delta(1.1, number["data"])
319
+ end
320
+
310
321
  def test_indexes
311
322
  Groonga::Schema.define do |schema|
312
323
  schema.create_table("Comments") do |table|
@@ -132,6 +132,31 @@ class ContextTest < Test::Unit::TestCase
132
132
  assert_equal(-1, context.match_escalation_threshold)
133
133
  end
134
134
 
135
+ sub_test_case("#force_match_escalation?") do
136
+ def setup
137
+ default_force_match_escalation = context.force_match_escalation?
138
+ begin
139
+ yield
140
+ ensure
141
+ context.force_match_escalation = default_force_match_escalation
142
+ end
143
+ end
144
+
145
+ def test_true
146
+ context.force_match_escalation = true
147
+ assert do
148
+ context.force_match_escalation?
149
+ end
150
+ end
151
+
152
+ def test_false
153
+ context.force_match_escalation = false
154
+ assert do
155
+ not context.force_match_escalation?
156
+ end
157
+ end
158
+ end
159
+
135
160
  def test_close
136
161
  context = Groonga::Context.new
137
162
  assert_false(context.closed?)