Skip to content

Commit

Permalink
out: use ShortText instead of Text by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Nov 5, 2014
1 parent ef29c39 commit d9a1d8e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
20 changes: 19 additions & 1 deletion lib/fluent/plugin/out_groonga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,10 @@ def guess
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?
Expand Down Expand Up @@ -468,6 +470,22 @@ def geo_point_values?
/\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
Expand Down
23 changes: 21 additions & 2 deletions test/output/test_type_guesser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,30 @@ def guess(sample_values)
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

0 comments on commit d9a1d8e

Please sign in to comment.