Kouhei Sutou
null+****@clear*****
Mon Jul 6 22:56:49 JST 2015
Kouhei Sutou 2015-07-06 22:56:49 +0900 (Mon, 06 Jul 2015) New Revision: 61cfd29118f242f22f996d1df123ba7f9ca491bb https://github.com/groonga/groonga/commit/61cfd29118f242f22f996d1df123ba7f9ca491bb Message: logical_select: support "_value.COLUMN" with command version 1 Added files: test/command/suite/sharding/logical_select/drilldown/labeled/output_columns/multiple/value_v1.expected test/command/suite/sharding/logical_select/drilldown/labeled/output_columns/multiple/value_v1.test Modified files: plugins/sharding/logical_select.rb Modified: plugins/sharding/logical_select.rb (+36 -5) =================================================================== --- plugins/sharding/logical_select.rb 2015-07-06 22:55:54 +0900 (b4982de) +++ plugins/sharding/logical_select.rb 2015-07-06 22:56:49 +0900 (b4f0139) @@ -98,8 +98,8 @@ module Groonga end end - def write_plain_drilldowns(writer, context) - plain_drilldown = context.plain_drilldown + def write_plain_drilldowns(writer, execute_context) + plain_drilldown = execute_context.plain_drilldown drilldowns = plain_drilldown.result_sets output_columns = plain_drilldown.output_columns @@ -122,8 +122,9 @@ module Groonga end end - def write_labeled_drilldowns(writer, context) - labeled_drilldowns = context.labeled_drilldowns + def write_labeled_drilldowns(writer, execute_context) + labeled_drilldowns = execute_context.labeled_drilldowns + is_command_version1 = (context.command_version == 1) writer.map("DRILLDOWNS", labeled_drilldowns.n_result_sets) do labeled_drilldowns.each do |drilldown| @@ -143,7 +144,15 @@ module Groonga writer.write(result_set.size) end writer.write_table_columns(result_set, output_columns) - writer.write_table_records(result_set, output_columns, options) + if is_command_version1 and drilldown.need_command_version2? + context.with_command_version(2) do + writer.write_table_records(result_set, + drilldown.output_columns_v2, + options) + end + else + writer.write_table_records(result_set, output_columns, options) + end end end end @@ -337,6 +346,28 @@ module Groonga table.column(@calc_target_name) end + def need_command_version2? + /[.\[]/ === @output_columns + end + + def output_columns_v2 + columns = @output_columns.strip.split(/ *, */) + converted_columns = columns.collect do |column| + match_data = /\A_value\.(.+)\z/.match(column) + if match_data.nil? + column + else + nth_key = keys.index(match_data[1]) + if nth_key + "_key[#{nth_key}]" + else + column + end + end + end + converted_columns.join(",") + end + private def parse_calc_types(raw_types) return TableGroupFlags::CALC_COUNT if raw_types.nil? Added: test/command/suite/sharding/logical_select/drilldown/labeled/output_columns/multiple/value_v1.expected (+177 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_select/drilldown/labeled/output_columns/multiple/value_v1.expected 2015-07-06 22:56:49 +0900 (a8ee410) @@ -0,0 +1,177 @@ +register sharding +[[0,0.0,0.0],true] +table_create Logs_20150203 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150203 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150203 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Logs_20150203 date COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Logs_20150203 action COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Logs_20150204 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150204 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Logs_20150204 date COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Logs_20150204 action COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Logs_20150205 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150205 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150205 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Logs_20150205 date COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +column_create Logs_20150205 action COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +load --table Logs_20150203 +[ +{ + "timestamp": "2015-02-03 12:49:00", + "memo": "2015-02-03 12:49:00", + "date": "2015-02-03", + "action": "Start" +}, +{ + "timestamp": "2015-02-03 23:59:59", + "memo": "2015-02-03 23:59:59", + "date": "2015-02-03", + "action": "Shutdown" +} +] +[[0,0.0,0.0],2] +load --table Logs_20150204 +[ +{ + "timestamp": "2015-02-04 00:00:00", + "memo": "2015-02-04 00:00:00", + "date": "2015-02-04", + "action": "Start" +}, +{ + "timestamp": "2015-02-04 13:49:00", + "memo": "2015-02-04 13:49:00", + "date": "2015-02-04", + "action": "Restart" +}, +{ + "timestamp": "2015-02-04 13:50:00", + "memo": "2015-02-04 13:50:00", + "date": "2015-02-04", + "action": "Restart" +} +] +[[0,0.0,0.0],3] +load --table Logs_20150205 +[ +{ + "timestamp": "2015-02-05 13:49:00", + "memo": "2015-02-05 13:49:00", + "date": "2015-02-05", + "action": "Restart" +}, +{ + "timestamp": "2015-02-05 13:50:00", + "memo": "2015-02-05 13:50:00", + "date": "2015-02-05", + "action": "Restart" +}, +{ + "timestamp": "2015-02-05 13:51:00", + "memo": "2015-02-05 13:51:00", + "date": "2015-02-05", + "action": "Restart" +}, +{ + "timestamp": "2015-02-05 13:52:00", + "memo": "2015-02-05 13:52:00", + "date": "2015-02-05", + "action": "Restart" +} +] +[[0,0.0,0.0],4] +logical_select Logs timestamp --limit 0 --drilldown[action_date].keys action,date --drilldown[action_date].output_columns _value.action,_value.date,_nsubrecs +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 9 + ], + [ + [ + "action", + "ShortText" + ], + [ + "date", + "ShortText" + ], + [ + "memo", + "ShortText" + ], + [ + "timestamp", + "Time" + ] + ] + ], + { + "action_date": [ + [ + 5 + ], + [ + [ + "action", + "ShortText" + ], + [ + "date", + "ShortText" + ], + [ + "_nsubrecs", + "Int32" + ] + ], + [ + "Start", + "2015-02-03", + 1 + ], + [ + "Shutdown", + "2015-02-03", + 1 + ], + [ + "Start", + "2015-02-04", + 1 + ], + [ + "Restart", + "2015-02-04", + 2 + ], + [ + "Restart", + "2015-02-05", + 4 + ] + ] + } + ] +] Added: test/command/suite/sharding/logical_select/drilldown/labeled/output_columns/multiple/value_v1.test (+92 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_select/drilldown/labeled/output_columns/multiple/value_v1.test 2015-07-06 22:56:49 +0900 (6a2be9b) @@ -0,0 +1,92 @@ +#@on-error omit +register sharding +#@on-error default + +table_create Logs_20150203 TABLE_NO_KEY +column_create Logs_20150203 timestamp COLUMN_SCALAR Time +column_create Logs_20150203 memo COLUMN_SCALAR ShortText +column_create Logs_20150203 date COLUMN_SCALAR ShortText +column_create Logs_20150203 action COLUMN_SCALAR ShortText + +table_create Logs_20150204 TABLE_NO_KEY +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +column_create Logs_20150204 memo COLUMN_SCALAR ShortText +column_create Logs_20150204 date COLUMN_SCALAR ShortText +column_create Logs_20150204 action COLUMN_SCALAR ShortText + +table_create Logs_20150205 TABLE_NO_KEY +column_create Logs_20150205 timestamp COLUMN_SCALAR Time +column_create Logs_20150205 memo COLUMN_SCALAR ShortText +column_create Logs_20150205 date COLUMN_SCALAR ShortText +column_create Logs_20150205 action COLUMN_SCALAR ShortText + +load --table Logs_20150203 +[ +{ + "timestamp": "2015-02-03 12:49:00", + "memo": "2015-02-03 12:49:00", + "date": "2015-02-03", + "action": "Start" +}, +{ + "timestamp": "2015-02-03 23:59:59", + "memo": "2015-02-03 23:59:59", + "date": "2015-02-03", + "action": "Shutdown" +} +] + +load --table Logs_20150204 +[ +{ + "timestamp": "2015-02-04 00:00:00", + "memo": "2015-02-04 00:00:00", + "date": "2015-02-04", + "action": "Start" +}, +{ + "timestamp": "2015-02-04 13:49:00", + "memo": "2015-02-04 13:49:00", + "date": "2015-02-04", + "action": "Restart" +}, +{ + "timestamp": "2015-02-04 13:50:00", + "memo": "2015-02-04 13:50:00", + "date": "2015-02-04", + "action": "Restart" +} +] + +load --table Logs_20150205 +[ +{ + "timestamp": "2015-02-05 13:49:00", + "memo": "2015-02-05 13:49:00", + "date": "2015-02-05", + "action": "Restart" +}, +{ + "timestamp": "2015-02-05 13:50:00", + "memo": "2015-02-05 13:50:00", + "date": "2015-02-05", + "action": "Restart" +}, +{ + "timestamp": "2015-02-05 13:51:00", + "memo": "2015-02-05 13:51:00", + "date": "2015-02-05", + "action": "Restart" +}, +{ + "timestamp": "2015-02-05 13:52:00", + "memo": "2015-02-05 13:52:00", + "date": "2015-02-05", + "action": "Restart" +} +] + +logical_select Logs timestamp \ + --limit 0 \ + --drilldown[action_date].keys action,date \ + --drilldown[action_date].output_columns _value.action,_value.date,_nsubrecs -------------- next part -------------- HTML����������������������������...Download