Kouhei Sutou
null+****@clear*****
Mon Oct 30 17:34:39 JST 2017
Kouhei Sutou 2017-10-30 17:34:39 +0900 (Mon, 30 Oct 2017) New Revision: 9621766b74e89381571a657e14eb4adff082209b https://github.com/ranguba/groonga-client/commit/9621766b74e89381571a657e14eb4adff082209b Message: Extract common code Modified files: lib/groonga/client/command-line/groonga-client-index-check.rb lib/groonga/client/command-line/groonga-client-index-recreate.rb lib/groonga/client/command-line/runner.rb Modified: lib/groonga/client/command-line/groonga-client-index-check.rb (+2 -19) =================================================================== --- lib/groonga/client/command-line/groonga-client-index-check.rb 2017-10-30 17:26:17 +0900 (c13d6e8) +++ lib/groonga/client/command-line/groonga-client-index-check.rb 2017-10-30 17:34:39 +0900 (783f13e) @@ -177,27 +177,10 @@ module Groonga column_name = index_column["name"] suffix = Time.now.strftime("%Y%m%d%H%M%S_%N") new_column_name = "#{column_name}_#{suffix}" - 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("|"), - source_table, - source_columns.join(",")) + column_create_similar(table_name, new_column_name, column_name) begin tokens = list_tokens(table_name) - broken_token = verify_tokens(source_table, + broken_token = verify_tokens(index_column.range, table_name, column_name, new_column_name, Modified: lib/groonga/client/command-line/groonga-client-index-recreate.rb (+0 -6) =================================================================== --- lib/groonga/client/command-line/groonga-client-index-recreate.rb 2017-10-30 17:26:17 +0900 (1e9238e) +++ lib/groonga/client/command-line/groonga-client-index-recreate.rb 2017-10-30 17:34:39 +0900 (da52d4d) @@ -91,12 +91,6 @@ module Groonga true end - def column_create_similar(table, column_name, base_column_name) - info = execute_command(:schema)["#{table}.#{base_column_name}"] - arguments = info.command.arguments.merge("name" => column_name) - execute_command(:column_create, arguments).body - end - def set_alias(alias_column, alias_name, real_name) table, column = alias_column.split(".", 2) values = [ Modified: lib/groonga/client/command-line/runner.rb (+27 -0) =================================================================== --- lib/groonga/client/command-line/runner.rb 2017-10-30 17:26:17 +0900 (d6a0c96) +++ lib/groonga/client/command-line/runner.rb 2017-10-30 17:34:39 +0900 (e0b3333) @@ -72,6 +72,33 @@ module Groonga :source => source).body end + def column_create_similar(table_name, column_name, base_column_name) + if object_exist?(:schema) + info = execute_command(:schema)["#{table_name}.#{base_column_name}"] + arguments = info.command.arguments.merge("name" => column_name) + execute_command(:column_create, arguments).body + else + base_column = column_list(table_name).find do |column| + column.name == base_column_name + end + range = base_column.range + source_columns = base_column.sources.collect do |source| + if source.include?(".") + source.split(".", 2)[1] + else + "_key" + end + end + flags = base_column.flags.dup + flags.delete("PERSISTENT") + column_create(table_name, + column_name, + flags.join("|"), + range, + source_columns.join(",")) + end + end + def column_remove(table, column) execute_command(:column_remove, :table => table, -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171030/08be080b/attachment-0001.htm