1
votes

I have a Hbase Table with the following description.

For a row key, my column would be of the form a_1, a_2,a_3,b_1,c_1,C_2 and so on, a compound key format.

Suppose one of my row is of the form

row key - row1
column family - c1
columns - a_1, a_2,a_3,b_1,b_2,c_1,C_2,d_9,d_99

Can I, by any operation retrieve a,b,c,d as the columns corresponding to row1, I am not bothered about whatever be the suffixes for a,b,c...

I can get all column names for a given row, add them to set by splitting the row keys by their first part and emit the set. I am worried, if there would be a better way of doing it by filters or some other hbase way of getting it done, please comment...

1
Is it better to change my rowkey to rowkey_columnpart1_columnpart2 ?Arun A K
there is a prefix filter so you will get all columns starting with a certain prefix (a b or c), will this help?Udy
@Udy the issue here is that I do not have the column name info for a given row key at prior.Arun A K
ok, i got it now. in that case, there is no option to get it besides as you suggested.Udy
@Udy Thanks for that... Just write back some other time in case you find a different way.Arun A K

1 Answers

0
votes

You can use COlumnPrefixFilter for that. You can see the following code

    Configuration hadoopConf = new Configuration();
    hadoopConf.set("hbase.zookeeper.quorum", "localhost");
    hadoopConf.set("hbase.zookeeper.property.clientPort", "2181");

    HTable hTable = new HTable(hadoopConf, "KunderaExamples");

    Scan scan = new Scan();
    scan.setFilter(new ColumnPrefixFilter("A".getBytes()));
    ResultScanner scanner = hTable.getScanner(scan);
    Iterator<Result> resultsIter = scanner.iterator();
    while (resultsIter.hasNext())
    {

        Result result = resultsIter.next();

        List<KeyValue> values = result.list();
        for (KeyValue value : values)
        {
            System.out.println(value.getKey());
            System.out.println(new String(value.getQualifier()));
            System.out.println(value.getValue());
        }
    }