[Groonga-commit] ranguba/groonga-client at d1ae4b7 [master] groonga-client: make --target-column workable

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jul 30 18:29:44 JST 2018


Kouhei Sutou	2018-07-30 18:29:44 +0900 (Mon, 30 Jul 2018)

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

  Message:
    groonga-client: make --target-column workable

  Modified files:
    lib/groonga/client/command-line/groonga-client.rb

  Modified: lib/groonga/client/command-line/groonga-client.rb (+16 -7)
===================================================================
--- lib/groonga/client/command-line/groonga-client.rb    2018-07-30 14:27:37 +0900 (472981c)
+++ lib/groonga/client/command-line/groonga-client.rb    2018-07-30 18:29:44 +0900 (b9db7d4)
@@ -231,6 +231,7 @@ module Groonga
             return unless target_table?(command)
             return unless target_column?(command)
 
+            command = Marshal.load(Marshal.dump(command))
             apply_target_columns(command)
             command[:request_id] ||= SecureRandom.uuid if @generate_request_id
             response =****@clien*****(command)
@@ -287,16 +288,19 @@ module Groonga
           def apply_target_columns(command)
             return if @target_columns.empty?
 
-            columns = command[:columns]
             values = command[:values]
-            return if columns.nil? and values.nil?
+            return if values.nil?
+
+            command = command.dup
 
+            values = JSON.parse(values)
+            columns = command[:columns]
             if columns
-              columns = columns.split(/\s*,\s/)
+              columns = columns.split(/\s*,\s*/)
               target_indexes = []
               new_columns = []
               columns.each_with_index do |column, i|
-                if @target_columns.any? {|name| name === column}
+                if load_target_column?(column)
                   target_indexes << i
                   new_columns << column
                 end
@@ -307,20 +311,25 @@ module Groonga
                   value[i]
                 end
               end
-              load_command[:values] = new_values.to_json
+              command[:values] = JSON.generate(new_values)
             else
               new_values = values.collect do |value|
                 new_value = {}
                 value.each do |key, value|
-                  if @target_columns.any? {|name| name === key}
+                  if load_target_column?(key)
                     new_value[key] = value
                   end
                 end
                 new_value
               end
-              load_command[:values] = new_values.to_json
+              command[:values] = JSON.generate(new_values)
             end
           end
+
+          def load_target_column?(column)
+            column == "_key" or
+              @target_columns.any? {|name| name === column}
+          end
         end
 
         class BareREPL
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180730/6f019b76/attachment-0001.htm 



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