[Groonga-commit] ranguba/groonga-client at 6421287 [master] index-check: improve

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Oct 30 17:10:03 JST 2017


Kouhei Sutou	2017-10-30 17:10:03 +0900 (Mon, 30 Oct 2017)

  New Revision: 6421287bea5cfdf12c8d84ca8d58668299a32861
  https://github.com/ranguba/groonga-client/commit/6421287bea5cfdf12c8d84ca8d58668299a32861

  Message:
    index-check: improve
    
      * Support multiple columns
      * Fix a bug that nothing is checked in index content check
      * Add more tests

  Modified files:
    groonga-client.gemspec
    lib/groonga/client/command-line/groonga-client-index-check.rb
    test/command-line/test-index-check.rb

  Modified: groonga-client.gemspec (+1 -1)
===================================================================
--- groonga-client.gemspec    2017-10-30 15:23:51 +0900 (c0c6f07)
+++ groonga-client.gemspec    2017-10-30 17:10:03 +0900 (873ae69)
@@ -49,7 +49,7 @@ Gem::Specification.new do |spec|
 
   spec.add_runtime_dependency("gqtp", ">= 1.0.4")
   spec.add_runtime_dependency("groonga-command", ">= 1.2.8")
-  spec.add_runtime_dependency("groonga-command-parser", ">= 1.0.7")
+  spec.add_runtime_dependency("groonga-command-parser", ">= 1.1.0")
   spec.add_runtime_dependency("hashie")
 
   spec.add_development_dependency("bundler")

  Modified: lib/groonga/client/command-line/groonga-client-index-check.rb (+44 -26)
===================================================================
--- lib/groonga/client/command-line/groonga-client-index-check.rb    2017-10-30 15:23:51 +0900 (1ef5079)
+++ lib/groonga/client/command-line/groonga-client-index-check.rb    2017-10-30 17:10:03 +0900 (a8c44d4)
@@ -145,35 +145,39 @@ module Groonga
             end
           end
 
-          def verify_tokens(table_name, old_column, new_column, tokens)
-            broken_index_tokens = []
+          def verify_tokens(source_table, table_name, old_column, new_column, tokens)
+            full_old_column = "#{table_name}.#{old_column}"
+            full_new_column = "#{table_name}.#{new_column}"
             tokens.each do |token|
-              query = Groonga::Client::ScriptSyntax.format_string(token)
+              case token
+              when String
+                value = Groonga::Client::ScriptSyntax.format_string(token)
+              else
+                value = token
+              end
               old_response = execute_command(:select,
-                                             :table => table_name,
-                                             :match_columns => old_column,
-                                             :query => query,
+                                             :table => source_table,
+                                             :filter => "#{full_old_column} @ #{value}",
                                              :output_columns => "_id",
                                              :limit => "-1",
                                              :sort_keys => "_id")
               new_response = execute_command(:select,
-                                             :table => table_name,
-                                             :match_columns => new_column,
-                                             :query => query,
+                                             :table => source_table,
+                                             :filter => "#{full_new_column} @ #{value}",
                                              :output_columns => "_id",
                                              :limit => "-1",
                                              :sort_keys => "_id")
-              old_response_ids = old_response.records.collect do |value|
-                value["_id"]
+              old_response_ids = old_response.records.collect do |record|
+                record["_id"]
               end
-              new_response_ids = new_response.records.collect do |value|
-                value["_id"]
+              new_response_ids = new_response.records.collect do |record|
+                record["_id"]
               end
               if old_response_ids != new_response_ids
-                broken_index_tokens << token
+                return token
               end
             end
-            broken_index_tokens
+            nil
           end
 
           def check_content(index_column)
@@ -183,27 +187,41 @@ module Groonga
             column_name = index_column["name"]
             suffix = Time.now.strftime("%Y%m%d%H%M%S_%N")
             new_column_name = "#{column_name}_#{suffix}"
-            type, source = index_column.sources.first.split(".")
+            source_table = nil
+            source_columns = []
+            index_column.sources.each do |source|
+              if source.include?(".")
+                source_table, source_column = source.split(".")
+                source_columns << source_column
+              else
+                source_table = source
+                source_columns << "_key"
+              end
+            end
             flags = index_column["flags"].split("|")
             flags.delete("PERSISTENT")
             column_create(table_name,
                           new_column_name,
                           flags.join("|"),
-                          type,
-                          source)
+                          source_table,
+                          source_columns.join(","))
             begin
               tokens = list_tokens(table_name)
-              broken_index_tokens = verify_tokens(table_name, column_name,
-                                                  new_column_name, tokens)
+              broken_token = verify_tokens(source_table,
+                                           table_name,
+                                           column_name,
+                                           new_column_name,
+                                           tokens)
+              if broken_token
+                $stderr.puts("Broken: #{table_name}.#{column_name}: " +
+                             "<#{broken_token}>")
+                false
+              else
+                true
+              end
             ensure
               column_remove(table_name, new_column_name)
             end
-            if broken_index_tokens.empty?
-              true
-            else
-              $stderr.puts("Broken: #{table_name}.#{column_name}")
-              false
-            end
           end
         end
       end

  Modified: test/command-line/test-index-check.rb (+139 -2)
===================================================================
--- test/command-line/test-index-check.rb    2017-10-30 15:23:51 +0900 (86cd4ab)
+++ test/command-line/test-index-check.rb    2017-10-30 17:10:03 +0900 (097da6a)
@@ -48,7 +48,7 @@ Source is missing: <Terms.memos_content>
     OUTPUT
 
     assert_equal([false, "", error_output],
-                 index_check("--method=source", "Terms.memos_content"))
+                 index_check("--method=source"))
   end
 
   sub_test_case("content") do
@@ -72,7 +72,144 @@ load --table Memos
       COMMANDS
 
       assert_equal([true, "", ""],
-                   index_check("--method=content", "Terms.memos_content"))
+                   index_check("--method=content"))
+    end
+
+    def test_all
+      restore(<<-COMMANDS)
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms memos_content1 \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+column_create Terms memos_content2 \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+
+load --table Memos
+[
+["_key", "content"],
+["groonga", "Groonga is fast"]
+]
+
+delete --table Terms --key is
+      COMMANDS
+
+      assert_equal([
+                     false,
+                     "",
+                     "Broken: Terms.memos_content1: <is>\n" +
+                     "Broken: Terms.memos_content2: <is>\n",
+                   ],
+                   index_check("--method=content"))
+    end
+
+
+    def test_specify
+      restore(<<-COMMANDS)
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms memos_content1 \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+column_create Terms memos_content2 \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+
+load --table Memos
+[
+["_key", "content"],
+["groonga", "Groonga is fast"]
+]
+
+delete --table Terms --key is
+      COMMANDS
+
+      assert_equal([
+                     false,
+                     "",
+                     "Broken: Terms.memos_content1: <is>\n",
+                   ],
+                   index_check("--method=content", "Terms.memos_content1"))
+    end
+
+    def test_broken_single_column
+      restore(<<-COMMANDS)
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms memos_content \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+
+load --table Memos
+[
+{"_key": "groonga", "content": "Groonga is fast"}
+]
+
+delete Terms --key is
+      COMMANDS
+
+      assert_equal([false, "", "Broken: Terms.memos_content: <is>\n"],
+                   index_check("--method=content"))
+    end
+
+    def test_key
+      restore(<<-COMMANDS)
+table_create Memos TABLE_HASH_KEY ShortText
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms memos_key \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos _key
+
+load --table Memos
+[
+{"_key": "groonga"}
+]
+
+delete Terms --key groonga
+      COMMANDS
+
+      assert_equal([false, "", "Broken: Terms.memos_key: <groonga>\n"],
+                   index_check("--method=content"))
+    end
+
+    def test_broken_multiple_column
+      restore(<<-COMMANDS)
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms memos \
+  COLUMN_INDEX|WITH_SECTION|WITH_POSITION \
+  Memos _key,content
+
+load --table Memos
+[
+{"_key": "groonga", "content": "Groonga is fast"}
+]
+
+delete Terms --key is
+      COMMANDS
+
+      assert_equal([false, "", "Broken: Terms.memos: <is>\n"],
+                   index_check("--method=content"))
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171030/b10f7b5a/attachment-0001.htm 



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