td 0.8.0 → 0.9.0
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/ChangeLog +6 -0
- data/README.rdoc +19 -2
- data/bin/td +2 -1
- data/lib/td/command/common.rb +21 -64
- data/lib/td/command/{database.rb → db.rb} +42 -31
- data/lib/td/command/help.rb +19 -0
- data/lib/td/command/import.rb +5 -7
- data/lib/td/command/job.rb +235 -0
- data/lib/td/command/list.rb +214 -85
- data/lib/td/command/query.rb +4 -234
- data/lib/td/command/schema.rb +96 -0
- data/lib/td/command/server.rb +1 -3
- data/lib/td/command/table.rb +17 -95
- data/lib/td/command/td.rb +1 -1
- data/lib/td/version.rb +1 -1
- metadata +24 -6
- data/lib/td/command/account.rb +0 -84
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
module TreasureData
|
3
|
+
module Command
|
4
|
+
|
5
|
+
def schema_show(op)
|
6
|
+
db_name, table_name = op.cmd_parse
|
7
|
+
|
8
|
+
client = get_client
|
9
|
+
table = get_table(client, db_name, table_name)
|
10
|
+
|
11
|
+
puts "#{db_name}.#{table_name} ("
|
12
|
+
table.schema.fields.each {|f|
|
13
|
+
puts " #{f.name}:#{f.type}"
|
14
|
+
}
|
15
|
+
puts ")"
|
16
|
+
end
|
17
|
+
|
18
|
+
def schema_set(op)
|
19
|
+
db_name, table_name, *columns = op.cmd_parse
|
20
|
+
schema = parse_columns(columns)
|
21
|
+
|
22
|
+
client = get_client
|
23
|
+
table = get_table(client, db_name, table_name)
|
24
|
+
|
25
|
+
client.update_schema(table.db_name, table.name, schema)
|
26
|
+
|
27
|
+
$stderr.puts "Schema is updated on #{db_name}.#{table_name} table."
|
28
|
+
end
|
29
|
+
|
30
|
+
def schema_add(op)
|
31
|
+
db_name, table_name, *columns = op.cmd_parse
|
32
|
+
schema = parse_columns(columns)
|
33
|
+
|
34
|
+
client = get_client
|
35
|
+
table = get_table(client, db_name, table_name)
|
36
|
+
|
37
|
+
schema = table.schema.merge(schema)
|
38
|
+
|
39
|
+
client.update_schema(table.db_name, table.name, schema)
|
40
|
+
|
41
|
+
$stderr.puts "Schema is updated on #{db_name}.#{table_name} table."
|
42
|
+
end
|
43
|
+
|
44
|
+
def schema_remove(op)
|
45
|
+
db_name, table_name, *columns = op.cmd_parse
|
46
|
+
|
47
|
+
client = get_client
|
48
|
+
table = get_table(client, db_name, table_name)
|
49
|
+
|
50
|
+
schema = table.schema
|
51
|
+
|
52
|
+
columns.each {|col|
|
53
|
+
deleted = false
|
54
|
+
schema.fields.delete_if {|f|
|
55
|
+
f.name == col && deleted = true
|
56
|
+
}
|
57
|
+
unless deleted
|
58
|
+
$stderr.puts "Column name '#{col}' does not exist."
|
59
|
+
exit 1
|
60
|
+
end
|
61
|
+
}
|
62
|
+
|
63
|
+
client.update_schema(table.db_name, table.name, schema)
|
64
|
+
|
65
|
+
$stderr.puts "Schema is updated on #{db_name}.#{table_name} table."
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def parse_columns(columns)
|
70
|
+
schema = Schema.new
|
71
|
+
|
72
|
+
columns.each {|column|
|
73
|
+
name, type = column.split(':',2)
|
74
|
+
name = name.to_s
|
75
|
+
type = type.to_s
|
76
|
+
|
77
|
+
API.validate_column_name(name)
|
78
|
+
type = API.normalize_type_name(type)
|
79
|
+
|
80
|
+
if schema.fields.find {|f| f.name == name }
|
81
|
+
$stderr.puts "Column name '#{name}' is duplicated."
|
82
|
+
exit 1
|
83
|
+
end
|
84
|
+
schema.add_field(name, type)
|
85
|
+
|
86
|
+
if name == 'v' || name == 'time'
|
87
|
+
$stderr.puts "Column name '#{name}' is reserved."
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
}
|
91
|
+
|
92
|
+
schema
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
data/lib/td/command/server.rb
CHANGED
data/lib/td/command/table.rb
CHANGED
@@ -2,17 +2,16 @@
|
|
2
2
|
module TreasureData
|
3
3
|
module Command
|
4
4
|
|
5
|
-
def
|
6
|
-
|
5
|
+
def table_create(op)
|
6
|
+
db_name, table_name = op.cmd_parse
|
7
7
|
|
8
|
+
#API.validate_database_name(db_name)
|
8
9
|
API.validate_table_name(table_name)
|
9
10
|
|
11
|
+
client = get_client
|
12
|
+
|
10
13
|
begin
|
11
|
-
|
12
|
-
client.create_log_table(db_name, table_name)
|
13
|
-
else
|
14
|
-
client.create_item_table(db_name, table_name)
|
15
|
-
end
|
14
|
+
client.create_log_table(db_name, table_name)
|
16
15
|
rescue NotFoundError
|
17
16
|
cmd_debug_error $!
|
18
17
|
$stderr.puts "Database '#{db_name}' does not exist."
|
@@ -26,24 +25,8 @@ module Command
|
|
26
25
|
|
27
26
|
$stderr.puts "Table '#{db_name}.#{table_name}' is created."
|
28
27
|
end
|
29
|
-
private :create_log_or_item_table
|
30
28
|
|
31
|
-
def
|
32
|
-
op = cmd_opt 'create-log-table', :db_name, :table_name
|
33
|
-
db_name, table_name = op.cmd_parse
|
34
|
-
|
35
|
-
create_log_or_item_table(true, db_name, table_name)
|
36
|
-
end
|
37
|
-
|
38
|
-
def create_item_table
|
39
|
-
op = cmd_opt 'create-item-table', :db_name, :table_name
|
40
|
-
db_name, table_name = op.cmd_parse
|
41
|
-
|
42
|
-
create_log_or_item_table(false, db_name, table_name)
|
43
|
-
end
|
44
|
-
|
45
|
-
def drop_table
|
46
|
-
op = cmd_opt 'drop-table', :db_name, :table_name
|
29
|
+
def table_delete(op)
|
47
30
|
db_name, table_name = op.cmd_parse
|
48
31
|
|
49
32
|
client = get_client
|
@@ -53,81 +36,20 @@ module Command
|
|
53
36
|
rescue NotFoundError
|
54
37
|
cmd_debug_error $!
|
55
38
|
$stderr.puts "Table '#{db_name}.#{table_name}' does not exist."
|
56
|
-
$stderr.puts "Use '#{$prog}
|
39
|
+
$stderr.puts "Use '#{$prog} table:list #{db_name}' to show list of the tables."
|
57
40
|
exit 1
|
58
41
|
end
|
59
42
|
|
60
43
|
$stderr.puts "Table '#{db_name}.#{table_name}' is deleted."
|
61
44
|
end
|
62
45
|
|
63
|
-
def
|
64
|
-
op = cmd_opt 'set-schema', :db_name, :table_name, :columns_?
|
65
|
-
|
66
|
-
op.banner << "\noptions:\n"
|
67
|
-
|
68
|
-
reset = nil
|
69
|
-
op.on('-R', '--reset', "Reset all columns", TrueClass) {|b|
|
70
|
-
reset = b
|
71
|
-
}
|
72
|
-
|
73
|
-
db_name, table_name, *columns = op.cmd_parse
|
74
|
-
|
75
|
-
if !reset && columns.empty?
|
76
|
-
puts op.to_s
|
77
|
-
exit 1
|
78
|
-
end
|
79
|
-
|
80
|
-
rmcols = []
|
81
|
-
|
82
|
-
schema = Schema.new
|
83
|
-
columns.each {|column|
|
84
|
-
name, type = column.split(':',2)
|
85
|
-
name = name.to_s
|
86
|
-
type = type.to_s
|
87
|
-
|
88
|
-
if name.empty?
|
89
|
-
rmcols << type
|
90
|
-
next
|
91
|
-
end
|
92
|
-
|
93
|
-
API.validate_column_name(name)
|
94
|
-
type = API.normalize_type_name(type)
|
95
|
-
|
96
|
-
if schema.fields.find {|f| f.name == name }
|
97
|
-
$stderr.puts "Column name '#{name}' is duplicated."
|
98
|
-
exit 1
|
99
|
-
end
|
100
|
-
schema.add_field(name, type)
|
101
|
-
|
102
|
-
if name == 'v' || name == 'time'
|
103
|
-
$stderr.puts "Column name '#{name}' is reserved."
|
104
|
-
exit 1
|
105
|
-
end
|
106
|
-
}
|
107
|
-
|
108
|
-
client = get_client
|
109
|
-
|
110
|
-
table = find_table(client, db_name, table_name)
|
111
|
-
|
112
|
-
unless reset
|
113
|
-
schema = table.schema.merge(schema)
|
114
|
-
schema.fields.delete_if {|f| rmcols.include?(f.name) }
|
115
|
-
end
|
116
|
-
|
117
|
-
client.update_schema(db_name, table_name, schema)
|
118
|
-
|
119
|
-
$stderr.puts "Schema is updated on #{db_name}.#{table_name} table."
|
120
|
-
$stderr.puts "Use '#{$prog} describe-table #{db_name} #{table_name}' to confirm the schema."
|
121
|
-
end
|
122
|
-
|
123
|
-
def show_tables
|
124
|
-
op = cmd_opt 'show-tables', :db_name?
|
46
|
+
def table_list(op)
|
125
47
|
db_name = op.cmd_parse
|
126
48
|
|
127
49
|
client = get_client
|
128
50
|
|
129
51
|
if db_name
|
130
|
-
db =
|
52
|
+
db = get_database(client, db_name)
|
131
53
|
dbs = [db]
|
132
54
|
else
|
133
55
|
dbs = client.databases
|
@@ -151,25 +73,23 @@ module Command
|
|
151
73
|
if rows.empty?
|
152
74
|
if db_name
|
153
75
|
$stderr.puts "Database '#{db_name}' has no tables."
|
154
|
-
$stderr.puts "Use '#{$prog} create
|
76
|
+
$stderr.puts "Use '#{$prog} table:create <db.table>' to create a table."
|
155
77
|
elsif dbs.empty?
|
156
78
|
$stderr.puts "There are no databases."
|
157
|
-
$stderr.puts "Use '#{$prog} create
|
79
|
+
$stderr.puts "Use '#{$prog} database:create <db>' to create a database."
|
158
80
|
else
|
159
81
|
$stderr.puts "There are no tables."
|
160
|
-
$stderr.puts "Use '#{$prog} create
|
82
|
+
$stderr.puts "Use '#{$prog} table:create <db.table>' to create a table."
|
161
83
|
end
|
162
84
|
end
|
163
85
|
end
|
164
86
|
|
165
|
-
def
|
166
|
-
op = cmd_opt 'describe-table', :db_name, :table_name
|
167
|
-
|
87
|
+
def table_show(op)
|
168
88
|
db_name, table_name = op.cmd_parse
|
169
89
|
|
170
90
|
client = get_client
|
171
91
|
|
172
|
-
table =
|
92
|
+
table = get_table(client, db_name, table_name)
|
173
93
|
|
174
94
|
puts "Name : #{table.db_name}.#{table.name}"
|
175
95
|
puts "Type : #{table.type}"
|
@@ -180,6 +100,8 @@ module Command
|
|
180
100
|
}
|
181
101
|
puts ")"
|
182
102
|
end
|
103
|
+
|
104
|
+
require 'td/command/import' # table:import
|
183
105
|
end
|
184
106
|
end
|
185
107
|
|
data/lib/td/command/td.rb
CHANGED
@@ -20,7 +20,7 @@ op.summary_indent = " "
|
|
20
20
|
puts op.to_s
|
21
21
|
puts ""
|
22
22
|
puts "commands:"
|
23
|
-
|
23
|
+
TreasureData::Command::List.show_help(op.summary_indent)
|
24
24
|
puts ""
|
25
25
|
puts "Type 'td help COMMAND' for more information on a specific command."
|
26
26
|
if errmsg
|
data/lib/td/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 9
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.9.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sadayuki Furuhashi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08
|
18
|
+
date: 2011-09-08 00:00:00 +09:00
|
19
19
|
default_executable: td
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -82,6 +82,22 @@ dependencies:
|
|
82
82
|
version: 0.8.0
|
83
83
|
type: :runtime
|
84
84
|
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: td-logger
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 19
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
- 2
|
97
|
+
- 2
|
98
|
+
version: 0.2.2
|
99
|
+
type: :runtime
|
100
|
+
version_requirements: *id005
|
85
101
|
description:
|
86
102
|
email:
|
87
103
|
executables:
|
@@ -92,12 +108,14 @@ extra_rdoc_files:
|
|
92
108
|
- ChangeLog
|
93
109
|
- README.rdoc
|
94
110
|
files:
|
95
|
-
- lib/td/command/account.rb
|
96
111
|
- lib/td/command/common.rb
|
97
|
-
- lib/td/command/
|
112
|
+
- lib/td/command/db.rb
|
113
|
+
- lib/td/command/help.rb
|
98
114
|
- lib/td/command/import.rb
|
115
|
+
- lib/td/command/job.rb
|
99
116
|
- lib/td/command/list.rb
|
100
117
|
- lib/td/command/query.rb
|
118
|
+
- lib/td/command/schema.rb
|
101
119
|
- lib/td/command/server.rb
|
102
120
|
- lib/td/command/table.rb
|
103
121
|
- lib/td/command/td.rb
|
data/lib/td/command/account.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
|
2
|
-
module TreasureData
|
3
|
-
module Command
|
4
|
-
|
5
|
-
def account
|
6
|
-
op = cmd_opt 'account', :user_name?
|
7
|
-
|
8
|
-
op.banner << "\noptions:\n"
|
9
|
-
|
10
|
-
force = false
|
11
|
-
op.on('-f', '--force', 'overwrite current setting', TrueClass) {|b|
|
12
|
-
force = true
|
13
|
-
}
|
14
|
-
|
15
|
-
user_name = op.cmd_parse
|
16
|
-
|
17
|
-
require 'td/config'
|
18
|
-
conf = nil
|
19
|
-
begin
|
20
|
-
conf = Config.read
|
21
|
-
rescue ConfigError
|
22
|
-
end
|
23
|
-
if conf && conf['account.user']
|
24
|
-
unless force
|
25
|
-
$stderr.puts "TreasureData account is already configured with '#{conf['account.user']}' account."
|
26
|
-
$stderr.puts "Add '-f' option to overwrite this setting."
|
27
|
-
exit 0
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
unless user_name
|
32
|
-
print "User name: "
|
33
|
-
line = STDIN.gets || ""
|
34
|
-
user_name = line.strip
|
35
|
-
end
|
36
|
-
|
37
|
-
if user_name.empty?
|
38
|
-
$stderr.puts "Canceled."
|
39
|
-
exit 0
|
40
|
-
end
|
41
|
-
|
42
|
-
client = nil
|
43
|
-
|
44
|
-
2.times do
|
45
|
-
begin
|
46
|
-
system "stty -echo" # TODO termios
|
47
|
-
print "Password: "
|
48
|
-
password = STDIN.gets || ""
|
49
|
-
password = password[0..-2] # strip \n
|
50
|
-
ensure
|
51
|
-
system "stty echo" # TODO termios
|
52
|
-
print "\n"
|
53
|
-
end
|
54
|
-
|
55
|
-
if password.empty?
|
56
|
-
$stderr.puts "Canceled."
|
57
|
-
exit 0
|
58
|
-
end
|
59
|
-
|
60
|
-
require 'td/client'
|
61
|
-
|
62
|
-
begin
|
63
|
-
client = Client.authenticate(user_name, password)
|
64
|
-
rescue TreasureData::AuthError
|
65
|
-
$stderr.puts "User name or password mismatched."
|
66
|
-
end
|
67
|
-
|
68
|
-
break if client
|
69
|
-
end
|
70
|
-
return unless client
|
71
|
-
|
72
|
-
$stderr.puts "Authenticated successfully."
|
73
|
-
|
74
|
-
conf ||= Config.new
|
75
|
-
conf["account.user"] = user_name
|
76
|
-
conf["account.apikey"] = client.apikey
|
77
|
-
conf.save
|
78
|
-
|
79
|
-
$stderr.puts "Use '#{$prog} create-database <db_name>' to create a database."
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|