Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

jeffdavies avatar image
jeffdavies asked Erick Ramirez commented

How do I use swagger with composite partition keys?

I'm getting an error message from Swagger when I try to read a specific record from a table. Here is my table definition:

USE jd;
CREATE TABLE customer (
    id uuid,
    name text,
    country text,
    state text,
    city text,
    PRIMARY KEY ((country, state, city) id)
);

Here is a screenshot of how I am querying my table. I'll paste in the URL of the specific call after this image:

screenshot-54.png

Here is the curl command that swagger creates for me:

curl -X GET "https://190b562f-adf8-4e48-9ae0-484eabc82478-us-east1.apps.astra.datastax.com/api/rest/v2/keyspaces/jd/customer/US%2CCA%2CSanta%20Clara%2Cdb6a74fd-7655-49eb-9212-1c1e1eb7b619?fields=country%2Cstate%2Ccity%2Cid" -H  "accept: application/json" -H  "X-Cassandra-Token: REDACTED"

And here is the response from swagger:

{
  "description": "not enough partition keys provided",
  "code": 400
}

Now I'm new to the Cassandra world, so I'm sure I'm not defining my partition keys correctly, but I don't know the correct format to use. Any help will be greatly appreciated.

- Jeff

api
screenshot-54.png (165.1 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

As the instruction on the UI suggests, you need specify composite keys by separating values with slashes like value1/value2/....

In your case you'll need to specify the primary key values in the UI as:

  • first item (partition key): US/CA/Santa Clara
  • second item (clustering key): db6a74fd-7655-49eb-9212-1c1e1eb7b619

I don't have an environment set up so I'm not able to test it right now. Please try it and let me know how you go. Cheers!

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thank you for the clarification. Part of my problem is that I'm un-learning the RDBMS way of things. I came across a youtube tutorial that stressed how Cassandra tables were designed with a "query first" point of view. I changed my table structures and I have the REST API chugging along just fine.

0 Likes 0 ·

All good. We're happy to help if you have any questions. Cheers!

0 Likes 0 ·