stargate / data-api

JSON document API for Apache Cassandra (formerly known as JSON API)
https://stargate.io
Apache License 2.0
13 stars 16 forks source link

Not able to use column names with upper-case letters, special characters #1349

Closed vkarpov15 closed 1 month ago

vkarpov15 commented 1 month ago

I created a keyspace in cqlsh:

CREATE KEYSPACE demo
  WITH REPLICATION = { 
   'class' : 'SimpleStrategy', 
   'replication_factor' : 1 
  };

Create table with _id as the primary key:

CREATE TABLE bots (
   "_id"           text, 
   name         text,
   PRIMARY KEY ("_id"));

Insert a new row into the table:

INSERT INTO bots ("_id", name) VALUES ('000000000000000000000000', 'test');

Send a curl command to filter by _id and you get a Filter type not supported error:

$ curl -H 'Content-Type: application/json' -H 'X-Cassandra-Token: Cassandra:Y2Fzc2FuZHJh:Y2Fzc2FuZHJh' -X POST -d '{"findOne":{"filter":{"_id":"000000000000000000000000"},"options":{}}}' http://127.0.0.1:8181/v1/demo/bots 
{"errors":[{"message":"Server internal error: Filter type not supported, unable to resolve to a filtering strategy","errorCode":"SERVER_INTERNAL_ERROR"}]}
$

This only seems to happen with _id, replace _id with id and this works fine.

vkarpov15 commented 1 month ago

It looks like this issue isn't limited to just _id, but also means you can't query by properties with uppercase letters. For example, consider the following setup:

CREATE TABLE people (
   id           text, 
   "firstName"  text,
   PRIMARY KEY (id));

CREATE INDEX ON people ("firstName");

INSERT INTO PEOPLE (id, "firstName") VALUES ('000000000000000000000000', 'John');

Making request that filters by firstName fails:

$ curl -H 'Content-Type: application/json' -H 'X-Cassandra-Token: Cassandra:Y2Fzc2FuZHJh:Y2Fzc2FuZHJh' -X POST -d '{"findOne":{"filter":{"firstName":"John"},"options":{}}}' http://127.0.0.1:8181/v1/demo/people 
{"errors":[{"message":"Server failed: root cause: (java.lang.RuntimeException) io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.UnknownColumnException: No column found for table people with name firstname","errorCode":"SERVER_UNHANDLED_ERROR"},{"message":"Server failed: root cause: (io.stargate.sgv2.jsonapi.service.operation.filters.table.codecs.UnknownColumnException) No column found for table people with name firstname","errorCode":"SERVER_UNHANDLED_ERROR"}]}

Works fine if you replace firstName with first_name.

tatu-at-datastax commented 1 month ago

It is possible there are 2 different problems (special handling for _id due to Collection requiring different kind of filter construction, vs. quoting for non-lower-case column names) or just 1 (quoting). But I can create failing tests for quoting and see if solving that might solve _id case too.

tatu-at-datastax commented 1 month ago

@vkarpov15 I noticed that you didn't include specific curl command you used -- would it be possible to add that, just so I know I am reproducing exact issue (like find vs findOne)

tatu-at-datastax commented 1 month ago

It definitely appears that:

  1. Creating tables with columns like _id or ID works fine (after fixes in PR)
  2. Inserting rows with columns like _id or ID also works fine (ditto)
  3. findOne()/find() fails with both
  4. Failure reason appears different between _id and ID (or similar), based on error message

I may need to create a different issue.

tatu-at-datastax commented 1 month ago

Changed description here to match the general problem with unquoted column names being used; to be fixed by #1355

tatu-at-datastax commented 1 month ago

This issue, PR that fixes (#1355) is for general problem: filed #1357 for follow-up work wrt _id.

tatu-at-datastax commented 1 month ago

@vkarpov15 Fixed almost all issues, but _id itself still problematic for findOne/find for some reason. So #1357 is for solving that. But at least Id and ID etc should now work.