fluent-plugin-cassandra-driver 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 7ac22674557433f0ea85c00863cee8ac7c59be11
4
- data.tar.gz: 7e2f89d4571c7cc7801e6386458212ea3a2f6d33
3
+ metadata.gz: fca7029206d19969af19c9cf4efd8ea790039d83
4
+ data.tar.gz: 2aac1bc2b292515c8257b9d3a2d9ef0718238398
5
5
  SHA512:
6
- metadata.gz: 5c9d9fac0898971fac9967c015af167e0155dd0fd8cffe4fa12a1c1005c94c5e44c6000609a428fe45e1c9d5ebe9d8d64b666577830d8734a776b44040e1c0d6
7
- data.tar.gz: 90128ed2a057a4618d1ce3b9104a8f635daaf7a4aeeb69e9b46d9e6dc6dcdeb763cb86238803b11ec557f0e8588270a088431ae6d008d52d8dc5e2ab533c3c56
6
+ metadata.gz: 37410f2a120900a86717907432110bfd39c1f56396dc99f531a023464325764448b817a564812c312c23937001226cad6be269b6cfd3309ea6bb1c7a01ca34b7
7
+ data.tar.gz: 100aadb2db5c245b5b387f57f001e7124fd15835de9be4862dfea64da1faaa2c98591c14c8920c474ba79ae22339c20ef899009455a0c3dfb19d988901e0595e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: fluent-plugin-cassandra-driver 0.0.2 ruby lib
5
+ # stub: fluent-plugin-cassandra-driver 0.0.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "fluent-plugin-cassandra-driver".freeze
9
- s.version = "0.0.2"
9
+ s.version = "0.0.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
@@ -27,6 +27,8 @@ Gem::Specification.new do |s|
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "fluent-plugin-cassandra-driver.gemspec",
30
+ "lib/fluent/plugin/mutators/string_mutator.rb",
31
+ "lib/fluent/plugin/mutators/timeuuid_mutator.rb",
30
32
  "lib/fluent/plugin/out_cassandra_driver.rb",
31
33
  "spec/spec.opts",
32
34
  "spec/spec_helper.rb"
@@ -0,0 +1,7 @@
1
+ module CassandraDriver
2
+ class StringMutator
3
+ def mutate(value)
4
+ "'#{value}'"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'cassandra'
2
+
3
+ module CassandraDriver
4
+ class TimeuuidMutator
5
+ @generator = Cassandra::Uuid::Generator.new
6
+
7
+ def mutate(value)
8
+ @generator.at(value).to_s
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,8 @@
1
1
  require 'cassandra'
2
2
  require 'msgpack'
3
3
  require 'json'
4
+ require 'mutators/string_mutator'
5
+ require 'mutators/timeuuid_mutator'
4
6
 
5
7
  module Fluent
6
8
  class CassandraCqlOutput < BufferedOutput
@@ -60,7 +62,7 @@ module Fluent
60
62
 
61
63
  def write(chunk)
62
64
  chunk.msgpack_each { |record|
63
- $log.info "Sending a new record to Cassandra: #{record.to_json}"
65
+ $log.debug "Sending a new record to Cassandra: #{record.to_json}"
64
66
 
65
67
  values = build_insert_values_string(self.schema.keys, self.data_keys, record, self.pop_data_keys)
66
68
 
@@ -76,6 +78,8 @@ module Fluent
76
78
 
77
79
  private
78
80
 
81
+ @mutators_map = {:string => ::CassandraDriver::StringMutator.new, :timeuuid => ::CassandraDriver::TimeuuidMutator.new}
82
+
79
83
  def get_session(hosts, keyspace)
80
84
  cluster = ::Cassandra.cluster(hosts: hosts)
81
85
 
@@ -84,11 +88,11 @@ module Fluent
84
88
 
85
89
  def build_insert_values_string(schema_keys, data_keys, record, pop_data_keys)
86
90
  values = data_keys.map.with_index do |key, index|
87
- if pop_data_keys
88
- self.schema[schema_keys[index]] == :string ? "'#{record.delete(key)}'" : record.delete(key)
89
- else
90
- self.schema[schema_keys[index]] == :string ? "'#{record[key]}'" : record[key]
91
- end
91
+ value = pop_data_keys ? record.delete(key) : record[key]
92
+ type = self.schema[schema_keys[index]]
93
+ mutator = @mutators_map.key?(type) ? @mutators_map[type] : nil
94
+
95
+ mutator ? mutator.mutate(value) : value
92
96
  end
93
97
 
94
98
  # if we have one more schema key than data keys,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-cassandra-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Lukyanov
@@ -125,6 +125,8 @@ files:
125
125
  - Rakefile
126
126
  - VERSION
127
127
  - fluent-plugin-cassandra-driver.gemspec
128
+ - lib/fluent/plugin/mutators/string_mutator.rb
129
+ - lib/fluent/plugin/mutators/timeuuid_mutator.rb
128
130
  - lib/fluent/plugin/out_cassandra_driver.rb
129
131
  - spec/spec.opts
130
132
  - spec/spec_helper.rb