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

pranauro_16383 avatar image
pranauro_16383 asked ·

How do I write to a tuple with a timestamp type through the Stargate API?

Maybe I am missing something fundamental here, but I have a simple test table:

CREATE TABLE test01.tupletest (
  id int PRIMARY KEY,
  t frozen<tuple<timestamp, text, int>>
)

I am easily able to add a row in cqlsh with the command

INSERT INTO test01.tupletest JSON '{"id":1, "t": ["2021-04-10", "", 0]}';

However, if I try to utilize the Stargate REST API, and send a payload of:

{"id":2,"t":["2021-04-10","",0]}

I get an error:

Bad request: Invalid Timestamp value: Text '2021-04-10' could not be parsed at index 10 (field at index 0 of Tuple '[2021-04-10, , 0]')
stargate
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.

doug.wettlaufer avatar image
doug.wettlaufer answered ·

@smadhavan this is referring to a POST, not a GET.

@pranauro_16383 the timestamp should be in ISO 8601 format. The following request works for me running stargate locally but the same will apply for Astra as well.

curl -L -X POST 'localhost:8082/v2/keyspaces/testks/tupletest' \
-H 'X-Cassandra-Token: TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{
    "id": 2,
    "t": [
        "2021-04-01T00:00:00Z",
        "",
        0
    ]
}'
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.

I've also logged the following to better handle timestamps in the REST API

https://github.com/stargate/stargate/issues/839

0 Likes 0 ·

Thanks, It's appreciated!

0 Likes 0 ·
smadhavan avatar image
smadhavan answered ·

@pranauro_16383, you don't have an index on the t column and hence you won't be able to use in your REST API GET query. See this example here from the Stargate REST API documentation for retrieving a value with a tuple column. You could also join the Stargate Discord community for collaborating. Thanks and good luck!

1 comment 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.

Thanks for the pointer to the Stargate Discord community.

Why would I need the index if I am not doing any GETs based upon the t column? This payload provided was on an INSERT.

One thing that I should have mentioned in my original message is that this is utilizing ASTRA.

0 Likes 0 ·