Created
July 18, 2012 15:33
-
-
Save sergeyenin/3136954 to your computer and use it in GitHub Desktop.
CassandraModelCql inserting 1 mln rows and counting it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
$:.unshift File.expand_path("../../lib/",__FILE__) | |
require 'rubygems' | |
require 'bundler' | |
begin | |
Bundler.setup(:default, :development) | |
rescue Bundler::BundlerError => e | |
$stderr.puts e.message | |
$stderr.puts "Run `bundle install` to install missing gems" | |
exit e.status_code | |
end | |
require 'progress_bar' | |
require 'rake' | |
require 'cassandra_model_cql' | |
class Timeline < CassandraModelCql::Table | |
end | |
CassandraModelCql::Configuration.read({'host'=>'127.0.0.1:9160', 'default_keyspace'=>'boombastick'}) | |
bar = ProgressBar.new(10**6 , :bar, :counter, :percentage, :elapsed, :eta) | |
#dropping old data schema | |
#conn = CassandraModelCql::Connection.new('127.0.0.1:9160') | |
#conn.execute('DROP TABLE timeline;') | |
#conn.execute('DROP KEYSPACE boombastick;') | |
#creating data schema | |
conn = CassandraModelCql::Connection.new('127.0.0.1:9160') | |
conn.execute('CREATE KEYSPACE boombastick WITH strategy_class = \'SimpleStrategy\' AND strategy_options:replication_factor = 1;') | |
create_table_command = <<-eos | |
CREATE TABLE timeline ( | |
user_id varchar, | |
tweet_id int, | |
author varchar, | |
body varchar, | |
PRIMARY KEY (user_id, tweet_id)); | |
eos | |
conn.execute(create_table_command) | |
(1..10**6).each do |x| | |
Timeline.create({'user_id' => "'test_user#{x}'", 'tweet_id' => x, 'author' => "'test_author#{x}'", 'body' => "'test_body#{x}'"}) | |
bar.increment! 1000 if (x % 1000) == 0 | |
end | |
puts Timeline.count(nil, {:limit=>10**6}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment