Class: Cassandra

Inherits:
Object show all
Defined in:
lib/right_support/db/cassandra_model.rb

Defined Under Namespace

Modules: Protocol

Instance Method Summary collapse

Instance Method Details

#get_indexed_slices(column_family, index_clause, *columns_and_options) ⇒ Object

Monkey patch get_indexed_slices so that it returns OrderedHash, otherwise cannot determine next start key when getting in chunks



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/right_support/db/cassandra_model.rb', line 83

def get_indexed_slices(column_family, index_clause, *columns_and_options)
  return false if Cassandra.VERSION.to_f < 0.7

  column_family, columns, _, options =
    extract_and_validate_params(column_family, [], columns_and_options, READ_DEFAULTS.merge(:key_count => 100, :key_start => ""))

  if index_clause.class != CassandraThrift::IndexClause
    index_expressions = index_clause.collect do |expression|
      create_index_expression(expression[:column_name], expression[:value], expression[:comparison])
    end

    index_clause = create_index_clause(index_expressions, options[:key_start], options[:key_count])
  end

  key_slices = _get_indexed_slices(column_family, index_clause, columns, options[:count], options[:start],
                                   options[:finish], options[:reversed], options[:consistency])

  key_slices.inject(OrderedHash.new) { |h, key_slice| h[key_slice.key] = key_slice.columns; h }
end

#get_range_single(column_family, options = {}) ⇒ Object

Monkey patch get_range_single so that it can return a array of key slices rather than converting it to a Hash



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/right_support/db/cassandra_model.rb', line 49

def get_range_single(column_family, options = {})
  return_empty_rows = options.delete(:return_empty_rows) || false
  slices_please     = options.delete(:slices_not_hash) || false

  column_family, _, _, options =
    extract_and_validate_params(column_family, "", [options],
                                READ_DEFAULTS.merge(:start_key  => '',
                                                    :finish_key => '',
                                                    :key_count  => 100,
                                                    :columns    => nil,
                                                    :reversed   => false
                                )
    )

  results = _get_range(column_family,
                       options[:start_key].to_s,
                       options[:finish_key].to_s,
                       options[:key_count],
                       options[:columns],
                       options[:start].to_s,
                       options[:finish].to_s,
                       options[:count],
                       options[:consistency],
                       options[:reversed])

  unless slices_please
    multi_key_slices_to_hash(column_family, results, return_empty_rows)
  else
    results
  end
end