Kouhei Sutou
null+****@clear*****
Thu May 5 23:35:36 JST 2016
Kouhei Sutou 2016-05-05 23:35:36 +0900 (Thu, 05 May 2016) New Revision: eb0156e2b27029640f86bf3bf41dfb68aca820de https://github.com/groonga/groonga/commit/eb0156e2b27029640f86bf3bf41dfb68aca820de Message: Add time_classify_hour() Added files: test/command/suite/select/function/time/time_classify_hour/default.expected test/command/suite/select/function/time/time_classify_hour/default.test test/command/suite/select/function/time/time_classify_hour/interval.expected test/command/suite/select/function/time/time_classify_hour/interval.test Modified files: plugins/functions/time.c Modified: plugins/functions/time.c (+24 -1) =================================================================== --- plugins/functions/time.c 2016-05-05 23:30:06 +0900 (1a31069) +++ plugins/functions/time.c 2016-05-05 23:35:36 +0900 (d391224) @@ -26,7 +26,8 @@ typedef enum { GRN_TIME_CLASSIFY_UNIT_SECOND, - GRN_TIME_CLASSIFY_UNIT_MINUTE + GRN_TIME_CLASSIFY_UNIT_MINUTE, + GRN_TIME_CLASSIFY_UNIT_HOUR } grn_time_classify_unit; static grn_obj * @@ -114,6 +115,11 @@ func_time_classify_raw(grn_ctx *ctx, tm.tm_min = (tm.tm_min / interval_raw) * interval_raw; tm.tm_sec = 0; break; + case GRN_TIME_CLASSIFY_UNIT_HOUR : + tm.tm_hour = (tm.tm_hour / interval_raw) * interval_raw; + tm.tm_min = 0; + tm.tm_sec = 0; + break; } if (!grn_time_from_tm(ctx, &classed_time_raw, &tm)) { @@ -157,6 +163,18 @@ func_time_classify_minute(grn_ctx *ctx, int n_args, grn_obj **args, GRN_TIME_CLASSIFY_UNIT_MINUTE); } +static grn_obj * +func_time_classify_hour(grn_ctx *ctx, int n_args, grn_obj **args, + grn_user_data *user_data) +{ + return func_time_classify_raw(ctx, + n_args, + args, + user_data, + "time_classify_hour", + GRN_TIME_CLASSIFY_UNIT_HOUR); +} + grn_rc GRN_PLUGIN_INIT(grn_ctx *ctx) { @@ -178,6 +196,11 @@ GRN_PLUGIN_REGISTER(grn_ctx *ctx) GRN_PROC_FUNCTION, func_time_classify_minute, NULL, NULL, 0, NULL); + grn_proc_create(ctx, + "time_classify_hour", -1, + GRN_PROC_FUNCTION, + func_time_classify_hour, + NULL, NULL, 0, NULL); return rc; } Added: test/command/suite/select/function/time/time_classify_hour/default.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/time/time_classify_hour/default.expected 2016-05-05 23:35:36 +0900 (2750dab) @@ -0,0 +1,63 @@ +plugin_register functions/time +[[0,0.0,0.0],true] +table_create Timestamps TABLE_PAT_KEY Time +[[0,0.0,0.0],true] +load --table Timestamps +[ +{"_key": "2016-05-05 21:59:59.999999"}, +{"_key": "2016-05-05 22:00:00.000000"}, +{"_key": "2016-05-05 22:00:00.000001"}, +{"_key": "2016-05-05 22:59:59.999999"}, +{"_key": "2016-05-05 23:00:00.000000"}, +{"_key": "2016-05-05 23:00:00.000001"} +] +[[0,0.0,0.0],6] +select Timestamps --sortby _id --limit -1 --output_columns '_key, time_classify_hour(_key)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 6 + ], + [ + [ + "_key", + "Time" + ], + [ + "time_classify_hour", + "null" + ] + ], + [ + 1462453199.999999, + 1462449600.0 + ], + [ + 1462453200.0, + 1462453200.0 + ], + [ + 1462453200.000001, + 1462453200.0 + ], + [ + 1462456799.999999, + 1462453200.0 + ], + [ + 1462456800.0, + 1462456800.0 + ], + [ + 1462456800.000001, + 1462456800.0 + ] + ] + ] +] Added: test/command/suite/select/function/time/time_classify_hour/default.test (+18 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/time/time_classify_hour/default.test 2016-05-05 23:35:36 +0900 (97cd1d9) @@ -0,0 +1,18 @@ +plugin_register functions/time + +table_create Timestamps TABLE_PAT_KEY Time + +load --table Timestamps +[ +{"_key": "2016-05-05 21:59:59.999999"}, +{"_key": "2016-05-05 22:00:00.000000"}, +{"_key": "2016-05-05 22:00:00.000001"}, +{"_key": "2016-05-05 22:59:59.999999"}, +{"_key": "2016-05-05 23:00:00.000000"}, +{"_key": "2016-05-05 23:00:00.000001"} +] + +select Timestamps \ + --sortby _id \ + --limit -1 \ + --output_columns '_key, time_classify_hour(_key)' Added: test/command/suite/select/function/time/time_classify_hour/interval.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/time/time_classify_hour/interval.expected 2016-05-05 23:35:36 +0900 (bbafdc6) @@ -0,0 +1,63 @@ +plugin_register functions/time +[[0,0.0,0.0],true] +table_create Timestamps TABLE_PAT_KEY Time +[[0,0.0,0.0],true] +load --table Timestamps +[ +{"_key": "2016-05-05 11:59:59.999999"}, +{"_key": "2016-05-05 12:00:00.000000"}, +{"_key": "2016-05-05 12:00:00.000001"}, +{"_key": "2016-05-05 13:59:59.999999"}, +{"_key": "2016-05-05 14:00:00.000000"}, +{"_key": "2016-05-05 14:00:00.000001"} +] +[[0,0.0,0.0],6] +select Timestamps --sortby _id --limit -1 --output_columns '_key, time_classify_hour(_key, 2)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 6 + ], + [ + [ + "_key", + "Time" + ], + [ + "time_classify_hour", + "null" + ] + ], + [ + 1462417199.999999, + 1462410000.0 + ], + [ + 1462417200.0, + 1462417200.0 + ], + [ + 1462417200.000001, + 1462417200.0 + ], + [ + 1462424399.999999, + 1462417200.0 + ], + [ + 1462424400.0, + 1462424400.0 + ], + [ + 1462424400.000001, + 1462424400.0 + ] + ] + ] +] Added: test/command/suite/select/function/time/time_classify_hour/interval.test (+18 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/time/time_classify_hour/interval.test 2016-05-05 23:35:36 +0900 (5c408d5) @@ -0,0 +1,18 @@ +plugin_register functions/time + +table_create Timestamps TABLE_PAT_KEY Time + +load --table Timestamps +[ +{"_key": "2016-05-05 11:59:59.999999"}, +{"_key": "2016-05-05 12:00:00.000000"}, +{"_key": "2016-05-05 12:00:00.000001"}, +{"_key": "2016-05-05 13:59:59.999999"}, +{"_key": "2016-05-05 14:00:00.000000"}, +{"_key": "2016-05-05 14:00:00.000001"} +] + +select Timestamps \ + --sortby _id \ + --limit -1 \ + --output_columns '_key, time_classify_hour(_key, 2)' -------------- next part -------------- HTML����������������������������... 下载