Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sharding: extract common code to RangeExpressionBuilder
- Loading branch information
Showing
5 changed files
with
93 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| require "sharding/range_expression_builder" | ||
| require "sharding/logical_enumerator" | ||
| require "sharding/logical_count" | ||
| require "sharding/logical_range_filter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| module Groonga | ||
| module Sharding | ||
| class RangeExpressionBuilder | ||
| def initialize(key, target_range, filter) | ||
| @key = key | ||
| @target_range = target_range | ||
| @filter = filter | ||
| end | ||
|
|
||
| def build_all(expression) | ||
| return if @filter.nil? | ||
|
|
||
| expression.parse(@filter) | ||
| end | ||
|
|
||
| def build_partial_min(expression) | ||
| expression.append_object(@key, Operator::PUSH, 1) | ||
| expression.append_operator(Operator::GET_VALUE, 1) | ||
| expression.append_constant(@target_range.min, Operator::PUSH, 1) | ||
| if @target_range.min_border == :include | ||
| expression.append_operator(Operator::GREATER_EQUAL, 2) | ||
| else | ||
| expression.append_operator(Operator::GREATER, 2) | ||
| end | ||
| if @filter | ||
| expression.parse(@filter) | ||
| expression.append_operator(Operator::AND, 2) | ||
| end | ||
| end | ||
|
|
||
| def build_partial_max(expression) | ||
| expression.append_object(@key, Operator::PUSH, 1) | ||
| expression.append_operator(Operator::GET_VALUE, 1) | ||
| expression.append_constant(@target_range.max, Operator::PUSH, 1) | ||
| if @target_range.max_border == :include | ||
| expression.append_operator(Operator::LESS_EQUAL, 2) | ||
| else | ||
| expression.append_operator(Operator::LESS, 2) | ||
| end | ||
| if @filter | ||
| expression.parse(@filter) | ||
| expression.append_operator(Operator::AND, 2) | ||
| end | ||
| end | ||
|
|
||
| def build_partial_min_and_max(expression) | ||
| between = Groonga::Context.instance["between"] | ||
| expression.append_object(between, Operator::PUSH, 1) | ||
| expression.append_object(@key, Operator::PUSH, 1) | ||
| expression.append_operator(Operator::GET_VALUE, 1) | ||
| expression.append_constant(@target_range.min, Operator::PUSH, 1) | ||
| expression.append_constant(@target_range.min_border, | ||
| Operator::PUSH, 1) | ||
| expression.append_constant(@target_range.max, Operator::PUSH, 1) | ||
| expression.append_constant(@target_range.max_border, | ||
| Operator::PUSH, 1) | ||
| expression.append_operator(Operator::CALL, 5) | ||
| if @filter | ||
| expression.parse(@filter) | ||
| expression.append_operator(Operator::AND, 2) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| sharding_scripts = \ | ||
| logical_count.rb \ | ||
| logical_enumerator.rb \ | ||
| logical_range_filter.rb | ||
| logical_range_filter.rb \ | ||
| range_expression_builder.rb |