[Groonga-commit] ranguba/rroonga at 16e9018 [master] Support Zstandard compression

Back to archive index

Masafumi Yokoyama null+****@clear*****
Mon Dec 12 19:40:33 JST 2016


Masafumi Yokoyama	2016-12-12 19:40:33 +0900 (Mon, 12 Dec 2016)

  New Revision: 16e90186e4748e027009a8638c35b9f430d773d9
  https://github.com/ranguba/rroonga/commit/16e90186e4748e027009a8638c35b9f430d773d9

  Message:
    Support Zstandard compression

  Modified files:
    ext/groonga/rb-grn-object.c
    ext/groonga/rb-grn-table.c
    ext/groonga/rb-grn-variable-size-column.c
    test/test-schema-dumper.rb
    test/test-variable-size-column.rb

  Modified: ext/groonga/rb-grn-object.c (+2 -0)
===================================================================
--- ext/groonga/rb-grn-object.c    2016-12-12 16:15:56 +0900 (222f8ff)
+++ ext/groonga/rb-grn-object.c    2016-12-12 19:40:33 +0900 (7b9a462)
@@ -918,6 +918,8 @@ rb_grn_object_inspect_content_flags_with_label (VALUE inspected,
             rb_ary_push(inspected_flags, rb_str_new_cstr("COMPRESS_ZLIB"));
         } else if (column_flags & GRN_OBJ_COMPRESS_LZ4) {
             rb_ary_push(inspected_flags, rb_str_new_cstr("COMPRESS_LZ4"));
+        } else if (column_flags & GRN_OBJ_COMPRESS_ZSTD) {
+            rb_ary_push(inspected_flags, rb_str_new_cstr("COMPRESS_ZSTD"));
         }
         break;
     case GRN_COLUMN_INDEX:

  Modified: ext/groonga/rb-grn-table.c (+4 -1)
===================================================================
--- ext/groonga/rb-grn-table.c    2016-12-12 16:15:56 +0900 (851931c)
+++ ext/groonga/rb-grn-table.c    2016-12-12 19:40:33 +0900 (d5ecb24)
@@ -231,6 +231,7 @@ rb_grn_table_inspect (VALUE self)
  *
  *     - +:zlib+ := 値をzlib圧縮して格納する。
  *     - +:lz4+ := 値をLZ4圧縮して格納する。
+ *     - +:zstd+ := 値をZstandard圧縮して格納する。
  *
  * @return [Groonga::FixSizeColumn, Groonga::VariableSizeColumn]
  */
@@ -312,10 +313,12 @@ rb_grn_table_define_column (int argc, VALUE *argv, VALUE self)
         flags |= GRN_OBJ_COMPRESS_LZ4;
     } else if (rb_grn_equal_option(rb_compress, "lz4")) {
         flags |= GRN_OBJ_COMPRESS_LZ4;
+    } else if (rb_grn_equal_option(rb_compress, "zstd")) {
+        flags |= GRN_OBJ_COMPRESS_ZSTD;
     } else {
         rb_raise(rb_eArgError,
                  "invalid compress type: %s: "
-                 "available types: [:zlib, :lz4, nil]",
+                 "available types: [:zlib, :lz4, :zstd, nil]",
                  rb_grn_inspect(rb_compress));
     }
 

  Modified: ext/groonga/rb-grn-variable-size-column.c (+13 -2)
===================================================================
--- ext/groonga/rb-grn-variable-size-column.c    2016-12-12 16:15:56 +0900 (2d7ea6b)
+++ ext/groonga/rb-grn-variable-size-column.c    2016-12-12 19:40:33 +0900 (83d11cb)
@@ -465,7 +465,7 @@ rb_grn_variable_size_column_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
  * @overload compressed?
  *   @return [Boolean] whether the column is compressed or not.
  * @overload compressed?(type)
- *   @param [:zlib, :lz4] type (nil)
+ *   @param [:zlib, :lz4, :zstd] type (nil)
  *   @return [Boolean] whether specified compressed type is used or not.
  * @since 1.3.1
  */
@@ -481,6 +481,7 @@ rb_grn_variable_size_column_compressed_p (int argc, VALUE *argv, VALUE self)
     grn_bool accept_any_type = GRN_FALSE;
     grn_bool need_zlib_check = GRN_FALSE;
     grn_bool need_lz4_check = GRN_FALSE;
+    grn_bool need_zstd_check = GRN_FALSE;
 
     rb_scan_args(argc, argv, "01", &type);
 
@@ -494,9 +495,11 @@ rb_grn_variable_size_column_compressed_p (int argc, VALUE *argv, VALUE self)
             need_lz4_check = GRN_TRUE;
         } else if (rb_grn_equal_option(type, "lz4")) {
             need_lz4_check = GRN_TRUE;
+        } else if (rb_grn_equal_option(type, "zstd")) {
+            need_zstd_check = GRN_TRUE;
         } else {
             rb_raise(rb_eArgError,
-                     "compressed type should be <:zlib> or <:lz4>: <%s>",
+                     "compressed type should be <:zlib>, <:lz4> or <:zstd>: <%s>",
                      rb_grn_inspect(type));
         }
     }
@@ -524,6 +527,14 @@ rb_grn_variable_size_column_compressed_p (int argc, VALUE *argv, VALUE self)
             compressed_p = GRN_BOOL_VALUE(&support_p);
         }
         break;
+      case GRN_OBJ_COMPRESS_ZSTD:
+        if (accept_any_type || need_zstd_check) {
+            grn_obj support_p;
+            GRN_BOOL_INIT(&support_p, 0);
+            grn_obj_get_info(context, NULL, GRN_INFO_SUPPORT_ZSTD, &support_p);
+            compressed_p = GRN_BOOL_VALUE(&support_p);
+        }
+        break;
     }
 
     return CBOOL2RVAL(compressed_p);

  Modified: test/test-schema-dumper.rb (+19 -1)
===================================================================
--- test/test-schema-dumper.rb    2016-12-12 16:15:56 +0900 (7ec8df0)
+++ test/test-schema-dumper.rb    2016-12-12 19:40:33 +0900 (320b069)
@@ -1,5 +1,5 @@
 # Copyright (C) 2009-2016  Kouhei Sutou <kou �� clear-code.com>
-# Copyright (C) 2014  Masafumi Yokoyama <myokoym �� gmail.com>
+# Copyright (C) 2014-2016  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
@@ -432,6 +432,16 @@ column_create Posts title #{flags} ShortText
         SCHEMA
       end
 
+      def test_zstd
+        define_column_compression_zstd_schema
+        flags = "COLUMN_SCALAR"
+        flags << "|COMPRESS_ZSTD" if context.support_zstd?
+        assert_equal(<<-SCHEMA, dump)
+table_create Posts TABLE_NO_KEY
+column_create Posts title #{flags} ShortText
+        SCHEMA
+      end
+
       def test_with_weight_vector
         define_column_compression_with_weight_vector_schema
         flags = "COLUMN_VECTOR|WITH_WEIGHT"
@@ -459,6 +469,14 @@ column_create Posts comments #{flags} ShortText
         end
       end
 
+      def define_column_compression_zstd_schema
+        Groonga::Schema.define do |schema|
+          schema.create_table("Posts") do |table|
+            table.short_text("title", :compress => :zstd)
+          end
+        end
+      end
+
       def define_column_compression_with_weight_vector_schema
         Groonga::Schema.define do |schema|
           schema.create_table("Posts") do |table|

  Modified: test/test-variable-size-column.rb (+10 -0)
===================================================================
--- test/test-variable-size-column.rb    2016-12-12 16:15:56 +0900 (f25096f)
+++ test/test-variable-size-column.rb    2016-12-12 19:40:33 +0900 (a5ba88f)
@@ -96,6 +96,16 @@ class VariableSizeColumnTest < Test::Unit::TestCase
     end
   end
 
+  def test_compressed_zstd?
+    description =****@users*****_column("description", "ShortText",
+                                       :compress => :zstd)
+    if context.support_zstd?
+      assert {description.compressed?(:zstd)}
+    else
+      assert {not description.compressed?(:zstd)}
+    end
+  end
+
   def test_inspect
     assert_equal("#<Groonga::VariableSizeColumn " +
                  "id: <#{@name.id}>, " +
-------------- next part --------------
HTML����������������������������...
Descargar 



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