Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase >> mail # user >> Using put for nullifying qualifiers


Copy link to this message
-
Re: Using put for nullifying qualifiers
Ted: Awesome. I can think of several use cases where this is useful, but im
pretty stuck on 0.92 right now.

I tried the null-version trick but must be doing something wrong. How do I
set version to null on a column? Isnt version equal to the timestamp
(primitive long)?

Setting timestamp to 0 and -1 doesnt work it seems.

HTable t = new HTable(tablename);
Put p = new Put(r1);
KeyValue kv1 = new KeyValue(r1, c1, c1, new byte[]{1});
KeyValue kv2 = new KeyValue(r1, c2, c2, new byte[]{1});
p.add(kv1);
p.add(kv2);
t.put(p);
t.flushCommits();
Result res = t.get(new Get(r1));
byte[] v1 = res.getValue(c1, c1);
byte[] v2 = res.getValue(c2, c2);
System.out.println("v1 " + v1[0] + " v2 " + v2[0]);

kv1 = new KeyValue(r1, c1, c1, -1, new byte[]{1});
p = new Put(r1);
p.add(kv1);
t.put(p);
res = t.get(new Get(r1));
v1 = res.getValue(c1, c1);
v2 = res.getValue(c2, c2);
System.out.println("v1 " + v1[0] + " v2 " + v2[0]);

This prints:
v1 1 v2 1
v1 1 v2 1

Any advice?
On Tue, May 22, 2012 at 10:45 PM, Ted Yu <[EMAIL PROTECTED]> wrote:

> That's right.
>
> In HBase 0.94 and trunk, check out the following API in HRegion:
>  public void mutateRowsWithLocks(Collection<Mutation> mutations,
>      Collection<byte[]> rowsToLock) throws IOException {
>
> It allows you to combine Put's and Delete's for a single region,
> atomically.
>
> On Tue, May 22, 2012 at 1:22 PM, Kristoffer Sjögren <[EMAIL PROTECTED]
> >wrote:
>
> > Thanks, sounds like that should do it.
> >
> > So im guessing it is correct to assume that _all_ KeyValues added to a
> > _single_ Put operation will either wholely succeed or wholely fail as
> long
> > as they belong to the same row?
> >
> > On Tue, May 22, 2012 at 8:30 PM, Tom Brown <[EMAIL PROTECTED]> wrote:
> >
> > > I don't think you can include a delete with a put and keep it atomic.
> > > You could include a null version of the column with your put, though,
> > > for a similar effect.
> > >
> > > --Tom
> > >
> > > On Tue, May 22, 2012 at 10:55 AM, Kristoffer Sjögren <[EMAIL PROTECTED]
> >
> > > wrote:
> > > > Hi
> > > >
> > > > I'm trying to use Put operations to replace ("set") already existing
> > rows
> > > > by nullify certain columns and qualifiers as part of an Put
> operation.
> > > >
> > > > The reason I want to do this is 1) keep the operation
> atomic/consistent
> > > 2)
> > > > avoid latency from first doing Delete then Put.
> > > >
> > > > Is there some way to do this kind of operation?
> > > >
> > > > Cheers,
> > > > -Kristoffer
> > >
> >
>
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB