fluent-plugin-cassandra-json 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/fluent-plugin-cassandra-json.gemspec +1 -1
- data/lib/fluent/plugin/out_cassandra_json.rb +4 -2
- data/test/plugin/test_out_cassandra_json.rb +88 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de8e8cdfc8a0ee72d199f0e3529b59ea56eb087afd31e6f88cf50c48d8ac426a
|
4
|
+
data.tar.gz: 8f41c9632542d10f41fccd3998273a6baec5f911ca70e788bac2e84a71181b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3533891f9b9e23ed8d5a06c2a9d0ec9f6f8efe6eb7b15bc0dd5ded34536efd85546a36a830c01b41bf755e20d8efd59c8bb28e85642a231bf7775c2171907741
|
7
|
+
data.tar.gz: 760a800663413e5de4d4447a93d36b49acba6a261eec417108bee24ff13267ac385da542fafc85b706c1f5c9cf4360089c81814213c2491b175a3b3e97e9d687
|
data/README.md
CHANGED
@@ -87,6 +87,14 @@ Use TTL option on INSERT
|
|
87
87
|
|
88
88
|
Specify whether this statement can be retried safely on timeout
|
89
89
|
|
90
|
+
Default value: `true`.
|
91
|
+
|
92
|
+
### default_unset (bool) (optional)
|
93
|
+
|
94
|
+
Specify whether column not defined in the JSON is set to null or is ignored (If false, column not defined in the JSON is set to null. It is cassandra default)
|
95
|
+
|
96
|
+
Default value: `false`.
|
97
|
+
|
90
98
|
### skip_invalid_rows (bool) (optional)
|
91
99
|
|
92
100
|
Treat request as success, even if invalid rows exist
|
@@ -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.
|
6
|
+
spec.version = "0.2.0"
|
7
7
|
spec.authors = ["joker1007"]
|
8
8
|
spec.email = ["kakyoin.hierophant@gmail.com"]
|
9
9
|
|
@@ -48,8 +48,10 @@ module Fluent
|
|
48
48
|
desc: "Use IF NOT EXIST option on INSERT"
|
49
49
|
config_param :ttl, :integer, default: nil,
|
50
50
|
desc: "Use TTL option on INSERT"
|
51
|
-
config_param :idempotent, :bool, default:
|
51
|
+
config_param :idempotent, :bool, default: true,
|
52
52
|
desc: "Specify whether this statement can be retried safely on timeout"
|
53
|
+
config_param :default_unset, :bool, default: false,
|
54
|
+
desc: "Specify whether column not defined in the JSON is set to null or is ignored (If false, column not defined in the JSON is set to null. It is cassandra default)"
|
53
55
|
|
54
56
|
config_param :skip_invalid_rows, :bool, default: true,
|
55
57
|
desc: "Treat request as success, even if invalid rows exist"
|
@@ -110,7 +112,7 @@ module Fluent
|
|
110
112
|
futures = chunk.open do |io|
|
111
113
|
io.map do |line|
|
112
114
|
line.chomp!
|
113
|
-
cql = "INSERT INTO #{keyspace}.#{table} JSON '#{line.gsub("'", "''")}'"
|
115
|
+
cql = "INSERT INTO #{keyspace}.#{table} JSON '#{line.gsub("'", "''")}'#{@default_unset ? " DEFAULT UNSET" : ""}"
|
114
116
|
cql << " IF NOT EXISTS" if @if_not_exists
|
115
117
|
cql << " USING TTL #{@ttl}" if @ttl && @ttl > 0
|
116
118
|
@log.debug(cql)
|
@@ -148,6 +148,94 @@ class CassandraJsonOutputTest < Test::Unit::TestCase
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
+
test "write data (default_unset is false)" do
|
152
|
+
conf = %[
|
153
|
+
hosts #{ENV.fetch("CASSANDRA_HOST", "127.0.0.1")}
|
154
|
+
port #{ENV.fetch("CASSANDRA_PORT", "9042")}
|
155
|
+
keyspace test_keyspace
|
156
|
+
table test_table
|
157
|
+
default_unset false
|
158
|
+
]
|
159
|
+
driver = create_driver(conf)
|
160
|
+
time = Time.local(2018, 5, 8, 14, 10, 5)
|
161
|
+
data = {
|
162
|
+
"id" => 1,
|
163
|
+
"col1" => "textdata",
|
164
|
+
"col2" => time,
|
165
|
+
"col3" => true,
|
166
|
+
"col4" => 1.23,
|
167
|
+
"col5" => [1, 2, 3],
|
168
|
+
"col6" => ["one", "two", "three"],
|
169
|
+
"col7" => {"key1" => "val1", "key2" => "val2"},
|
170
|
+
}
|
171
|
+
data2 = {
|
172
|
+
"id" => 1,
|
173
|
+
"col1" => "textdata2",
|
174
|
+
}
|
175
|
+
driver.run do
|
176
|
+
driver.feed("tag", Time.now.to_i, data)
|
177
|
+
driver.flush
|
178
|
+
result = @session.execute("SELECT * FROM test_keyspace.test_table")
|
179
|
+
assert { result.size == 1 }
|
180
|
+
driver.feed("tag", Time.now.to_i, data2)
|
181
|
+
end
|
182
|
+
|
183
|
+
result = @session.execute("SELECT * FROM test_keyspace.test_table")
|
184
|
+
assert { result.size == 1 }
|
185
|
+
|
186
|
+
first = result.each.to_a[0]
|
187
|
+
assert { first["id"] == 1 }
|
188
|
+
assert { first["col1"] == "textdata2" }
|
189
|
+
(2..7).each do |i|
|
190
|
+
assert { first["col#{i}"].nil? }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
test "write data (default_unset is true)" do
|
195
|
+
conf = %[
|
196
|
+
hosts #{ENV.fetch("CASSANDRA_HOST", "127.0.0.1")}
|
197
|
+
port #{ENV.fetch("CASSANDRA_PORT", "9042")}
|
198
|
+
keyspace test_keyspace
|
199
|
+
table test_table
|
200
|
+
default_unset true
|
201
|
+
]
|
202
|
+
driver = create_driver(conf)
|
203
|
+
time = Time.local(2018, 5, 8, 14, 10, 5)
|
204
|
+
data = {
|
205
|
+
"id" => 1,
|
206
|
+
"col1" => "textdata",
|
207
|
+
"col2" => time,
|
208
|
+
"col3" => true,
|
209
|
+
"col4" => 1.23,
|
210
|
+
"col5" => [1, 2, 3],
|
211
|
+
"col6" => ["one", "two", "three"],
|
212
|
+
"col7" => {"key1" => "val1", "key2" => "val2"},
|
213
|
+
}
|
214
|
+
data2 = {
|
215
|
+
"id" => 1,
|
216
|
+
"col1" => "textdata2",
|
217
|
+
}
|
218
|
+
driver.run do
|
219
|
+
driver.feed("tag", Time.now.to_i, data)
|
220
|
+
driver.flush
|
221
|
+
result = @session.execute("SELECT * FROM test_keyspace.test_table")
|
222
|
+
assert { result.size == 1 }
|
223
|
+
driver.feed("tag", Time.now.to_i, data2)
|
224
|
+
end
|
225
|
+
|
226
|
+
result = @session.execute("SELECT * FROM test_keyspace.test_table")
|
227
|
+
assert { result.size == 1 }
|
228
|
+
|
229
|
+
first = result.each.to_a[0]
|
230
|
+
expected = data.dup
|
231
|
+
expected["col1"] = "textdata2"
|
232
|
+
expected["col6"] = Set.new(data["col6"])
|
233
|
+
assert { first["id"] == expected["id"] }
|
234
|
+
(1..7).each do |i|
|
235
|
+
assert { first["col#{i}"] == expected["col#{i}"] }
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
151
239
|
private
|
152
240
|
|
153
241
|
def create_driver(conf = CONFIG)
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|