[Groonga-commit] ranguba/rroonga at 5ac24bb [master] Implement Groonga::Column#apply_window_function

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jun 14 14:28:05 JST 2016


Kouhei Sutou	2016-06-14 14:28:05 +0900 (Tue, 14 Jun 2016)

  New Revision: 5ac24bbd89817b4feae0afe04c89db30920eb0e5
  https://github.com/ranguba/rroonga/commit/5ac24bbd89817b4feae0afe04c89db30920eb0e5

  Message:
    Implement Groonga::Column#apply_window_function

  Modified files:
    ext/groonga/rb-grn-column.c
    test/test-column.rb

  Modified: ext/groonga/rb-grn-column.c (+11 -1)
===================================================================
--- ext/groonga/rb-grn-column.c    2016-06-14 14:03:15 +0900 (9426180)
+++ ext/groonga/rb-grn-column.c    2016-06-14 14:28:05 +0900 (2160513)
@@ -829,14 +829,19 @@ rb_grn_column_apply_window_function (int argc, VALUE *argv, VALUE self)
     grn_ctx *context;
     grn_obj *column;
     grn_obj *table;
+    VALUE rb_table;
     grn_window_definition definition;
     grn_obj *window_function_call = NULL;
     VALUE rb_options;
     VALUE rb_sort_keys;
+    VALUE rb_builder;
+    VALUE rb_window_function_call;
 
     rb_grn_column_deconstruct(SELF(self), &column, &context,
                               NULL, &table,
                               NULL, NULL, NULL);
+    rb_table = GRNOBJECT2RVAL(Qnil, context, table, GRN_FALSE);
+
     memset(&definition, 0, sizeof(grn_window_definition));
 
     rb_scan_args(argc, argv, "01", &rb_options);
@@ -862,7 +867,12 @@ rb_grn_column_apply_window_function (int argc, VALUE *argv, VALUE self)
                                     rb_table);
     }
 
-    /* TODO: set window_function_call */
+    rb_builder = rb_grn_record_expression_builder_new(rb_table, Qnil);
+    rb_window_function_call =
+        rb_grn_record_expression_builder_build(rb_builder);
+    rb_grn_object_deconstruct(RB_GRN_OBJECT(DATA_PTR(rb_window_function_call)),
+                              &window_function_call, NULL,
+                              NULL, NULL, NULL, NULL);
 
     rc = grn_table_apply_window_function(context,
                                          table,

  Modified: test/test-column.rb (+29 -0)
===================================================================
--- test/test-column.rb    2016-06-14 14:03:15 +0900 (2124afd)
+++ test/test-column.rb    2016-06-14 14:28:05 +0900 (bdeb70d)
@@ -349,6 +349,35 @@ class ColumnTest < Test::Unit::TestCase
     end
   end
 
+  def test_apply_window_function
+    Groonga::Schema.define do |schema|
+      schema.create_table("Comments") do |table|
+        table.uint32("nth")
+      end
+    end
+    comments = Groonga["Comments"]
+    nth = Groonga["Comments.nth"]
+
+    5.times do
+      comments.add
+    end
+
+    options = {
+      :sort_keys => [["_id", "desc"]],
+    }
+    nth.apply_window_function(options) do |record|
+      record.call("record_number")
+    end
+    assert_equal([
+                   [1, 5],
+                   [2, 4],
+                   [3, 3],
+                   [4, 2],
+                   [5, 1],
+                 ],
+                 comments.collect {|comment| [comment.id, comment.nth]})
+  end
+
   private
   def assert_content_search(expected_records, term)
     records = @bookmarks_index_content.search(term).records
-------------- next part --------------
HTML����������������������������...
Download 



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