2

I need to get the list of column qualifiers available in a HBase table.

Suppose I have a table 'Customers' with column 'info:Age' and 'contact:PhoneNo'. To get the list of column families I see there's a method 'getColumnDescriptors' which returns the value 'info' and 'contact'.

But how to retrieve the full column names 'info:Age' and 'contact:PhoneNo' from the table or atleast the qualifiers 'Age' and 'PhoneNo' alone.

With the method 'getRowWithColumns' I am able to get the list of column names where I have to pass the row key value.

Will I be able to achieve this through any other convenient way?

abarisone
  • 3,707
  • 11
  • 35
  • 54
Edwin Vivek N
  • 564
  • 8
  • 28
  • I have a solution working for Java, but I don't know if I can post it as it is C++ post, if you want I can post it and you just have to change a few things for C++ – Alexi Coard Jul 21 '16 at 13:33

1 Answers1

0

Here is a working solution in Java as you asked, you just have to change a few things to translate it to C++.

Basically this method will scan the table and retrieves the column qualifiers, then I add them into a list if this list does not already contains it.

Here, I look at all the rows, but if all your rows always have the same columns, you can just scan the first row, using a Get for example (look at the HBase documentation, I've written several examples there).

    public ArrayList<String> getColumnName(String tablename) {
    ArrayList<String> properties = new ArrayList<String>();
    try {
        Table table = this.connection.getTable(TableName.valueOf(tablename));
        Scan scan = new Scan();
        ResultScanner rs = table.getScanner(scan);
        try {
            for (Result r = rs.next(); r != null; r = rs.next()) {
                for (Cell c : r.rawCells()) {
                    String family = new String(CellUtil.cloneFamily(c));
                    String qualifier = new String(CellUtil.cloneQualifier(c));
                    System.out.println("Column Family : "+ family);
                    System.out.println("Column Qualifier : " + qualifier);
                    if (!properties.contains(qualifier))
                        properties.add(new String(CellUtil.cloneQualifier(c)));
                }

            }
        } finally {
            rs.close(); // always close the ResultScanner!
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return properties;
}
Alexi Coard
  • 7,106
  • 12
  • 38
  • 58