Sha256: 3de3b7c9d5200a5f596d8dc24f0c2beec317ecf64383bc5ea2db7a6d9ab4e519

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

#!/usr/bin/env ruby
require 'rubygems'
require 'wukong'

# An example (and test) of streaming batches of data into distributed cassandra db
# Stream in whatever you like that has a key and value. Notice that you must
# have already defined a column space called 'Cruft' in storage-conf.xml as well
# as a column family called 'OhBaby'

class Mapper < Wukong::Streamer::CassandraStreamer

  # you must redefine the column space, batch size, and db-seeds  or they will
  # be defaults. For testing on local machine simply seed db with 127.0.0.1:9160

  def initialize *args
    self.column_space = 'Cruft'
    self.batch_size = 100
    self.db_seeds = "127.0.0.1:9160"
    super(*args)
    @iter = 0
  end

  def process key, value, *_, &blk
    insert_into_db(key, value)
    yield [key, value] if (@iter %10 == 0)
  end

  # you must specify the column family, key, and value here
  def insert_into_db key, value
    @iter += 1
    cassandra_db.insert(:OhBaby, key, {"value" => value}, :consistency => Cassandra::Consistency::ANY) unless key.blank?
  end
end

#
# Executes the script
#
Wukong::Script.new(
  Mapper,
  nil
).run

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wukong-1.5.4 examples/keystore/cassandra_batch_test.rb
wukong-1.5.3 examples/keystore/cassandra_batch_test.rb
wukong-1.5.2 examples/keystore/cassandra_batch_test.rb
wukong-1.5.1 examples/keystore/cassandra_batch_test.rb
wukong-1.5.0 examples/keystore/cassandra_batch_test.rb
wukong-1.4.12 examples/keystore/cassandra_batch_test.rb
wukong-1.4.11 examples/keystore/cassandra_batch_test.rb
wukong-1.4.10 examples/keystore/cassandra_batch_test.rb