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 Mon, 03 Aug 2015 21:43:34 GMT
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> 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>
> 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