icebox 0.0.3 → 0.0.4
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.
- data/VERSION +1 -1
- data/bin/icebox +24 -1
- data/icebox.gemspec +2 -2
- data/lib/icebox.rb +9 -8
- data/test/test_icebox.rb +3 -23
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.4
|
data/bin/icebox
CHANGED
|
@@ -5,10 +5,33 @@ require 'optparse'
|
|
|
5
5
|
require 'icebox'
|
|
6
6
|
|
|
7
7
|
opts = OptionParser.new do |opts|
|
|
8
|
-
opts.banner = "
|
|
8
|
+
opts.banner = "
|
|
9
|
+
Icebox: Multitool for Infobright Community Edition
|
|
10
|
+
--------------------------------------------------
|
|
11
|
+
Usage:
|
|
12
|
+
#{File.basename(__FILE__)} create_table_as <database> <table> <select_query>
|
|
13
|
+
#{File.basename(__FILE__)} insert_into <database> <table> <select_query>
|
|
14
|
+
#{File.basename(__FILE__)} load_data_infile <database> <table> <csv_file>
|
|
15
|
+
#{File.basename(__FILE__)} [-h|-?|--help]
|
|
16
|
+
"
|
|
9
17
|
opts.on_tail("-h", "-?", "--help", "Show this message") do
|
|
10
18
|
puts opts
|
|
11
19
|
exit
|
|
12
20
|
end
|
|
13
21
|
end
|
|
14
22
|
opts.parse!
|
|
23
|
+
|
|
24
|
+
subcommand = ARGV.shift
|
|
25
|
+
case subcommand
|
|
26
|
+
when 'create_table_as'
|
|
27
|
+
db = ARGV.shift
|
|
28
|
+
Icebox.new(database: db).create_table_as *ARGV
|
|
29
|
+
when 'insert_into'
|
|
30
|
+
db = ARGV.shift
|
|
31
|
+
Icebox.new(database: db).insert_into *ARGV
|
|
32
|
+
when 'load_data_infile'
|
|
33
|
+
db = ARGV.shift
|
|
34
|
+
Icebox.new(database: db).insert_into *ARGV
|
|
35
|
+
else
|
|
36
|
+
puts opts
|
|
37
|
+
end
|
data/icebox.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{icebox}
|
|
8
|
-
s.version = "0.0.
|
|
8
|
+
s.version = "0.0.4"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Riley Goodside"]
|
|
12
|
-
s.date = %q{2011-10-
|
|
12
|
+
s.date = %q{2011-10-26}
|
|
13
13
|
s.default_executable = %q{icebox}
|
|
14
14
|
s.description = %q{Ruby library and command-line utility for working with Infobright Community Edition}
|
|
15
15
|
s.email = %q{riley.goodside@gmail.com}
|
data/lib/icebox.rb
CHANGED
|
@@ -9,20 +9,22 @@ module Icebox
|
|
|
9
9
|
class Icebox
|
|
10
10
|
attr_accessor :db
|
|
11
11
|
|
|
12
|
-
def initialize(
|
|
12
|
+
def initialize(db_or_options = {})
|
|
13
13
|
# Icebox is configurable using a YAML file in /etc/icebox.conf
|
|
14
14
|
# The root-level key :connections should be an array of option sets to be
|
|
15
15
|
# passed to the Sequel#mysql method. Right now, only the first is used.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
if @db.nil?
|
|
17
|
+
if db_or_options.class == Hash
|
|
19
18
|
begin
|
|
20
|
-
|
|
19
|
+
defaults = YAML.load(File.open("/etc/icebox.conf"))[:connections][0]
|
|
21
20
|
rescue
|
|
22
|
-
|
|
21
|
+
defaults = {database: 'test', socket: '/tmp/mysql-ib.sock'}
|
|
23
22
|
end
|
|
24
|
-
@db = Sequel.mysql(
|
|
23
|
+
@db = Sequel.mysql(defaults.merge(db_or_options))
|
|
24
|
+
else
|
|
25
|
+
@db = db_or_options
|
|
25
26
|
end
|
|
27
|
+
raise "Initialization of Icebox object failed" unless @db
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def load_data_infile(table, path=nil, opts={})
|
|
@@ -54,7 +56,7 @@ module Icebox
|
|
|
54
56
|
|
|
55
57
|
def insert_into(table, sql)
|
|
56
58
|
pipe = "/tmp/icebox_pipe_for_#{table}"
|
|
57
|
-
sql.sub
|
|
59
|
+
sql = sql.sub /\s*;\s*/, '' # Chop off semicolon if present
|
|
58
60
|
|
|
59
61
|
# Simultaneously export and re-import CSV through FIFO pipe:
|
|
60
62
|
@db.disconnect # Needed for fork; Reconnects automatically
|
|
@@ -81,7 +83,6 @@ module Icebox
|
|
|
81
83
|
"#{col[0]} #{col[1][:db_type]}"
|
|
82
84
|
end.join(',')
|
|
83
85
|
@db << "CREATE TABLE #{table} (#{fields_definition})"
|
|
84
|
-
|
|
85
86
|
insert_into table, "SELECT * FROM #{view}"
|
|
86
87
|
@db.drop_view view
|
|
87
88
|
end
|
data/test/test_icebox.rb
CHANGED
|
@@ -48,36 +48,16 @@ class TestIcebox < Test::Unit::TestCase
|
|
|
48
48
|
assert_equal BigDecimal.new("8675309.8675309"), t.order(:dc.desc).get(:dc)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
should "append
|
|
51
|
+
should "append data either from CSV or from SELECT query" do
|
|
52
52
|
@box.load_data_infile 'test_table', '/tmp/test_table.csv'
|
|
53
53
|
count_1 = @db[:test_table].count
|
|
54
|
-
@box.load_data_infile 'test_table', '/tmp/test_table.csv'
|
|
55
|
-
count_2 = @db[:test_table].count
|
|
56
|
-
|
|
57
|
-
assert_equal 3, count_1
|
|
58
|
-
assert_equal 6, count_2
|
|
59
|
-
end
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
@box.load_data_infile 'test_table', '/tmp/test_table.csv'
|
|
63
|
-
count_1 = @db[:test_table].count
|
|
55
|
+
@box.insert_into 'test_table', 'SELECT * FROM test_table'
|
|
64
56
|
@box.insert_into 'test_table', 'SELECT * FROM test_table'
|
|
65
57
|
count_2 = @db[:test_table].count
|
|
66
58
|
|
|
67
59
|
assert_equal 3, count_1
|
|
68
|
-
assert_equal
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
should "not have race conditions when #insert_into is called rapidly" do
|
|
72
|
-
@box.load_data_infile 'test_table', '/tmp/test_table.csv'
|
|
73
|
-
count_1 = @db[:test_table].count
|
|
74
|
-
5.times do
|
|
75
|
-
@box.insert_into 'test_table', 'SELECT * FROM test_table'
|
|
76
|
-
end
|
|
77
|
-
count_2 = @db[:test_table].count
|
|
78
|
-
|
|
79
|
-
assert_equal 3, count_1
|
|
80
|
-
assert_equal 3 * (2**5), count_2
|
|
60
|
+
assert_equal 12, count_2
|
|
81
61
|
end
|
|
82
62
|
|
|
83
63
|
teardown do
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: icebox
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.0.
|
|
5
|
+
version: 0.0.4
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Riley Goodside
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-10-
|
|
13
|
+
date: 2011-10-26 00:00:00 -04:00
|
|
14
14
|
default_executable: icebox
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
127
127
|
requirements:
|
|
128
128
|
- - ">="
|
|
129
129
|
- !ruby/object:Gem::Version
|
|
130
|
-
hash:
|
|
130
|
+
hash: 1669429252515157681
|
|
131
131
|
segments:
|
|
132
132
|
- 0
|
|
133
133
|
version: "0"
|