Class: TableSchema
- Inherits:
-
Object
- Object
- TableSchema
- Defined in:
- lib/rbhive/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, field_sep = '\t', line_sep = '\n', &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, 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
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
3 4 5 |
# File 'lib/rbhive/schema.rb', line 3 def columns @columns end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/rbhive/schema.rb', line 2 def name @name end |
#partitions ⇒ Object (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_statement ⇒ Object
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_statement ⇒ Object
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_statement ⇒ Object
27 28 29 |
# File 'lib/rbhive/schema.rb', line 27 def replace_columns_statement alter_columns_statement("REPLACE") end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/rbhive/schema.rb', line 35 def to_s table_statement end |