[Groonga-commit] groonga/groonga at a4a9502 [master] Add a script that checks object_list response

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jul 22 11:57:05 JST 2016


Kouhei Sutou	2016-07-22 11:57:05 +0900 (Fri, 22 Jul 2016)

  New Revision: a4a95023917d71e64d9eda30a928f6b283dd1919
  https://github.com/groonga/groonga/commit/a4a95023917d71e64d9eda30a928f6b283dd1919

  Message:
    Add a script that checks object_list response

  Added files:
    tools/groonga-object-list-checker.rb

  Added: tools/groonga-object-list-checker.rb (+104 -0) 100755
===================================================================
--- /dev/null
+++ tools/groonga-object-list-checker.rb    2016-07-22 11:57:05 +0900 (31d85c0)
@@ -0,0 +1,104 @@
+#!/usr/bin/env ruby
+#
+# Copyright(C) 2016  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# 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
+
+require "pp"
+require "json"
+require "groonga/command/parser"
+
+if ARGV.empty?
+  puts("Usage:")
+  puts(" #{$0} schema.grn object_list_result.json")
+  puts(" #{$0} schema.grn < object_list_result.json")
+  puts(" groonga DB_PATH object_list | #{$0} schema.grn")
+  exit(false)
+end
+
+schema_grn = ARGV.shift
+
+schema = {}
+Groonga::Command::Parser.parse(File.read(schema_grn)) do |type, *args|
+  case type
+  when :on_command
+    command, = args
+    case command.name
+    when "table_create"
+      if command.table_no_key?
+        type = "table:no_key"
+      elsif command.table_pat_key?
+        type = "table:pat_key"
+      elsif command.table_dat_key?
+        type = "table:dat_key"
+      else
+        type = "table:hash_key"
+      end
+      name = command[:name]
+      schema[name] ||= []
+      schema[name] << {
+        :type => type,
+        :flags => command.flags.join("|"),
+      }
+    when "column_create"
+      if command.column_index?
+        type = "column:index"
+      elsif command.column_vector? or command.type == "ShortText"
+        type = "column:var_size"
+      else
+        type = "column:fix_size"
+      end
+      name = "#{command[:table]}.#{command[:name]}"
+      schema[name] ||= []
+      schema[name] << {
+        :type => type,
+        :flags => command.flags.join("|"),
+      }
+    end
+  end
+end
+
+MAX_RESERVED_ID = 255
+response = JSON.parse(ARGF.read)
+body = response[1]
+body.each do |name, object|
+  id = object["id"]
+  next if id <= MAX_RESERVED_ID
+  normalized_name = name.gsub(/\d{4}\d{2}(?:\d{2})?/, "YYYYMMDD")
+
+  definitions = schema[normalized_name]
+  if definitions.nil?
+    next if object["type"]["name"] == "proc"
+    puts("Unknown table/column: #{name}(#{id})")
+    exit(false)
+  end
+
+  type = object["type"]
+  if type.nil?
+    puts("[invalid][no-type] #{id}:#{name}")
+    puts(PP.pp(object, "").gsub(/^/, "  "))
+    next
+  end
+
+  type_name = type["name"]
+  valid_type_names = definitions.collect {|definition| definition[:type]}
+  unless valid_type_names.include?(type["name"])
+    expected = "expected:[#{valid_type_names.join(", ")}]"
+    puts("[invalid][wrong-type] #{id}:#{name} <#{type_name}> #{expected}")
+    puts(PP.pp(object, "").gsub(/^/, "  "))
+    puts(PP.pp(definitions, "").gsub(/^/, "  "))
+    next
+  end
+end
-------------- next part --------------
HTML����������������������������...
下载 



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