What are you trying to do? What happens when you run the below code? Thanks, St.Ack
2009/12/16 <[email protected]> > Hi there, > > I don't know how to use ColumnValueFilter in hbase-0.20.2 > to read some rows through my built Secondary Index. > Any suggestions or samples? > > > public static void readFilteredRowsFromSecondaryIndex() throws IOException > { > > IndexedTable table = new IndexedTable(config, > Bytes.toBytes("test_table")); > > Filter filter = new > ColumnValueFilter(Bytes.toBytes("columnfamily1:column1"), > CompareOp.EQUAL, > Bytes.toBytes("ray1-40")); > > ResultScanner scanner = table.getIndexedScanner("column1", > > HConstants.EMPTY_START_ROW, > null, > new byte[][] { > Bytes.toBytes("columnfamily1:column1"), > > Bytes.toBytes("columnfamily1:column1")}, > filter, > new byte[][] { > Bytes.toBytes("columnfamily1:column1"), > > Bytes.toBytes("columnfamily1:column1")}); > for (Result rowResult : scanner) { > > > System.out.println(Bytes.toString(rowResult.getValue(Bytes.toBytes("columnfamily1:column1")))); > } > > table.close(); > } > > > --------------------------------------------------------------------------------------------------------------------------------------------------- > public static void createTableWithSecondaryIndexes() throws IOException { > //HBaseConfiguration conf = new HBaseConfiguration(); > 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(config); > > 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); > } > > > ----------------------------------------------------------------------------------------------------------------------------------------- > > public static void writeToTable() throws IOException { > //HBaseConfiguration conf = new HBaseConfiguration(); > > IndexedTable table = new IndexedTable(config, > 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(); > } > > > 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. > > --------------------------------------------------------------------------- > > > >
