Kouhei Sutou
null+****@clear*****
Mon Nov 3 22:39:15 JST 2014
Kouhei Sutou 2014-11-03 22:39:15 +0900 (Mon, 03 Nov 2014) New Revision: 20319e0da8d6445d8ae96bfd08c72903bb34ec01 https://github.com/droonga/droonga-engine/commit/20319e0da8d6445d8ae96bfd08c72903bb34ec01 Message: search: ignore nonexistent column in attributes GitHub: fix #26 Added files: test/command/suite/groonga/select/output_columns/default/array.expected test/command/suite/groonga/select/output_columns/default/array.test test/command/suite/groonga/select/output_columns/nonexistent.expected test/command/suite/groonga/select/output_columns/nonexistent.test Modified files: lib/droonga/searcher.rb Modified: lib/droonga/searcher.rb (+31 -15) =================================================================== --- lib/droonga/searcher.rb 2014-11-02 22:44:48 +0900 (3708001) +++ lib/droonga/searcher.rb 2014-11-03 22:39:15 +0900 (23cdc58) @@ -462,14 +462,16 @@ module Droonga sub_record_table = table.range sub_attributes = format(attribute[:attributes], sub_record_table) - format_attribute_subrecs(label, sub_attributes) + yield(format_attribute_subrecs(label, sub_attributes)) else expression = attribute[:expression] if expression - format_attribute_expression(label, expression) + yield(format_attribute_expression(label, expression)) else column = table.column(source) - format_attribute_column(label, column) + if column + yield(format_attribute_column(label, column)) + end end end end @@ -495,9 +497,13 @@ module Droonga end def format(attributes, table) - attributes.collect do |attribute| - format_attribute(attribute, table) + formatted_attributes = [] + attributes.each do |attribute| + format_attribute(attribute, table) do |formatted_attribute| + formatted_attributes << formatted_attribute + end end + formatted_attributes end end @@ -522,9 +528,10 @@ module Droonga def format(attributes, table) formatted_attributes = {} attributes.each do |attribute| - formatted_attribute = format_attribute(attribute, table) - attribute_name = attribute[:label] - formatted_attributes[attribute_name] = formatted_attribute + format_attribute(attribute, table) do |formatted_attribute| + attribute_name = attribute[:label] + formatted_attributes[attribute_name] = formatted_attribute + end end formatted_attributes end @@ -547,25 +554,28 @@ module Droonga private def record_value(record, attribute) - if attribute[:source] == "_subrecs" + source = attribute[:source] + if source == "_subrecs" if record.table.is_a?(Groonga::Array) target_record = record.value else target_record = record end - target_record.sub_records.collect do |sub_record| + values = target_record.sub_records.collect do |sub_record| sub_attributes = attribute[:attributes] format_record(sub_attributes, sub_record) end + yield(values) else expression = attribute[:expression] if expression variable = attribute[:variable] variable.value = record - expression.execute + yield(expression.execute) else - column_value = record[attribute[:source]] - format_column_value(column_value) + return unless record.have_column?(source) + column_value = record[source] + yield(format_column_value(column_value)) end end end @@ -589,9 +599,13 @@ module Droonga private def format_record(attributes, record) + formatted_record = [] attributes.collect do |attribute| - record_value(record, attribute) + record_value(record, attribute) do |formatted_value| + formatted_record << formatted_value + end end + formatted_record end end @@ -602,7 +616,9 @@ module Droonga def format_record(attributes, record) values = {} attributes.each do |attribute| - values[attribute[:label]] = record_value(record, attribute) + record_value(record, attribute) do |formatted_value| + values[attribute[:label]] = formatted_value + end end values end Added: test/command/suite/groonga/select/output_columns/default/array.expected (+33 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/select/output_columns/default/array.expected 2014-11-03 22:39:15 +0900 (0d8f3dd) @@ -0,0 +1,33 @@ +{ + "inReplyTo": "request-id", + "statusCode": 200, + "type": "select.result", + "body": [ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "message", + "Text" + ] + ], + [ + 1, + "Droonga is started." + ] + ] + ] + ] +} Added: test/command/suite/groonga/select/output_columns/default/array.test (+38 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/select/output_columns/default/array.test 2014-11-03 22:39:15 +0900 (3b155a4) @@ -0,0 +1,38 @@ +#@disable-logging +{ + "dataset": "Default", + "type": "table_create", + "body": { + "name" : "Logs", + "flags" : "TABLE_NO_KEY" + } +} +{ + "dataset": "Default", + "type": "column_create", + "body": { + "table" : "Logs", + "name" : "message", + "flags" : "COLUMN_SCALAR", + "type" : "Text" + } +} +{ + "dataset": "Default", + "type": "add", + "body": { + "table": "Logs", + "values": { + "message": "Droonga is started." + } + } +} +#@enable-logging + +{ + "dataset": "Default", + "type": "select", + "body": { + "table": "Logs" + } +} Added: test/command/suite/groonga/select/output_columns/nonexistent.expected (+28 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/select/output_columns/nonexistent.expected 2014-11-03 22:39:15 +0900 (6dca625) @@ -0,0 +1,28 @@ +{ + "inReplyTo": "request-id", + "statusCode": 200, + "type": "select.result", + "body": [ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 1 + ], + [ + [ + "_id", + "UInt32" + ] + ], + [ + 1 + ] + ] + ] + ] +} Added: test/command/suite/groonga/select/output_columns/nonexistent.test (+26 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/groonga/select/output_columns/nonexistent.test 2014-11-03 22:39:15 +0900 (58d844d) @@ -0,0 +1,26 @@ +#@disable-logging +{ + "dataset": "Default", + "type": "table_create", + "body": { + "name" : "IDs", + "flags" : "TABLE_NO_KEY" + } +} +{ + "dataset": "Default", + "type": "add", + "body": { + "table": "IDs" + } +} +#@enable-logging + +{ + "dataset": "Default", + "type": "select", + "body": { + "table": "IDs", + "output_columns": "_id, _key" + } +} -------------- next part -------------- HTML����������������������������...Download