Class: TableSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/rbhive/schema.rb

Defined Under Namespace

Classes: Column

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, comment = nil, field_sep = '\t', line_sep = '\n', &blk) ⇒ TableSchema

Returns a new instance of TableSchema.



4
5
6
7
8
9
# File 'lib/rbhive/schema.rb', line 4

def initialize(name, comment=nil, field_sep='\t', line_sep='\n', &blk)
  @name, @comment, @field_sep, @line_sep = name, comment, field_sep, line_sep
  @columns = []
  @partitions = []
  instance_eval(&blk) if blk
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



3
4
5
# File 'lib/rbhive/schema.rb', line 3

def columns
  @columns
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/rbhive/schema.rb', line 2

def name
  @name
end

#partitionsObject (readonly)

Returns the value of attribute partitions.



3
4
5
# File 'lib/rbhive/schema.rb', line 3

def partitions
  @partitions
end

Instance Method Details

#add_columns_statementObject



31
32
33
# File 'lib/rbhive/schema.rb', line 31

def add_columns_statement
  alter_columns_statement("ADD")
end

#column(name, type, comment = nil) ⇒ Object



11
12
13
# File 'lib/rbhive/schema.rb', line 11

def column(name, type, comment=nil)
  @columns << Column.new(name, type, comment)
end

#create_table_statementObject



19
20
21
22
23
24
25
# File 'lib/rbhive/schema.rb', line 19

def create_table_statement()
  %[CREATE TABLE #{table_statement}
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '#{@field_sep}'
LINES TERMINATED BY '#{@line_sep}'
STORED AS TEXTFILE]
end

#partition(name, type, comment = nil) ⇒ Object



15
16
17
# File 'lib/rbhive/schema.rb', line 15

def partition(name, type, comment=nil)
  @partitions << Column.new(name, type, comment)
end

#replace_columns_statementObject



27
28
29
# File 'lib/rbhive/schema.rb', line 27

def replace_columns_statement
  alter_columns_statement("REPLACE")
end

#to_sObject



35
36
37
# File 'lib/rbhive/schema.rb', line 35

def to_s
  table_statement
end