hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bing Li <lbl...@gmail.com>
Subject Re: The Problems When Retrieving By BinaryComparator
Date Sat, 25 Feb 2012 06:46:14 GMT
Mr Gupta,

Yes, you are right. After changing Bytes.toBytes(1000) to
Bytes.toBytes(1000L), it works fine.

However, the following exception still exists.

     [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)
     [java]  at org.apache.hadoop.hbase.util.Bytes.toLong(Bytes.java:478)
     [java]  at
com.greatfree.testing.hbase.OrderedQualifierValue.main(Unknown Source)

After searching on the Web, one said it was possible that int type was
inserted into the table while retrieving the long value. I created the
table again and inserted the long type. But I still got the exception. I am
trying to solve the problem.

Thanks so much!
Bing


On Sat, Feb 25, 2012 at 8:31 AM, T Vinod Gupta <tvinod@readypulse.com>wrote:

> when you do  Bytes.toBytes(1000), you are not telling it whether 1000 is
> integer or long.. you have to be super careful here..
> i didnt read the flow fully but this caught my eye immediate.. try
> repopulating properly and use proper types when using Bytes.
>
> thanks
>
> On Fri, Feb 24, 2012 at 4:25 PM, Bing Li <lblabs@gmail.com> wrote:
>
>> 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)
>>     [java] at org.apache.hadoop.hbase.util.Bytes.toLong(Bytes.java:478)
>>     [java] at
>> com.greatfree.testing.hbase.OrderedQualifierValue.main(Unknown Source)
>>
>> Could you please give me a hand? Thanks so much!
>>
>> Best regards,
>> Bing
>>
>
>

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