This is an automated email from the ASF dual-hosted git repository.

rameshkumar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c89b306231 HIVE-27293 Vectorization: Incorrect results with nvl for 
ORC table (#4379)
7c89b306231 is described below

commit 7c89b306231773759172ee67f05ff81f7d08f20c
Author: Ramesh Kumar <[email protected]>
AuthorDate: Fri Jun 9 07:59:44 2023 -0700

    HIVE-27293 Vectorization: Incorrect results with nvl for ORC table (#4379)
    
    @ramesh0201 Reviewed by @ayushtkn @rkirtir @difin
---
 data/files/esource.txt                             |   3 +
 .../queries/clientpositive/vectorization_nvl.q     |  50 +++++++
 .../clientpositive/llap/vectorization_nvl.q.out    | 165 +++++++++++++++++++++
 .../hive/ql/exec/vector/Decimal64ColumnVector.java |   4 +-
 4 files changed, 220 insertions(+), 2 deletions(-)

diff --git a/data/files/esource.txt b/data/files/esource.txt
new file mode 100644
index 00000000000..e73c3927096
--- /dev/null
+++ b/data/files/esource.txt
@@ -0,0 +1,3 @@
+12345|30001231|9|19613|IND|222222|-1.00|abc|20230414|0
+67891|20410308|2|19313|IND|5555555|-1.00|def|20230414|0
+15678|20370904|1|NULL|IND|4444444|NULL|xyz|20230414|0
diff --git a/ql/src/test/queries/clientpositive/vectorization_nvl.q 
b/ql/src/test/queries/clientpositive/vectorization_nvl.q
new file mode 100644
index 00000000000..8f2472f9c51
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/vectorization_nvl.q
@@ -0,0 +1,50 @@
+drop table if exists esource;
+drop table if exists etarget;
+
+create table if not exists esource_txt (
+ client_id string,
+   id_enddate decimal(10,0),                     
+   client_gender string,                         
+   birthday decimal(10,0),                       
+   nationality string,
+   address_zipcode string,                       
+   income decimal(15,2),                         
+   address string,
+   part_date int
+) row format delimited fields terminated by '|'
+ lines terminated by '\n' stored as textfile;
+
+create table esource like esource_txt;
+alter table esource set fileformat orc;
+
+load data local inpath '../../data/files/esource.txt' overwrite into table 
esource_txt;
+
+insert overwrite table esource select * from esource_txt;
+
+Select * from esource where part_date = 20230414;
+
+CREATE EXTERNAL TABLE etarget(                   
+   client_id string,
+   id_enddate decimal(10,0),                     
+   client_gender string,                         
+   birthday decimal(10,0),                       
+   nationality string,
+   address_zipcode string,                       
+   income decimal(15,2),                         
+   address string,
+   part_date int,
+   bdata_no int)
+ CLUSTERED BY (                                    
+   bdata_no)                                       
+ INTO 1 BUCKETS                                    
+ ROW FORMAT SERDE                                  
+   'org.apache.hadoop.hive.ql.io.orc.OrcSerde'     
+ STORED AS INPUTFORMAT                             
+   'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' 
+ OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat';
+
+
+ insert overwrite table etarget
+select mt.*, floor(rand() * 1) as bdata_no from (select nvl(np.client_id,' 
'),nvl(np.id_enddate,cast(0 as decimal(10,0))),nvl(np.client_gender,' 
'),nvl(np.birthday,cast(0 as decimal(10,0))),nvl(np.nationality,' 
'),nvl(np.address_zipcode,' '),nvl(np.income,cast(0 as 
decimal(15,2))),nvl(np.address,' '),nvl(np.part_date,cast(0 as int)) from 
(select * from esource where part_date = 20230414) np) mt;
+
+select client_id,birthday,income from etarget;
diff --git a/ql/src/test/results/clientpositive/llap/vectorization_nvl.q.out 
b/ql/src/test/results/clientpositive/llap/vectorization_nvl.q.out
new file mode 100644
index 00000000000..c0ecef16eff
--- /dev/null
+++ b/ql/src/test/results/clientpositive/llap/vectorization_nvl.q.out
@@ -0,0 +1,165 @@
+PREHOOK: query: drop table if exists esource
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table if exists esource
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: drop table if exists etarget
+PREHOOK: type: DROPTABLE
+POSTHOOK: query: drop table if exists etarget
+POSTHOOK: type: DROPTABLE
+PREHOOK: query: create table if not exists esource_txt (
+ client_id string,
+   id_enddate decimal(10,0),                     
+   client_gender string,                         
+   birthday decimal(10,0),                       
+   nationality string,
+   address_zipcode string,                       
+   income decimal(15,2),                         
+   address string,
+   part_date int
+) row format delimited fields terminated by '|'
+ lines terminated by '\n' stored as textfile
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@esource_txt
+POSTHOOK: query: create table if not exists esource_txt (
+ client_id string,
+   id_enddate decimal(10,0),                     
+   client_gender string,                         
+   birthday decimal(10,0),                       
+   nationality string,
+   address_zipcode string,                       
+   income decimal(15,2),                         
+   address string,
+   part_date int
+) row format delimited fields terminated by '|'
+ lines terminated by '\n' stored as textfile
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@esource_txt
+PREHOOK: query: create table esource like esource_txt
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@esource
+POSTHOOK: query: create table esource like esource_txt
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@esource
+PREHOOK: query: alter table esource set fileformat orc
+PREHOOK: type: ALTERTABLE_FILEFORMAT
+PREHOOK: Input: default@esource
+PREHOOK: Output: default@esource
+POSTHOOK: query: alter table esource set fileformat orc
+POSTHOOK: type: ALTERTABLE_FILEFORMAT
+POSTHOOK: Input: default@esource
+POSTHOOK: Output: default@esource
+PREHOOK: query: load data local inpath '../../data/files/esource.txt' 
overwrite into table esource_txt
+PREHOOK: type: LOAD
+#### A masked pattern was here ####
+PREHOOK: Output: default@esource_txt
+POSTHOOK: query: load data local inpath '../../data/files/esource.txt' 
overwrite into table esource_txt
+POSTHOOK: type: LOAD
+#### A masked pattern was here ####
+POSTHOOK: Output: default@esource_txt
+PREHOOK: query: insert overwrite table esource select * from esource_txt
+PREHOOK: type: QUERY
+PREHOOK: Input: default@esource_txt
+PREHOOK: Output: default@esource
+POSTHOOK: query: insert overwrite table esource select * from esource_txt
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@esource_txt
+POSTHOOK: Output: default@esource
+POSTHOOK: Lineage: esource.address SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:address, type:string, comment:null), 
]
+POSTHOOK: Lineage: esource.address_zipcode SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:address_zipcode, type:string, 
comment:null), ]
+POSTHOOK: Lineage: esource.birthday SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:birthday, type:decimal(10,0), 
comment:null), ]
+POSTHOOK: Lineage: esource.client_gender SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:client_gender, type:string, 
comment:null), ]
+POSTHOOK: Lineage: esource.client_id SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:client_id, type:string, 
comment:null), ]
+POSTHOOK: Lineage: esource.id_enddate SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:id_enddate, type:decimal(10,0), 
comment:null), ]
+POSTHOOK: Lineage: esource.income SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:income, type:decimal(15,2), 
comment:null), ]
+POSTHOOK: Lineage: esource.nationality SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:nationality, type:string, 
comment:null), ]
+POSTHOOK: Lineage: esource.part_date SIMPLE 
[(esource_txt)esource_txt.FieldSchema(name:part_date, type:int, comment:null), ]
+PREHOOK: query: Select * from esource where part_date = 20230414
+PREHOOK: type: QUERY
+PREHOOK: Input: default@esource
+#### A masked pattern was here ####
+POSTHOOK: query: Select * from esource where part_date = 20230414
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@esource
+#### A masked pattern was here ####
+12345  30001231        9       19613   IND     222222  -1.00   abc     20230414
+67891  20410308        2       19313   IND     5555555 -1.00   def     20230414
+15678  20370904        1       NULL    IND     4444444 NULL    xyz     20230414
+PREHOOK: query: CREATE EXTERNAL TABLE etarget(                   
+   client_id string,
+   id_enddate decimal(10,0),                     
+   client_gender string,                         
+   birthday decimal(10,0),                       
+   nationality string,
+   address_zipcode string,                       
+   income decimal(15,2),                         
+   address string,
+   part_date int,
+   bdata_no int)
+ CLUSTERED BY (                                    
+   bdata_no)                                       
+ INTO 1 BUCKETS                                    
+ ROW FORMAT SERDE                                  
+   'org.apache.hadoop.hive.ql.io.orc.OrcSerde'     
+ STORED AS INPUTFORMAT                             
+   'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' 
+ OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@etarget
+POSTHOOK: query: CREATE EXTERNAL TABLE etarget(                   
+   client_id string,
+   id_enddate decimal(10,0),                     
+   client_gender string,                         
+   birthday decimal(10,0),                       
+   nationality string,
+   address_zipcode string,                       
+   income decimal(15,2),                         
+   address string,
+   part_date int,
+   bdata_no int)
+ CLUSTERED BY (                                    
+   bdata_no)                                       
+ INTO 1 BUCKETS                                    
+ ROW FORMAT SERDE                                  
+   'org.apache.hadoop.hive.ql.io.orc.OrcSerde'     
+ STORED AS INPUTFORMAT                             
+   'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' 
+ OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@etarget
+PREHOOK: query: insert overwrite table etarget
+select mt.*, floor(rand() * 1) as bdata_no from (select nvl(np.client_id,' 
'),nvl(np.id_enddate,cast(0 as decimal(10,0))),nvl(np.client_gender,' 
'),nvl(np.birthday,cast(0 as decimal(10,0))),nvl(np.nationality,' 
'),nvl(np.address_zipcode,' '),nvl(np.income,cast(0 as 
decimal(15,2))),nvl(np.address,' '),nvl(np.part_date,cast(0 as int)) from 
(select * from esource where part_date = 20230414) np) mt
+PREHOOK: type: QUERY
+PREHOOK: Input: default@esource
+PREHOOK: Output: default@etarget
+POSTHOOK: query: insert overwrite table etarget
+select mt.*, floor(rand() * 1) as bdata_no from (select nvl(np.client_id,' 
'),nvl(np.id_enddate,cast(0 as decimal(10,0))),nvl(np.client_gender,' 
'),nvl(np.birthday,cast(0 as decimal(10,0))),nvl(np.nationality,' 
'),nvl(np.address_zipcode,' '),nvl(np.income,cast(0 as 
decimal(15,2))),nvl(np.address,' '),nvl(np.part_date,cast(0 as int)) from 
(select * from esource where part_date = 20230414) np) mt
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@esource
+POSTHOOK: Output: default@etarget
+POSTHOOK: Lineage: etarget.address EXPRESSION 
[(esource)esource.FieldSchema(name:address, type:string, comment:null), ]
+POSTHOOK: Lineage: etarget.address_zipcode EXPRESSION 
[(esource)esource.FieldSchema(name:address_zipcode, type:string, comment:null), 
]
+POSTHOOK: Lineage: etarget.bdata_no EXPRESSION []
+POSTHOOK: Lineage: etarget.birthday EXPRESSION 
[(esource)esource.FieldSchema(name:birthday, type:decimal(10,0), comment:null), 
]
+POSTHOOK: Lineage: etarget.client_gender EXPRESSION 
[(esource)esource.FieldSchema(name:client_gender, type:string, comment:null), ]
+POSTHOOK: Lineage: etarget.client_id EXPRESSION 
[(esource)esource.FieldSchema(name:client_id, type:string, comment:null), ]
+POSTHOOK: Lineage: etarget.id_enddate EXPRESSION 
[(esource)esource.FieldSchema(name:id_enddate, type:decimal(10,0), 
comment:null), ]
+POSTHOOK: Lineage: etarget.income EXPRESSION 
[(esource)esource.FieldSchema(name:income, type:decimal(15,2), comment:null), ]
+POSTHOOK: Lineage: etarget.nationality EXPRESSION 
[(esource)esource.FieldSchema(name:nationality, type:string, comment:null), ]
+POSTHOOK: Lineage: etarget.part_date SIMPLE []
+PREHOOK: query: select client_id,birthday,income from etarget
+PREHOOK: type: QUERY
+PREHOOK: Input: default@etarget
+#### A masked pattern was here ####
+POSTHOOK: query: select client_id,birthday,income from etarget
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@etarget
+#### A masked pattern was here ####
+12345  19613   -1.00
+67891  19313   -1.00
+15678  0       0.00
diff --git 
a/storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/Decimal64ColumnVector.java
 
b/storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/Decimal64ColumnVector.java
index 7f47b905f24..a06ce39b46c 100644
--- 
a/storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/Decimal64ColumnVector.java
+++ 
b/storage-api/src/java/org/apache/hadoop/hive/ql/exec/vector/Decimal64ColumnVector.java
@@ -136,12 +136,12 @@ public class Decimal64ColumnVector extends 
LongColumnVector implements IDecimalC
           decimal64ColVector.vector[inputElementNum], 
decimal64ColVector.scale);
       scratchHiveDecWritable.mutateEnforcePrecisionScale(precision, scale);
       if (scratchHiveDecWritable.isSet()) {
-        vector[inputElementNum] = scratchHiveDecWritable.serialize64(scale);
+        vector[outputElementNum] = scratchHiveDecWritable.serialize64(scale);
       } else {
 
         // In effect, the input is NULL because of out-of-range 
precision/scale.
         noNulls = false;
-        isNull[inputElementNum] = true;
+        isNull[outputElementNum] = true;
       }
     } else {
 

Reply via email to