fluent-plugin-cassandra-json 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c364b934b9fb53c16a262267d5e02b1066c79f556bb66f1b2b8efec97a9e79d7
4
- data.tar.gz: f19d96c2ae49cb1dee50c5501255fba0ed7b5831af8355ad4991cbe69f517504
3
+ metadata.gz: 8f0a54cd332017c0ef51daa42703420d01cc81163a08c65bfc265c1672fea7d4
4
+ data.tar.gz: e74da50b90ac352caba817515223a17dea06eeac53011aa433c261a5e2160e9d
5
5
  SHA512:
6
- metadata.gz: 81a10a01729f9427ccd5bcb0163ba307d3e2278070475cf8e87ad4b26ce0d2bcc05e280df9f1da358a623e0bd753ded06a58e177ece25000b45f5017e19bdb7c
7
- data.tar.gz: 61cda410a57bf545a84fbcfc9ea2785452f62e6ea27f566b3a7f465e977676de6cc363ae792f925f080cda8bafe4d2d629c6b7d40a7950d4b4a89bada5235f34
6
+ metadata.gz: a1e5f642dc19ae1811f9f556a39e941fa4754e19bc7ac127a9dba64bab4abd285df56448b5b311c23bbec647ee0ff488d22acff81205728ac391c6e4431e9aca
7
+ data.tar.gz: d46fd63678806d8f7f194fc7044403142dd5954c70b8b4f459f41430efe7b822fae3e571b94626ce038618cfee54a3c5f40d6662eebad63ebd958b0d6f0a194b
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-cassandra-json"
6
- spec.version = "0.1.1"
6
+ spec.version = "0.1.2"
7
7
  spec.authors = ["joker1007"]
8
8
  spec.email = ["kakyoin.hierophant@gmail.com"]
9
9
 
@@ -69,7 +69,7 @@ module Fluent
69
69
  @cluster_options.merge!(username: @username) if @username
70
70
  @cluster_options.merge!(password: @password) if @password
71
71
  formatter_config = conf.elements("format")[0]
72
- @formatter = formatter_create(usage: 'out_bigquery_for_insert', type: 'json', conf: formatter_config)
72
+ @formatter = formatter_create(usage: 'out_cassandra_for_insert', type: 'json', conf: formatter_config)
73
73
  end
74
74
 
75
75
  def start
@@ -106,7 +106,7 @@ module Fluent
106
106
  futures = chunk.open do |io|
107
107
  io.map do |line|
108
108
  line.chomp!
109
- cql = "INSERT INTO #{keyspace}.#{table} JSON '#{line}'"
109
+ cql = "INSERT INTO #{keyspace}.#{table} JSON '#{line.gsub("'", "''")}'"
110
110
  cql << " IF NOT EXISTS" if @if_not_exists
111
111
  cql << " USING TTL #{@ttl}" if @ttl && @ttl > 0
112
112
  @log.debug(cql)
@@ -41,7 +41,110 @@ class CassandraJsonOutputTest < Test::Unit::TestCase
41
41
  assert { result.size == 1 }
42
42
 
43
43
  first = result.each.to_a[0]
44
- assert { first == data.tap { |d| d["col6"] = Set.new(%w(one two three)) } }
44
+ expected = data.dup
45
+ expected["col6"] = Set.new(data["col6"])
46
+ assert { first["id"] == expected["id"] }
47
+ (1..7).each do |i|
48
+ assert { first["col#{i}"] == expected["col#{i}"] }
49
+ end
50
+ end
51
+
52
+ test "quoted data" do
53
+ driver = create_driver
54
+ time = Time.local(2018, 5, 8, 14, 10, 5)
55
+ data = {
56
+ "id" => 1,
57
+ "col1" => "text'data",
58
+ "col2" => time,
59
+ "col3" => true,
60
+ "col4" => 1.23,
61
+ "col5" => [1, 2, 3],
62
+ "col6" => ["one", "t\"wo", "th'r''ee"],
63
+ "col7" => {"key1" => "val1", "key2" => "val2"},
64
+ }
65
+ invalid_data = data.merge("id" => "invalid")
66
+ driver.run do
67
+ driver.feed("tag", Time.now.to_i, data)
68
+ driver.feed("tag", Time.now.to_i, data)
69
+ driver.feed("tag", Time.now.to_i, invalid_data)
70
+ end
71
+ result = @session.execute("SELECT * FROM test_keyspace.test_table")
72
+ assert { result.size == 1 }
73
+
74
+ first = result.each.to_a[0]
75
+ data["col6"] = Set.new(data["col6"])
76
+ assert { first["id"] == data["id"] }
77
+ (1..7).each do |i|
78
+ assert { first["col#{i}"] == data["col#{i}"] }
79
+ end
80
+ end
81
+
82
+ test "write data (if not exist)" do
83
+ conf = %[
84
+ hosts #{ENV.fetch("CASSANDRA_HOST", "127.0.0.1")}
85
+ port #{ENV.fetch("CASSANDRA_PORT", "9042")}
86
+ keyspace test_keyspace
87
+ table test_table
88
+ if_not_exists true
89
+ ]
90
+ driver = create_driver(conf)
91
+ time = Time.local(2018, 5, 8, 14, 10, 5)
92
+ data = {
93
+ "id" => 1,
94
+ "col1" => "textdata",
95
+ "col2" => time,
96
+ "col3" => true,
97
+ "col4" => 1.23,
98
+ "col5" => [1, 2, 3],
99
+ "col6" => ["one", "two", "three"],
100
+ "col7" => {"key1" => "val1", "key2" => "val2"},
101
+ }
102
+ driver.run do
103
+ driver.feed("tag", Time.now.to_i, data)
104
+ end
105
+ result = @session.execute("SELECT * FROM test_keyspace.test_table")
106
+ assert { result.size == 1 }
107
+
108
+ first = result.each.to_a[0]
109
+ data["col6"] = Set.new(data["col6"])
110
+ assert { first["id"] == data["id"] }
111
+ (1..7).each do |i|
112
+ assert { first["col#{i}"] == data["col#{i}"] }
113
+ end
114
+ end
115
+
116
+ test "write data (ttl)" do
117
+ conf = %[
118
+ hosts #{ENV.fetch("CASSANDRA_HOST", "127.0.0.1")}
119
+ port #{ENV.fetch("CASSANDRA_PORT", "9042")}
120
+ keyspace test_keyspace
121
+ table test_table
122
+ ttl 30
123
+ ]
124
+ driver = create_driver(conf)
125
+ time = Time.local(2018, 5, 8, 14, 10, 5)
126
+ data = {
127
+ "id" => 1,
128
+ "col1" => "textdata",
129
+ "col2" => time,
130
+ "col3" => true,
131
+ "col4" => 1.23,
132
+ "col5" => [1, 2, 3],
133
+ "col6" => ["one", "two", "three"],
134
+ "col7" => {"key1" => "val1", "key2" => "val2"},
135
+ }
136
+ driver.run do
137
+ driver.feed("tag", Time.now.to_i, data)
138
+ end
139
+ result = @session.execute("SELECT * FROM test_keyspace.test_table")
140
+ assert { result.size == 1 }
141
+
142
+ first = result.each.to_a[0]
143
+ data["col6"] = Set.new(data["col6"])
144
+ assert { first["id"] == data["id"] }
145
+ (1..7).each do |i|
146
+ assert { first["col#{i}"] == data["col#{i}"] }
147
+ end
45
148
  end
46
149
 
47
150
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-cassandra-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-10 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler