简体   繁体   中英

HBase Column data types

I am working on the hbase java client and i am able to get the metadata out of the hbase data store like all the table names ,columns families and columns but i am not able to get the data type of the hbase column i searched on google and came to know that it is not possible to get the type of data

with the help of hbase java client HTableDescriptor , HColumnDescriptor

another question is i am getting the meta data this way i think this is not the way if any one can optimize this code would really help me

public List<ColumnFamily> getMetaDataOfTable(String tableName) {
        HTable table = null;
        try {
            HTableDescriptor tableDescriptor = admin.getTableDescriptor(Bytes
                    .toBytes(tableName));
            HColumnDescriptor[] columnDescriptor = tableDescriptor
                    .getColumnFamilies();
            for (HColumnDescriptor temp : columnDescriptor) {
                ColumnFamily columnFamily = new ColumnFamily();
                columnFamily.setName(temp.getNameAsString());
                columnFamilies.add(columnFamily);
            }

            table = new HTable(conf, tableName);
            Scan scan = new Scan();

            for (ColumnFamily columnFamily : columnFamilies) {
                scan.addFamily(Bytes.toBytes(columnFamily.getName()));
                ResultScanner scanner = table.getScanner(scan);
                for (Result result = scanner.next(); result != null; result = scanner
                        .next()) {

                    Map<byte[], byte[]> map = result.getFamilyMap(Bytes
                            .toBytes(columnFamily.getName()));
                    columnFamily.setColumnsList(getColumns(map));
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                table.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return columnFamilies;
    }

Please help me if you can thanks

While working with HBase you can only work with column families and they do not hold a type. At least not until version 0.98 that I am using.

Anyway, column families should be used to group columns such that each group of columns is used for something else, but usage is not restricted.

Also the maximum recommended number of column families is 3.

Now, to go back to your question, currently there is no mechanism to define columns inside HBase , only families, and inside families you can set values for columns dynamically.

Basically a row in HBase is a set of cells, each cell is identified by the column name. The data is stored binary and you need to have codecs for the data. Bytes.toXXX methods can be used to encode/decode data.

The HBase book is a good reference and also you can first take a look at the datamodel and have a clear view of the structure.

If you want specify column type with HBase, this is possible with Apache Phoenix (a SQL layer/drive to HBase):

https://phoenix.apache.org/language/datatypes.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM