Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
257 additions
and
1 deletion.
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
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,119 @@ | ||
| # Copyright (C) 2015 Kouhei Sutou <kou@clear-code.com> | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License as published by the Free Software Foundation; either | ||
| # version 2.1 of the License, or (at your option) any later version. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
|
||
| require "groonga/command/base" | ||
|
|
||
| module Groonga | ||
| module Command | ||
| # A command class that represents `range_filter` command. | ||
| # | ||
| # @since 1.1.0 | ||
| class RangeFilter < Base | ||
| Command.register("range_filter", self) | ||
|
|
||
| class << self | ||
| def parameter_names | ||
| [ | ||
| :table, | ||
| :column, | ||
| :min, | ||
| :min_border, | ||
| :max, | ||
| :max_border, | ||
| :offset, | ||
| :limit, | ||
| :filter, | ||
| :output_columns, | ||
| ] | ||
| end | ||
| end | ||
|
|
||
| # @return [String] `table` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def table | ||
| self[:table] | ||
| end | ||
|
|
||
| # @return [String] `column` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def column | ||
| self[:column] | ||
| end | ||
|
|
||
| # @return [String] `min` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def min | ||
| self[:min] | ||
| end | ||
|
|
||
| # @return [String] `min_border` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def min_border | ||
| self[:min_border] | ||
| end | ||
|
|
||
| # @return [String] `max` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def max | ||
| self[:max] | ||
| end | ||
|
|
||
| # @return [String] `max_border` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def max_border | ||
| self[:max_border] | ||
| end | ||
|
|
||
| # @return [String] `offset` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def offset | ||
| value = self[:offset] | ||
| value = value.to_i unless value.nil? | ||
| value | ||
| end | ||
|
|
||
| # @return [String] `limit` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def limit | ||
| value = self[:limit] | ||
| value = value.to_i unless value.nil? | ||
| value | ||
| end | ||
|
|
||
| # @return [String] `filter` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def filter | ||
| self[:filter] | ||
| end | ||
|
|
||
| # @return [String] `output_columns` parameter value. | ||
| # | ||
| # @since 1.1.0 | ||
| def output_columns | ||
| self[:output_columns] | ||
| 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 |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| # Copyright (C) 2015 Kouhei Sutou <kou@clear-code.com> | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License as published by the Free Software Foundation; either | ||
| # version 2.1 of the License, or (at your option) any later version. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
|
||
| class RangeFilterCommandTest < Test::Unit::TestCase | ||
| private | ||
| def range_filter_command(pair_arguments={}, ordered_arguments=[]) | ||
| Groonga::Command::RangeFilter.new("range_filter", | ||
| pair_arguments, | ||
| ordered_arguments) | ||
| end | ||
|
|
||
| class ConstructorTest < self | ||
| def test_ordered_arguments | ||
| table = "Logs" | ||
| column = "timestamp", | ||
| min = "2015-01-26 00:00:00" | ||
| min_border = "include" | ||
| max = "2015-01-27 00:00:00" | ||
| max_border = "exclude" | ||
| offset = "10" | ||
| limit = "20" | ||
| filter = "value == 10" | ||
| output_columns = "_key, timestamp" | ||
|
|
||
| ordered_arguments = [ | ||
| table, | ||
| column, | ||
| min, | ||
| min_border, | ||
| max, | ||
| max_border, | ||
| offset, | ||
| limit, | ||
| filter, | ||
| output_columns, | ||
| ] | ||
| command = range_filter_command({}, ordered_arguments) | ||
| assert_equal({ | ||
| :table => table, | ||
| :column => column, | ||
| :min => min, | ||
| :min_border => min_border, | ||
| :max => max, | ||
| :max_border => max_border, | ||
| :offset => offset, | ||
| :limit => limit, | ||
| :filter => filter, | ||
| :output_columns => output_columns, | ||
| }, | ||
| command.arguments) | ||
| end | ||
| end | ||
|
|
||
| class TableTest < self | ||
| def test_reader | ||
| command = range_filter_command(:table => "Logs") | ||
| assert_equal("Logs", command.table) | ||
| end | ||
| end | ||
|
|
||
| class ColumnTest < self | ||
| def test_reader | ||
| command = range_filter_command(:column => "timestamp") | ||
| assert_equal("timestamp", command.column) | ||
| end | ||
| end | ||
|
|
||
| class MinTest < self | ||
| def test_reader | ||
| command = range_filter_command(:min => "2015-01-26 00:00:00") | ||
| assert_equal("2015-01-26 00:00:00", command.min) | ||
| end | ||
| end | ||
|
|
||
| class MinBorderTest < self | ||
| def test_reader | ||
| command = range_filter_command(:min_border => "include") | ||
| assert_equal("include", command.min_border) | ||
| end | ||
| end | ||
|
|
||
| class MaxTest < self | ||
| def test_reader | ||
| command = range_filter_command(:max => "2015-01-26 00:00:00") | ||
| assert_equal("2015-01-26 00:00:00", command.max) | ||
| end | ||
| end | ||
|
|
||
| class MaxBorderTest < self | ||
| def test_reader | ||
| command = range_filter_command(:max_border => "include") | ||
| assert_equal("include", command.max_border) | ||
| end | ||
| end | ||
|
|
||
| class OffsetTest < self | ||
| def test_reader | ||
| command = range_filter_command(:offset => "10") | ||
| assert_equal(10, command.offset) | ||
| end | ||
| end | ||
|
|
||
| class LimitTest < self | ||
| def test_reader | ||
| command = range_filter_command(:limit => "20") | ||
| assert_equal(20, command.limit) | ||
| end | ||
| end | ||
|
|
||
| class FilterTest < self | ||
| def test_reader | ||
| command = range_filter_command(:filter => "value == 10") | ||
| assert_equal("value == 10", command.filter) | ||
| end | ||
| end | ||
|
|
||
| class OutputColumnsTest < self | ||
| def test_reader | ||
| command = range_filter_command(:output_columns => "_key, timestamp") | ||
| assert_equal("_key, timestamp", command.output_columns) | ||
| end | ||
| end | ||
| end |