hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vladimir Rodionov <vladrodio...@gmail.com>
Subject Re: Get using `.addColumn()` and `.setFilter()`
Date Tue, 04 Aug 2015 01:21:06 GMT
How about this one?

Get get = new Get(row)
 get.addFamily(FAMILY);

 FilterList list = new FilterList(Operator.MUST_PASS_ONE);

list.addFilter( new ColumnPrefixFilter(Bytes.toBytes("sess")));
list.addFilter( new ColumnPrefixFilter(Bytes.toBytes("name")));
get.setFilter(list);

-Vlad

On Aug 3, 2015 4:21 PM, "Ted Yu" <yuzhihong@gmail.com> wrote:

> Combining ColumnPrefixFilter and QualifierFilter in FilterList should work.
>
> I think the above should be a bit slower compared to using
> MultipleColumnPrefixFilter.
> Take a look at the implementation of MultipleColumnPrefixFilter ,
> especially filterColumn() method where optimization is made.
>
> If you have time, you can try both approaches.
>
> Cheers
>
> On Mon, Aug 3, 2015 at 4:14 PM, Dmitry Minkovsky <dminkovsky@gmail.com>
> wrote:
>
> > Thanks guys.
> >
> > Ted: your solution involves more filtration. I hadn't seen
> > MultipleColumnPrefixFilter but I have seen FilterList which I found can
> be
> > used to combine ColumnPrefixFilter and QualifierFilter for the desired
> > effect. But this uses filtration. Does this filtration scale?
> >
> > Vlad: this doesn't work. The filter excludes the name column.
> >
> > On Monday, August 3, 2015, Vladimir Rodionov <vladrodionov@gmail.com>
> > wrote:
> >
> > > Get get = new Get(row)
> > >             .addFamily(FAMILY)
> > >             .setFilter(new ColumnPrefixFilter(Bytes.toBytes("sess")));
> > >
> > > should work.
> > >
> > > -Vlad
> > >
> > > On Mon, Aug 3, 2015 at 2:41 PM, Ted Yu <yuzhihong@gmail.com
> > <javascript:;>>
> > > wrote:
> > >
> > > > Is there column with prefix 'name' whose column name is longer than
> > > 'name'
> > > > (such as 'name0') ?
> > > >
> > > > If not, take a look at MultipleColumnPrefixFilter
> > > >
> > > >
> > > > Cheers
> > > >
> > > > On Mon, Aug 3, 2015 at 1:39 PM, Dmitry Minkovsky <
> dminkovsky@gmail.com
> > > <javascript:;>>
> > > > wrote:
> > > >
> > > > > I'm trying to construct a `Get` the does two things:
> > > > >
> > > > > - Gets a cell by specific, known column qualifier, and
> > > > > - Gets more cells by column qualifier prefix
> > > > >
> > > > >
> > > > >
> > > > > public class Test {
> > > > >
> > > > >     public static final byte[] FAMILY = Bytes.toBytes("f");
> > > > >
> > > > >     public static void main(String[] args) throws IOException {
> > > > >
> > > > >         // Make a connection
> > > > >
> > > > >
> > > > >         Configuration config = HBaseConfiguration.create();
> > > > >         Connection connection =
> > > > ConnectionFactory.createConnection(config);
> > > > >
> > > > >         Table table = connection.getTable(TableName.valueOf("t"));
> > > > >
> > > > >         // Create a sample row
> > > > >
> > > > >         byte[] row = Bytes.toBytes("row1");
> > > > >
> > > > >
> > > > >         Put put = new Put(row)
> > > > >             .addColumn(FAMILY, Bytes.toBytes("name"),
> > > > > Bytes.toBytes("dima"))
> > > > >             .addColumn(FAMILY, Bytes.toBytes("sess:100"),
> > > > > Bytes.toBytes("deadbeef"))
> > > > >             .addColumn(FAMILY, Bytes.toBytes("age"),
> > > > Bytes.toBytes("30"));
> > > > >
> > > > >         table.put(put);
> > > > >
> > > > >
> > > > >         // Query for the sample row
> > > > >
> > > > >
> > > > >         Get get = new Get(row)
> > > > >             .addColumn(FAMILY, Bytes.toBytes("name"))
> > > > >             .setFilter(new
> > ColumnPrefixFilter(Bytes.toBytes("sess")));
> > > > >
> > > > >         Result result = table.get(get);
> > > > >
> > > > >         System.out.println(result.size());
> > > > >
> > > > >         Map<byte[], byte[]> map = result.getFamilyMap(FAMILY);
> > > > >
> > > > >         if (map != null) {
> > > > >             for (Map.Entry<byte[], byte[]> entry : map.entrySet())
> {
> > > > >                 System.out.println("key: `" +
> > > > > Bytes.toString(entry.getKey()) + "`, value: `" +
> > > > > Bytes.toString(entry.getValue()) + "`");
> > > > >             }
> > > > >         }
> > > > >
> > > > >         table.close();
> > > > >         connection.close();
> > > > >     }
> > > > > }
> > > > >
> > > > >
> > > > > The desire here is to get two columns/cells: "name" and "sess:100".
> > > > > However, I get no cells. I think this happens because I only add
> > "name"
> > > > and
> > > > > then filter it out. What is the best way to get the desired effect?
> > > > >
> > > >
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message