Class: MassiveRecord::Adapters::Thrift::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/massive_record/adapters/thrift/scanner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, table_name, column_family_names, opts = {}) ⇒ Scanner

Returns a new instance of Scanner.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 10

def initialize(connection, table_name, column_family_names, opts = {})
  @connection = connection
  @table_name = table_name
  @column_family_names = column_family_names.collect{|n| n.split(":").first}
  @column_family_names = opts[:columns] unless opts[:columns].nil?
  @formatted_column_family_names = @column_family_names.collect{|n| "#{n.split(":").first}:"}
  @start_key = opts[:start_key].to_s
  @offset_key = opts[:offset_key].to_s
  @created_at = opts[:created_at].to_s
  @limit = opts[:limit] || 10
end

Instance Attribute Details

#column_family_namesObject

Returns the value of attribute column_family_names.



6
7
8
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 6

def column_family_names
  @column_family_names
end

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 6

def connection
  @connection
end

#created_atObject

Returns the value of attribute created_at.



7
8
9
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 7

def created_at
  @created_at
end

#formatted_column_family_namesObject

Returns the value of attribute formatted_column_family_names.



8
9
10
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 8

def formatted_column_family_names
  @formatted_column_family_names
end

#limitObject

Returns the value of attribute limit.



7
8
9
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 7

def limit
  @limit
end

#offset_keyObject

Returns the value of attribute offset_key.



7
8
9
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 7

def offset_key
  @offset_key
end

#opened_scannerObject

Returns the value of attribute opened_scanner.



6
7
8
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 6

def opened_scanner
  @opened_scanner
end

#start_keyObject

Returns the value of attribute start_key.



7
8
9
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 7

def start_key
  @start_key
end

#table_nameObject

Returns the value of attribute table_name.



6
7
8
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 6

def table_name
  @table_name
end

Instance Method Details

#closeObject



34
35
36
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 34

def close
  connection.scannerClose(opened_scanner)
end

#fetch_rows(opts = {}) ⇒ Object



42
43
44
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 42

def fetch_rows(opts = {})
  populate_rows(fetch_trows(opts))
end

#fetch_trows(opts = {}) ⇒ Object



38
39
40
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 38

def fetch_trows(opts = {})
  connection.scannerGetList(opened_scanner, limit)
end

#keyObject



22
23
24
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 22

def key
  offset_key.empty? ? start_key : offset_key
end

#openObject



26
27
28
29
30
31
32
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 26

def open
  if created_at.empty?
    self.opened_scanner = connection.scannerOpen(table_name, key, formatted_column_family_names)
  else
    self.opened_scanner = connection.scannerOpenTs(table_name, key, formatted_column_family_names, created_at)
  end
end

#populate_row(result) ⇒ Object



52
53
54
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 52

def populate_row(result)
  Row.populate_from_trow_result(result, connection, table_name, column_family_names)
end

#populate_rows(results) ⇒ Object



46
47
48
49
50
# File 'lib/massive_record/adapters/thrift/scanner.rb', line 46

def populate_rows(results)
  results.collect do |result|
    populate_row(result) unless result.row.match(/^#{start_key.gsub("|", "\\|")}/).nil?
  end.select{|r| !r.nil?}
end