Class: HipsterSqlToHbase::ResultTreeToHbaseConverter
- Inherits:
-
Object
- Object
- HipsterSqlToHbase::ResultTreeToHbaseConverter
- Defined in:
- lib/result_tree_to_hbase_converter.rb
Overview
This class takes care of all HBase (Thrift) conversion magic by transforming the ResultTree objects into ThriftCallGroup objects.
Instance Method Summary collapse
-
#convert(result_tree) ⇒ Object
Depending on the SQL sentence type, call the appropriate function.
-
#create_table_sentence(hash) ⇒ Object
When SQL sentence is a CREATE TABLE query generate the Thrift column descriptors/families in accordance to the specified query values.
-
#insert_sentence(hash) ⇒ Object
When SQL sentence is an INSERT query generate the Thrift mutations according to the specified query values.
-
#select_sentence(hash) ⇒ Object
When SQL sentence is a SELECT query generate the Thrift filters according to the specified query values.
Instance Method Details
#convert(result_tree) ⇒ Object
Depending on the SQL sentence type, call the appropriate function.
29 30 31 |
# File 'lib/result_tree_to_hbase_converter.rb', line 29 def convert(result_tree) send("#{result_tree[:query_type].to_s}_sentence",result_tree[:query_hash]) end |
#create_table_sentence(hash) ⇒ Object
When SQL sentence is a CREATE TABLE query generate the Thrift column descriptors/families in accordance to the specified query values.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/result_tree_to_hbase_converter.rb', line 66 def create_table_sentence(hash) thrift_method = "createTable" thrift_table = hash[:table] thrift_columns = [] hash[:columns].each do |col_name| col_descriptor = Hbase::ColumnDescriptor.new col_descriptor.name = col_name thrift_columns << col_descriptor end HipsterSqlToHbase::ThriftCallGroup.new([{:method => thrift_method,:arguments => [thrift_table,thrift_columns]}]) end |
#insert_sentence(hash) ⇒ Object
When SQL sentence is an INSERT query generate the Thrift mutations according to the specified query values.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/result_tree_to_hbase_converter.rb', line 35 def insert_sentence(hash) thrift_method = "mutateRow" thrift_table = hash[:into] thrift_calls = [] hash[:values].each do |value_set| thrift_row = SecureRandom.uuid thrift_mutations = [] i = 0 hash[:columns].each do |col| thrift_mutations << HBase::Mutation.new(column: col, value: value_set[i].to_s) i += 1 end thrift_calls << {:method => thrift_method,:arguments => [thrift_table,thrift_row,thrift_mutations,{}]} end HipsterSqlToHbase::ThriftCallGroup.new(thrift_calls,true) end |
#select_sentence(hash) ⇒ Object
When SQL sentence is a SELECT query generate the Thrift filters according to the specified query values.
54 55 56 57 58 59 60 61 62 |
# File 'lib/result_tree_to_hbase_converter.rb', line 54 def select_sentence(hash) thrift_method = "getRowsByScanner" thrift_table = hash[:from] thrift_columns = hash[:select] thrift_filters = recurse_where(hash[:where] || []) thrift_limit = hash[:limit] HipsterSqlToHbase::ThriftCallGroup.new([{:method => thrift_method,:arguments => [thrift_table,thrift_columns,thrift_filters,thrift_limit,{}]}]) end |