def remove_index(self, index):
<EOL>query = []<EOL>remainder = []<EOL>for i in range(<NUM_LIT:0>, len(self.pieces), <NUM_LIT:2>):<EOL><INDENT>const = self.pieces[i]<EOL>if const.hash_field == index.hash_key:<EOL><INDENT>query.append(const)<EOL><DEDENT>elif index.range_key is not None and const.range_field == index.range_key:<EOL><INDENT>query.append(const)<EOL><DEDENT>else:<EOL><INDENT>remainder.append(const)<EOL><DEDENT><DEDENT>if len(query) == <NUM_LIT:1>:<EOL><INDENT>query_constraints = query[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>query_constraints = Conjunction.and_(query)<EOL><DEDENT>if not remainder:<EOL><INDENT>filter_constraints = None<EOL><DEDENT>elif len(remainder) == <NUM_LIT:1>:<EOL><INDENT>filter_constraints = remainder[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>filter_constraints = Conjunction.and_(remainder)<EOL><DEDENT>return (query_constraints, filter_constraints)<EOL>
This one takes some explanation. When we do a query with a WHERE
statement, it may end up being a scan and it may end up being a query.
If it is a query, we need to remove the hash and range key constraints
from the expression and return that as the query_constraints. The
remaining constraints, if any, are returned as the filter_constraints.