incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian O'Neill" <b...@alumni.brown.edu>
Subject Re: Blobs in CQL?
Date Thu, 11 Apr 2013 13:22:05 GMT
Sylvain,

Interesting, when I look at the actual bytes returned, I see the byte array
is prefixed with the keyspace and table name.

I assume I'm doing something wrong in the select.  Am I incorrectly using
the ResultSet?

-brian

On Thu, Apr 11, 2013 at 9:09 AM, Brian O'Neill <bone@alumni.brown.edu>wrote:

> Yep, it worked like a charm.  (PreparedStatement avoided the hex
> conversion)
>
> But now, I'm seeing a few extra bytes come back in the select….
> (I'll keep digging, but maybe you have some insight?)
>
> I see this:
>
> ERROR [2013-04-11 13:05:03,461] com.skookle.dao.RepositoryDao:
> repository.add() byte.length()=[259804]
>
> ERROR [2013-04-11 13:08:08,487] com.skookle.dao.RepositoryDao:
> repository.get() [foo.jpeg] byte.length()=[259861]
>
> (Notice the length's don't match up)
>
> Using this code:
>
>     public void addContent(String key, byte[] data)
>
>             throws NoHostAvailableException {
>
>         LOG.error("repository.add() byte.length()=[" + data.length + "]");
>
>         String statement = "INSERT INTO " + KEYSPACE + "." + TABLE + "(key,
> data) VALUES (?, ?)";
>
>         PreparedStatement ps = session.prepare(statement);
>
>         BoundStatement bs = ps.bind(key, ByteBuffer.wrap(data));
>
>         session.execute(bs);
>
>     }
>
>
>     public byte[] getContent(String key) throws NoHostAvailableException {
>
>         Query select = select("data").from(KEYSPACE, TABLE).where(eq("key",
> key));
>
>         ResultSet resultSet = session.execute(select);
>
>         byte[] data = resultSet.one().getBytes("data").array();
>
>         LOG.error("repository.get() [" + key + "] byte.length()=[" + data.
> length + "]");
>
>         return data;
>
>     }
>
> ---
>
> Brian O'Neill
>
> Lead Architect, Software Development
>
> *Health Market Science*
>
> *The Science of Better Results*
>
> 2700 Horizon Drive • King of Prussia, PA • 19406****
>
> M: 215.588.6024 • @boneill42 <http://www.twitter.com/boneill42>  •
>
> healthmarketscience.com
>
>
> This information transmitted in this email message is for the intended
> recipient only and may contain confidential and/or privileged material. If
> you received this email in error and are not the intended recipient, or the
> person responsible to deliver it to the intended recipient, please contact
> the sender at the email above and delete this email and any attachments and
> destroy any copies thereof. Any review, retransmission, dissemination,
> copying or other use of, or taking any action in reliance upon, this
> information by persons or entities other than the intended recipient is
> strictly prohibited.****
>
> ** **
>
>
> From: Sylvain Lebresne <sylvain@datastax.com>
> Reply-To: <user@cassandra.apache.org>
> Date: Thursday, April 11, 2013 8:48 AM
> To: "user@cassandra.apache.org" <user@cassandra.apache.org>
> Cc: Gabriel Ciuloaica <gciuloaica@gmail.com>
> Subject: Re: Blobs in CQL?
>
>
> Hopefully, the prepared statement doesn't do the conversion.
>>
>
> It does not.
>
>
>> (I'm not sure if it is a limitation of the CQL protocol itself)
>>
>> thanks again,
>> -brian
>>
>>
>>
>> ---
>> Brian O'Neill
>> Lead Architect, Software Development
>> Health Market Science
>> The Science of Better Results
>> 2700 Horizon Drive • King of Prussia, PA • 19406
>> M: 215.588.6024 • @boneill42 <http://www.twitter.com/boneill42>  •
>> healthmarketscience.com
>>
>> This information transmitted in this email message is for the intended
>> recipient only and may contain confidential and/or privileged material. If
>> you received this email in error and are not the intended recipient, or
>> the person responsible to deliver it to the intended recipient, please
>> contact the sender at the email above and delete this email and any
>> attachments and destroy any copies thereof. Any review, retransmission,
>> dissemination, copying or other use of, or taking any action in reliance
>> upon, this information by persons or entities other than the intended
>> recipient is strictly prohibited.
>>
>>
>>
>>
>>
>>
>>
>> On 4/11/13 8:34 AM, "Gabriel Ciuloaica" <gciuloaica@gmail.com> wrote:
>>
>> >I'm not using the query builder but the PreparedStatement.
>> >
>> >Here is the sample code: https://gist.github.com/devsprint/5363023
>> >
>> >Gabi
>> >On 4/11/13 3:27 PM, Brian O'Neill wrote:
>> >> Great!
>> >>
>> >> Thanks Gabriel.  Do you have an example? (are using QueryBuilder?)
>> >> I couldn't find the part of  the API that allowed you to pass in the
>> >>byte
>> >> array.
>> >>
>> >> -brian
>> >>
>> >> ---
>> >> Brian O'Neill
>> >> Lead Architect, Software Development
>> >> Health Market Science
>> >> The Science of Better Results
>> >> 2700 Horizon Drive € King of Prussia, PA € 19406
>> >> M: 215.588.6024 € @boneill42 <http://www.twitter.com/boneill42>
 €
>> >> healthmarketscience.com
>> >>
>> >> This information transmitted in this email message is for the intended
>> >> recipient only and may contain confidential and/or privileged material.
>> >>If
>> >> you received this email in error and are not the intended recipient, or
>> >> the person responsible to deliver it to the intended recipient, please
>> >> contact the sender at the email above and delete this email and any
>> >> attachments and destroy any copies thereof. Any review, retransmission,
>> >> dissemination, copying or other use of, or taking any action in
>> reliance
>> >> upon, this information by persons or entities other than the intended
>> >> recipient is strictly prohibited.
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> On 4/11/13 8:25 AM, "Gabriel Ciuloaica" <gciuloaica@gmail.com> wrote:
>> >>
>> >>> Hi Brian,
>> >>>
>> >>> I'm using the blobs to store images in cassandra(1.2.3) using the
>> >>> java-driver version 1.0.0-beta1.
>> >>> There is no need to convert a byte array into hex.
>> >>>
>> >>> Br,
>> >>> Gabi
>> >>>
>> >>> On 4/11/13 3:21 PM, Brian O'Neill wrote:
>> >>>> I started playing around with the CQL driver.
>> >>>> Has anyone used blobs with it yet?
>> >>>>
>> >>>> Are you forced to convert a byte[] to hex?
>> >>>> (e.g. I have a photo that I want to store in C* using the java-driver
>> >>>> API)
>> >>>>
>> >>>> -brian
>> >>>>
>> >>>> --
>> >>>> Brian ONeill
>> >>>> Lead Architect, Health Market Science (
>> http://healthmarketscience.com)
>> >>>> mobile:215.588.6024
>> >>>> blog: http://brianoneill.blogspot.com/
>> >>>> twitter: @boneill42
>> >>
>> >
>>
>>
>>
>


-- 
Brian ONeill
Lead Architect, Health Market Science (http://healthmarketscience.com)

mobile:215.588.6024
blog: http://brianoneill.blogspot.com/
twitter: @boneill42

Mime
View raw message