Masafumi Yokoyama
null+****@clear*****
Wed Feb 11 23:20:47 JST 2015
Masafumi Yokoyama 2015-02-11 23:20:47 +0900 (Wed, 11 Feb 2015) New Revision: 86dd3865cf10d7200b48ed1f8296338291a431fc https://github.com/ranguba/rroonga/commit/86dd3865cf10d7200b48ed1f8296338291a431fc Message: (WIP) Support calculation for drilldown Added files: test/test-table-drilldown.rb Modified files: ext/groonga/rb-grn-table.c lib/groonga/record.rb Modified: ext/groonga/rb-grn-table.c (+20 -1) =================================================================== --- ext/groonga/rb-grn-table.c 2015-02-11 02:01:39 +0900 (7c28d07) +++ ext/groonga/rb-grn-table.c 2015-02-11 23:20:47 +0900 (020ce93) @@ -1,7 +1,7 @@ /* -*- coding: utf-8; mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* + Copyright (C) 2014-2015 Masafumi Yokoyama <yokoyama �� clear-code.com> Copyright (C) 2009-2014 Kouhei Sutou <kou �� clear-code.com> - Copyright (C) 2014 Masafumi Yokoyama <myokoym �� gmail.com> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -1313,6 +1313,10 @@ rb_grn_table_sort (int argc, VALUE *argv, VALUE self) * @option options :max_n_sub_records * グループ化した後のレコードのそれぞれについて最大 _:max_n_sub_records_ 件まで * そのグループに含まれる _table_ のレコードをサブレコードとして格納する。 + * @option options :calc_target + * TODO + * @option options :calc_types + * TODO */ static VALUE rb_grn_table_group (int argc, VALUE *argv, VALUE self) @@ -1325,6 +1329,7 @@ rb_grn_table_group (int argc, VALUE *argv, VALUE self) unsigned int max_n_sub_records = 0; grn_rc rc; VALUE rb_keys, rb_options, rb_max_n_sub_records; + VALUE rb_calc_target, rb_calc_types; VALUE *rb_group_keys; VALUE rb_results; @@ -1345,6 +1350,8 @@ rb_grn_table_group (int argc, VALUE *argv, VALUE self) rb_grn_scan_options(rb_options, "max_n_sub_records", &rb_max_n_sub_records, + "calc_target", &rb_calc_target, + "calc_types", &rb_calc_types, NULL); if (!NIL_P(rb_max_n_sub_records)) @@ -1396,6 +1403,18 @@ rb_grn_table_group (int argc, VALUE *argv, VALUE self) results[i].flags = 0; results[i].op = GRN_OP_OR; + if (!NIL_P(rb_calc_target)) { + const char *name = NULL; + unsigned int name_size = 0; + ruby_object_to_column_name(rb_calc_target, &name, &name_size); + results[i].calc_target = grn_obj_column(context, table, + name, name_size); + } + if (results[i].calc_target) { + // TODO results[i].flags |= drilldown->calc_types; + results[i].flags |= GRN_TABLE_GROUP_CALC_MAX; + } + rb_result = GRNOBJECT2RVAL(Qnil, context, result, GRN_TRUE); rb_ary_push(rb_results, rb_result); } Modified: lib/groonga/record.rb (+6 -1) =================================================================== --- lib/groonga/record.rb 2015-02-11 02:01:39 +0900 (631d4df) +++ lib/groonga/record.rb 2015-02-11 23:20:47 +0900 (b14c43f) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2014 Masafumi Yokoyama <myokoym �� gmail.com> +# Copyright (C) 2014-2015 Masafumi Yokoyama <yokoyama �� clear-code.com> # Copyright (C) 2009-2014 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or @@ -346,6 +346,11 @@ module Groonga SubRecords.new(self) end + # @return [Integer] TODO. + def max + self["_max"] + end + # @private def methods(include_inherited=true) original_methods = super Added: test/test-table-drilldown.rb (+81 -0) 100644 =================================================================== --- /dev/null +++ test/test-table-drilldown.rb 2015-02-11 23:20:47 +0900 (71aa2bb) @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015 Masafumi Yokoyama <yokoyama �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +class TableDrilldownTest < Test::Unit::TestCase + include GroongaTestUtils + + setup :setup_database + + setup + def setup_memos + @tags = Groonga::PatriciaTrie.create(:name => "Tags", :key_type => "ShortText") + + @memos = Groonga::Hash.create(:name => "Memos", :key_type => "ShortText") + @memos.define_column("tag", "Tags") + @memos.define_column("priority", "Int64") + + @memo1 =****@memos*****("Groonga1", + :tag => "Groonga", + :priority => 10) + @memo2 =****@memos*****("Groonga2", + :tag => "Groonga", + :priority => 20) + @memo3 =****@memos*****("Groonga3", + :tag => "Groonga", + :priority => 40) + @memo4 =****@memos*****("Mroonga1", + :tag => "Mroonga", + :priority => 50) + @memo5 =****@memos*****("Mroonga2", + :tag => "Mroonga", + :priority => 25) + @memo6 =****@memos*****("Mroonga3", + :tag => "Mroonga", + :priority => 10) + @memo7 =****@memos*****("Rroonga1", + :tag => "Rroonga", + :priority => 25) + @memo8 =****@memos*****("Rroonga2", + :tag => "Rroonga", + :priority => -25) + @memo9 =****@memos*****("Rroonga3", + :tag => "Rroonga", + :priority => 0) + end + + setup + def setup_variables + @result = nil + end + + def test_max + grouped_memos =****@memos*****("tag", + :calc_target => :priority, + :calc_types => [:max]) + + # TODO: sort + expected_groups = grouped_memos.collect do |group| + [group._key, group._max] + end + assert_equal([ + [:Groonga, 40], + [:Mroonga, 50], + [:Rroonga, 25], + ], + expected_groups) + end +end -------------- next part -------------- HTML����������������������������...Download