[ 
https://issues.apache.org/jira/browse/PHOENIX-3470?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15654391#comment-15654391
 ] 

James Taylor commented on PHOENIX-3470:
---------------------------------------

Sounds like your asking for a new Phoenix boolean data type that maps to the 
way HBase serializes a boolean (in the same way we have our unsigned_* types 
for this purpose), but that's not feasible in this case as we couldn't disallow 
a true boolean value like we disallow negative numbers for our unsigned types. 
Phoenix requires that the natural sort order match the binary sort order of the 
serialized bytes. Otherwise we'd have to constantly re-sort which is expensive. 
In the HBase scheme, true would sort ahead of false (much like negative numbers 
sort ahead of positive numbers in HBase serialization) which isn't correct. 
It's unfortunate that HBase didn't consider their serialization format more 
carefully.

If you use Phoenix APIs or at a minimum our PDataType serialization when the 
data is written, you'll be fine.

> Boolean values discrepancy with HBase byte format
> -------------------------------------------------
>
>                 Key: PHOENIX-3470
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3470
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.8.0
>            Reporter: Maksim Zhuk
>             Fix For: verify
>
>
> There's an inconsstency between Phoenix and Hbase in handling boolean "true" 
> in byte format.
> [Phoenix|https://phoenix.apache.org/language/datatypes.html#boolean_type] - 
> "The binary representation is a single byte with 0 for false and 1 for true"
> [HBase|https://hbase.apache.org/apidocs/src-html/org/apache/hadoop/hbase/util/Bytes.html#line.739]
>  - "True becomes -1 and false becomes 0"
> {code:title=org.apache.hadoop.hbase.util.Bytes|borderStyle=solid}
>   /**
>    * Convert a boolean to a byte array. True becomes -1
>    * and false becomes 0.
>    *
>    * @param b value
>    * @return <code>b</code> encoded in a byte array.
>    */
>   public static byte [] toBytes(final boolean b) {
>     return new byte[] { b ? (byte) -1 : (byte) 0 };
>   }
> {code}
> When Phoenix metadata is applied over the existing HBase table this causes 
> issues for queries like "... WHERE FIELD=TRUE ..." not finding any results.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to