Navigation Menu

Skip to content

Commit

Permalink
select drilldown: support calc_types and calc_target
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 21, 2015
1 parent ed10056 commit 8375847
Show file tree
Hide file tree
Showing 9 changed files with 427 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/proc.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
81 changes: 81 additions & 0 deletions test/command/suite/select/drilldown/plain/calc_types/avg.expected
@@ -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
]
]
]
]
25 changes: 25 additions & 0 deletions test/command/suite/select/drilldown/plain/calc_types/avg.test
@@ -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
81 changes: 81 additions & 0 deletions test/command/suite/select/drilldown/plain/calc_types/max.expected
@@ -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
]
]
]
]
25 changes: 25 additions & 0 deletions test/command/suite/select/drilldown/plain/calc_types/max.test
@@ -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
81 changes: 81 additions & 0 deletions test/command/suite/select/drilldown/plain/calc_types/min.expected
@@ -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
]
]
]
]
25 changes: 25 additions & 0 deletions test/command/suite/select/drilldown/plain/calc_types/min.test
@@ -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

0 comments on commit 8375847

Please sign in to comment.