Class: RBHive::TableSchema

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

Defined Under Namespace

Classes: Column

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, comment = nil, options = {}, &blk) ⇒ TableSchema

Returns a new instance of TableSchema.



5
6
7
8
9
10
11
12
13
14
# File 'lib/rbhive/table_schema.rb', line 5

def initialize(name, comment=nil, options={}, &blk)
  @name, @comment = name, comment
  @location = options[:location] || nil
  @field_sep = options[:field_sep] || "\t"
  @line_sep = options[:line_sep] || "\n"
  @collection_sep = options[:collection_sep] || "|"
  @columns = []
  @partitions = []
  instance_eval(&blk) if blk
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



4
5
6
# File 'lib/rbhive/table_schema.rb', line 4

def columns
  @columns
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#partitionsObject (readonly)

Returns the value of attribute partitions.



4
5
6
# File 'lib/rbhive/table_schema.rb', line 4

def partitions
  @partitions
end

Instance Method Details

#add_columns_statementObject



38
39
40
# File 'lib/rbhive/table_schema.rb', line 38

def add_columns_statement
  alter_columns_statement("ADD")
end

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



16
17
18
# File 'lib/rbhive/table_schema.rb', line 16

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

#create_table_statementObject



24
25
26
27
28
29
30
31
32
# File 'lib/rbhive/table_schema.rb', line 24

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

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



20
21
22
# File 'lib/rbhive/table_schema.rb', line 20

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

#replace_columns_statementObject



34
35
36
# File 'lib/rbhive/table_schema.rb', line 34

def replace_columns_statement
  alter_columns_statement("REPLACE")
end

#to_sObject



42
43
44
# File 'lib/rbhive/table_schema.rb', line 42

def to_s
  table_statement
end