DataStax Stargate Document API

206 views Asked by At

What does the a JSON blob with search filters, allowed operators: $eq, $ne, $in, $nin, $gt, $lt, $gte, $lte, $exists in the Swagger documentation that is shown in the DataStax Document API Swagger UI, it's not that documented so I want to ask if the query string is based on MongoDB?

2

There are 2 answers

0
clunven On BEST ANSWER

The Document API exposed on top of Cassandra is provided by the open source project Stargate, indeed developed by Datastax and embedded in their Saas solution Astra.

The JSON query String than you created is parsed and converted in a proper CQL query under the hood.

Source code doesn't lie you can find the full code here and specially parsing of the where clause here

public List<FilterCondition> convertToFilterOps(
 List<PathSegment> prependedPath, 
 JsonNode filterJson) {
 
 List<FilterCondition> conditions = new ArrayList<>();

 if (!filterJson.isObject()) {
  throw new DocumentAPIRequestException("Search was expecting a JSON object as input.");
 }

 ObjectNode input = (ObjectNode) filterJson;
 Iterator<String> fields = input.fieldNames();
 while (fields.hasNext()) {
  String fieldName = fields.next();
  if (fieldName.isEmpty()) {
    throw new DocumentAPIRequestException(
        "The field(s) you are searching for can't be the empty string!");
  }
 ...
0
Eric Borczuk On

The query string is pretty similar in spirit to what you'd find with Mongo.

Here are some sample where clauses to give an idea:

{"name": {"$eq": "Eric"}} - simple enough, matches documents that have a field name with value Eric

{"a.age": {"$gt": 0}} - You can also reference nested fields in a document

{"friends.[0].name": {"$in": ["Cassandra"]}} - Array elements are referenced using [], this would match if the document's first friend is named Cassandra.

{"friends.*.age": {"$gte": 24}} - Wildcard * can be used to match any element in an array, or any field at a particular level of nesting. This matches any friend whose age is >= 24.