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?

Reply via email to