Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Custom packing & unpacking
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
stantonk  
View profile  
 More options Nov 1 2012, 7:29 pm
From: stantonk <stant...@gmail.com>
Date: Thu, 1 Nov 2012 16:29:45 -0700 (PDT)
Local: Thurs, Nov 1 2012 7:29 pm
Subject: Custom packing & unpacking

I am trying to do some custom packing/unpacking and am not having much luck.

Basically, I have a CF like this:

create column family CF
  with comparator = 'CompositeType(UTF8Type, LongType, UTF8Type)'
  and key_validation_class=LongType
  and default_validation_class=UTF8Type;

And pycassa happily marshals the data like so:

>>> CF.get(123, column_count=1)

OrderedDict([((u'astring', 123, u'anotherstring'), {'ajson': 'blob'})])

And I am manually converting the column names from a tuple of (u'astring',
123, u'anotherstring') into a delimited str (e.g.
"astring,123,anotherstring") for use in a url. When storing new columns, I
have to change it back to a tuple, and have to do tuple(s.split(',')).

What I want is to have these conversion steps on the column names be
transparent. I fiddled with a couple of different techniques:

class MyType(CassandraType):

    @staticmethod
    def pack(val):
        return val.split(',')

    @staticmethod
    def unpack(val):
        return ','.join(['%s'] * len(val)) % val

This obviously doesn't work because by the time these methods are called,
the value passed in is somewhat unpacked:

'^TastringP*i!^Tanotherstring'

looks like there's some padding character in the front of the strings, ^T,
and I can unpack the number in the middle using struct.unpack('>I', 'P*i!'),
but I have no way of telling where the LongType in the middle of the
CompositeType is?

If I try inheriting from CompositeType instead of CassandraType but try the
same static methods, I get the same results. It seems like the pack and
unpack methods aren't running at the very last step, at least in the case
of CompositeTypes?

btw, I am on pycassa 1.6.0, but I tried in 1.7.2 also and got the same
results.

Thanks, hopefully there is enough info here...I tried tracing the
marshaling code for a bit but I don't know enough about Thrift or the
underlying storage protocol for Cassandra so it was difficult to follow :-\


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.