Kouhei Sutou 2019-04-17 15:47:26 +0900 (Wed, 17 Apr 2019) Revision: 46d6e2f7d90d1425fd1c611650c7d893a9403c35 https://github.com/groonga/groonga/commit/46d6e2f7d90d1425fd1c611650c7d893a9403c35 Message: sharding: accept dynamic column application options as Hash Modified files: plugins/sharding/dynamic_columns.rb plugins/sharding/logical_count.rb plugins/sharding/logical_range_filter.rb plugins/sharding/logical_select.rb Modified: plugins/sharding/dynamic_columns.rb (+24 -11) =================================================================== --- plugins/sharding/dynamic_columns.rb 2019-04-17 13:02:20 +0900 (2796cc31d) +++ plugins/sharding/dynamic_columns.rb 2019-04-17 15:47:26 +0900 (e182ea39d) @@ -116,15 +116,13 @@ module Groonga end end - result_sets = [] - targets.each do |result_set, condition| + targets.each do |result_set, options| normal_contexts.each do |context| - context.apply(result_set, condition) + context.apply(result_set, options) end - result_sets << result_set end window_function_contexts.each do |context| - context.apply_window_function(result_sets) + context.apply_window_function(targets) end end end @@ -197,10 +195,19 @@ module Groonga (not @window_group_keys.empty?) end - def apply(table, condition=nil) - column = table.create_column(@label, @flags, @type) + def apply(table, options=nil) + pp [table, options, context_target?(options)] + if context_target?(options) + column = table.find_column(@label) + p column if column.is_a?(Accessor) + else + column = table.create_column(@label, @flags, @type) + end + p column return if table.empty? + condition = nil + condition = options[:condition] if options expression = Expression.create(table) begin expression.parse(@value) @@ -211,16 +218,18 @@ module Groonga end end - def apply_window_function(tables) + def apply_window_function(targets) executor = WindowFunctionExecutor.new begin executor.source = @value executor.sort_keys = @window_sort_keys.join(", ") executor.group_keys = @window_group_keys.join(", ") executor.output_column_name = @label - tables.each do |table| - column = table.create_column(@label, @flags, @type) - return if table.empty? + targets.each do |table, options| + unless context_target?(options) + table.create_column(@label, @flags, @type) + end + next if table.empty? executor.add_table(table) end executor.execute @@ -252,6 +261,10 @@ module Groonga Column.parse_flags(error_message_tag, flags_raw) end + def context_target?(options) + options and options[:context] + end + def error_message_tag "[logical_select][columns][#{@stage}][#{@label}]" end Modified: plugins/sharding/logical_count.rb (+2 -2) =================================================================== --- plugins/sharding/logical_count.rb 2019-04-17 13:02:20 +0900 (490dfd266) +++ plugins/sharding/logical_count.rb 2019-04-17 15:47:26 +0900 (55084eb5f) @@ -151,7 +151,7 @@ module Groonga table = context.table.select_all @temporary_tables << table context.table = table - apply_targets << [table, nil] + apply_targets << [table] end @dynamic_columns.apply_initial(apply_targets) end @@ -162,7 +162,7 @@ module Groonga if @post_filter if @dynamic_columns.have_filtered? apply_targets =****@conte***** do |context| - [context.table, nil] + [context.table] end @dynamic_columns.apply_filtered(apply_targets) end Modified: plugins/sharding/logical_range_filter.rb (+8 -5) =================================================================== --- plugins/sharding/logical_range_filter.rb 2019-04-17 13:02:20 +0900 (a376c4323) +++ plugins/sharding/logical_range_filter.rb 2019-04-17 15:47:26 +0900 (80a0850ae) @@ -95,7 +95,6 @@ module Groonga attr_accessor :current_offset attr_accessor :current_limit attr_reader :result_sets - attr_reader :unsorted_result_sets attr_reader :temporary_tables attr_reader :threshold def initialize(input) @@ -193,7 +192,7 @@ module Groonga result_set = HashTable.create(:flags => ObjectFlags::WITH_SUBREC, :key_type => first_shard.table) @context.temporary_tables << result_set - targets = [[result_set, nil]] + targets = [[result_set]] @context.dynamic_columns.apply_initial(targets) @context.dynamic_columns.apply_filtered(targets) @context.result_sets << result_set @@ -493,7 +492,9 @@ module Groonga end @temporary_tables << @target_table end - @context.dynamic_columns.apply_initial([[@target_table, nil]]) + apply_targets = [] + apply_targets << [@target_table] + @context.dynamic_columns.apply_initial(apply_targets) end execute_filter(range_index, expression_builder) @@ -829,7 +830,7 @@ module Groonga if n_matched_records <=****@conte*****_offset @context.current_offset -= n_matched_records - result_set.close + @temporary_tables << result_set return end @@ -919,7 +920,9 @@ module Groonga result_set = result_set.select_all @temporary_tables << result_set end - @context.dynamic_columns.apply_filtered([[result_set, nil]]) + apply_targets = [] + apply_targets << [result_set] + @context.dynamic_columns.apply_filtered(apply_targets) end unless @post_filter.nil? Modified: plugins/sharding/logical_select.rb (+4 -4) =================================================================== --- plugins/sharding/logical_select.rb 2019-04-17 13:02:20 +0900 (5dfa30e26) +++ plugins/sharding/logical_select.rb 2019-04-17 15:47:26 +0900 (ef0b6abca) @@ -626,7 +626,7 @@ module Groonga if****@conte*****_columns.have_initial? targets = [] @context.shard_targets.each do |_, target_table| - targets << [target_table, nil] + targets << [target_table] end @context.dynamic_columns.apply_initial(targets) end @@ -638,14 +638,14 @@ module Groonga result_set = HashTable.create(:flags => ObjectFlags::WITH_SUBREC, :key_type => first_shard.table) @context.temporary_tables << result_set - targets = [[result_set, nil]] + targets = [[result_set]] @context.dynamic_columns.apply_initial(targets) @context.dynamic_columns.apply_filtered(targets) @context.result_sets << result_set else targets = [] @context.shard_results.each do |_, result_set, condition| - targets << [result_set, condition] + targets << [result_set, {condition: condition}] end @context.dynamic_columns.apply_filtered(targets) @context.shard_results.each do |shard_executor, result_set, _| @@ -713,7 +713,7 @@ module Groonga end end result_set = group_result.table - drilldown.dynamic_columns.apply_initial([[result_set, nil]]) + drilldown.dynamic_columns.apply_initial([[result_set]]) result_set = apply_drilldown_filter(drilldown, result_set) if drilldown.sort_keys.empty? drilldown.result_set = result_set -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190417/d6b962bc/attachment-0001.html>