[Groonga-commit] ranguba/rroonga at 90ad19a [master] Add Groonga::Column#apply_window_function

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Jun 13 18:31:55 JST 2016


Kouhei Sutou	2016-06-13 18:31:55 +0900 (Mon, 13 Jun 2016)

  New Revision: 90ad19ac62680a0f13ae87cd830f628604e06851
  https://github.com/ranguba/rroonga/commit/90ad19ac62680a0f13ae87cd830f628604e06851

  Message:
    Add Groonga::Column#apply_window_function
    
    It's not worked yet.
    
    TODO:
    
      * Support creating expression that calls window function
      * Stop to provide it to IndexColumn

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

  Modified: ext/groonga/rb-grn-column.c (+66 -0)
===================================================================
--- ext/groonga/rb-grn-column.c    2016-06-13 18:30:38 +0900 (1a3889f)
+++ ext/groonga/rb-grn-column.c    2016-06-13 18:31:55 +0900 (9426180)
@@ -812,6 +812,69 @@ rb_grn_column_rename (VALUE self, VALUE rb_name)
     return self;
 }
 
+/*
+ * Applies the window function to records in the table of the
+ * column. Results are stored into the column.
+ *
+ * @overload apply_window_function(options={}) {|record| }
+ *   @param options [::Hash] The name and value pairs.
+ *   @option options [::Array<String>] :sort_keys
+ *
+ * @since 6.0.4
+ */
+static VALUE
+rb_grn_column_apply_window_function (int argc, VALUE *argv, VALUE self)
+{
+    grn_rc rc;
+    grn_ctx *context;
+    grn_obj *column;
+    grn_obj *table;
+    grn_window_definition definition;
+    grn_obj *window_function_call = NULL;
+    VALUE rb_options;
+    VALUE rb_sort_keys;
+
+    rb_grn_column_deconstruct(SELF(self), &column, &context,
+                              NULL, &table,
+                              NULL, NULL, NULL);
+    memset(&definition, 0, sizeof(grn_window_definition));
+
+    rb_scan_args(argc, argv, "01", &rb_options);
+    rb_grn_scan_options(rb_options,
+                        "sort_keys", &rb_sort_keys,
+                        NULL);
+
+    if (!NIL_P(rb_sort_keys)) {
+        VALUE rb_table;
+
+        if (!RVAL2CBOOL(rb_obj_is_kind_of(rb_sort_keys, rb_cArray)))
+            rb_raise(rb_eArgError, ":sort_keys should be an array of key: <%s>",
+                     rb_grn_inspect(rb_sort_keys));
+
+        definition.n_sort_keys = RARRAY_LEN(rb_sort_keys);
+        definition.sort_keys = ALLOCA_N(grn_table_sort_key,
+                                        definition.n_sort_keys);
+        rb_table = GRNOBJECT2RVAL(Qnil, context, table, GRN_FALSE);
+        rb_grn_table_sort_keys_fill(context,
+                                    definition.sort_keys,
+                                    definition.n_sort_keys,
+                                    rb_sort_keys,
+                                    rb_table);
+    }
+
+    /* TODO: set window_function_call */
+
+    rc = grn_table_apply_window_function(context,
+                                         table,
+                                         column,
+                                         &definition,
+                                         window_function_call);
+    rb_grn_context_check(context, self);
+    rb_grn_rc_check(rc, self);
+
+    return self;
+}
+
 void
 rb_grn_init_column (VALUE mGrn)
 {
@@ -846,6 +909,9 @@ rb_grn_init_column (VALUE mGrn)
 
     rb_define_method(rb_cGrnColumn, "rename", rb_grn_column_rename, 1);
 
+    rb_define_method(rb_cGrnColumn, "apply_window_function",
+                     rb_grn_column_apply_window_function, -1);
+
     rb_grn_init_fix_size_column(mGrn);
     rb_grn_init_variable_size_column(mGrn);
     rb_grn_init_index_column(mGrn);
-------------- next part --------------
HTML����������������������������...
Download 



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