hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marcus Herou" <marcus.he...@tailsweep.com>
Subject HBase one-to-many, many-to-one, many-to-many
Date Tue, 22 Jul 2008 13:33:44 GMT
Hi.

What is the best practice in hbase when it comes to creating "mapping"
tables between objects?

Let's say you want to create two tables named "User" and "Role" where the
user can be in many roles.

User->Role

I guess you could create some specially, proprietary cells like role:someuid
which contains the ref to the Role table but this seems a little strange.

Another quite normal example (for me at lesast) is to tag various content.

Eg:
BlogEntry<-BlogEntryCategory->Category

where in a rdbms the BlogEntryCategory would just contain two cols
blogEntryId and categoryId.

Howto model that with column families ?

Right now I'm creating Serializers which can serialize arrays back and forth

Eg StringArraySerializer
 public byte[] serialize(Object object) throws IOException
    {
        String[] a = (String[])object;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < a.length; i++)
        {
            sb.append(a[i]);
            if(i < (a.length - 1))
            {
                sb.append(this.delimiter);
            }
        }
        return sb.toString().getBytes("UTF-8");
    }

    public Object deserialize(byte[] bytes) throws IOException
    {
        String str = new String(bytes, "UTF-8");
        StringTokenizer st = new StringTokenizer(str, delimiter);

        List<String> list = new ArrayList();
        while(st.hasMoreTokens())
        {
            String token = st.nextToken();
            list.add(token);
        }
        return list.toArray(new String[list.size()]);
    }


and then store the byte[] in hbase. Ugly....

Please guide my sorry ass.

Kindly

//Marcus




-- 
Marcus Herou CTO and co-founder Tailsweep AB
+46702561312
marcus.herou@tailsweep.com
http://www.tailsweep.com/
http://blogg.tailsweep.com/

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message