Navigation Menu

Skip to content

Commit

Permalink
sharding: extract convenient code as Table#select_all
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 31, 2017
1 parent fa566d7 commit 72ad95d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
10 changes: 10 additions & 0 deletions lib/mrb/scripts/table.rb
Expand Up @@ -61,6 +61,16 @@ def apply_window_function(output_column,
end
end

def select_all
expression = Expression.create(self)
begin
expression.append_constant(true, Operator::PUSH, 1)
select(expression)
ensure
expression.close
end
end

private
def ensure_sort_keys_accept_nil(keys, &block)
return yield(nil) if keys.nil?
Expand Down
15 changes: 2 additions & 13 deletions plugins/sharding/logical_select.rb
Expand Up @@ -692,7 +692,7 @@ def execute

@context.dynamic_columns.each_initial do |dynamic_column|
if @target_table == @shard.table
@target_table = create_all_match_table(@target_table)
@target_table = @target_table.select_all
@context.temporary_tables << @target_table
end
dynamic_column.apply(@target_table)
Expand Down Expand Up @@ -765,8 +765,7 @@ def add_result_set(result_set, condition)

@context.dynamic_columns.each_filtered do |dynamic_column|
if result_set == @shard.table
@context.temporary_tables << result_set
result_set = create_all_match_table(result_set)
result_set = result_set.select_all
end
dynamic_column.apply(result_set, condition)
end
Expand All @@ -779,16 +778,6 @@ def add_result_set(result_set, condition)
@result_sets << sorted_result_set
end
end

def create_all_match_table(table)
expression = Expression.create(table)
begin
expression.append_constant(true, Operator::PUSH, 1)
table.select(expression)
ensure
expression.close
end
end
end
end
end
Expand Down

0 comments on commit 72ad95d

Please sign in to comment.