Is there any JAVA API to create Hive tables dynamically based on HBase tables?
Hi, the short answer is no.
The longer answer...
The HBase schema is really just the table name, the column families and then some attributes about the table. There are no column entries or data types. In HBase / MapRDB Binary, you only can store Byte data types. (Character Byte arrays or small blobs)
So if you have an HBase table... you can't really create a schema for Hive.
The other real problem is that HBase / MapRDB are really unstructured. You can create a column (cell) on the fly and you don't have any set schema. Hive has schema enforcement on read.
If you wanted to take a random row from an HBase table, you could build a Hive DDL string and use the hbase serde to define the schema in hive, however all of your fields would be strings so there is no type enforcement. And if you get a different row, you may or may not get the same number of columns or column descriptors. So some data may not appear in your hive table.
Now if I haven't convinced you... and if you really wanted to do this... you could scan your hbase table and for each row you can collect the column descriptor names. You can create a map to store them... going from memory, the tree map will keep only a distinct value and will store them in lexicographical order which is how you may want to add them to your schema. (I don't think that order matters and that under the cover Hive will order the results to match the schema. But since you don't have a schema, you might as well put them in sort order. ) From this list of known columns, you can make a DDL string and create the Hive table. You would also have to pull some metadata about the table so you can create the path required for MapRDB.
So while you can do it... Do you really want to and live with the limitations?
Retrieving data ...