[Groonga-commit] groonga/groonga at e842709 [master] logical_select: add support for descendant sorted window function

Back to archive index
Kouhei Sutou null+****@clear*****
Thu Apr 25 15:15:43 JST 2019


Kouhei Sutou	2019-04-25 15:15:43 +0900 (Thu, 25 Apr 2019)

  Revision: e842709767cfdb67cca4107902f89717a2b40c89
  https://github.com/groonga/groonga/commit/e842709767cfdb67cca4107902f89717a2b40c89

  Message:
    logical_select: add support for descendant sorted window function

  Removed files:
    test/command/suite/sharding/logical_select/columns/stage/filtered/window_function/window_count/descending.reject
    test/command/suite/sharding/logical_select/columns/stage/initial/window_function/window_count/descending.reject
  Modified files:
    lib/window_function_executor.c
    test/command/suite/sharding/logical_select/columns/stage/filtered/window_function/window_count/descending.test
    test/command/suite/sharding/logical_select/columns/stage/initial/window_function/window_count/descending.test

  Modified: lib/window_function_executor.c (+28 -1)
===================================================================
--- lib/window_function_executor.c    2019-04-25 11:50:45 +0900 (f3cfaecc3)
+++ lib/window_function_executor.c    2019-04-25 15:15:43 +0900 (f4fba2221)
@@ -262,6 +262,30 @@ grn_window_function_executor_set_output_column_name(grn_ctx *ctx,
   GRN_API_RETURN(ctx->rc);
 }
 
+static bool
+grn_window_function_executor_is_ascending(grn_ctx *ctx,
+                                          grn_window_function_executor *executor)
+{
+  const size_t sort_keys_len = GRN_TEXT_LEN(&(executor->sort_keys));
+  if (sort_keys_len == 0) {
+    return true;
+  }
+
+  const char *sort_keys = GRN_TEXT_VALUE(&(executor->sort_keys));
+  for (size_t i = 0; i < sort_keys_len; i++) {
+    switch (sort_keys[i]) {
+    case ' ' :
+      break;
+    case '-' :
+      return false;
+    default :
+      return true;
+    }
+  }
+
+  return true;
+}
+
 grn_rc
 grn_window_function_executor_execute(grn_ctx *ctx,
                                      grn_window_function_executor *executor)
@@ -300,8 +324,11 @@ grn_window_function_executor_execute(grn_ctx *ctx,
 
   grn_window_function_executor_rewind(ctx, executor);
 
+  const bool is_ascending =
+    grn_window_function_executor_is_ascending(ctx, executor);
   for (size_t i = 0; i < n_tables; i++) {
-    grn_obj *table = GRN_PTR_VALUE_AT(&(executor->tables), i);
+    size_t nth_table = (is_ascending ? i : (n_tables - i - 1));
+    grn_obj *table = GRN_PTR_VALUE_AT(&(executor->tables), nth_table);
 
     grn_obj *output_column = grn_obj_column(ctx,
                                             table,

  Deleted: test/command/suite/sharding/logical_select/columns/stage/filtered/window_function/window_count/descending.reject (+0 -81) 100644
===================================================================
--- test/command/suite/sharding/logical_select/columns/stage/filtered/window_function/window_count/descending.reject    2019-04-25 11:50:45 +0900 (cc97cb37a)
+++ /dev/null
@@ -1,81 +0,0 @@
-plugin_register sharding
-[[0,0.0,0.0],true]
-table_create Logs_20170415 TABLE_NO_KEY
-[[0,0.0,0.0],true]
-column_create Logs_20170415 timestamp COLUMN_SCALAR Time
-[[0,0.0,0.0],true]
-column_create Logs_20170415 price COLUMN_SCALAR UInt32
-[[0,0.0,0.0],true]
-column_create Logs_20170415 n_likes COLUMN_SCALAR UInt32
-[[0,0.0,0.0],true]
-table_create Logs_20170416 TABLE_NO_KEY
-[[0,0.0,0.0],true]
-column_create Logs_20170416 timestamp COLUMN_SCALAR Time
-[[0,0.0,0.0],true]
-column_create Logs_20170416 price COLUMN_SCALAR UInt32
-[[0,0.0,0.0],true]
-column_create Logs_20170416 n_likes COLUMN_SCALAR UInt32
-[[0,0.0,0.0],true]
-load --table Logs_20170415
-[
-{"timestamp": "2017/04/15 00:00:00", "n_likes": 2, "price": 100},
-{"timestamp": "2017/04/15 01:00:00", "n_likes": 1, "price": 100},
-{"timestamp": "2017/04/15 02:00:00", "n_likes": 2, "price": 200}
-]
-[[0,0.0,0.0],3]
-load --table Logs_20170416
-[
-{"timestamp": "2017/04/16 10:00:00", "n_likes": 1, "price": 300},
-{"timestamp": "2017/04/16 11:00:00", "n_likes": 2, "price": 400},
-{"timestamp": "2017/04/16 12:00:00", "n_likes": 1, "price": 500}
-]
-[[0,0.0,0.0],3]
-logical_select Logs   --shard_key timestamp   --filter 'price > 100'   --columns[count].stage filtered   --columns[count].type UInt32   --columns[count].flags COLUMN_SCALAR   --columns[count].value 'window_count()'   --columns[count].window.sort_keys -price   --output_columns _id,price,count
-[
-  [
-    0,
-    0.0,
-    0.0
-  ],
-  [
-    [
-      [
-        4
-      ],
-      [
-        [
-          "_id",
-          "UInt32"
-        ],
-        [
-          "price",
-          "UInt32"
-        ],
-        [
-          "count",
-          "UInt32"
-        ]
-      ],
-      [
-        3,
-        200,
-        1
-      ],
-      [
-        1,
-        300,
-        4
-      ],
-      [
-        2,
-        400,
-        3
-      ],
-      [
-        3,
-        500,
-        2
-      ]
-    ]
-  ]
-]

  Modified: test/command/suite/sharding/logical_select/columns/stage/filtered/window_function/window_count/descending.test (+0 -2)
===================================================================
--- test/command/suite/sharding/logical_select/columns/stage/filtered/window_function/window_count/descending.test    2019-04-25 11:50:45 +0900 (43d6b9571)
+++ test/command/suite/sharding/logical_select/columns/stage/filtered/window_function/window_count/descending.test    2019-04-25 15:15:43 +0900 (7803888be)
@@ -1,5 +1,3 @@
-#@omit TODO: Implement me
-
 #@on-error omit
 plugin_register sharding
 #@on-error default

  Deleted: test/command/suite/sharding/logical_select/columns/stage/initial/window_function/window_count/descending.reject (+0 -91) 100644
===================================================================
--- test/command/suite/sharding/logical_select/columns/stage/initial/window_function/window_count/descending.reject    2019-04-25 11:50:45 +0900 (8820abfb9)
+++ /dev/null
@@ -1,91 +0,0 @@
-plugin_register sharding
-[[0,0.0,0.0],true]
-table_create Logs_20170415 TABLE_NO_KEY
-[[0,0.0,0.0],true]
-column_create Logs_20170415 timestamp COLUMN_SCALAR Time
-[[0,0.0,0.0],true]
-column_create Logs_20170415 price COLUMN_SCALAR UInt32
-[[0,0.0,0.0],true]
-column_create Logs_20170415 n_likes COLUMN_SCALAR UInt32
-[[0,0.0,0.0],true]
-table_create Logs_20170416 TABLE_NO_KEY
-[[0,0.0,0.0],true]
-column_create Logs_20170416 timestamp COLUMN_SCALAR Time
-[[0,0.0,0.0],true]
-column_create Logs_20170416 price COLUMN_SCALAR UInt32
-[[0,0.0,0.0],true]
-column_create Logs_20170416 n_likes COLUMN_SCALAR UInt32
-[[0,0.0,0.0],true]
-load --table Logs_20170415
-[
-{"timestamp": "2017/04/15 00:00:00", "n_likes": 2, "price": 100},
-{"timestamp": "2017/04/15 01:00:00", "n_likes": 1, "price": 200},
-{"timestamp": "2017/04/15 02:00:00", "n_likes": 2, "price": 300}
-]
-[[0,0.0,0.0],3]
-load --table Logs_20170416
-[
-{"timestamp": "2017/04/16 10:00:00", "n_likes": 1, "price": 400},
-{"timestamp": "2017/04/16 11:00:00", "n_likes": 2, "price": 500},
-{"timestamp": "2017/04/16 12:00:00", "n_likes": 1, "price": 600}
-]
-[[0,0.0,0.0],3]
-logical_select Logs   --shard_key timestamp   --columns[count].stage initial   --columns[count].type UInt32   --columns[count].flags COLUMN_SCALAR   --columns[count].value 'window_count()'   --columns[count].window.sort_keys -price   --output_columns _id,price,count
-[
-  [
-    0,
-    0.0,
-    0.0
-  ],
-  [
-    [
-      [
-        6
-      ],
-      [
-        [
-          "_id",
-          "UInt32"
-        ],
-        [
-          "price",
-          "UInt32"
-        ],
-        [
-          "count",
-          "UInt32"
-        ]
-      ],
-      [
-        1,
-        100,
-        3
-      ],
-      [
-        2,
-        200,
-        2
-      ],
-      [
-        3,
-        300,
-        1
-      ],
-      [
-        1,
-        400,
-        6
-      ],
-      [
-        2,
-        500,
-        5
-      ],
-      [
-        3,
-        600,
-        4
-      ]
-    ]
-  ]
-]

  Modified: test/command/suite/sharding/logical_select/columns/stage/initial/window_function/window_count/descending.test (+0 -2)
===================================================================
--- test/command/suite/sharding/logical_select/columns/stage/initial/window_function/window_count/descending.test    2019-04-25 11:50:45 +0900 (de2ed9434)
+++ test/command/suite/sharding/logical_select/columns/stage/initial/window_function/window_count/descending.test    2019-04-25 15:15:43 +0900 (84776e2bd)
@@ -1,5 +1,3 @@
-#@omit TODO: Implement me
-
 #@on-error omit
 plugin_register sharding
 #@on-error default
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190425/e258f606/attachment-0001.html>


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