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

Xuefu Zhang commented on HIVE-18434:
------------------------------------

Thanks for the explanation. While your patch may fix the particular problem, 
I'm afraid it might introduce inconsistency in treating string literals for 
numbers. My understanding is that Hive treats and implicitly converts number 
string literals (such as "3.1415926" as double rather than decimal. When a 
decimal (as precise data type) and a double (as imprecise data type) appear in 
the same numeric or logical operations, the result data type is double. For 
instance:
{code}
hive> explain select 3.14BD + "3.14";
OK
STAGE DEPENDENCIES:
  Stage-0 is a root stage

STAGE PLANS:
  Stage: Stage-0
    Fetch Operator
      limit: -1
      Processor Tree:
        TableScan
          alias: _dummy_table
          Row Limit Per Split: 1
          Statistics: Num rows: 1 Data size: 1 Basic stats: COMPLETE Column 
stats: COMPLETE
          Select Operator
            expressions: 6.28 (type: double)
            outputColumnNames: _col0
            Statistics: Num rows: 1 Data size: 8 Basic stats: COMPLETE Column 
stats: COMPLETE
            ListSink

hive> desc dec1;
OK
name                    string                                      
value                   decimal(5,2)                                

hive> explain select * from dec1 where value="3.14";
OK
STAGE DEPENDENCIES:
  Stage-0 is a root stage

STAGE PLANS:
  Stage: Stage-0
    Fetch Operator
      limit: -1
      Processor Tree:
        TableScan
          alias: dec1
          filterExpr: (value = '3.14') (type: boolean)
          Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column 
stats: NONE
          Filter Operator
            predicate: (value = '3.14') (type: boolean)
            Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column 
stats: NONE
            Select Operator
              expressions: name (type: string), value (type: decimal(5,2))
              outputColumnNames: _col0, _col1
              Statistics: Num rows: 1 Data size: 0 Basic stats: PARTIAL Column 
stats: NONE
              ListSink
{code}
I believe that {{ filterExpr: (value = '3.14') (type: boolean)}} will convert 
both side to double and than compare internally.

The problem you described seems to be one related to constant optimization. 
Specifically, the select op should project {{a}} instead of the following:
{code}
              Select Operator
                expressions: -1511503446182.5518 (type: decimal(19,6))
{code}
The numeric comparison should be still based on double. We cannot just use 
what's is used in the filter condition to rewrite the projection columns.

> Type is not determined correctly for comparison between decimal column and 
> string constant
> ------------------------------------------------------------------------------------------
>
>                 Key: HIVE-18434
>                 URL: https://issues.apache.org/jira/browse/HIVE-18434
>             Project: Hive
>          Issue Type: Bug
>          Components: Types
>            Reporter: Ashutosh Chauhan
>            Assignee: Ashutosh Chauhan
>         Attachments: HIVE-18434.patch
>
>




--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to