From null+ranguba at clear-code.com Mon Dec 12 09:13:39 2011 From: null+ranguba at clear-code.com (null+ranguba at clear-code.com) Date: Mon, 12 Dec 2011 14:13:39 +0000 Subject: [groonga-commit:4157] ranguba/rroonga [master] [schema] support TokyoGeoPoint and WGS84GeoPoint. Message-ID: <20111212142729.628172C4171@taiyaki.ru> Kouhei Sutou 2011-12-12 14:13:39 +0000 (Mon, 12 Dec 2011) New Revision: 126f77c7f3f27fdfde9ac5e5a711a2bd08b1372d Log: [schema] support TokyoGeoPoint and WGS84GeoPoint. Modified files: lib/groonga/schema.rb test/test-schema.rb Modified: lib/groonga/schema.rb (+33 -0) =================================================================== --- lib/groonga/schema.rb 2011-12-12 14:08:08 +0000 (adb624a) +++ lib/groonga/schema.rb 2011-12-12 14:13:39 +0000 (8042052) @@ -1316,6 +1316,39 @@ module Groonga end alias_method :bool, :boolean + # Defines a 8 bit signed integer column named @name at . + # + # @param [String or Symbol] name the column name + # @param [Hash] options ({}) the options + # @see Groonga::Schema::TableDefinition#column for + # available @options at . + def integer8(name, options={}) + column(name, "Int8", options) + end + alias_method :int8, :integer8 + + # Defines a geo point in Tokyo geodetic system column + # named @name at . + # + # @param [String or Symbol] name the column name + # @param [Hash] options ({}) the options + # @see Groonga::Schema::TableDefinition#column for + # available @options at . + def tokyo_geo_point(name, options={}) + column(name, "TokyoGeoPoint", options) + end + + # Defines a geo point in WGS 84 (World Geodetic System) column + # named @name at . + # + # @param [String or Symbol] name the column name + # @param [Hash] options ({}) the options + # @see Groonga::Schema::TableDefinition#column for + # available @options at . + def wgs84_geo_point(name, options={}) + column(name, "WGS84GeoPoint", options) + end + # @private def [](name, definition_class=nil) @definitions.find do |definition| Modified: test/test-schema.rb (+16 -0) =================================================================== --- test/test-schema.rb 2011-12-12 14:08:08 +0000 (c7741d2) +++ test/test-schema.rb 2011-12-12 14:13:39 +0000 (589aba7) @@ -465,6 +465,22 @@ class SchemaTest < Test::Unit::TestCase assert_equal(context["Bool"], context["Posts.public"].range) end + def test_tokyo_geo_point_column + assert_nil(context["Posts.location"]) + Groonga::Schema.create_table("Posts") do |table| + table.tokyo_geo_point :location + end + assert_equal(context["TokyoGeoPoint"], context["Posts.location"].range) + end + + def test_wgs84_geo_point_column + assert_nil(context["Posts.location"]) + Groonga::Schema.create_table("Posts") do |table| + table.wgs84_geo_point :location + end + assert_equal(context["WGS84GeoPoint"], context["Posts.location"].range) + end + def test_remove_column Groonga::Schema.create_table("Posts") do |table| table.long_text :content From null+ranguba at clear-code.com Mon Dec 12 09:08:08 2011 From: null+ranguba at clear-code.com (null+ranguba at clear-code.com) Date: Mon, 12 Dec 2011 14:08:08 +0000 Subject: [groonga-commit:4158] ranguba/rroonga [master] [schema] support Int8, Int16, UInt8 and UInt16. Message-ID: <20111212142729.567892C414B@taiyaki.ru> Kouhei Sutou 2011-12-12 14:08:08 +0000 (Mon, 12 Dec 2011) New Revision: 55bf9a7be7b5ef30b527bb40ec3b97a73af70ab2 Log: [schema] support Int8, Int16, UInt8 and UInt16. Modified files: lib/groonga/schema.rb test/test-schema.rb Modified: lib/groonga/schema.rb (+44 -0) =================================================================== --- lib/groonga/schema.rb 2011-11-28 08:01:01 +0000 (8eab3d3) +++ lib/groonga/schema.rb 2011-12-12 14:08:08 +0000 (adb624a) @@ -1158,6 +1158,28 @@ module Groonga self end + # Defines a 8 bit signed integer column named @name at . + # + # @param [String or Symbol] name the column name + # @param [Hash] options ({}) the options + # @see Groonga::Schema::TableDefinition#column for + # available @options at . + def integer8(name, options={}) + column(name, "Int8", options) + end + alias_method :int8, :integer8 + + # Defines a 16 bit signed integer column named @name at . + # + # @param [String or Symbol] name the column name + # @param [Hash] options ({}) the options + # @see Groonga::Schema::TableDefinition#column for + # available @options at . + def integer16(name, options={}) + column(name, "Int16", options) + end + alias_method :int16, :integer16 + # ??? _name_ ?32bit???????????????? # # _options_ ???????? @@ -1177,6 +1199,28 @@ module Groonga end alias_method :int64, :integer64 + # Defines a 8 bit unsigned integer column named @name at . + # + # @param [String or Symbol] name the column name + # @param [Hash] options ({}) the options + # @see Groonga::Schema::TableDefinition#column for + # available @options at . + def unsigned_integer8(name, options={}) + column(name, "UInt8", options) + end + alias_method :uint8, :unsigned_integer8 + + # Defines a 16 bit unsigned integer column named @name at . + # + # @param [String or Symbol] name the column name + # @param [Hash] options ({}) the options + # @see Groonga::Schema::TableDefinition#column for + # available @options at . + def unsigned_integer16(name, options={}) + column(name, "UInt16", options) + end + alias_method :uint16, :unsigned_integer16 + # ??? _name_ ?32bit???????????????? # # _options_ ???????? Modified: test/test-schema.rb (+32 -0) =================================================================== --- test/test-schema.rb 2011-11-28 08:01:01 +0000 (ce04fe2) +++ test/test-schema.rb 2011-12-12 14:08:08 +0000 (c7741d2) @@ -343,6 +343,22 @@ class SchemaTest < Test::Unit::TestCase end end + def test_integer8_column + assert_nil(context["Posts.rate"]) + Groonga::Schema.create_table("Posts") do |table| + table.integer8 :rate + end + assert_equal(context["Int8"], context["Posts.rate"].range) + end + + def test_integer16_column + assert_nil(context["Posts.rate"]) + Groonga::Schema.create_table("Posts") do |table| + table.integer16 :rate + end + assert_equal(context["Int16"], context["Posts.rate"].range) + end + def test_integer32_column assert_nil(context["Posts.rate"]) Groonga::Schema.create_table("Posts") do |table| @@ -359,6 +375,22 @@ class SchemaTest < Test::Unit::TestCase assert_equal(context["Int64"], context["Posts.rate"].range) end + def test_unsigned_integer8_column + assert_nil(context["Posts.n_viewed"]) + Groonga::Schema.create_table("Posts") do |table| + table.unsigned_integer8 :n_viewed + end + assert_equal(context["UInt8"], context["Posts.n_viewed"].range) + end + + def test_unsigned_integer16_column + assert_nil(context["Posts.n_viewed"]) + Groonga::Schema.create_table("Posts") do |table| + table.unsigned_integer16 :n_viewed + end + assert_equal(context["UInt16"], context["Posts.n_viewed"].range) + end + def test_unsigned_integer32_column assert_nil(context["Posts.n_viewed"]) Groonga::Schema.create_table("Posts") do |table| From null+ranguba at clear-code.com Mon Dec 12 09:20:01 2011 From: null+ranguba at clear-code.com (null+ranguba at clear-code.com) Date: Mon, 12 Dec 2011 14:20:01 +0000 Subject: [groonga-commit:4159] ranguba/rroonga [master] [schema] use WGS84GeoPoint as the default geo point. Message-ID: <20111212142729.815F12C43EB@taiyaki.ru> Kouhei Sutou 2011-12-12 14:20:01 +0000 (Mon, 12 Dec 2011) New Revision: 2a69b3e5a202afb2e76c3b4b78a1df3e64857a05 Log: [schema] use WGS84GeoPoint as the default geo point. Modified files: lib/groonga/schema.rb test/test-schema-type.rb test/test-schema.rb Modified: lib/groonga/schema.rb (+2 -0) =================================================================== --- lib/groonga/schema.rb 2011-12-12 14:18:54 +0000 (ce9f27c) +++ lib/groonga/schema.rb 2011-12-12 14:20:01 +0000 (0a4e95c) @@ -544,6 +544,7 @@ module Groonga "date" => "Time", "boolean" => "Bool", "tokyo_geo_point" => "TokyoGeoPoint", + "geo_point" => "WGS84GeoPoint", "wgs84_geo_point" => "WGS84GeoPoint", "delimit" => "TokenDelimit", "token_delimit" => "TokenDelimit", @@ -1358,6 +1359,7 @@ module Groonga def wgs84_geo_point(name, options={}) column(name, "WGS84GeoPoint", options) end + alias_method :geo_point, :wgs84_geo_point # @private def [](name, definition_class=nil) Modified: test/test-schema-type.rb (+1 -0) =================================================================== --- test/test-schema-type.rb 2011-12-12 14:18:54 +0000 (b1d90de) +++ test/test-schema-type.rb 2011-12-12 14:20:01 +0000 (1115e3f) @@ -109,6 +109,7 @@ class SchemaTypeTest < Test::Unit::TestCase end def test_normalize_wgs84_geo_point + assert_normalize_type("WGS84GeoPoint", "geo_point") assert_normalize_type("WGS84GeoPoint", "wgs84_geo_point") assert_normalize_type("WGS84GeoPoint", "WGS84GeoPoint") end Modified: test/test-schema.rb (+8 -0) =================================================================== --- test/test-schema.rb 2011-12-12 14:18:54 +0000 (589aba7) +++ test/test-schema.rb 2011-12-12 14:20:01 +0000 (1ca90d2) @@ -481,6 +481,14 @@ class SchemaTest < Test::Unit::TestCase assert_equal(context["WGS84GeoPoint"], context["Posts.location"].range) end + def test_geo_point_column + assert_nil(context["Posts.location"]) + Groonga::Schema.create_table("Posts") do |table| + table.geo_point :location + end + assert_equal(context["WGS84GeoPoint"], context["Posts.location"].range) + end + def test_remove_column Groonga::Schema.create_table("Posts") do |table| table.long_text :content From null+ranguba at clear-code.com Mon Dec 12 09:16:29 2011 From: null+ranguba at clear-code.com (null+ranguba at clear-code.com) Date: Mon, 12 Dec 2011 14:16:29 +0000 Subject: [groonga-commit:4160] ranguba/rroonga [master] [schema] support shortcuts for Int8, Int16, UInt8 and UInt16. Message-ID: <20111212142729.6DA222C4309@taiyaki.ru> Kouhei Sutou 2011-12-12 14:16:29 +0000 (Mon, 12 Dec 2011) New Revision: 130fcfb4a9432219dc6e58e1cad73f750c2ccc00 Log: [schema] support shortcuts for Int8, Int16, UInt8 and UInt16. Modified files: lib/groonga/schema.rb test/test-schema-type.rb Modified: lib/groonga/schema.rb (+8 -0) =================================================================== --- lib/groonga/schema.rb 2011-12-12 14:13:39 +0000 (8042052) +++ lib/groonga/schema.rb 2011-12-12 14:16:29 +0000 (e1b50dc) @@ -516,6 +516,10 @@ module Groonga "text" => "Text", "binary" => "LongText", "long_text" => "LongText", + "int8" => "Int8", + "integer8" => "Int8", + "int16" => "Int16", + "integer16" => "Int16", "int" => "Int32", "integer" => "Int32", "int32" => "Int32", @@ -523,6 +527,10 @@ module Groonga "decimal" => "Int64", "int64" => "Int64", "integer64" => "Int64", + "uint8" => "UInt8", + "unsigned_integer8" => "UInt8", + "uint16" => "UInt16", + "unsigned_integer16" => "UInt16", "uint" => "UInt32", "unsigned_integer" => "UInt32", "uint32" => "UInt32", Modified: test/test-schema-type.rb (+24 -0) =================================================================== --- test/test-schema-type.rb 2011-12-12 14:13:39 +0000 (33bf509) +++ test/test-schema-type.rb 2011-12-12 14:16:29 +0000 (50b59a5) @@ -33,6 +33,18 @@ class SchemaTypeTest < Test::Unit::TestCase assert_normalize_type("LongText", "LongText") end + def test_normalize_integer8 + assert_normalize_type("Int8", "int8") + assert_normalize_type("Int8", "integer8") + assert_normalize_type("Int8", "Int8") + end + + def test_normalize_integer16 + assert_normalize_type("Int16", "int16") + assert_normalize_type("Int16", "integer16") + assert_normalize_type("Int16", "Int16") + end + def test_normalize_integer32 assert_normalize_type("Int32", "int") assert_normalize_type("Int32", "integer") @@ -47,6 +59,18 @@ class SchemaTypeTest < Test::Unit::TestCase assert_normalize_type("Int64", "Int64") end + def test_normalize_unsigned_integer8 + assert_normalize_type("UInt8", "uint8") + assert_normalize_type("UInt8", "unsigned_integer8") + assert_normalize_type("UInt8", "UInt8") + end + + def test_normalize_unsigned_integer16 + assert_normalize_type("UInt16", "uint16") + assert_normalize_type("UInt16", "unsigned_integer16") + assert_normalize_type("UInt16", "UInt16") + end + def test_normalize_unsigned_integer32 assert_normalize_type("UInt32", "uint") assert_normalize_type("UInt32", "unsigned_integer") From null+ranguba at clear-code.com Mon Dec 12 09:18:54 2011 From: null+ranguba at clear-code.com (null+ranguba at clear-code.com) Date: Mon, 12 Dec 2011 14:18:54 +0000 Subject: [groonga-commit:4161] ranguba/rroonga [master] [schema] support shortcuts for TokyoGeoPoint and WGS84GeoPoint. Message-ID: <20111212142729.7784D2C43E6@taiyaki.ru> Kouhei Sutou 2011-12-12 14:18:54 +0000 (Mon, 12 Dec 2011) New Revision: cf5c89b54e69b672fd8d5efedfc3ce90b12258ff Log: [schema] support shortcuts for TokyoGeoPoint and WGS84GeoPoint. Modified files: lib/groonga/schema.rb test/test-schema-type.rb Modified: lib/groonga/schema.rb (+2 -0) =================================================================== --- lib/groonga/schema.rb 2011-12-12 14:16:29 +0000 (e1b50dc) +++ lib/groonga/schema.rb 2011-12-12 14:18:54 +0000 (ce9f27c) @@ -543,6 +543,8 @@ module Groonga "time" => "Time", "date" => "Time", "boolean" => "Bool", + "tokyo_geo_point" => "TokyoGeoPoint", + "wgs84_geo_point" => "WGS84GeoPoint", "delimit" => "TokenDelimit", "token_delimit" => "TokenDelimit", "unigram" => "TokenUnigram", Modified: test/test-schema-type.rb (+10 -0) =================================================================== --- test/test-schema-type.rb 2011-12-12 14:16:29 +0000 (50b59a5) +++ test/test-schema-type.rb 2011-12-12 14:18:54 +0000 (b1d90de) @@ -103,6 +103,16 @@ class SchemaTypeTest < Test::Unit::TestCase assert_normalize_type("Bool", "Bool") end + def test_normalize_tokyo_geo_point + assert_normalize_type("TokyoGeoPoint", "tokyo_geo_point") + assert_normalize_type("TokyoGeoPoint", "TokyoGeoPoint") + end + + def test_normalize_wgs84_geo_point + assert_normalize_type("WGS84GeoPoint", "wgs84_geo_point") + assert_normalize_type("WGS84GeoPoint", "WGS84GeoPoint") + end + def test_normalize_delimit assert_normalize_type("TokenDelimit", "delimit") assert_normalize_type("TokenDelimit", "token_delimit") From null+ranguba at clear-code.com Mon Dec 12 09:25:26 2011 From: null+ranguba at clear-code.com (null+ranguba at clear-code.com) Date: Mon, 12 Dec 2011 14:25:26 +0000 Subject: [groonga-commit:4162] ranguba/rroonga [master] [schema][dumper] support Boolean and more built-in types. Message-ID: <20111212142729.8AB1F2C43EC@taiyaki.ru> Kouhei Sutou 2011-12-12 14:25:26 +0000 (Mon, 12 Dec 2011) New Revision: 95a04c48810028ebf6825572c636f7b2807e51b3 Log: [schema][dumper] support Boolean and more built-in types. Reported by @mashiro. Thanks!!! Modified files: lib/groonga/dumper.rb test/test-schema-dumper.rb Modified: lib/groonga/dumper.rb (+10 -8) =================================================================== --- lib/groonga/dumper.rb 2011-12-12 14:20:01 +0000 (ca4e291) +++ lib/groonga/dumper.rb 2011-12-12 14:25:26 +0000 (54bfda3) @@ -302,14 +302,12 @@ module Groonga def column_method(column) range = column.range case range.name - when "Int32" - "integer32" - when "Int64" - "integer64" - when "UInt32" - "unsigned_integer32" - when "UInt64" - "unsigned_integer64" + when "Bool" + "boolean" + when /\AInt(8|16|32|64)\z/ + "integer#{$1}" + when /\AUInt(8|16|32|64)\z/ + "unsigned_integer#{$1}" when "Float" "float" when "Time" @@ -320,6 +318,10 @@ module Groonga "text" when "LongText" "long_text" + when "TokyoGeoPoint" + "tokyo_geo_point" + when "WGS84GeoPoint" + "wgs84_geo_point" else raise ArgumentError, "unsupported column: #{column.inspect}" end Modified: test/test-schema-dumper.rb (+48 -0) =================================================================== --- test/test-schema-dumper.rb 2011-12-12 14:20:01 +0000 (2959251) +++ test/test-schema-dumper.rb 2011-12-12 14:25:26 +0000 (065925f) @@ -28,6 +28,29 @@ class SchemaDumperTest < Test::Unit::TestCase end end + def define_built_in_types_schema + Groonga::Schema.define do |schema| + schema.create_table("Posts") do |table| + table.boolean :public + table.int8 :int8 + table.uint8 :uint8 + table.int16 :int16 + table.uint16 :uint16 + table.int32 :int32 + table.uint32 :uint32 + table.int64 :int64 + table.uint64 :uint64 + table.float :vote_average + table.time :published_at + table.short_text :title + table.text :content + table.long_text :attachment + table.tokyo_geo_point :location_tokyo + table.wgs84_geo_point :location_wgs84 + end + end + end + def define_reference_schema Groonga::Schema.define do |schema| schema.create_table("Items") do |table| @@ -79,6 +102,31 @@ end EOS end + def test_built_in_types + define_built_in_types_schema + assert_equal(<<-EOS, dump) +create_table("Posts", + :force => true) do |table| + table.long_text("attachment") + table.text("content") + table.integer16("int16") + table.integer32("int32") + table.integer64("int64") + table.integer8("int8") + table.tokyo_geo_point("location_tokyo") + table.wgs84_geo_point("location_wgs84") + table.boolean("public") + table.time("published_at") + table.short_text("title") + table.unsigned_integer16("uint16") + table.unsigned_integer32("uint32") + table.unsigned_integer64("uint64") + table.unsigned_integer8("uint8") + table.float("vote_average") +end +EOS + end + def test_reference define_reference_schema assert_equal(<<-EOS, dump) From null+ranguba at clear-code.com Thu Dec 15 22:56:03 2011 From: null+ranguba at clear-code.com (null+ranguba at clear-code.com) Date: Fri, 16 Dec 2011 03:56:03 +0000 Subject: [groonga-commit:4163] ranguba/rroonga [master] [schema] accept type object as column type. fixes #1002 Message-ID: <20111216035718.C84202C417F@taiyaki.ru> Kouhei Sutou 2011-12-16 03:56:03 +0000 (Fri, 16 Dec 2011) New Revision: 581147b81e76832a28d9f4edaa989ccefa1be3bc Log: [schema] accept type object as column type. fixes #1002 Modified files: lib/groonga/schema.rb test/test-schema.rb Modified: lib/groonga/schema.rb (+9 -7) =================================================================== --- lib/groonga/schema.rb 2011-12-12 14:25:26 +0000 (0a4e95c) +++ lib/groonga/schema.rb 2011-12-16 03:56:03 +0000 (0dc0d3c) @@ -1740,23 +1740,25 @@ module Groonga end end table.define_column(@name, - normalize_type(context), + resolved_type(context), options) end private - def normalize_type(context) + def resolved_type(context) + return @type if @type.is_a?(Groonga::Object) if @type.respond_to?(:call) - resolved_type = @type.call(context) + resolved_type_name = @type.call(context) else - resolved_type = @type + resolved_type_name = @type end - Schema.normalize_type(resolved_type, :context => context) + normalized_type_name = Schema.normalize_type(resolved_type_name, + :context => context) + context[normalized_type_name] end def same_column?(context, column) - # TODO: should check column type and other options. - column.range == context[normalize_type(context)] + column.range == resolved_type(context) end def define_options(context, table) Modified: test/test-schema.rb (+25 -11) =================================================================== --- test/test-schema.rb 2011-12-12 14:25:26 +0000 (1ca90d2) +++ test/test-schema.rb 2011-12-16 03:56:03 +0000 (8f1099a) @@ -512,26 +512,40 @@ class SchemaTest < Test::Unit::TestCase assert_equal("Posts.body", content.name) end - def test_column_again - Groonga::Schema.create_table("Posts") do |table| - table.text :content + class DefineColumnAgainTest < self + def test_same_option + Groonga::Schema.create_table("Posts") do |table| + table.text :content + end + + assert_nothing_raised do + Groonga::Schema.create_table("Posts") do |table| + table.text :content + end + end end - assert_nothing_raised do + def test_difference_type Groonga::Schema.create_table("Posts") do |table| table.text :content end - end - end - def test_column_again_with_difference_type - Groonga::Schema.create_table("Posts") do |table| - table.text :content + assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do + Groonga::Schema.create_table("Posts") do |table| + table.integer :content + end + end end - assert_raise(Groonga::Schema::ColumnCreationWithDifferentOptions) do + def test_same_option_by_groonga_object Groonga::Schema.create_table("Posts") do |table| - table.integer :content + table.text :content + end + + assert_nothing_raised do + Groonga::Schema.create_table("Posts") do |table| + table.column(:content, Groonga["Text"]) + end end end end From null+ranguba at clear-code.com Sun Dec 18 20:11:53 2011 From: null+ranguba at clear-code.com (null+ranguba at clear-code.com) Date: Mon, 19 Dec 2011 01:11:53 +0000 Subject: [groonga-commit:4164] ranguba/rroonga [master] add Groonga::VariableSizeColumn#compressed?. fixes #1004 Message-ID: <20111219011314.AE7BA2C414D@taiyaki.ru> Kouhei Sutou 2011-12-19 01:11:53 +0000 (Mon, 19 Dec 2011) New Revision: 6aa26d1599a7fc0f1729facd88de2969667bd23d Log: add Groonga::VariableSizeColumn#compressed?. fixes #1004 Modified files: ext/groonga/rb-grn-variable-size-column.c test/test-variable-size-column.rb Modified: ext/groonga/rb-grn-variable-size-column.c (+77 -1) =================================================================== --- ext/groonga/rb-grn-variable-size-column.c 2011-12-16 03:56:03 +0000 (85e6212) +++ ext/groonga/rb-grn-variable-size-column.c 2011-12-19 01:11:53 +0000 (219e194) @@ -1,6 +1,6 @@ /* -*- coding: utf-8; c-file-style: "ruby" -*- */ /* - Copyright (C) 2009 Kouhei Sutou + Copyright (C) 2009-2011 Kouhei Sutou This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -29,6 +29,80 @@ VALUE rb_cGrnVariableSizeColumn; */ /* + * Document-method: compressed? + * + * call-seq: + * column.compressed? -> boolean + * column.compressed?(type) -> boolean + * + * Returns whether the column is compressed or not. If + * @type@ is specified, it returns whether the column is + * compressed by @type@ or not. + * + * @return [Boolean] whether the column is compressed or not. + * @param [:zlib, :lzo] type (nil) If @type@ isn't @nil@, + * it checks whether specified compressed type is used or + * not. + * @since 1.3.1 + */ +static VALUE +rb_grn_variable_size_column_compressed_p (int argc, VALUE *argv, VALUE self) +{ + RbGrnColumn *rb_grn_column; + grn_ctx *context = NULL; + grn_obj *column; + grn_obj_flags flags; + VALUE type; + grn_bool compressed_p = GRN_FALSE; + grn_bool accept_any_type = GRN_FALSE; + grn_bool need_zlib_check = GRN_FALSE; + grn_bool need_lzo_check = GRN_FALSE; + + rb_scan_args(argc, argv, "01", &type); + + if (NIL_P(type)) { + accept_any_type = GRN_TRUE; + } else { + if (rb_grn_equal_option(type, "zlib")) { + need_zlib_check = GRN_TRUE; + } else if (rb_grn_equal_option(type, "lzo")) { + need_lzo_check = GRN_TRUE; + } else { + rb_raise(rb_eArgError, + "compressed type should be <:zlib> or <:lzo>: <%s>", + rb_grn_inspect(type)); + } + } + + rb_grn_column = SELF(self); + rb_grn_object_deconstruct(RB_GRN_OBJECT(rb_grn_column), &column, &context, + NULL, NULL, + NULL, NULL); + + flags = column->header.flags; + switch (flags & GRN_OBJ_COMPRESS_MASK) { + case GRN_OBJ_COMPRESS_ZLIB: + if (accept_any_type || need_zlib_check) { + grn_obj support_p; + GRN_BOOL_INIT(&support_p, 0); + grn_obj_get_info(context, NULL, GRN_INFO_SUPPORT_ZLIB, &support_p); + compressed_p = GRN_BOOL_VALUE(&support_p); + } + break; + case GRN_OBJ_COMPRESS_LZO: + if (accept_any_type || need_lzo_check) { + grn_obj support_p; + GRN_BOOL_INIT(&support_p, 0); + grn_obj_get_info(context, NULL, GRN_INFO_SUPPORT_LZO, &support_p); + compressed_p = GRN_BOOL_VALUE(&support_p); + } + break; + } + + return CBOOL2RVAL(compressed_p); +} + +/* * Document-method: defrag * * call-seq: @@ -77,6 +151,8 @@ rb_grn_init_variable_size_column (VALUE mGrn) rb_cGrnVariableSizeColumn = rb_define_class_under(mGrn, "VariableSizeColumn", rb_cGrnColumn); + rb_define_method(rb_cGrnVariableSizeColumn, "compressed?", + rb_grn_variable_size_column_compressed_p, -1); rb_define_method(rb_cGrnVariableSizeColumn, "defrag", rb_grn_variable_size_column_defrag, -1); } Modified: test/test-variable-size-column.rb (+30 -0) =================================================================== --- test/test-variable-size-column.rb 2011-12-16 03:56:03 +0000 (e06db2a) +++ test/test-variable-size-column.rb 2011-12-19 01:11:53 +0000 (93deac0) @@ -62,6 +62,36 @@ class VariableSizeColumnTest < Test::Unit::TestCase assert_not_predicate(@nick_names, :scalar?) end + def test_compressed? + description = @users.define_column("description", "ShortText", + :compress => :zlib) + if context.support_zlib? + assert_predicate(description, :compressed?) + else + assert_not_predicate(description, :compressed?) + end + end + + def test_compressed_zlib? + description = @users.define_column("description", "ShortText", + :compress => :zlib) + if context.support_zlib? + assert_send([description, :compressed?, :zlib]) + else + assert_not_send([description, :compressed?, :zlib]) + end + end + + def test_compressed_lzo? + description = @users.define_column("description", "ShortText", + :compress => :lzo) + if context.support_lzo? + assert_send([description, :compressed?, :lzo]) + else + assert_not_send([description, :compressed?, :lzo]) + end + end + def test_inspect assert_equal("#, " +