cqle: support more comparisons in LWT conditional

also fixes an issue where iff did not use the column's db_field

PYTHON-528
This commit is contained in:
Adam Holmberg
2016-04-04 16:04:41 -05:00
parent 94db2f6547
commit 19fb14bf15
3 changed files with 10 additions and 4 deletions

View File

@@ -60,6 +60,11 @@ class EqualsOperator(BaseWhereOperator):
cql_symbol = '='
class NotEqualsOperator(BaseWhereOperator):
symbol = 'NE'
cql_symbol = '!='
class InOperator(EqualsOperator):
symbol = 'IN'
cql_symbol = 'IN'

View File

@@ -560,10 +560,11 @@ class AbstractQuerySet(object):
raise QueryException('{0} is not a valid query operator'.format(operator))
clone._conditional.append(operator)
for col_name, val in kwargs.items():
for arg, val in kwargs.items():
if isinstance(val, Token):
raise QueryException("Token() values are not valid in conditionals")
col_name, col_op = self._parse_filter_arg(arg)
try:
column = self.model._get_column(col_name)
except KeyError:
@@ -574,7 +575,9 @@ class AbstractQuerySet(object):
else:
query_val = column.to_database(val)
clone._conditional.append(ConditionalClause(col_name, query_val))
operator_class = BaseWhereOperator.get_operator(col_op or 'EQ')
operator = operator_class()
clone._conditional.append(WhereClause(column.db_field_name, operator, query_val))
return clone

View File

@@ -527,8 +527,6 @@ class BaseCQLStatement(UnicodeMixin):
:param clause: The clause that will be added to the iff statement
:type clause: ConditionalClause
"""
if not isinstance(clause, ConditionalClause):
raise StatementException('only instances of AssignmentClause can be added to statements')
clause.set_context_id(self.context_counter)
self.context_counter += clause.get_context_size()
self.conditionals.append(clause)