0

Let say i have this table

CREATE TABLE mykeyspace.post (
  id uuid PRIMARY KEY,
  title text,
  photos set<frozen <photoIds>>
); 

and UDT :

CREATE TYPE mykeyspace.photoIds (
  photoId uuid,
  details text
);

How can I paginated through photos, means 10 photos at a time for given post id ?

Manish Kumar
  • 10,214
  • 25
  • 77
  • 147
  • What do you mean by 'paginated through photos' ? Do you mean you want Cassandra to return 10 photos set at a time ? Or do you mean that for a given id and title you want to paginate through the set of photos ? – Adrien Piquerez Oct 21 '15 at 07:23
  • Let say a post X can have 100 photos. So `photos` will have some thing like `[id1, id2,..id100]` So i want to get 1..10, 11..20, 21..29 image id for the given post id x – Manish Kumar Oct 21 '15 at 07:29
  • for the given post id i want to paginate through `photos` – Manish Kumar Oct 21 '15 at 07:30

2 Answers2

3

Paging through collections is not supported.

See reference manual:

Keep collections small to prevent delays during querying because Cassandra reads a collection in its entirety. The collection is not paged internally.

As discussed earlier, collections are designed to store only a small amount of data.

Stefan Podkowinski
  • 5,206
  • 1
  • 20
  • 25
1

May I propose another schema for your table post :

CREATE TABLE mykeyspace.post (
  id uuid,
  title text static,
  photo photo,
  PRIMARY KEY (id, photo)
);

CREATE TYPE mykeyspace.photo (
  id uuid,
  details text
);

This schema means :

  • There is one partition by id => a partition is equivalent to a post
  • There is one title by partition/post
  • There is multiple photo ids by partition/post

This schema should serve your goal very well until you reach about 100.000 photos by partition/post. If you have never used static columns before, you can refer to Datastax documentation

The driver can do the paging for you. See Paging Feature in Datastax Java driver documentation.

The Cql query looks like this :

select photo.id, photo.details from post where id=*your_post_id*;

PS : I think you should not use uppercase in your schema.

Adrien Piquerez
  • 1,009
  • 10
  • 11