Hi,
createTableWithSecondaryIndexes()
writeToTable()
After running above two functions, I can see two tablescreated in HBase
(test_table and test_table-column1).
There are 100 rows data in test_table , but I can't see any data in
test_table-column1.
I want to know whether I should configure something to make secondary index
work.
Thanks.
public void writeToTable() throws IOException {
HBaseConfiguration conf = new HBaseConfiguration();
conf.addResource(new Path(hbase_res));
IndexedTable table = new IndexedTable(conf,
Bytes.toBytes("test_table"));
String row = "test_row";
Put row_update = null;
byte[] column = Bytes.toBytes("columnfamily1");
byte[][] qualifier = new byte[][] {
Bytes.toBytes("column1"),
Bytes.toBytes("column2"),
Bytes.toBytes("column3"),
};
for (int i = 0; i < 100; i++) {
row_update = new Put(Bytes.toBytes(row + i));
row_update.add(column, qualifier[0], Bytes.toBytes("ray1-" +
(i/4)));
row_update.add(column, qualifier[1], Bytes.toBytes("ray2-" +
i));
row_update.add(column, qualifier[2], Bytes.toBytes("ray3-" +
i));
table.put(row_update);
}
table.close();
}
public void createTableWithSecondaryIndexes() throws IOException {
HBaseConfiguration conf = new HBaseConfiguration();
conf.addResource(new Path(hbase_res));
HTableDescriptor desc = new HTableDescriptor("test_table");
desc.addFamily(new HColumnDescriptor("columnfamily1"));
IndexedTableDescriptor idx_desc = new IndexedTableDescriptor(desc);
idx_desc.addIndex(new IndexSpecification("column1",
Bytes.toBytes("columnfamily1:column1")));
IndexedTableAdmin admin = null;
admin = new IndexedTableAdmin(conf);
if (admin.tableExists(Bytes.toBytes("test_table"))) {
if (admin.isTableEnabled("test_table")) {
admin.disableTable(Bytes.toBytes("test_table"));
}
admin.deleteTable(Bytes.toBytes("test_table"));
}
if (admin.tableExists(Bytes.toBytes("test_table-column1"))) {
if (admin.isTableEnabled("test_table-column1")) {
admin.disableTable(Bytes.toBytes("test_table-column1"));
}
admin.deleteTable(Bytes.toBytes("test_table-column1"));
}
admin.createIndexedTable(idx_desc);
}
Fleming Chiu(邱宏明)
707-6128
[email protected]
週一無肉日吃素救地球(Meat Free Monday Taiwan)
---------------------------------------------------------------------------
TSMC PROPERTY
This email communication (and any attachments) is proprietary information
for the sole use of its
intended recipient. Any unauthorized review, use or distribution by anyone
other than the intended
recipient is strictly prohibited. If you are not the intended recipient,
please notify the sender by
replying to this email, and then delete this email and any copies of it
immediately. Thank you.
---------------------------------------------------------------------------