Apologies if this reply us not relevant, I'm posting just in case my approach
to this problem is useful.

I'm using 20.1 and I'm looking to solve this sane problem by applying the
filter to a scan on the root table  and using the results to create
RowFilter instances which I use in a second scan. The second scan is against
the indexed table.



y_823910 wrote:
> 
> 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.                                                     
> 
> --------------------------------------------------------------------------- 
> 
> 
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/read-Filtered-Rows-From-Secondary-Index-tp26807781p26813826.html
Sent from the HBase User mailing list archive at Nabble.com.

Reply via email to