Navigation Menu

Skip to content

Commit

Permalink
logical_select : add post_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
komainu8 committed Feb 19, 2018
1 parent 3c272cd commit bb614c2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions plugins/sharding/logical_select.rb
Expand Up @@ -28,6 +28,7 @@ class LogicalSelectCommand < Command
"match_columns",
"query",
"drilldown_filter",
"post_filter",
])

def run_body(input)
Expand Down Expand Up @@ -99,6 +100,7 @@ def cache_key(input)
key << "#{drilldown.filter}\0"
key << drilldown.dynamic_columns.cache_key
end
key << "#{input[:post_filter]}\0"
dynamic_columns = DynamicColumns.parse(input)
key << dynamic_columns.cache_key
key
Expand Down Expand Up @@ -278,6 +280,7 @@ class ExecuteContext
attr_reader :labeled_drilldowns
attr_reader :temporary_tables
attr_reader :expressions
attr_reader :post_filter
def initialize(input)
@input = input
@enumerator = LogicalEnumerator.new("logical_select", @input)
Expand All @@ -300,6 +303,8 @@ def initialize(input)
@temporary_tables = []

@expressions = []

@post_filter = @input[:post_filter]
end

def close
Expand Down Expand Up @@ -682,6 +687,7 @@ def initialize(context, shard, shard_range)
@match_columns = @context.match_columns
@query = @context.query
@filter = @context.filter
@post_filter = @context.post_filter
@sort_keys = @context.sort_keys
@result_sets = @context.result_sets
@unsorted_result_sets = @context.unsorted_result_sets
Expand Down Expand Up @@ -778,6 +784,12 @@ def filter_table
add_result_set(table.select(expression), expression)
end

def apply_post_filter(table)
expression = create_expression(table)
expression.parse(@post_filter)
table.select(expression)
end

def add_result_set(result_set, condition)
query_logger.log(:size, ":",
"select(#{result_set.size})[#{@shard.table_name}]")
Expand All @@ -794,6 +806,12 @@ def add_result_set(result_set, condition)
dynamic_column.apply(result_set, condition)
end

unless @post_filter.nil?
filtered_table = result_set
result_set = apply_post_filter(filtered_table)
@context.temporary_tables << filtered_table
end

if @sort_keys.empty?
@result_sets << result_set
else
Expand Down

0 comments on commit bb614c2

Please sign in to comment.