Kouhei Sutou
null+****@clear*****
Fri May 6 00:22:54 JST 2016
Kouhei Sutou 2016-05-06 00:22:54 +0900 (Fri, 06 May 2016) New Revision: 3d6d1cdf5d8db6859fc4acbcef2ddde19722711c https://github.com/groonga/groonga/commit/3d6d1cdf5d8db6859fc4acbcef2ddde19722711c Message: Add time_classify_year() Added files: test/command/suite/select/function/time/time_classify_year/default.expected test/command/suite/select/function/time/time_classify_year/default.test test/command/suite/select/function/time/time_classify_year/interval.expected test/command/suite/select/function/time/time_classify_year/interval.test Modified files: plugins/functions/time.c Modified: plugins/functions/time.c (+28 -1) =================================================================== --- plugins/functions/time.c 2016-05-06 00:17:19 +0900 (2e6cb92) +++ plugins/functions/time.c 2016-05-06 00:22:54 +0900 (a5a5c0d) @@ -30,7 +30,8 @@ typedef enum { GRN_TIME_CLASSIFY_UNIT_HOUR, GRN_TIME_CLASSIFY_UNIT_DAY, GRN_TIME_CLASSIFY_UNIT_WEEK, - GRN_TIME_CLASSIFY_UNIT_MONTH + GRN_TIME_CLASSIFY_UNIT_MONTH, + GRN_TIME_CLASSIFY_UNIT_YEAR } grn_time_classify_unit; static grn_obj * @@ -57,6 +58,7 @@ func_time_classify_raw(grn_ctx *ctx, accept_interval = GRN_FALSE; break; case GRN_TIME_CLASSIFY_UNIT_MONTH : + case GRN_TIME_CLASSIFY_UNIT_YEAR : accept_interval = GRN_TRUE; break; } @@ -190,6 +192,14 @@ func_time_classify_raw(grn_ctx *ctx, tm.tm_min = 0; tm.tm_sec = 0; break; + case GRN_TIME_CLASSIFY_UNIT_YEAR : + tm.tm_year = (((1900 + tm.tm_year) / interval_raw) * interval_raw) - 1900; + tm.tm_mon = 0; + tm.tm_mday = 1; + tm.tm_hour = 0; + tm.tm_min = 0; + tm.tm_sec = 0; + break; } if (!grn_time_from_tm(ctx, &classed_time_raw, &tm)) { @@ -281,6 +291,18 @@ func_time_classify_month(grn_ctx *ctx, int n_args, grn_obj **args, GRN_TIME_CLASSIFY_UNIT_MONTH); } +static grn_obj * +func_time_classify_year(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_year", + GRN_TIME_CLASSIFY_UNIT_YEAR); +} + grn_rc GRN_PLUGIN_INIT(grn_ctx *ctx) { @@ -322,6 +344,11 @@ GRN_PLUGIN_REGISTER(grn_ctx *ctx) GRN_PROC_FUNCTION, func_time_classify_month, NULL, NULL, 0, NULL); + grn_proc_create(ctx, + "time_classify_year", -1, + GRN_PROC_FUNCTION, + func_time_classify_year, + NULL, NULL, 0, NULL); return rc; } Added: test/command/suite/select/function/time/time_classify_year/default.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/time/time_classify_year/default.expected 2016-05-06 00:22:54 +0900 (a6a9b1d) @@ -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": "2015-12-31 23:59:59.999999"}, +{"_key": "2016-01-01 00:00:00.000000"}, +{"_key": "2016-01-01 00:00:00.000001"}, +{"_key": "2016-12-31 23:59:59.999999"}, +{"_key": "2017-01-01 00:00:00.000000"}, +{"_key": "2017-01-01 00:00:00.000001"} +] +[[0,0.0,0.0],6] +select Timestamps --sortby _id --limit -1 --output_columns '_key, time_classify_year(_key)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 6 + ], + [ + [ + "_key", + "Time" + ], + [ + "time_classify_year", + "null" + ] + ], + [ + 1451573999.999999, + 1420038000.0 + ], + [ + 1451574000.0, + 1451574000.0 + ], + [ + 1451574000.000001, + 1451574000.0 + ], + [ + 1483196399.999999, + 1451574000.0 + ], + [ + 1483196400.0, + 1483196400.0 + ], + [ + 1483196400.000001, + 1483196400.0 + ] + ] + ] +] Added: test/command/suite/select/function/time/time_classify_year/default.test (+18 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/time/time_classify_year/default.test 2016-05-06 00:22:54 +0900 (2e03245) @@ -0,0 +1,18 @@ +plugin_register functions/time + +table_create Timestamps TABLE_PAT_KEY Time + +load --table Timestamps +[ +{"_key": "2015-12-31 23:59:59.999999"}, +{"_key": "2016-01-01 00:00:00.000000"}, +{"_key": "2016-01-01 00:00:00.000001"}, +{"_key": "2016-12-31 23:59:59.999999"}, +{"_key": "2017-01-01 00:00:00.000000"}, +{"_key": "2017-01-01 00:00:00.000001"} +] + +select Timestamps \ + --sortby _id \ + --limit -1 \ + --output_columns '_key, time_classify_year(_key)' Added: test/command/suite/select/function/time/time_classify_year/interval.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/time/time_classify_year/interval.expected 2016-05-06 00:22:54 +0900 (05aff46) @@ -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": "2015-12-31 23:59:59.999999"}, +{"_key": "2016-01-01 00:00:00.000000"}, +{"_key": "2016-01-01 00:00:00.000001"}, +{"_key": "2017-12-31 23:59:59.999999"}, +{"_key": "2018-01-01 00:00:00.000000"}, +{"_key": "2018-01-01 00:00:00.000001"} +] +[[0,0.0,0.0],6] +select Timestamps --sortby _id --limit -1 --output_columns '_key, time_classify_year(_key, 2)' +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 6 + ], + [ + [ + "_key", + "Time" + ], + [ + "time_classify_year", + "null" + ] + ], + [ + 1451573999.999999, + 1388502000.0 + ], + [ + 1451574000.0, + 1451574000.0 + ], + [ + 1451574000.000001, + 1451574000.0 + ], + [ + 1514732399.999999, + 1451574000.0 + ], + [ + 1514732400.0, + 1514732400.0 + ], + [ + 1514732400.000001, + 1514732400.0 + ] + ] + ] +] Added: test/command/suite/select/function/time/time_classify_year/interval.test (+18 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/time/time_classify_year/interval.test 2016-05-06 00:22:54 +0900 (e3e1e8c) @@ -0,0 +1,18 @@ +plugin_register functions/time + +table_create Timestamps TABLE_PAT_KEY Time + +load --table Timestamps +[ +{"_key": "2015-12-31 23:59:59.999999"}, +{"_key": "2016-01-01 00:00:00.000000"}, +{"_key": "2016-01-01 00:00:00.000001"}, +{"_key": "2017-12-31 23:59:59.999999"}, +{"_key": "2018-01-01 00:00:00.000000"}, +{"_key": "2018-01-01 00:00:00.000001"} +] + +select Timestamps \ + --sortby _id \ + --limit -1 \ + --output_columns '_key, time_classify_year(_key, 2)' -------------- next part -------------- HTML����������������������������... Download