[Groonga-commit] groonga/groonga at 8375847 [master] select drilldown: support calc_types and calc_target

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 21 15:43:53 JST 2015


Kouhei Sutou	2015-01-21 15:43:53 +0900 (Wed, 21 Jan 2015)

  New Revision: 8375847cdf8f4302038c085501451f629bbaba9f
  https://github.com/groonga/groonga/commit/8375847cdf8f4302038c085501451f629bbaba9f

  Message:
    select drilldown: support calc_types and calc_target

  Added files:
    test/command/suite/select/drilldown/plain/calc_types/avg.expected
    test/command/suite/select/drilldown/plain/calc_types/avg.test
    test/command/suite/select/drilldown/plain/calc_types/max.expected
    test/command/suite/select/drilldown/plain/calc_types/max.test
    test/command/suite/select/drilldown/plain/calc_types/min.expected
    test/command/suite/select/drilldown/plain/calc_types/min.test
    test/command/suite/select/drilldown/plain/calc_types/sum.expected
    test/command/suite/select/drilldown/plain/calc_types/sum.test
  Modified files:
    lib/proc.c

  Modified: lib/proc.c (+13 -6)
===================================================================
--- lib/proc.c    2015-01-21 15:42:47 +0900 (fd81957)
+++ lib/proc.c    2015-01-21 15:43:53 +0900 (053220a)
@@ -713,8 +713,13 @@ grn_select_drilldown(grn_ctx *ctx, grn_obj *table,
     int offset;
     int limit;
 
-    if (!g.table) {
-      continue;
+    if (drilldown->calc_target_name) {
+      g.calc_target = grn_obj_column(ctx, table,
+                                     drilldown->calc_target_name,
+                                     drilldown->calc_target_name_len);
+    }
+    if (g.calc_target) {
+      g.flags |= drilldown->calc_types;
     }
 
     grn_table_group(ctx, table, &keys[i], 1, &g, 1);
@@ -1254,7 +1259,7 @@ proc_select(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
     drilldown->label_len = 0;
     drilldown_info_fill(ctx, drilldown,
                         VAR(9), VAR(10), VAR(11), VAR(12), VAR(13),
-                        NULL, NULL);
+                        VAR(20), VAR(21));
     n_drilldowns++;
   } else {
     unsigned int i;
@@ -6516,7 +6521,7 @@ proc_request_cancel(grn_ctx *ctx, int nargs, grn_obj **args,
 void
 grn_db_init_builtin_query(grn_ctx *ctx)
 {
-  grn_expr_var vars[21];
+  grn_expr_var vars[23];
 
   DEF_VAR(vars[0], "name");
   DEF_VAR(vars[1], "table");
@@ -6540,8 +6545,10 @@ grn_db_init_builtin_query(grn_ctx *ctx)
   DEF_VAR(vars[18], "query_flags");
   DEF_VAR(vars[19], "query_expander");
   DEF_VAR(vars[20], "adjuster");
-  DEF_COMMAND("define_selector", proc_define_selector, 21, vars);
-  DEF_COMMAND("select", proc_select, 20, vars + 1);
+  DEF_VAR(vars[21], "drilldown_calc_types");
+  DEF_VAR(vars[22], "drilldown_calc_target");
+  DEF_COMMAND("define_selector", proc_define_selector, 23, vars);
+  DEF_COMMAND("select", proc_select, 22, vars + 1);
 
   DEF_VAR(vars[0], "values");
   DEF_VAR(vars[1], "table");

  Added: test/command/suite/select/drilldown/plain/calc_types/avg.expected (+81 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/calc_types/avg.expected    2015-01-21 15:43:53 +0900 (c98db76)
@@ -0,0 +1,81 @@
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61},
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0}
+]
+[[0,0.0,0.0],9]
+select Memos   --limit 0   --drilldown tag   --drilldown_calc_types AVG   --drilldown_calc_target priority   --drilldown_output_columns _key,_avg
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "priority",
+          "Int64"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_avg",
+          "Float"
+        ]
+      ],
+      [
+        "Groonga",
+        30.0
+      ],
+      [
+        "Mroonga",
+        31.0
+      ],
+      [
+        "Rroonga",
+        -2.0
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/drilldown/plain/calc_types/avg.test (+25 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/calc_types/avg.test    2015-01-21 15:43:53 +0900 (9a8cd2e)
@@ -0,0 +1,25 @@
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos tag COLUMN_SCALAR Tags
+column_create Memos priority COLUMN_SCALAR Int64
+
+load --table Memos
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61},
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0}
+]
+
+select Memos \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types AVG \
+  --drilldown_calc_target priority \
+  --drilldown_output_columns _key,_avg

  Added: test/command/suite/select/drilldown/plain/calc_types/max.expected (+81 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/calc_types/max.expected    2015-01-21 15:43:53 +0900 (78795af)
@@ -0,0 +1,81 @@
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 40},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 50},
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 25},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 10},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 25},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -25},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0}
+]
+[[0,0.0,0.0],9]
+select Memos   --limit 0   --drilldown tag   --drilldown_calc_types MAX   --drilldown_calc_target priority   --drilldown_output_columns _key,_max
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "priority",
+          "Int64"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_max",
+          "Int64"
+        ]
+      ],
+      [
+        "Groonga",
+        40
+      ],
+      [
+        "Mroonga",
+        50
+      ],
+      [
+        "Rroonga",
+        25
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/drilldown/plain/calc_types/max.test (+25 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/calc_types/max.test    2015-01-21 15:43:53 +0900 (a0c5b4f)
@@ -0,0 +1,25 @@
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos tag COLUMN_SCALAR Tags
+column_create Memos priority COLUMN_SCALAR Int64
+
+load --table Memos
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 40},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 50},
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 25},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 10},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 25},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -25},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0}
+]
+
+select Memos \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types MAX \
+  --drilldown_calc_target priority \
+  --drilldown_output_columns _key,_max

  Added: test/command/suite/select/drilldown/plain/calc_types/min.expected (+81 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/calc_types/min.expected    2015-01-21 15:43:53 +0900 (e3973b3)
@@ -0,0 +1,81 @@
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 40},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 50},
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 25},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 5},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 25},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -25},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0}
+]
+[[0,0.0,0.0],9]
+select Memos   --limit 0   --drilldown tag   --drilldown_calc_types MIN   --drilldown_calc_target priority   --drilldown_output_columns _key,_min
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "priority",
+          "Int64"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_min",
+          "Int64"
+        ]
+      ],
+      [
+        "Groonga",
+        10
+      ],
+      [
+        "Mroonga",
+        5
+      ],
+      [
+        "Rroonga",
+        -25
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/drilldown/plain/calc_types/min.test (+25 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/calc_types/min.test    2015-01-21 15:43:53 +0900 (d6cc4f1)
@@ -0,0 +1,25 @@
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos tag COLUMN_SCALAR Tags
+column_create Memos priority COLUMN_SCALAR Int64
+
+load --table Memos
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 40},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 50},
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 25},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 5},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 25},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -25},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0}
+]
+
+select Memos \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types MIN \
+  --drilldown_calc_target priority \
+  --drilldown_output_columns _key,_min

  Added: test/command/suite/select/drilldown/plain/calc_types/sum.expected (+76 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/calc_types/sum.expected    2015-01-21 15:43:53 +0900 (fa7bee9)
@@ -0,0 +1,76 @@
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos value COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga is fast!", "tag": "Groonga", "value": 10},
+{"_key": "Mroonga is fast!", "tag": "Mroonga", "value": 20},
+{"_key": "Groonga sticker!", "tag": "Groonga", "value": 40},
+{"_key": "Rroonga is fast!", "tag": "Rroonga", "value": 80}
+]
+[[0,0.0,0.0],4]
+select Memos   --limit 0   --drilldown tag   --drilldown_calc_types SUM   --drilldown_calc_target value   --drilldown_output_columns _key,_sum
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        4
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "tag",
+          "Tags"
+        ],
+        [
+          "value",
+          "Int64"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_sum",
+          "Int64"
+        ]
+      ],
+      [
+        "Groonga",
+        50
+      ],
+      [
+        "Mroonga",
+        20
+      ],
+      [
+        "Rroonga",
+        80
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/drilldown/plain/calc_types/sum.test (+20 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/drilldown/plain/calc_types/sum.test    2015-01-21 15:43:53 +0900 (55c5030)
@@ -0,0 +1,20 @@
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos tag COLUMN_SCALAR Tags
+column_create Memos value COLUMN_SCALAR Int64
+
+load --table Memos
+[
+{"_key": "Groonga is fast!", "tag": "Groonga", "value": 10},
+{"_key": "Mroonga is fast!", "tag": "Mroonga", "value": 20},
+{"_key": "Groonga sticker!", "tag": "Groonga", "value": 40},
+{"_key": "Rroonga is fast!", "tag": "Rroonga", "value": 80}
+]
+
+select Memos \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types SUM \
+  --drilldown_calc_target value \
+  --drilldown_output_columns _key,_sum
-------------- next part --------------
HTML����������������������������...
Descargar 



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