[Groonga-commit] groonga/groonga at c3c58d3 [master] logical_range_filter: apply initial stage dynamic columns only in range

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jan 22 16:16:19 JST 2018


Kouhei Sutou	2018-01-22 16:16:19 +0900 (Mon, 22 Jan 2018)

  New Revision: c3c58d35e4cd7fe7406dc5b99e7059f2e26b7a96
  https://github.com/groonga/groonga/commit/c3c58d35e4cd7fe7406dc5b99e7059f2e26b7a96

  Message:
    logical_range_filter: apply initial stage dynamic columns only in range

  Added files:
    test/command/suite/sharding/logical_range_filter/columns/stage/initial/range.expected
    test/command/suite/sharding/logical_range_filter/columns/stage/initial/range.test
  Modified files:
    plugins/sharding/logical_range_filter.rb
    plugins/sharding/range_expression_builder.rb

  Modified: plugins/sharding/logical_range_filter.rb (+11 -1)
===================================================================
--- plugins/sharding/logical_range_filter.rb    2018-01-22 15:40:45 +0900 (2435bc706)
+++ plugins/sharding/logical_range_filter.rb    2018-01-22 16:16:19 +0900 (2f818fc90)
@@ -251,7 +251,17 @@ module Groonga
 
           @context.dynamic_columns.each_initial do |dynamic_column|
             if @target_table ==****@shard*****
-              @target_table = @target_table.select_all
+              if @cover_type == :all
+                @target_table = @target_table.select_all
+              else
+                expression_builder.filter = nil
+                @target_table = create_expression(@target_table) do |expression|
+                  expression_builder.build(expression, @shard_range)
+                  @target_table.select(expression)
+                end
+                @cover_type = :all
+                expression_builder.filter = @filter
+              end
               @context.temporary_tables << @target_table
             end
             dynamic_column.apply(@target_table)

  Modified: plugins/sharding/range_expression_builder.rb (+15 -0)
===================================================================
--- plugins/sharding/range_expression_builder.rb    2018-01-22 15:40:45 +0900 (cc80735d4)
+++ plugins/sharding/range_expression_builder.rb    2018-01-22 16:16:19 +0900 (8cd01fd4a)
@@ -16,6 +16,21 @@ module Groonga
         @filter = nil
       end
 
+      def build(expression, shard_range)
+        cover_type = @target_range.cover_type(shard_range)
+        case cover_type
+        when :all
+          build_all(expression)
+        when :partial_min
+          build_partial_min(expression)
+        when :partial_max
+          build_partial_max(expression)
+        when :partial_min_and_max
+          build_partial_min_and_max(expression)
+        when :none
+        end
+      end
+
       def build_all(expression)
         build_condition(expression)
       end

  Added: test/command/suite/sharding/logical_range_filter/columns/stage/initial/range.expected (+106 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_range_filter/columns/stage/initial/range.expected    2018-01-22 16:16:19 +0900 (27574f906)
@@ -0,0 +1,106 @@
+plugin_register sharding
+[[0,0.0,0.0],true]
+table_create Logs_20170315 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20170315 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20170315 price COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create Logs_20170315 category COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Logs_20170316 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20170316 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20170316 price COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create Logs_20170316 category COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+table_create Logs_20170317 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20170317 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20170317 price COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+column_create Logs_20170317 category COLUMN_SCALAR ShortText
+[[0,0.0,0.0],true]
+load --table Logs_20170315
+[
+{"timestamp": "2017/03/15 00:00:00", "price": 1000, "category": "X"},
+{"timestamp": "2017/03/15 01:00:00", "price":  900, "category": "X"},
+{"timestamp": "2017/03/15 02:00:00", "price":  300, "category": "X"}
+]
+[[0,0.0,0.0],3]
+load --table Logs_20170316
+[
+{"timestamp": "2017/03/16 10:00:00", "price":  530, "category": "X"},
+{"timestamp": "2017/03/16 11:00:00", "price":  520, "category": "X"},
+{"timestamp": "2017/03/16 12:00:00", "price":  110, "category": "X"}
+]
+[[0,0.0,0.0],3]
+load --table Logs_20170317
+[
+{"timestamp": "2017/03/17 20:00:00", "price":  800, "category": "X"},
+{"timestamp": "2017/03/17 21:00:00", "price":  400, "category": "X"},
+{"timestamp": "2017/03/17 22:00:00", "price":  300, "category": "X"}
+]
+[[0,0.0,0.0],3]
+table_create Times TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+column_create Times logs_20170315 COLUMN_INDEX Logs_20170315 timestamp
+[[0,0.0,0.0],true]
+column_create Times logs_20170316 COLUMN_INDEX Logs_20170316 timestamp
+[[0,0.0,0.0],true]
+column_create Times logs_20170317 COLUMN_INDEX Logs_20170317 timestamp
+[[0,0.0,0.0],true]
+log_level --level debug
+[[0,0.0,0.0],true]
+logical_range_filter Logs   --shard_key timestamp   --min "2017/03/15 01:00:00"   --min_border "include"   --max "2017/03/17 21:00:00"   --max_border "exclude"   --columns[initial_id].stage initial   --columns[initial_id].type UInt32   --columns[initial_id].flags COLUMN_SCALAR   --columns[initial_id].value 'window_sum(price)'   --columns[initial_id].window.group_keys 'category'   --output_columns _id,initial_id
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        "_id",
+        "UInt32"
+      ],
+      [
+        "initial_id",
+        "UInt32"
+      ]
+    ],
+    [
+      2,
+      1200
+    ],
+    [
+      3,
+      1200
+    ],
+    [
+      1,
+      1160
+    ],
+    [
+      2,
+      1160
+    ],
+    [
+      3,
+      1160
+    ],
+    [
+      1,
+      800
+    ]
+  ]
+]
+#|d| [logical_range_filter][select] <Logs_20170315>: dynamic columns are used
+#|d| [logical_range_filter][select] <Logs_20170316>: dynamic columns are used
+#|d| [logical_range_filter][select] <Logs_20170317>: dynamic columns are used
+log_level --level notice
+[[0,0.0,0.0],true]

  Added: test/command/suite/sharding/logical_range_filter/columns/stage/initial/range.test (+61 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_range_filter/columns/stage/initial/range.test    2018-01-22 16:16:19 +0900 (c311fa77f)
@@ -0,0 +1,61 @@
+#@on-error omit
+plugin_register sharding
+#@on-error default
+
+table_create Logs_20170315 TABLE_NO_KEY
+column_create Logs_20170315 timestamp COLUMN_SCALAR Time
+column_create Logs_20170315 price COLUMN_SCALAR UInt32
+column_create Logs_20170315 category COLUMN_SCALAR ShortText
+
+table_create Logs_20170316 TABLE_NO_KEY
+column_create Logs_20170316 timestamp COLUMN_SCALAR Time
+column_create Logs_20170316 price COLUMN_SCALAR UInt32
+column_create Logs_20170316 category COLUMN_SCALAR ShortText
+
+table_create Logs_20170317 TABLE_NO_KEY
+column_create Logs_20170317 timestamp COLUMN_SCALAR Time
+column_create Logs_20170317 price COLUMN_SCALAR UInt32
+column_create Logs_20170317 category COLUMN_SCALAR ShortText
+
+load --table Logs_20170315
+[
+{"timestamp": "2017/03/15 00:00:00", "price": 1000, "category": "X"},
+{"timestamp": "2017/03/15 01:00:00", "price":  900, "category": "X"},
+{"timestamp": "2017/03/15 02:00:00", "price":  300, "category": "X"}
+]
+
+load --table Logs_20170316
+[
+{"timestamp": "2017/03/16 10:00:00", "price":  530, "category": "X"},
+{"timestamp": "2017/03/16 11:00:00", "price":  520, "category": "X"},
+{"timestamp": "2017/03/16 12:00:00", "price":  110, "category": "X"}
+]
+
+load --table Logs_20170317
+[
+{"timestamp": "2017/03/17 20:00:00", "price":  800, "category": "X"},
+{"timestamp": "2017/03/17 21:00:00", "price":  400, "category": "X"},
+{"timestamp": "2017/03/17 22:00:00", "price":  300, "category": "X"}
+]
+
+table_create Times TABLE_PAT_KEY Time
+column_create Times logs_20170315 COLUMN_INDEX Logs_20170315 timestamp
+column_create Times logs_20170316 COLUMN_INDEX Logs_20170316 timestamp
+column_create Times logs_20170317 COLUMN_INDEX Logs_20170317 timestamp
+
+#@add-important-log-levels debug
+log_level --level debug
+logical_range_filter Logs \
+  --shard_key timestamp \
+  --min "2017/03/15 01:00:00" \
+  --min_border "include" \
+  --max "2017/03/17 21:00:00" \
+  --max_border "exclude" \
+  --columns[initial_id].stage initial \
+  --columns[initial_id].type UInt32 \
+  --columns[initial_id].flags COLUMN_SCALAR \
+  --columns[initial_id].value 'window_sum(price)' \
+  --columns[initial_id].window.group_keys 'category' \
+  --output_columns _id,initial_id
+log_level --level notice
+#@remove-important-log-levels debug
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180122/66e74890/attachment-0001.htm 



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