Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/td/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ def database(db_name)
raise NotFoundError, "Database '#{db_name}' does not exist"
end

# @param [String] db
# @param [String] table
# @param [String] db_name
# @param [String] table_name
# @option params [Fixnum] :expire_days days to expire table
# @option params [Boolean] :include_v (true) include v column on Hive
# @option params [Boolean] :detect_schema (true) detect schema on import
# @return [true]
def create_log_table(db_name, table_name, params={})
Expand All @@ -108,10 +107,9 @@ def update_schema(db_name, table_name, schema)
@api.update_schema(db_name, table_name, schema.to_json)
end

# @param [String] db
# @param [String] table
# @param [String] db_name
# @param [String] table_name
# @option params [Fixnum] :expire_days days to expire table
# @option params [Boolean] :include_v (true) include v column on Hive
# @option params [Boolean] :detect_schema (true) detect schema on import
# @return [true]
def update_table(db_name, table_name, params={})
Expand All @@ -137,10 +135,10 @@ def delete_table(db_name, table_name)
# @return [Array] Tables
def tables(db_name)
m = @api.list_tables(db_name)
m.map {|table_name, (type, schema, count, created_at, updated_at, estimated_storage_size, last_import, last_log_timestamp, expire_days, include_v)|
m.map {|table_name, (type, schema, count, created_at, updated_at, estimated_storage_size, last_import, last_log_timestamp, expire_days)|
schema = Schema.new.from_json(schema)
Table.new(self, db_name, table_name, type, schema, count, created_at, updated_at,
estimated_storage_size, last_import, last_log_timestamp, expire_days, include_v)
estimated_storage_size, last_import, last_log_timestamp, expire_days)
}
end

Expand Down
4 changes: 1 addition & 3 deletions lib/td/client/api/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def list_tables(db)
estimated_storage_size = m['estimated_storage_size'].to_i
schema = JSON.parse(m['schema'] || '[]')
expire_days = m['expire_days']
include_v = m['include_v']
result[name] = [type, schema, count, created_at, updated_at, estimated_storage_size, last_import, last_log_timestamp, expire_days, include_v]
result[name] = [type, schema, count, created_at, updated_at, estimated_storage_size, last_import, last_log_timestamp, expire_days]
}
return result
end
Expand Down Expand Up @@ -89,7 +88,6 @@ def update_expire(db, table, expire_days)
# @param [String] db
# @param [String] table
# @option params [Fixnum] :expire_days days to expire table
# @option params [Boolean] :include_v (true) include v column on Hive
# @option params [Boolean] :detect_schema (true) detect schema on import
# @return [true]
def update_table(db, table, params={})
Expand Down
5 changes: 2 additions & 3 deletions lib/td/client/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Table < Model
# @param [String] last_import
# @param [String] last_log_timestamp
# @param [Fixnum, String] expire_days
def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil, estimated_storage_size=nil, last_import=nil, last_log_timestamp=nil, expire_days=nil, include_v=false)
def initialize(client, db_name, table_name, type, schema, count, created_at=nil, updated_at=nil, estimated_storage_size=nil, last_import=nil, last_log_timestamp=nil, expire_days=nil)
super(client)
@database = nil
@db_name = db_name
Expand All @@ -167,7 +167,6 @@ def initialize(client, db_name, table_name, type, schema, count, created_at=nil,
@last_import = last_import
@last_log_timestamp = last_log_timestamp
@expire_days = expire_days
@include_v = include_v
end

# @!attribute [r] type
Expand All @@ -176,7 +175,7 @@ def initialize(client, db_name, table_name, type, schema, count, created_at=nil,
# @!attribute [r] schema
# @!attribute [r] count
# @!attribute [r] estimated_storage_size
attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size, :include_v
attr_reader :type, :db_name, :table_name, :schema, :count, :estimated_storage_size

alias database_name db_name
alias name table_name
Expand Down
39 changes: 7 additions & 32 deletions spec/td/client/table_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

it 'should create a new table with params' do
stub_api_request(:post, "/v3/table/create/#{e db_name}/#{e(table_name)}/log").
with(:body => {'include_v' => 'false'}).
to_return(:body => {'database' => db_name, 'table' => table_name, 'type' => 'log', 'include_v' => 'false'}.to_json)
expect(api.create_log_table(db_name, table_name, include_v: false)).to be true
with(:body => {'expire_days' => 3}).
to_return(:body => {'database' => db_name, 'table' => table_name, 'type' => 'log', 'expire_days' => 3}.to_json)
expect(api.create_log_table(db_name, table_name, expire_days: 3)).to be true
end

it 'should return 400 error with invalid name' do
Expand Down Expand Up @@ -78,9 +78,9 @@

it 'should create a new table with params' do
stub_api_request(:post, "/v3/table/create/#{e db_name}/#{e(table_name)}/log").
with(:body => {'include_v' => 'false'}).
to_return(:body => {'database' => db_name, 'table' => table_name, 'type' => 'log', 'include_v' => 'false'}.to_json)
expect(client.create_log_table(db_name, table_name, include_v: false)).to be true
with(:body => {'expire_days' => 3}).
to_return(:body => {'database' => db_name, 'table' => table_name, 'type' => 'log', 'expire_days' => 3}.to_json)
expect(client.create_log_table(db_name, table_name, expire_days: 3)).to be true
end

it 'should return 400 error with invalid name' do
Expand Down Expand Up @@ -232,32 +232,7 @@
end
end

describe 'handle include_v' do
it 'should set/unset include_v flag' do
stub_api_request(:get, '/v3/table/list/db').
to_return(:body => {'tables' => [
{'name' => 'table', 'type' => 'log', 'include_v' => true},
]}.to_json)

table = client.table('db', 'table')
expect(table.include_v).to eq true

stub_api_request(:get, '/v3/table/list/db').
to_return(:body => {'tables' => [
{'name' => 'table', 'type' => 'log', 'include_v' => false},
]}.to_json)

stub_api_request(:post, '/v3/table/update/db/table').
with(:body => {'include_v' => "false"}).
to_return(:body => {"database"=>"db","table"=>"table","type"=>"log"}.to_json)
api.update_table('db', 'table', include_v: "false")

table = client.table('db', 'table')
expect(table.include_v).to eq false
end
end

describe 'tail' do
describe 'tail' do
let :packed do
s = StringIO.new
pk = MessagePack::Packer.new(s)
Expand Down