[Groonga-commit] groonga/groonga-command at 5d4d2fe [master] Support logical_range_filter command

Back to archive index

Hiroshi Hatake null+****@clear*****
Fri Feb 13 14:15:43 JST 2015


Hiroshi Hatake	2015-02-13 14:15:43 +0900 (Fri, 13 Feb 2015)

  New Revision: 5d4d2fe3117bf2ff4deb5d2a550968a89a4ce383
  https://github.com/groonga/groonga-command/commit/5d4d2fe3117bf2ff4deb5d2a550968a89a4ce383

  Merged 1c44ba3: Merge pull request #5 from cosmo0920/support-logical-range-filter

  Message:
    Support logical_range_filter command

  Added files:
    lib/groonga/command/logical-range-filter.rb
    test/command/test-logical-range-filter.rb
  Modified files:
    lib/groonga/command.rb

  Modified: lib/groonga/command.rb (+1 -0)
===================================================================
--- lib/groonga/command.rb    2015-02-13 14:17:46 +0900 (e096e20)
+++ lib/groonga/command.rb    2015-02-13 14:15:43 +0900 (ad1a0e9)
@@ -29,6 +29,7 @@ require "groonga/command/dump"
 require "groonga/command/get"
 require "groonga/command/load"
 require "groonga/command/logical-count"
+require "groonga/command/logical-range-filter"
 require "groonga/command/normalize"
 require "groonga/command/range-filter"
 require "groonga/command/register"

  Added: lib/groonga/command/logical-range-filter.rb (+129 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/command/logical-range-filter.rb    2015-02-13 14:15:43 +0900 (0dda46e)
@@ -0,0 +1,129 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2015  Hiroshi Hatake <hatake �� 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 `logical_count` command.
+    #
+    # @since 1.1.1
+    class LogicalRangeFilter < Base
+      Command.register("logical_range_filter", self)
+
+      class << self
+        def parameter_names
+          [
+            :logical_table,
+            :shard_key,
+            :min,
+            :min_border,
+            :max,
+            :max_border,
+            :order,
+            :offset,
+            :limit,
+            :filter,
+            :output_columns,
+          ]
+        end
+      end
+
+      # @return [String] `logical_table` parameter value.
+      #
+      # @since 1.1.1
+      def logical_table
+        self[:logical_table]
+      end
+
+      # @return [String] `shard_key` parameter value.
+      #
+      # @since 1.1.1
+      def shard_key
+        self[:shard_key]
+      end
+
+      # @return [String] `min` parameter value.
+      #
+      # @since 1.1.1
+      def min
+        self[:min]
+      end
+
+      # @return [String] `min_border` parameter value.
+      #
+      # @since 1.1.1
+      def min_border
+        self[:min_border]
+      end
+
+      # @return [String] `max` parameter value.
+      #
+      # @since 1.1.1
+      def max
+        self[:max]
+      end
+
+      # @return [String] `max_border` parameter value.
+      #
+      # @since 1.1.1
+      def max_border
+        self[:max_border]
+      end
+
+      # @return [String] `order` parameter value.
+      #
+      # @since 1.1.1
+      def order
+        self[:order]
+      end
+
+      # @return [String] `offset` parameter value.
+      #
+      # @since 1.1.1
+      def offset
+        value = self[:offset]
+        value = value.to_i unless value.nil?
+        value
+      end
+
+      # @return [String] `limit` parameter value.
+      #
+      # @since 1.1.1
+      def limit
+        value = self[:limit]
+        value = value.to_i unless value.nil?
+        value
+      end
+
+      # @return [String] `filter` parameter value.
+      #
+      # @since 1.1.1
+      def filter
+        self[:filter]
+      end
+
+      # @return [String] `output_columns` parameter value.
+      #
+      # @since 1.1.1
+      def output_columns
+        self[:output_columns]
+      end
+    end
+  end
+end

  Added: test/command/test-logical-range-filter.rb (+132 -0) 100644
===================================================================
--- /dev/null
+++ test/command/test-logical-range-filter.rb    2015-02-13 14:15:43 +0900 (6917777)
@@ -0,0 +1,132 @@
+# Copyright (C) 2015  Hiroshi Hatake <hatake �� 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 LogicalRangeFilterCommandTest < Test::Unit::TestCase
+  private
+  def logical_range_filter_command(pair_arguments={}, ordered_arguments=[])
+    Groonga::Command::LogicalRangeFilter.new("logical_range_filter",
+                                             pair_arguments,
+                                             ordered_arguments)
+  end
+
+  class ConstructorTest < self
+    def test_ordered_arguments
+      logical_table  = "Logs"
+      shard_key      = "timestamp",
+      min            = "2015-02-12 00:00:00"
+      min_border     = "include"
+      max            = "2015-02-13 00:00:00"
+      max_border     = "exclude"
+      order          = "asending"
+      filter         = "value == 10"
+      offset         = "10"
+      limit          = "20"
+      output_columns = "_key, timestamp"
+
+      ordered_arguments = [
+        logical_table,
+        shard_key,
+        min,
+        min_border,
+        max,
+        max_border,
+        order,
+        offset,
+        limit,
+        filter,
+        output_columns,
+      ]
+      command = logical_range_filter_command({}, ordered_arguments)
+      assert_equal({
+                     :logical_table  => logical_table,
+                     :shard_key      => shard_key,
+                     :min            => min,
+                     :min_border     => min_border,
+                     :max            => max,
+                     :max_border     => max_border,
+                     :order          => order,
+                     :filter         => filter,
+                     :offset         => offset,
+                     :limit          => limit,
+                     :output_columns => output_columns,
+                   },
+                   command.arguments)
+    end
+  end
+
+  class LogicalTableTest < self
+    def test_reader
+      command = logical_range_filter_command(:logical_table => "Logs")
+      assert_equal("Logs", command.logical_table)
+    end
+  end
+
+  class ShardKeyTest < self
+    def test_reader
+      command = logical_range_filter_command(:shard_key => "timestamp")
+      assert_equal("timestamp", command.shard_key)
+    end
+  end
+
+  class MinTest < self
+    def test_reader
+      command = logical_range_filter_command(:min => "2015-02-13 00:00:00")
+      assert_equal("2015-02-13 00:00:00", command.min)
+    end
+  end
+
+  class MaxTest < self
+    def test_reader
+      command = logical_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 = logical_range_filter_command(:max_border => "include")
+      assert_equal("include", command.max_border)
+    end
+  end
+
+  class OffsetTest < self
+    def test_reader
+      command = logical_range_filter_command(:offset => "10")
+      assert_equal(10, command.offset)
+    end
+  end
+
+  class LimitTest < self
+    def test_reader
+      command = logical_range_filter_command(:limit => "20")
+      assert_equal(20, command.limit)
+    end
+  end
+
+  class FilterTest < self
+    def test_reader
+      command = logical_range_filter_command(:filter => "value == 10")
+      assert_equal("value == 10", command.filter)
+    end
+  end
+
+  class OutputColumnsTest < self
+    def test_reader
+      command = logical_range_filter_command(:output_columns => "_key, timestamp")
+      assert_equal("_key, timestamp", command.output_columns)
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index