td 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ == 2011-08-18 version 0.7.5
3
+
4
+ * set-schema: adds column instead of replacing all columns
5
+ * set-schema: adds -R, --reset option
6
+
7
+
2
8
  == 2011-08-18 version 0.7.4
3
9
 
4
10
  * Added set-schema subcommand
data/lib/td/api.rb CHANGED
@@ -125,7 +125,7 @@ class API
125
125
  name = m['name']
126
126
  type = (m['type'] || '?').to_sym
127
127
  count = (m['count'] || 0).to_i # TODO?
128
- schema = JSON.parse(m['schema']) # FIXME?
128
+ schema = JSON.parse(m['schema'] || '[]')
129
129
  result[name] = [type, schema, count]
130
130
  }
131
131
  return result
data/lib/td/client.rb CHANGED
@@ -245,8 +245,16 @@ class Schema
245
245
  @fields << Field.new(name, type)
246
246
  end
247
247
 
248
- def to_s
249
- @fields.map {|f| "#{f.name}:#{f.type}" }.join(',')
248
+ def merge(schema)
249
+ nf = @fields.dup
250
+ schema.fields.each {|f|
251
+ if i = nf.find_index {|sf| sf.name == f.name }
252
+ nf[i] = f
253
+ else
254
+ nf << f
255
+ end
256
+ }
257
+ Schema.new(nf)
250
258
  end
251
259
 
252
260
  def to_json(*args)
@@ -63,14 +63,33 @@ module Command
63
63
  def set_schema
64
64
  op = cmd_opt 'set-schema', :db_name, :table_name, :columns_?
65
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
+
66
73
  db_name, table_name, *columns = op.cmd_parse
67
74
 
75
+ if !reset && columns.empty?
76
+ puts op.to_s
77
+ exit 1
78
+ end
79
+
80
+ rmcols = []
81
+
68
82
  schema = Schema.new
69
83
  columns.each {|column|
70
84
  name, type = column.split(':',2)
71
85
  name = name.to_s
72
86
  type = type.to_s
73
87
 
88
+ if name.empty?
89
+ rmcols << type
90
+ next
91
+ end
92
+
74
93
  API.validate_column_name(name)
75
94
  type = API.normalize_type_name(type)
76
95
 
@@ -88,7 +107,12 @@ module Command
88
107
 
89
108
  client = get_client
90
109
 
91
- find_table(client, db_name, table_name)
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
92
116
 
93
117
  client.update_schema(db_name, table_name, schema)
94
118
 
data/lib/td/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
 
3
- VERSION = '0.7.4'
3
+ VERSION = '0.7.5'
4
4
 
5
5
  end
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: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 4
10
- version: 0.7.4
9
+ - 5
10
+ version: 0.7.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sadayuki Furuhashi