Merge "rest: add more operators in complex queries"
This commit is contained in:
@@ -245,8 +245,11 @@ Details about the resource can also be retrieved at the same time:
|
||||
{{ scenarios['search-resource-for-user-details']['doc'] }}
|
||||
|
||||
|
||||
The supported operators are: `=`, `<`, `>`, `<=`, `>=`, `!=`, `in`,
|
||||
`like`, `or`, `and` and `not`.
|
||||
The supported operators are: equal to (`=`, `==` or `eq`), less than (`<` or
|
||||
`lt`), greater than (`>` or `gt`), less than or equal to (`<=`, `le` or `≤`)
|
||||
greater than or equal to (`>=`, `ge` or `≥`) not equal to (`!=`, `ne` or `≠`),
|
||||
value is in (`in`), value is like (`like`), or (`or` or `∨`), and (`and` or
|
||||
`∧`) and negation (`not`).
|
||||
|
||||
Aggregation across metrics
|
||||
==========================
|
||||
|
||||
@@ -339,43 +339,43 @@ class SQLAlchemyIndexer(indexer.IndexerDriver):
|
||||
|
||||
class QueryTransformer(object):
|
||||
unary_operators = {
|
||||
"not": sqlalchemy.or_,
|
||||
u"not": sqlalchemy.not_,
|
||||
}
|
||||
|
||||
binary_operators = {
|
||||
"=": operator.eq,
|
||||
"==": operator.eq,
|
||||
"eq": operator.eq,
|
||||
u"=": operator.eq,
|
||||
u"==": operator.eq,
|
||||
u"eq": operator.eq,
|
||||
|
||||
"<": operator.lt,
|
||||
"lt": operator.lt,
|
||||
u"<": operator.lt,
|
||||
u"lt": operator.lt,
|
||||
|
||||
">": operator.gt,
|
||||
"gt": operator.gt,
|
||||
u">": operator.gt,
|
||||
u"gt": operator.gt,
|
||||
|
||||
"<=": operator.le,
|
||||
"≤": operator.le,
|
||||
"le": operator.le,
|
||||
u"<=": operator.le,
|
||||
u"≤": operator.le,
|
||||
u"le": operator.le,
|
||||
|
||||
">=": operator.ge,
|
||||
"≥": operator.ge,
|
||||
"ge": operator.ge,
|
||||
u">=": operator.ge,
|
||||
u"≥": operator.ge,
|
||||
u"ge": operator.ge,
|
||||
|
||||
"!=": operator.ne,
|
||||
"≠": operator.ne,
|
||||
"ne": operator.ne,
|
||||
u"!=": operator.ne,
|
||||
u"≠": operator.ne,
|
||||
u"ne": operator.ne,
|
||||
|
||||
"in": lambda field_name, values: field_name.in_(values),
|
||||
u"in": lambda field_name, values: field_name.in_(values),
|
||||
|
||||
"like": lambda field, value: field.like(value),
|
||||
u"like": lambda field, value: field.like(value),
|
||||
}
|
||||
|
||||
multiple_operators = {
|
||||
"or": sqlalchemy.or_,
|
||||
"∨": sqlalchemy.or_,
|
||||
u"or": sqlalchemy.or_,
|
||||
u"∨": sqlalchemy.or_,
|
||||
|
||||
"and": sqlalchemy.and_,
|
||||
"∧": sqlalchemy.and_,
|
||||
u"and": sqlalchemy.and_,
|
||||
u"∧": sqlalchemy.and_,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -849,9 +849,21 @@ class SearchResourceTypeController(rest.RestController):
|
||||
voluptuous.All(
|
||||
voluptuous.Length(min=1, max=1),
|
||||
{
|
||||
voluptuous.Any("=", "<=", ">=", "!=", "in", "like"):
|
||||
voluptuous.All(voluptuous.Length(min=1, max=1), dict),
|
||||
voluptuous.Any("and", "or", "not"): [_SearchSchema],
|
||||
voluptuous.Any(
|
||||
u"=", u"==", u"eq",
|
||||
u"<", u"lt",
|
||||
u">", u"gt",
|
||||
u"<=", u"≤", u"le",
|
||||
u">=", u"≥", u"ge",
|
||||
u"!=", u"≠", u"ne",
|
||||
u"in",
|
||||
u"like",
|
||||
): voluptuous.All(voluptuous.Length(min=1, max=1), dict),
|
||||
voluptuous.Any(
|
||||
u"and", u"∨",
|
||||
u"or", u"∧",
|
||||
u"not",
|
||||
): [_SearchSchema],
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1739,7 +1739,7 @@ class ResourceTest(RestTest):
|
||||
params=self.attributes)
|
||||
created_resource = json.loads(result.text)
|
||||
result = self.app.post_json("/v1/search/resource/generic",
|
||||
params={"=": {"user_id": u1}},
|
||||
params={"eq": {"user_id": u1}},
|
||||
status=200)
|
||||
resources = json.loads(result.text)
|
||||
self.assertGreaterEqual(len(resources), 1)
|
||||
@@ -1779,7 +1779,7 @@ class ResourceTest(RestTest):
|
||||
i = json.loads(result.text)
|
||||
result = self.app.post_json(
|
||||
"/v1/search/resource/generic",
|
||||
params={">=": {"started_at": "2014-01-01"}},
|
||||
params={"≥": {"started_at": "2014-01-01"}},
|
||||
status=200)
|
||||
resources = json.loads(result.text)
|
||||
self.assertGreaterEqual(len(resources), 2)
|
||||
|
||||
Reference in New Issue
Block a user