Class: RBHive::TableSchema
- Inherits:
-
Object
- Object
- RBHive::TableSchema
- Defined in:
- lib/rbhive/table_schema.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#name ⇒ Object
Returns the value of attribute name.
-
#partitions ⇒ Object
readonly
Returns the value of attribute partitions.
Instance Method Summary collapse
- #add_columns_statement ⇒ Object
- #column(name, type, comment = nil) ⇒ Object
- #create_table_statement ⇒ Object
-
#initialize(name, comment = nil, options = {}, &blk) ⇒ TableSchema
constructor
A new instance of TableSchema.
- #partition(name, type, comment = nil) ⇒ Object
- #replace_columns_statement ⇒ Object
- #to_s ⇒ Object
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, ={}, &blk) @name, @comment = name, comment @location = [:location] || nil @field_sep = [:field_sep] || "\t" @line_sep = [:line_sep] || "\n" @collection_sep = [:collection_sep] || "|" @columns = [] @partitions = [] instance_eval(&blk) if blk end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/rbhive/table_schema.rb', line 4 def columns @columns end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rbhive/table_schema.rb', line 3 def name @name end |
#partitions ⇒ Object (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_statement ⇒ Object
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_statement ⇒ Object
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}' LINES TERMINATED BY '#{@line_sep}' COLLECTION ITEMS TERMINATED BY '#{@collection_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_statement ⇒ Object
34 35 36 |
# File 'lib/rbhive/table_schema.rb', line 34 def replace_columns_statement alter_columns_statement("REPLACE") end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/rbhive/table_schema.rb', line 42 def to_s table_statement end |