You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Jerry Lam <ch...@gmail.com> on 2012/09/20 16:31:05 UTC

How to specify empty value in HBase shell

Hi HBase Community:

I have been struggling to find a way to specify empty value/empty column
qualifier in the hbase shell, but unsuccessful.

I google it, nothing comes up. I don't know JRuby so that might be why. Do
you know how?

Example:

scan 'Table',  {COLUMNS => 'cf:'} // note that the column family is cf and
the column qualifier is empty (i.e. new byte[0])

The above query will return all columns instead of the empty one.

I need only the values associated with the empty column qualifier. Please
help ~

Jerry

Re: How to specify empty value in HBase shell

Posted by Stack <st...@duboce.net>.
On Fri, Sep 21, 2012 at 7:33 AM, Jerry Lam <ch...@gmail.com> wrote:
> Hi St.Ack:
>
> I made some dirty changes to the script yesterday to work for me.
> Basically, I changed the parse_column_name(column) function to:
>
> def parse_column_name(column)
>       split =
> org.apache.hadoop.hbase.KeyValue.parseColumn(column.to_java_bytes)
>       return split[0], (split.length > 1) ? split[1] :
> (org.apache.hadoop.hbase.KeyValue.getDelimiter(column.to_java_bytes, 0,
> column.to_java_bytes.length(), 58) > 0) ? ''.to_java_bytes : nil
> end
>
> Not sure if it makes sense as the general solution to the problem but at
> least it seems to do the job.

Seems reasonable to me.
St.Ack

Re: How to specify empty value in HBase shell

Posted by Jerry Lam <ch...@gmail.com>.
Hi St.Ack:

I made some dirty changes to the script yesterday to work for me.
Basically, I changed the parse_column_name(column) function to:

def parse_column_name(column)
      split =
org.apache.hadoop.hbase.KeyValue.parseColumn(column.to_java_bytes)
      return split[0], (split.length > 1) ? split[1] :
(org.apache.hadoop.hbase.KeyValue.getDelimiter(column.to_java_bytes, 0,
column.to_java_bytes.length(), 58) > 0) ? ''.to_java_bytes : nil
end

Not sure if it makes sense as the general solution to the problem but at
least it seems to do the job.

The end result is that, if user specify COLUMNS without the delimiter, it
is treated as column family without qualifier. If there is delimiter but
the split has only 1 element, then the column qualifier is set to empty
value.

Best Regards,

Jerry


On Fri, Sep 21, 2012 at 12:42 AM, Stack <st...@duboce.net> wrote:

> On Thu, Sep 20, 2012 at 7:31 AM, Jerry Lam <ch...@gmail.com> wrote:
> > Hi HBase Community:
> >
> > I have been struggling to find a way to specify empty value/empty column
> > qualifier in the hbase shell, but unsuccessful.
> >
> > I google it, nothing comes up. I don't know JRuby so that might be why.
> Do
> > you know how?
> >
> > Example:
> >
> > scan 'Table',  {COLUMNS => 'cf:'} // note that the column family is cf
> and
> > the column qualifier is empty (i.e. new byte[0])
> >
> > The above query will return all columns instead of the empty one.
> >
>
> Sounds like no qualifier means all columns to shell.
>
> Do you have to use the 'empty qualifier'?  Thats a bit odd.  You
> really need it in your model?
>
> In the shell we are doing this:
>
>
>         columns.each do |c|
>           family, qualifier = parse_column_name(c.to_s)
>           if qualifier
>             scan.addColumn(family, qualifier)
>           else
>             scan.addFamily(family)
>           end
>         end
>
>
> If no qualifier, we think its a scan of the family.
>
> I don't really have a good answer for you.  In shell, what would you
> suggest we add so we do addColumn rather than addFamily if qualifier
> is empty?
>
> St.Ack
>

Re: How to specify empty value in HBase shell

Posted by Stack <st...@duboce.net>.
On Thu, Sep 20, 2012 at 7:31 AM, Jerry Lam <ch...@gmail.com> wrote:
> Hi HBase Community:
>
> I have been struggling to find a way to specify empty value/empty column
> qualifier in the hbase shell, but unsuccessful.
>
> I google it, nothing comes up. I don't know JRuby so that might be why. Do
> you know how?
>
> Example:
>
> scan 'Table',  {COLUMNS => 'cf:'} // note that the column family is cf and
> the column qualifier is empty (i.e. new byte[0])
>
> The above query will return all columns instead of the empty one.
>

Sounds like no qualifier means all columns to shell.

Do you have to use the 'empty qualifier'?  Thats a bit odd.  You
really need it in your model?

In the shell we are doing this:


        columns.each do |c|
          family, qualifier = parse_column_name(c.to_s)
          if qualifier
            scan.addColumn(family, qualifier)
          else
            scan.addFamily(family)
          end
        end


If no qualifier, we think its a scan of the family.

I don't really have a good answer for you.  In shell, what would you
suggest we add so we do addColumn rather than addFamily if qualifier
is empty?

St.Ack