Reputation: 21
Is it possible to select a blob from Cassandra and get it as a Stream byte? I don't want to download all bytes from database and then send it via webapi to the user.
Upvotes: 1
Views: 508
Reputation: 13731
I'm not sure I fully understand the goal of your question, but if your idea is that you have a very large blob and you want to be able to jump to its middle instead of reading all of it - and then send only specific byte ranges to the users, then the answer is no - you can't. As you probably noticed Cassandra or Scylla offer no API for fetching parts of a blob. You need to read (and write) the entire blob in one CQL operation, and can't for example read bytes 1 million through 2 million.
This is one of the reasons that you are limited in blob size. The hard limit is 2GB size, but the documentation such as https://docs.datastax.com/en/cql/3.1/cql/cql_reference/blob_r.html suggests that even 1 MB (!) is too large.
The simple workaround is to split your blob into pieces of smaller size (e.g, 100 KB). For example, you can put all of them in one partition ordered by the piece index which will be the clustering key. If the pieces are constant size, you can easily and efficiently skip in the partition right to the position you want to read. If the blob grows even huger (e.g., a multi-gigabyte video file) you can also split it to multiple partitions to get better load balancing (since different partitions can go to different nodes) and better efficiency.
Upvotes: 3