[
https://issues.apache.org/jira/browse/HIVE-18434?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16323101#comment-16323101
]
Ashutosh Chauhan commented on HIVE-18434:
-----------------------------------------
Lets set up some test data.
{code}
create table t1 (a decimal (19,6))
insert into t1 values (-1511503446182.551758)
select * from t1
-1511503446182.551758
{code}
Good case
{code}
explain select * from t1 where a = -1511503446182.551758
STAGE DEPENDENCIES:
Stage-1 is a root stage
Stage-0 depends on stages: Stage-1
STAGE PLANS:
Stage: Stage-1
Map Reduce
Map Operator Tree:
TableScan
alias: t1
Statistics: Num rows: 1 Data size: 21 Basic stats: COMPLETE Column
stats: NONE
Filter Operator
predicate: (a = -1511503446182.551758) (type: boolean)
Statistics: Num rows: 1 Data size: 21 Basic stats: COMPLETE
Column stats: NONE
Select Operator
expressions: -1511503446182.551758 (type: decimal(19,6))
outputColumnNames: _col0
Statistics: Num rows: 1 Data size: 21 Basic stats: COMPLETE
Column stats: NONE
File Output Operator
compressed: false
Statistics: Num rows: 1 Data size: 21 Basic stats: COMPLETE
Column stats: NONE
table:
input format:
org.apache.hadoop.mapred.SequenceFileInputFormat
output format:
org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
Stage: Stage-0
Fetch Operator
limit: -1
Processor Tree:
ListSink
select * from t1 where a = -1511503446182.551758
-1511503446182.551758
{code}
Now, bad case
{code}
explain select * from t1 where a = '-1511503446182.551758'
STAGE DEPENDENCIES:
Stage-1 is a root stage
Stage-0 depends on stages: Stage-1
STAGE PLANS:
Stage: Stage-1
Map Reduce
Map Operator Tree:
TableScan
alias: t1
Statistics: Num rows: 1 Data size: 21 Basic stats: COMPLETE Column
stats: NONE
Filter Operator
predicate: (UDFToDouble(a) = -1.5115034461825518E12) (type:
boolean)
Statistics: Num rows: 1 Data size: 21 Basic stats: COMPLETE
Column stats: NONE
Select Operator
expressions: -1511503446182.5518 (type: decimal(19,6))
outputColumnNames: _col0
Statistics: Num rows: 1 Data size: 21 Basic stats: COMPLETE
Column stats: NONE
File Output Operator
compressed: false
Statistics: Num rows: 1 Data size: 21 Basic stats: COMPLETE
Column stats: NONE
table:
input format:
org.apache.hadoop.mapred.SequenceFileInputFormat
output format:
org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe
Stage: Stage-0
Fetch Operator
limit: -1
Processor Tree:
ListSink
select * from t1 where a = '-1511503446182.551758'
-1511503446182.551800
{code}
As you observe we get a row which doesn't exist in table in bad case. Reason
for that is type resolution determines that expr type is double and adds a cast
on both sides which results in double getting evaluated and thus incorrect
results {{predicate: (UDFToDouble(a) = -1.5115034461825518E12)}}
Patch fixes this by coercing string constant into decimal and thus expression
is evaluated in decimals.
> 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)