[Groonga-commit] groonga/fluent-plugin-groonga at d9a1d8e [master] out: use ShortText instead of Text by default

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Nov 5 15:50:27 JST 2014


Kouhei Sutou	2014-11-05 15:50:27 +0900 (Wed, 05 Nov 2014)

  New Revision: d9a1d8e5c1c213f82501ede87d177a6f1caf5e41
  https://github.com/groonga/fluent-plugin-groonga/commit/d9a1d8e5c1c213f82501ede87d177a6f1caf5e41

  Message:
    out: use ShortText instead of Text by default

  Modified files:
    lib/fluent/plugin/out_groonga.rb
    test/output/test_type_guesser.rb

  Modified: lib/fluent/plugin/out_groonga.rb (+19 -1)
===================================================================
--- lib/fluent/plugin/out_groonga.rb    2014-11-05 15:44:47 +0900 (26a4b9b)
+++ lib/fluent/plugin/out_groonga.rb    2014-11-05 15:50:27 +0900 (6b195f2)
@@ -384,8 +384,10 @@ module Fluent
           return "Int64"         if int64_values?
           return "Float"         if float_values?
           return "WGS84GeoPoint" if geo_point_values?
+          return "LongText"      if long_text_values?
+          return "Text"          if text_values?
 
-          "Text"
+          "ShortText"
         end
 
         def vector?
@@ -468,6 +470,22 @@ module Fluent
               /\A-?\d+(?:\.\d+)[,x]-?\d+(?:\.\d+)\z/ =~ sample_value
           end
         end
+
+        MAX_SHORT_TEXT_SIZE = 2 ** 12
+        MAX_TEXT_SIZE       = 2 ** 16
+        def text_values?
+          @sample_values.any? do |sample_value|
+            sample_value.is_a?(String) and
+              sample_value.bytesize > MAX_SHORT_TEXT_SIZE
+          end
+        end
+
+        def long_text_values?
+          @sample_values.any? do |sample_value|
+            sample_value.is_a?(String) and
+              sample_value.bytesize > MAX_TEXT_SIZE
+          end
+        end
       end
 
       class Table

  Modified: test/output/test_type_guesser.rb (+21 -2)
===================================================================
--- test/output/test_type_guesser.rb    2014-11-05 15:44:47 +0900 (a7cc0fe)
+++ test/output/test_type_guesser.rb    2014-11-05 15:50:27 +0900 (9c786f7)
@@ -122,11 +122,30 @@ class OutputTypeGuesserTest < Test::Unit::TestCase
       end
     end
 
+    sub_test_case "ShortText" do
+      test "max" do
+        message = "X" * (2 ** 12)
+        assert_equal("ShortText", guess([message]))
+      end
+    end
+
     sub_test_case "Text" do
-      test "message" do
-        message = "failed to load data"
+      test "min" do
+        message = "X" * (2 ** 12 + 1)
         assert_equal("Text", guess([message]))
       end
+
+      test "max" do
+        message = "X" * (2 ** 16)
+        assert_equal("Text", guess([message]))
+      end
+    end
+
+    sub_test_case "LongText" do
+      test "min" do
+        message = "X" * (2 ** 16 + 1)
+        assert_equal("LongText", guess([message]))
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
下載 



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