Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase >> mail # user >> The Problems When Retrieving By BinaryComparator


Copy link to this message
-
The Problems When Retrieving By BinaryComparator
Dear all,

I created a table as follows. I need to retrieve by the column of "Salary",
which is a long type data. Some errors are got as follows.

ROW                                 COLUMN+CELL

 Classmate1                         column=ClassmateFamily:Address,
timestamp=1330118559432, value=Canada
 Classmate1                         column=ClassmateFamily:Age,
timestamp=1330118559429, value=42
 Classmate1                         column=ClassmateFamily:Career,
timestamp=1330118559431, value=Faculty
 Classmate1                         column=ClassmateFamily:Hobby,
timestamp=1330118559433, value=Soccer
 Classmate1                         column=ClassmateFamily:Name,
timestamp=1330118559427, value=Bing
 Classmate1                         column=ClassmateFamily:Salary,
timestamp=1330121577483, value=\x00\x00\x00\x00\x00\x00\x03\xEA  (1002 -
long)
 Classmate2                         column=ClassmateFamily:Address,
timestamp=1330118559436, value=US
 Classmate2                         column=ClassmateFamily:Age,
timestamp=1330118559434, value=52
 Classmate2                         column=ClassmateFamily:Career,
timestamp=1330118559435, value=Educator
 Classmate2                         column=ClassmateFamily:Hobby,
timestamp=1330118559437, value=Music
 Classmate2                         column=ClassmateFamily:Name,
timestamp=1330118559433, value=GreatFree
 Classmate2                         column=ClassmateFamily:Salary,
timestamp=1330118559393, value=\x00\x00\x00\x00\x00\x00\x05\xDC  (1500 -
long)
 Classmate3                         column=ClassmateFamily:Address,
timestamp=1330118559440, value=US
 Classmate3                         column=ClassmateFamily:Age,
timestamp=1330118559438, value=100
 Classmate3                         column=ClassmateFamily:Career,
timestamp=1330118559439, value=Researcher
 Classmate3                         column=ClassmateFamily:Hobby,
timestamp=1330118559442, value=Science
 Classmate3                         column=ClassmateFamily:Name,
timestamp=1330118559437, value=LBLabs
 Classmate3                         column=ClassmateFamily:Salary,
timestamp=1330118559397, value=\x00\x00\x00\x00\x00\x00\x07\x08  (1800 -
long)
 Classmate4                         column=ClassmateFamily:Address,
timestamp=1330118559445, value=Baoji
 Classmate4                         column=ClassmateFamily:Age,
timestamp=1330118559443, value=41
 Classmate4                         column=ClassmateFamily:Career,
timestamp=1330118559444, value=Lawyer
 Classmate4                         column=ClassmateFamily:Hobby,
timestamp=1330118559446, value=Drawing
 Classmate4                         column=ClassmateFamily:Name,
timestamp=1330118559442, value=Dezhi
 Classmate4                         column=ClassmateFamily:Salary,
timestamp=1330118559399, value=\x00\x00\x00\x00\x00\x00\x03   (800 - long)

The code is listed below.

                Filter filter = new
ValueFilter(CompareFilter.CompareOp.LESS, new
BinaryComparator(Bytes.toBytes(1000))); // The filter line *

                Scan scan = new Scan();
                scan.addColumn(Bytes.toBytes("ClassmateFamily"),
Bytes.toBytes("Salary"));
                scan.setFilter(filter);

                ResultScanner scanner = table.getScanner(scan);
                for (Result result : scanner)
                {
                        for (KeyValue kv : result.raw())
                        {
                                System.out.println("KV: " + kv + ", Value:
" + Bytes.toLong(kv.getValue()));
                        }
                }
                scanner.close();

                System.out.println("------------------------------------");

                Get get = new Get(Bytes.toBytes("Classmate3"));
                get.setFilter(filter);
                Result result = table.get(get);
                for (KeyValue kv : result.raw())
                {
                        System.out.println("KV: " + kv + ", Value: " +
Bytes.toLong(kv.getValue()));
                }

I think the correct result should be like the one below. Only the rows that
are less than 1000 must be returned, right?

     [java] KV: Classmate4/ClassmateFamily:Salary/1330118559399/Put/vlen=8,
Value: 800
     [java] ------------------------------------
But, the actual result is as follows. Some rows which are higher than 1000
are returned. Why?

     [java] KV: Classmate1/ClassmateFamily:Salary/1330121577483/Put/vlen=8,
Value: 1002
     [java] KV: Classmate2/ClassmateFamily:Salary/1330118559393/Put/vlen=8,
Value: 1500
     [java] KV: Classmate3/ClassmateFamily:Salary/1330118559397/Put/vlen=8,
Value: 1800
     [java] KV: Classmate4/ClassmateFamily:Salary/1330118559399/Put/vlen=8,
Value: 800
     [java] ------------------------------------
     [java] KV: Classmate3/ClassmateFamily:Salary/1330118559397/Put/vlen=8,
Value: 1800

If I change the filter line to the following one,

         Filter filter = new ValueFilter(CompareFilter.CompareOp.GREATER,
new BinaryComparator(Bytes.toBytes(1000))); // The filter line *

I guess the correct result should be as follows. The ones that are higher
than 1000 must be returned.

     [java] KV: Classmate1/ClassmateFamily:Salary/1330121577483/Put/vlen=8,
Value: 1002
     [java] KV: Classmate2/ClassmateFamily:Salary/1330118559393/Put/vlen=8,
Value: 1500
     [java] KV: Classmate3/ClassmateFamily:Salary/1330118559397/Put/vlen=8,
Value: 1800
     [java] ------------------------------------
     [java] KV: Classmate3/ClassmateFamily:Salary/1330118559397/Put/vlen=8,
Value: 1800

But in practice, I got a different result and an exception as follows. I
cannot figure out the problem.

     [java] ------------------------------------
     [java] Exception in thread "main" java.lang.IllegalArgumentException:
offset (0) + length (8) exceed the capacity of the array: 2
     [java] at
org.apache.hadoop.hbase.util.Bytes.explainWrongLengthOrOffset(Bytes.java:527)
     [java] at org.apache.hadoop.hbase.util.Bytes.toLong(Bytes.java:505)
     [jav
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB