@@ -189,7 +189,7 @@ def result_conditions(conditions, results)
189189 end
190190
191191 # Decide which fields should be selected
192- def expand_selected_fields ( select )
192+ def expand_selected_fields ( select , later_indexlookup_steps )
193193 # We just pick whatever is contained in the index that is either
194194 # mentioned in the query or required for the next lookup
195195 # TODO: Potentially try query.all_fields for those not required
@@ -198,6 +198,14 @@ def expand_selected_fields(select)
198198 select += @next_step . index . hash_fields \
199199 unless @next_step . nil? ||
200200 !@next_step . is_a? ( Plans ::IndexLookupPlanStep )
201+
202+ if !@next_step . is_a? ( Plans ::IndexLookupPlanStep ) \
203+ and !later_indexlookup_steps . nil?
204+ later_indexlookup_steps . each do |later_indexlookup_step |
205+ select += later_indexlookup_step . index . hash_fields
206+ end
207+ end
208+
201209 select &= @step . index . all_fields
202210
203211 select
@@ -254,8 +262,18 @@ def include_row?(row, eq_conditions, range)
254262 end
255263
256264 if range
257- range_check = row [ range . field . id ] . method ( range . operator )
258- select &&= range_check . call range . value
265+ if row [ range . field . id ] . nil?
266+ # if range condition field is null, remove the row from the result
267+ select = false
268+ else
269+ range_check = row [ range . field . id ] . method ( range . operator )
270+ begin
271+ select &&= range_check . call range . value
272+ rescue Exception => e
273+ puts e
274+ throw e
275+ end
276+ end
259277 end
260278
261279 select
@@ -365,8 +383,16 @@ def prepare_query_steps(steps, fields, conditions)
365383 subclass_step_name = step_class . name . sub \
366384 'NoSE::Backend::Backend' , self . class . name
367385 step_class = Object . const_get subclass_step_name
368- step_class . new client , fields , conditions ,
369- step , next_step , prev_step
386+ if step_class == NoSE ::Backend ::CassandraBackend ::IndexLookupStatementStep \
387+ and steps . index ( next_step ) + 2 < steps . size
388+ #and steps[steps.index(next_step) + 1].is_a?(NoSE::Backend::CassandraBackend::IndexLookupStatementStep)
389+ later_indexlookup_steps = steps [ ( steps . index ( next_step ) + 1 ) ..-1 ] . select { |s | s . is_a? Plans ::IndexLookupPlanStep }
390+ step_class . new client , fields , conditions ,
391+ step , next_step , prev_step , later_indexlookup_steps
392+ else
393+ step_class . new client , fields , conditions ,
394+ step , next_step , prev_step
395+ end
370396 end
371397 end
372398
0 commit comments