Skip to content

Instantly share code, notes, and snippets.

@tylerflint
Created December 12, 2011 20:48
Show Gist options
  • Save tylerflint/1469025 to your computer and use it in GitHub Desktop.
Save tylerflint/1469025 to your computer and use it in GitHub Desktop.
monetdb create binary import
#!/usr/bin/env ruby
require 'rubygems'
require 'mongo'
db = Mongo::Connection.new.db('monet')
coll = db.collection('web_requests')
File.open('/Users/tylerflint/Desktop/monet-import.sql', 'a+') do |f|
coll.find().each do |row|
ai = row['ai']
ci = row['ci']
pd = row['pd']
rt = row['rt']
pt = row['pt']
t = row['t'].to_s.gsub(/ UTC/, '.000000')
if ai && ci && pd && rt && pt && t
if ai.length > 1 && ci.length > 1 && pd.length > 1 && rt > 0 && pt.length > 1 && t.length > 1
unless pt =~ /\|/
line = "#{row['ai']}|#{row['ci']}|#{row['pd']}|#{row['rt']}|#{row['pt']}|#{t}\n"
f.write(line)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment