[Groonga-commit] groonga/groonga at 870683c [master] mrb: stop to define #find_index to meaningless objects

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 25 18:37:57 JST 2016


Kouhei Sutou	2016-01-25 18:37:57 +0900 (Mon, 25 Jan 2016)

  New Revision: 870683c1e0a7cc6730a91ddf42152dd06d2f2c03
  https://github.com/groonga/groonga/commit/870683c1e0a7cc6730a91ddf42152dd06d2f2c03

  Message:
    mrb: stop to define #find_index to meaningless objects

  Added files:
    lib/mrb/mrb_indexable.c
    lib/mrb/mrb_indexable.h
    lib/mrb/scripts/accessor.rb
    lib/mrb/scripts/fixed_size_column.rb
    lib/mrb/scripts/variable_size_column.rb
  Modified files:
    lib/ctx_impl_mrb.c
    lib/mrb/mrb_object.c
    lib/mrb/scripts/initialize/post.rb
    lib/mrb/scripts/scan_info_data.rb
    lib/mrb/scripts/sources.am
    lib/mrb/scripts/table.rb
    lib/mrb/sources.am
    test/command_line/suite/grndb/test_check.rb

  Modified: lib/ctx_impl_mrb.c (+2 -0)
===================================================================
--- lib/ctx_impl_mrb.c    2016-01-25 18:15:57 +0900 (5cbaf58)
+++ lib/ctx_impl_mrb.c    2016-01-25 18:37:57 +0900 (0888c91)
@@ -38,6 +38,7 @@
 # include "mrb/mrb_object.h"
 # include "mrb/mrb_object_flags.h"
 # include "mrb/mrb_database.h"
+# include "mrb/mrb_indexable.h"
 # include "mrb/mrb_table.h"
 # include "mrb/mrb_array.h"
 # include "mrb/mrb_hash_table.h"
@@ -149,6 +150,7 @@ mrb_groonga_init(mrb_state *mrb, mrb_value self)
   grn_mrb_object_init(ctx);
   grn_mrb_object_flags_init(ctx);
   grn_mrb_database_init(ctx);
+  grn_mrb_indexable_init(ctx);
   grn_mrb_table_init(ctx);
   grn_mrb_array_init(ctx);
   grn_mrb_hash_table_init(ctx);

  Added: lib/mrb/mrb_indexable.c (+75 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_indexable.c    2016-01-25 18:37:57 +0900 (5c2a415)
@@ -0,0 +1,75 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2013-2016 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "../grn_ctx_impl.h"
+
+#ifdef GRN_WITH_MRUBY
+#include <mruby.h>
+#include <mruby/data.h>
+
+#include "mrb_ctx.h"
+#include "mrb_indexable.h"
+#include "mrb_operator.h"
+#include "mrb_converter.h"
+
+static mrb_value
+indexable_find_index(mrb_state *mrb, mrb_value self)
+{
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
+  grn_obj *object;
+  mrb_value mrb_operator;
+  grn_operator operator;
+  grn_index_datum index_datum;
+  int n_index_data;
+
+  mrb_get_args(mrb, "o", &mrb_operator);
+  object = DATA_PTR(self);
+  operator = grn_mrb_value_to_operator(mrb, mrb_operator);
+  n_index_data = grn_column_find_index_data(ctx,
+                                            object,
+                                            operator,
+                                            &index_datum,
+                                            1);
+  if (n_index_data == 0) {
+    return mrb_nil_value();
+  } else {
+    grn_mrb_data *data;
+    struct RClass *klass;
+    mrb_value args[2];
+
+    data = &(ctx->impl->mrb);
+    klass = mrb_class_get_under(mrb, data->module, "IndexInfo");
+    args[0] = grn_mrb_value_from_grn_obj(mrb, index_datum.index);
+    args[1] = mrb_fixnum_value(index_datum.section);
+    return mrb_obj_new(mrb, klass, 2, args);
+  }
+}
+
+void
+grn_mrb_indexable_init(grn_ctx *ctx)
+{
+  grn_mrb_data *data = &(ctx->impl->mrb);
+  mrb_state *mrb = data->state;
+  struct RClass *module;
+
+  module = mrb_define_module_under(mrb, data->module, "Indexable");
+
+  mrb_define_method(mrb, module, "find_index",
+                    indexable_find_index, MRB_ARGS_REQ(1));
+}
+#endif

  Added: lib/mrb/mrb_indexable.h (+32 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_indexable.h    2016-01-25 18:37:57 +0900 (7634dd6)
@@ -0,0 +1,32 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2016 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#pragma once
+
+#include "../grn_ctx.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void grn_mrb_indexable_init(grn_ctx *ctx);
+
+#ifdef __cplusplus
+}
+#endif
+

  Modified: lib/mrb/mrb_object.c (+0 -35)
===================================================================
--- lib/mrb/mrb_object.c    2016-01-25 18:15:57 +0900 (7f0c281)
+++ lib/mrb/mrb_object.c    2016-01-25 18:37:57 +0900 (367f98d)
@@ -86,39 +86,6 @@ object_get_name(mrb_state *mrb, mrb_value self)
 }
 
 static mrb_value
-object_find_index(mrb_state *mrb, mrb_value self)
-{
-  grn_ctx *ctx = (grn_ctx *)mrb->ud;
-  grn_obj *object;
-  mrb_value mrb_operator;
-  grn_operator operator;
-  grn_index_datum index_datum;
-  int n_index_data;
-
-  mrb_get_args(mrb, "o", &mrb_operator);
-  object = DATA_PTR(self);
-  operator = grn_mrb_value_to_operator(mrb, mrb_operator);
-  n_index_data = grn_column_find_index_data(ctx,
-                                            object,
-                                            operator,
-                                            &index_datum,
-                                            1);
-  if (n_index_data == 0) {
-    return mrb_nil_value();
-  } else {
-    grn_mrb_data *data;
-    struct RClass *klass;
-    mrb_value args[2];
-
-    data = &(ctx->impl->mrb);
-    klass = mrb_class_get_under(mrb, data->module, "IndexInfo");
-    args[0] = grn_mrb_value_from_grn_obj(mrb, index_datum.index);
-    args[1] = mrb_fixnum_value(index_datum.section);
-    return mrb_obj_new(mrb, klass, 2, args);
-  }
-}
-
-static mrb_value
 object_grn_inspect(mrb_state *mrb, mrb_value self)
 {
   grn_ctx *ctx = (grn_ctx *)mrb->ud;
@@ -257,8 +224,6 @@ grn_mrb_object_init(grn_ctx *ctx)
 
   mrb_define_method(mrb, klass, "id", object_get_id, MRB_ARGS_NONE());
   mrb_define_method(mrb, klass, "name", object_get_name, MRB_ARGS_NONE());
-  mrb_define_method(mrb, klass, "find_index",
-                    object_find_index, MRB_ARGS_REQ(1));
   mrb_define_method(mrb, klass, "grn_inspect",
                     object_grn_inspect, MRB_ARGS_NONE());
   mrb_define_method(mrb, klass, "==", object_equal, MRB_ARGS_REQ(1));

  Added: lib/mrb/scripts/accessor.rb (+5 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/scripts/accessor.rb    2016-01-25 18:37:57 +0900 (3ae08fb)
@@ -0,0 +1,5 @@
+module Groonga
+  class Accessor
+    include Indexable
+  end
+end

  Added: lib/mrb/scripts/fixed_size_column.rb (+5 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/scripts/fixed_size_column.rb    2016-01-25 18:37:57 +0900 (4fab9fb)
@@ -0,0 +1,5 @@
+module Groonga
+  class FixedSizeColumn
+    include Indexable
+  end
+end

  Modified: lib/mrb/scripts/initialize/post.rb (+3 -0)
===================================================================
--- lib/mrb/scripts/initialize/post.rb    2016-01-25 18:15:57 +0900 (25ee828)
+++ lib/mrb/scripts/initialize/post.rb    2016-01-25 18:37:57 +0900 (589b9e8)
@@ -10,7 +10,10 @@ require "object"
 require "database"
 require "table"
 require "record"
+require "fixed_size_column"
+require "variable_size_column"
 require "index_column"
+require "accessor"
 require "command"
 require "table_cursor"
 require "index_cursor"

  Modified: lib/mrb/scripts/scan_info_data.rb (+2 -0)
===================================================================
--- lib/mrb/scripts/scan_info_data.rb    2016-01-25 18:15:57 +0900 (d203c13)
+++ lib/mrb/scripts/scan_info_data.rb    2016-01-25 18:37:57 +0900 (e30b389)
@@ -287,6 +287,8 @@ module Groonga
         call_relational_resolve_index_accessor(object)
       when Bulk
         self.query = object
+      when Procedure
+        nil
       else
         call_relational_resolve_index_db_obj(object)
       end

  Modified: lib/mrb/scripts/sources.am (+3 -0)
===================================================================
--- lib/mrb/scripts/sources.am    2016-01-25 18:15:57 +0900 (5631058)
+++ lib/mrb/scripts/sources.am    2016-01-25 18:37:57 +0900 (07cfa48)
@@ -1,4 +1,5 @@
 RUBY_SCRIPT_FILES =				\
+	accessor.rb				\
 	backtrace_entry.rb			\
 	command.rb				\
 	command_line_parser.rb			\
@@ -10,6 +11,7 @@ RUBY_SCRIPT_FILES =				\
 	expression_rewriter.rb			\
 	expression_rewriters.rb			\
 	expression_size_estimator.rb		\
+	fixed_size_column.rb			\
 	id.rb					\
 	index_column.rb				\
 	index_cursor.rb				\
@@ -27,4 +29,5 @@ RUBY_SCRIPT_FILES =				\
 	scan_info_search_index.rb		\
 	table.rb				\
 	table_cursor.rb				\
+	variable_size_column.rb			\
 	writer.rb

  Modified: lib/mrb/scripts/table.rb (+1 -0)
===================================================================
--- lib/mrb/scripts/table.rb    2016-01-25 18:15:57 +0900 (9387d02)
+++ lib/mrb/scripts/table.rb    2016-01-25 18:37:57 +0900 (745e9fb)
@@ -1,6 +1,7 @@
 module Groonga
   class Table
     include Enumerable
+    include Indexable
 
     def columns
       context = Context.instance

  Added: lib/mrb/scripts/variable_size_column.rb (+5 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/scripts/variable_size_column.rb    2016-01-25 18:37:57 +0900 (3d75502)
@@ -0,0 +1,5 @@
+module Groonga
+  class VariableSizeColumn
+    include Indexable
+  end
+end

  Modified: lib/mrb/sources.am (+2 -0)
===================================================================
--- lib/mrb/sources.am    2016-01-25 18:15:57 +0900 (68c8fd9)
+++ lib/mrb/sources.am    2016-01-25 18:37:57 +0900 (db19eb2)
@@ -37,6 +37,8 @@ libgrnmrb_la_SOURCES =				\
 	mrb_hash_table.h			\
 	mrb_id.c				\
 	mrb_id.h				\
+	mrb_indexable.c				\
+	mrb_indexable.h				\
 	mrb_index_column.c			\
 	mrb_index_column.h			\
 	mrb_index_cursor.c			\

  Modified: test/command_line/suite/grndb/test_check.rb (+30 -0)
===================================================================
--- test/command_line/suite/grndb/test_check.rb    2016-01-25 18:15:57 +0900 (e185da3)
+++ test/command_line/suite/grndb/test_check.rb    2016-01-25 18:37:57 +0900 (e80f319)
@@ -163,5 +163,35 @@ Database is locked. It may be broken. Re-create the database.
 [Users.name] Data column is locked. It may be broken. (1) Truncate the column (truncate Users.name) or clear lock of the column (lock_clear Users.name) and (2) load data again.
       MESSAGE
     end
+
+    def test_indexed_data_column
+      groonga("table_create", "Users", "TABLE_HASH_KEY", "ShortText")
+      groonga("column_create", "Users", "age", "COLUMN_SCALAR", "UInt8")
+      groonga("column_create", "Users", "name", "COLUMN_SCALAR", "ShortText")
+
+      groonga("table_create", "Names", "TABLE_PAT_KEY", "ShortText")
+      groonga("column_create", "Names", "users_name",
+              "COLUMN_INDEX", "Users", "name")
+
+      groonga("table_create", "NormalizedNames", "TABLE_PAT_KEY", "ShortText",
+              "--normalizer", "NormalizerAuto")
+      groonga("column_create", "NormalizedNames", "users_name",
+              "COLUMN_INDEX", "Users", "name")
+
+      groonga("lock_acquire", "Users")
+      groonga("lock_acquire", "Users.age")
+      groonga("lock_acquire", "Users.name")
+      groonga("lock_acquire", "Names")
+      groonga("lock_acquire", "Names.users_name")
+      groonga("lock_acquire", "NormalizedNames")
+      groonga("lock_acquire", "NormalizedNames.users_name")
+
+      error = assert_raise(CommandRunner::Error) do
+        grndb("check", "--target", "Users.name")
+      end
+      assert_equal(<<-MESSAGE, error.error_output)
+[Users.name] Data column is locked. It may be broken. (1) Truncate the column (truncate Users.name) or clear lock of the column (lock_clear Users.name) and (2) load data again.
+      MESSAGE
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index