[Groonga-commit] ranguba/rroonga at f1aa4c2 [master] Support COMPRESS_ZLIB/COMPRESS_LZ4 flag for Groonga::SchemaDumper

Back to archive index

Masafumi Yokoyama null+****@clear*****
Sun Nov 2 18:20:52 JST 2014


Masafumi Yokoyama	2014-11-02 18:20:52 +0900 (Sun, 02 Nov 2014)

  New Revision: f1aa4c2194cac365ae0773501e012c642229c665
  https://github.com/ranguba/rroonga/commit/f1aa4c2194cac365ae0773501e012c642229c665

  Message:
    Support COMPRESS_ZLIB/COMPRESS_LZ4 flag for Groonga::SchemaDumper
    
    GitHub: #28, #31

  Modified files:
    lib/groonga/dumper.rb
    test/test-schema-dumper.rb

  Modified: lib/groonga/dumper.rb (+8 -1)
===================================================================
--- lib/groonga/dumper.rb    2014-11-01 18:09:56 +0900 (f6b5544)
+++ lib/groonga/dumper.rb    2014-11-02 18:20:52 +0900 (5fc2061)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2011-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
@@ -602,7 +603,13 @@ module Groonga
           flags << "COLUMN_VECTOR"
         end
         flags << "WITH_WEIGHT" if column.with_weight?
-        # TODO: support COMPRESS_ZLIB and COMPRESS_LZO?
+        if column.is_a?(Groonga::VariableSizeColumn)
+          if column.compressed?(:zlib)
+            flags << "COMPRESS_ZLIB"
+          elsif column.compressed?(:lz4)
+            flags << "COMPRESS_LZ4"
+          end
+        end
         parameters << "#{flags.join('|')}"
         parameters << "#{column.range.name}"
         write("column_create #{parameters.join(' ')}\n")

  Modified: test/test-schema-dumper.rb (+55 -0)
===================================================================
--- test/test-schema-dumper.rb    2014-11-01 18:09:56 +0900 (0181009)
+++ test/test-schema-dumper.rb    2014-11-02 18:20:52 +0900 (2234a00)
@@ -1,4 +1,5 @@
 # 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
@@ -329,6 +330,60 @@ column_create Accounts name COLUMN_SCALAR ShortText
       SCHEMA
     end
 
+    class ColumnCompressionTest < self
+      def test_zlib
+        define_column_compression_zlib_schema
+        assert_equal(<<-SCHEMA, dump)
+table_create Posts TABLE_NO_KEY
+column_create Posts title COLUMN_SCALAR|COMPRESS_ZLIB ShortText
+        SCHEMA
+      end
+
+      def test_lz4
+        define_column_compression_lz4_schema
+        assert_equal(<<-SCHEMA, dump)
+table_create Posts TABLE_NO_KEY
+column_create Posts title COLUMN_SCALAR|COMPRESS_LZ4 ShortText
+        SCHEMA
+      end
+
+      def test_with_weight_vector
+        define_column_compression_with_weight_vector_schema
+        assert_equal(<<-SCHEMA, dump)
+table_create Posts TABLE_NO_KEY
+column_create Posts comments COLUMN_VECTOR|WITH_WEIGHT|COMPRESS_ZLIB ShortText
+        SCHEMA
+      end
+
+      private
+      def define_column_compression_zlib_schema
+        Groonga::Schema.define do |schema|
+          schema.create_table("Posts") do |table|
+            table.short_text("title", :compress => :zlib)
+          end
+        end
+      end
+
+      def define_column_compression_lz4_schema
+        Groonga::Schema.define do |schema|
+          schema.create_table("Posts") do |table|
+            table.short_text("title", :compress => :lz4)
+          end
+        end
+      end
+
+      def define_column_compression_with_weight_vector_schema
+        Groonga::Schema.define do |schema|
+          schema.create_table("Posts") do |table|
+            table.short_text("comments",
+                             :type => :vector,
+                             :with_weight => true,
+                             :compress => :zlib)
+          end
+        end
+      end
+    end
+
     private
     def dump
       Groonga::Schema.dump(:syntax => :command)
-------------- next part --------------
HTML����������������������������...
下載 



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