def _query_and_op(self, tree, table, method_name, method_kwargs):
result = []<EOL>if tree.keys_in:<EOL><INDENT>if tree.using:<EOL><INDENT>raise SyntaxError("<STR_LIT>")<EOL><DEDENT>keys = self._iter_where_in(tree)<EOL><DEDENT>else:<EOL><INDENT>visitor = Visitor(self.reserved_words)<EOL>(action, kwargs, _) = self._build_query(table, tree, visitor)<EOL>attrs = [visitor.get_field(table.hash_key.name)]<EOL>if table.range_key is not None:<EOL><INDENT>attrs.append(visitor.get_field(table.range_key.name))<EOL><DEDENT>kwargs["<STR_LIT>"] = attrs<EOL>kwargs["<STR_LIT>"] = visitor.expression_values<EOL>kwargs["<STR_LIT>"] = visitor.attribute_names<EOL>if (<EOL>visitor.expression_values is None<EOL>and callable(self.caution_callback)<EOL>and not self.caution_callback(method_name)  <EOL>):<EOL><INDENT>return False<EOL><DEDENT>method = getattr(self.connection, action + "<STR_LIT:2>")<EOL>keys = method(table.name, **kwargs)<EOL>if self._explaining:<EOL><INDENT>try:<EOL><INDENT>list(keys)<EOL><DEDENT>except ExplainSignal:<EOL><INDENT>keys = [{}]<EOL><DEDENT><DEDENT><DEDENT>method = getattr(self.connection, method_name + "<STR_LIT:2>")<EOL>count = <NUM_LIT:0><EOL>for key in keys:<EOL><INDENT>try:<EOL><INDENT>ret = method(table.name, key, **method_kwargs)<EOL><DEDENT>except CheckFailed:<EOL><INDENT>continue<EOL><DEDENT>count += <NUM_LIT:1><EOL>if ret:<EOL><INDENT>result.append(ret)<EOL><DEDENT><DEDENT>if result:<EOL><INDENT>return result<EOL><DEDENT>else:<EOL><INDENT>return count<EOL><DEDENT>
Query the table and perform an operation on each item