diff --git a/contrib/src/test/queries/clientpositive/dboutput.q b/contrib/src/test/queries/clientpositive/dboutput.q
index 2a76242a78cc..80108aa03900 100644
--- a/contrib/src/test/queries/clientpositive/dboutput.q
+++ b/contrib/src/test/queries/clientpositive/dboutput.q
@@ -1,3 +1,4 @@
+--!qt:database:derby:qdb
 --! qt:dataset:src
 set hive.optimize.limit=false;
 set hive.mapred.mode=nonstrict;
@@ -20,13 +21,13 @@ DESCRIBE FUNCTION EXTENDED dboutput;
 
 EXPLAIN FROM src
 
-SELECT dboutput ( 'jdbc:derby:../build/test_dboutput_db\;create=true','','',
+SELECT dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE app_info ( kkey VARCHAR(255) NOT NULL, vvalue VARCHAR(255) NOT NULL, UNIQUE(kkey))' ),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','a'),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','b')
 
 limit 1;
@@ -34,20 +35,20 @@ limit 1;
 
 FROM src 
 
-SELECT dboutput ( 'jdbc:derby:../build/test_dboutput_db\;create=true','','',
+SELECT dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE app_info ( kkey INTEGER NOT NULL, vvalue VARCHAR(255) NOT NULL, UNIQUE(kkey))' ),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','a'),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','b')
 
 limit 1;
 
 EXPLAIN SELECT
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)',key,value)
 
 FROM src WHERE key < 10;
@@ -55,12 +56,11 @@ FROM src WHERE key < 10;
 
 SELECT
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)',key,value)
 
 FROM src WHERE key < 10;
 
-dfs -rmr ../build/test_dboutput_db;
 dfs -rmr derby.log;
 
 DROP TEMPORARY FUNCTION dboutput;
diff --git a/contrib/src/test/results/clientpositive/dboutput.q.out b/contrib/src/test/results/clientpositive/dboutput.q.out
index 471f074e34b4..0fe4108ce44c 100644
--- a/contrib/src/test/results/clientpositive/dboutput.q.out
+++ b/contrib/src/test/results/clientpositive/dboutput.q.out
@@ -24,13 +24,13 @@ Function class:org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOut
 Function type:TEMPORARY
 PREHOOK: query: EXPLAIN FROM src
 
-SELECT dboutput ( 'jdbc:derby:../build/test_dboutput_db\;create=true','','',
+#### A masked pattern was here ####
 'CREATE TABLE app_info ( kkey VARCHAR(255) NOT NULL, vvalue VARCHAR(255) NOT NULL, UNIQUE(kkey))' ),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','a'),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','b')
 
 limit 1
@@ -39,13 +39,13 @@ PREHOOK: Input: default@src
 #### A masked pattern was here ####
 POSTHOOK: query: EXPLAIN FROM src
 
-SELECT dboutput ( 'jdbc:derby:../build/test_dboutput_db\;create=true','','',
+#### A masked pattern was here ####
 'CREATE TABLE app_info ( kkey VARCHAR(255) NOT NULL, vvalue VARCHAR(255) NOT NULL, UNIQUE(kkey))' ),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','a'),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','b')
 
 limit 1
@@ -64,7 +64,7 @@ STAGE PLANS:
             alias: src
             Statistics: Num rows: 500 Data size: 5312 Basic stats: COMPLETE Column stats: COMPLETE
             Select Operator
-              expressions: dboutput('jdbc:derby:../build/test_dboutput_db;create=true','','','CREATE TABLE app_info ( kkey VARCHAR(255) NOT NULL, vvalue VARCHAR(255) NOT NULL, UNIQUE(kkey))') (type: int), dboutput('jdbc:derby:../build/test_dboutput_db','','','INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','a') (type: int), dboutput('jdbc:derby:../build/test_dboutput_db','','','INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','b') (type: int)
+#### A masked pattern was here ####
               outputColumnNames: _col0, _col1, _col2
               Statistics: Num rows: 500 Data size: 6000 Basic stats: COMPLETE Column stats: COMPLETE
               Limit
@@ -87,13 +87,13 @@ STAGE PLANS:
 
 PREHOOK: query: FROM src 
 
-SELECT dboutput ( 'jdbc:derby:../build/test_dboutput_db\;create=true','','',
+#### A masked pattern was here ####
 'CREATE TABLE app_info ( kkey INTEGER NOT NULL, vvalue VARCHAR(255) NOT NULL, UNIQUE(kkey))' ),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','a'),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','b')
 
 limit 1
@@ -102,13 +102,13 @@ PREHOOK: Input: default@src
 #### A masked pattern was here ####
 POSTHOOK: query: FROM src 
 
-SELECT dboutput ( 'jdbc:derby:../build/test_dboutput_db\;create=true','','',
+#### A masked pattern was here ####
 'CREATE TABLE app_info ( kkey INTEGER NOT NULL, vvalue VARCHAR(255) NOT NULL, UNIQUE(kkey))' ),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','a'),
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)','20','b')
 
 limit 1
@@ -118,7 +118,7 @@ POSTHOOK: Input: default@src
 0	0	1
 PREHOOK: query: EXPLAIN SELECT
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)',key,value)
 
 FROM src WHERE key < 10
@@ -127,7 +127,7 @@ PREHOOK: Input: default@src
 #### A masked pattern was here ####
 POSTHOOK: query: EXPLAIN SELECT
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)',key,value)
 
 FROM src WHERE key < 10
@@ -150,7 +150,7 @@ STAGE PLANS:
               predicate: (UDFToDouble(key) < 10.0D) (type: boolean)
               Statistics: Num rows: 166 Data size: 29548 Basic stats: COMPLETE Column stats: COMPLETE
               Select Operator
-                expressions: dboutput('jdbc:derby:../build/test_dboutput_db','','','INSERT INTO app_info (kkey,vvalue) VALUES (?,?)',key,value) (type: int)
+#### A masked pattern was here ####
                 outputColumnNames: _col0
                 Statistics: Num rows: 166 Data size: 664 Basic stats: COMPLETE Column stats: COMPLETE
                 File Output Operator
@@ -170,7 +170,7 @@ STAGE PLANS:
 
 PREHOOK: query: SELECT
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)',key,value)
 
 FROM src WHERE key < 10
@@ -179,7 +179,7 @@ PREHOOK: Input: default@src
 #### A masked pattern was here ####
 POSTHOOK: query: SELECT
 
-dboutput('jdbc:derby:../build/test_dboutput_db','','',
+#### A masked pattern was here ####
 'INSERT INTO app_info (kkey,vvalue) VALUES (?,?)',key,value)
 
 FROM src WHERE key < 10
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/README_DO_NOT_TOUCH_FILES.txt b/data/files/dataconnector_derbydb/db_for_connectortest.db/README_DO_NOT_TOUCH_FILES.txt
deleted file mode 100644
index a4bc14529893..000000000000
--- a/data/files/dataconnector_derbydb/db_for_connectortest.db/README_DO_NOT_TOUCH_FILES.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-
-# *************************************************************************
-# ***              DO NOT TOUCH FILES IN THIS DIRECTORY!                ***
-# *** FILES IN THIS DIRECTORY AND SUBDIRECTORIES CONSTITUTE A DERBY     ***
-# *** DATABASE, WHICH INCLUDES THE DATA (USER AND SYSTEM) AND THE       ***
-# *** FILES NECESSARY FOR DATABASE RECOVERY.                            ***
-# *** EDITING, ADDING, OR DELETING ANY OF THESE FILES MAY CAUSE DATA    ***
-# *** CORRUPTION AND LEAVE THE DATABASE IN A NON-RECOVERABLE STATE.     ***
-# *************************************************************************
\ No newline at end of file
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/README_DO_NOT_TOUCH_FILES.txt b/data/files/dataconnector_derbydb/db_for_connectortest.db/log/README_DO_NOT_TOUCH_FILES.txt
deleted file mode 100644
index 56df292f65e5..000000000000
--- a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/README_DO_NOT_TOUCH_FILES.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-
-# *************************************************************************
-# ***              DO NOT TOUCH FILES IN THIS DIRECTORY!                ***
-# *** FILES IN THIS DIRECTORY ARE USED BY THE DERBY DATABASE RECOVERY   ***
-# *** SYSTEM. EDITING, ADDING, OR DELETING FILES IN THIS DIRECTORY      ***
-# *** WILL CAUSE THE DERBY RECOVERY SYSTEM TO FAIL, LEADING TO          ***
-# *** NON-RECOVERABLE CORRUPT DATABASES.                                ***
-# *************************************************************************
\ No newline at end of file
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log.ctrl b/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log.ctrl
deleted file mode 100644
index 72970858356e..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log.ctrl and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log1.dat
deleted file mode 100644
index 90e9f35f33e2..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log2.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log2.dat
deleted file mode 100644
index 5b71eabb8441..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/log2.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/logmirror.ctrl b/data/files/dataconnector_derbydb/db_for_connectortest.db/log/logmirror.ctrl
deleted file mode 100644
index 72970858356e..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/log/logmirror.ctrl and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/README_DO_NOT_TOUCH_FILES.txt b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/README_DO_NOT_TOUCH_FILES.txt
deleted file mode 100644
index 2bdad0612743..000000000000
--- a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/README_DO_NOT_TOUCH_FILES.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-
-# *************************************************************************
-# ***              DO NOT TOUCH FILES IN THIS DIRECTORY!                ***
-# *** FILES IN THIS DIRECTORY ARE USED BY THE DERBY DATABASE TO STORE   *** 
-# *** USER AND SYSTEM DATA. EDITING, ADDING, OR DELETING FILES IN THIS  ***
-# *** DIRECTORY WILL CORRUPT THE ASSOCIATED DERBY DATABASE AND MAKE     ***
-# *** IT NON-RECOVERABLE.                                               ***
-# *************************************************************************
\ No newline at end of file
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c10.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c10.dat
deleted file mode 100644
index 58fdae2772f1..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c10.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c101.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c101.dat
deleted file mode 100644
index 111817812287..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c101.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c111.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c111.dat
deleted file mode 100644
index 71b1f8d3f96f..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c111.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c121.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c121.dat
deleted file mode 100644
index fbf18b9c97f9..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c121.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c130.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c130.dat
deleted file mode 100644
index 7b2a6548baad..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c130.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c141.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c141.dat
deleted file mode 100644
index 3d983c2400ee..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c141.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c150.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c150.dat
deleted file mode 100644
index e2ea5767cbeb..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c150.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c161.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c161.dat
deleted file mode 100644
index 90960e6d4a00..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c161.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c171.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c171.dat
deleted file mode 100644
index 55d40959a493..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c171.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c180.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c180.dat
deleted file mode 100644
index 53bd1ebb49ac..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c180.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c191.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c191.dat
deleted file mode 100644
index aa2505224f39..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c191.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1a1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1a1.dat
deleted file mode 100644
index 9d14471d1bf4..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1a1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1b1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1b1.dat
deleted file mode 100644
index ae562fbef302..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1b1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1c0.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1c0.dat
deleted file mode 100644
index c5b91e2c3fef..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1c0.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1d1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1d1.dat
deleted file mode 100644
index 451f02f45f24..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1d1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1e0.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1e0.dat
deleted file mode 100644
index 761408d3b348..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1e0.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1f1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1f1.dat
deleted file mode 100644
index 78d701f45559..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c1f1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c20.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c20.dat
deleted file mode 100644
index ae1bbe9466a0..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c20.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c200.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c200.dat
deleted file mode 100644
index c3a7808dd76b..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c200.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c211.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c211.dat
deleted file mode 100644
index 54e1586958ac..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c211.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c221.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c221.dat
deleted file mode 100644
index 59900bc01279..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c221.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c230.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c230.dat
deleted file mode 100644
index 16b2db882b58..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c230.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c241.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c241.dat
deleted file mode 100644
index 3d5e31d86398..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c241.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c251.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c251.dat
deleted file mode 100644
index 4b963f10a98c..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c251.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c260.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c260.dat
deleted file mode 100644
index 25f81fde7841..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c260.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c271.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c271.dat
deleted file mode 100644
index 51cde573e72a..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c271.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c281.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c281.dat
deleted file mode 100644
index cfed875dfcea..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c281.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c290.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c290.dat
deleted file mode 100644
index 4d10db46799e..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c290.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2a1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2a1.dat
deleted file mode 100644
index 8e2ed6afe90b..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2a1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2b1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2b1.dat
deleted file mode 100644
index 2a2969247718..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2b1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2c1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2c1.dat
deleted file mode 100644
index 5511575f62c4..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2c1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2d0.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2d0.dat
deleted file mode 100644
index 4adc6e4470f8..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2d0.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2e1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2e1.dat
deleted file mode 100644
index b37b9b254234..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2e1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2f0.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2f0.dat
deleted file mode 100644
index d854b4b482d6..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c2f0.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c300.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c300.dat
deleted file mode 100644
index 2053e0105b40..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c300.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c31.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c31.dat
deleted file mode 100644
index f8c4ecff3e26..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c31.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c311.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c311.dat
deleted file mode 100644
index f60c260f85bd..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c311.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c321.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c321.dat
deleted file mode 100644
index a9d745366de2..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c321.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c331.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c331.dat
deleted file mode 100644
index 85ee72b31368..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c331.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c340.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c340.dat
deleted file mode 100644
index d99b11a3f2df..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c340.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c351.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c351.dat
deleted file mode 100644
index f822f4cb0c68..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c351.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c361.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c361.dat
deleted file mode 100644
index b5c8f259d0d1..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c361.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c371.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c371.dat
deleted file mode 100644
index ad11f01b25b6..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c371.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c380.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c380.dat
deleted file mode 100644
index 3f593e1428bb..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c380.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c391.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c391.dat
deleted file mode 100644
index dee460e6a7da..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c391.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3a1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3a1.dat
deleted file mode 100644
index 3790bd8f9117..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3a1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3b1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3b1.dat
deleted file mode 100644
index 2ce6c70dea2a..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3b1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3c0.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3c0.dat
deleted file mode 100644
index 4d061cf0609e..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3c0.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3d1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3d1.dat
deleted file mode 100644
index 45c9fa244b0a..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3d1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3e1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3e1.dat
deleted file mode 100644
index 48f53e682fad..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3e1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3f1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3f1.dat
deleted file mode 100644
index 08acdcee31e2..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c3f1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c400.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c400.dat
deleted file mode 100644
index 1e8976f89fb6..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c400.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c41.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c41.dat
deleted file mode 100644
index e1d102a75147..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c41.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c411.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c411.dat
deleted file mode 100644
index 8aba2fb6bffc..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c411.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c421.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c421.dat
deleted file mode 100644
index 65775ee7bfbd..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c421.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c430.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c430.dat
deleted file mode 100644
index 55c948db3494..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c430.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c441.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c441.dat
deleted file mode 100644
index 3948b2a3c5aa..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c441.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c451.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c451.dat
deleted file mode 100644
index fe1ab73e129b..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c451.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c461.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c461.dat
deleted file mode 100644
index e6d98541fb79..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c461.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c470.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c470.dat
deleted file mode 100644
index c9f2eb1cae75..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c470.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c481.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c481.dat
deleted file mode 100644
index 397b291728da..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c481.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c490.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c490.dat
deleted file mode 100644
index 6b1f5d86597d..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c490.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c4a0.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c4a0.dat
deleted file mode 100644
index 6b1f5d86597d..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c4a0.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c51.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c51.dat
deleted file mode 100644
index 0c8c56cb5583..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c51.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c60.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c60.dat
deleted file mode 100644
index 7efed3a7db6b..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c60.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c71.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c71.dat
deleted file mode 100644
index c0b1303cf68d..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c71.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c81.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c81.dat
deleted file mode 100644
index 799f89699cac..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c81.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c90.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c90.dat
deleted file mode 100644
index a49c8a0af51c..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/c90.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/ca1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/ca1.dat
deleted file mode 100644
index 07f4c4c95225..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/ca1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cb1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cb1.dat
deleted file mode 100644
index e26dcacb8a60..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cb1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cc0.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cc0.dat
deleted file mode 100644
index 226872006d7e..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cc0.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cd1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cd1.dat
deleted file mode 100644
index d919a1b0e320..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cd1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/ce1.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/ce1.dat
deleted file mode 100644
index 299e0c4095c5..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/ce1.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cf0.dat b/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cf0.dat
deleted file mode 100644
index fb40ee421916..000000000000
Binary files a/data/files/dataconnector_derbydb/db_for_connectortest.db/seg0/cf0.dat and /dev/null differ
diff --git a/data/files/dataconnector_derbydb/db_for_connectortest.db/service.properties b/data/files/dataconnector_derbydb/db_for_connectortest.db/service.properties
deleted file mode 100644
index 16ecc5edf017..000000000000
--- a/data/files/dataconnector_derbydb/db_for_connectortest.db/service.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-#/private/tmp/db_for_connectortest.db
-# ********************************************************************
-# ***                Please do NOT edit this file.                 ***
-# *** CHANGING THE CONTENT OF THIS FILE MAY CAUSE DATA CORRUPTION. ***
-# ********************************************************************
-#Tue Jun 08 12:05:32 PDT 2021
-SysschemasIndex2Identifier=225
-SyscolumnsIdentifier=144
-SysconglomeratesIndex1Identifier=49
-SysconglomeratesIdentifier=32
-SyscolumnsIndex2Identifier=177
-SysschemasIndex1Identifier=209
-SysconglomeratesIndex3Identifier=81
-SystablesIndex2Identifier=129
-SyscolumnsIndex1Identifier=161
-derby.serviceProtocol=org.apache.derby.database.Database
-SysschemasIdentifier=192
-derby.storage.propertiesId=16
-SysconglomeratesIndex2Identifier=65
-derby.serviceLocale=en_US
-SystablesIdentifier=96
-SystablesIndex1Identifier=113
-#--- last line, don't put anything after this line ---
diff --git a/itests/pom.xml b/itests/pom.xml
index 2d8b04efc5de..07b3e8e998df 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -520,20 +520,6 @@
               
             
           
-          
-            copy-database
-            install
-            
-              
-                
-                  
-                
-              
-            
-            
-              run
-            
-          
         
       
     
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/AbstractExternalDB.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/AbstractExternalDB.java
index fe12a31f4272..2bac0b0f9309 100644
--- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/AbstractExternalDB.java
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/AbstractExternalDB.java
@@ -21,25 +21,20 @@
 import org.slf4j.LoggerFactory;
 import sqlline.SqlLine;
 
-import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.io.PrintStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
 import java.util.Objects;
-import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 
 /**
- * The class is in charge of connecting and populating dockerized databases for qtest.
+ * The class is in charge of managing the lifecycle of databases for qtest.
  *
  * The database should have at least one root user (admin/superuser) able to modify every aspect of the system. The user
  * either exists by default when the database starts or must created right after startup.
@@ -86,111 +81,6 @@ public void clear(AbstractExternalDB db) {
     protected String dbName = "qtestDB";
     private Path initScript;
 
-    private static final int MAX_STARTUP_WAIT = 5 * 60 * 1000;
-
-    protected static class ProcessResults {
-        final String stdout;
-        final String stderr;
-        final int rc;
-
-        public ProcessResults(String stdout, String stderr, int rc) {
-            this.stdout = stdout;
-            this.stderr = stderr;
-            this.rc = rc;
-        }
-    }
-
-    private final String getDockerContainerName() {
-        return String.format("qtestExternalDB-%s", getClass().getSimpleName());
-    }
-
-    private String[] buildRunCmd() {
-        List cmd = new ArrayList<>(4 + getDockerAdditionalArgs().length);
-        cmd.add("docker");
-        cmd.add("run");
-        cmd.add("--rm");
-        cmd.add("--name");
-        cmd.add(getDockerContainerName());
-        cmd.addAll(Arrays.asList(getDockerAdditionalArgs()));
-        cmd.add(getDockerImageName());
-        return cmd.toArray(new String[cmd.size()]);
-    }
-
-    private String[] buildRmCmd() {
-        return new String[] { "docker", "rm", "-f", "-v", getDockerContainerName() };
-    }
-
-    private String[] buildLogCmd() {
-        return new String[] { "docker", "logs", getDockerContainerName() };
-    }
-
-    private ProcessResults runCmd(String[] cmd, long secondsToWait)
-            throws IOException, InterruptedException {
-        LOG.info("Going to run: " + String.join(" ", cmd));
-        Process proc = Runtime.getRuntime().exec(cmd);
-        if (!proc.waitFor(Math.abs(secondsToWait), TimeUnit.SECONDS)) {
-          throw new RuntimeException("Process " + cmd[0] + " failed to run in " + secondsToWait + " seconds");
-        }
-        BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
-        final StringBuilder lines = new StringBuilder();
-        reader.lines().forEach(s -> lines.append(s).append('\n'));
-
-        reader = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
-        final StringBuilder errLines = new StringBuilder();
-        reader.lines().forEach(s -> errLines.append(s).append('\n'));
-        LOG.info("Result lines#: {}(stdout);{}(stderr)",lines.length(), errLines.length());
-        return new ProcessResults(lines.toString(), errLines.toString(), proc.exitValue());
-    }
-
-    private ProcessResults runCmdAndPrintStreams(String[] cmd, long secondsToWait)
-            throws InterruptedException, IOException {
-        ProcessResults results = runCmd(cmd, secondsToWait);
-        LOG.info("Stdout from proc: " + results.stdout);
-        LOG.info("Stderr from proc: " + results.stderr);
-        return results;
-    }
-
-
-    public void launchDockerContainer() throws Exception {
-        runCmdAndPrintStreams(buildRmCmd(), 600);
-        if (runCmdAndPrintStreams(buildRunCmd(), 600).rc != 0) {
-          printDockerEvents();
-          throw new RuntimeException("Unable to start docker container");
-        }
-        long startTime = System.currentTimeMillis();
-        ProcessResults pr;
-        do {
-            Thread.sleep(1000);
-            pr = runCmdAndPrintStreams(buildLogCmd(), 30);
-            if (pr.rc != 0) {
-              printDockerEvents();
-              throw new RuntimeException("Failed to get docker logs");
-            }
-        } while (startTime + MAX_STARTUP_WAIT >= System.currentTimeMillis() && !isContainerReady(pr));
-        if (startTime + MAX_STARTUP_WAIT < System.currentTimeMillis()) {
-          printDockerEvents();
-          throw new RuntimeException(
-              String.format("Container initialization failed within %d seconds. Please check the hive logs.",
-                  MAX_STARTUP_WAIT / 1000));
-        }
-      }
-
-    protected void printDockerEvents() {
-      try {
-        runCmdAndPrintStreams(new String[] { "docker", "events", "--since", "24h", "--until", "0s" }, 3);
-      } catch (Exception e) {
-        LOG.warn("A problem was encountered while attempting to retrieve Docker events (the system made an analytical"
-            + " best effort to list the events to reveal the root cause). No further actions are necessary.", e);
-      }
-    }
-
-    public void cleanupDockerContainer() throws IOException, InterruptedException {
-        if (runCmdAndPrintStreams(buildRmCmd(), 600).rc != 0) {
-            throw new RuntimeException("Unable to remove docker container");
-        }
-    }
-
-
     protected final String getContainerHostAddress() {
         String hostAddress = System.getenv("HIVE_TEST_DOCKER_HOST");
         if (hostAddress != null) {
@@ -224,12 +114,6 @@ protected String getRootPassword() {
 
     protected abstract int getPort();
 
-    protected abstract String getDockerImageName();
-
-    protected abstract String[] getDockerAdditionalArgs();
-
-    protected abstract boolean isContainerReady(ProcessResults pr);
-
     private String[] SQLLineCmdBuild(String sqlScriptFile) {
         return new String[] {"-u", getJdbcUrl(),
                             "-d", getJdbcDriver(),
@@ -265,7 +149,6 @@ public void setInitScript(Path initScript) {
      * Starts the database and performs any initialization required.
      */
     public void start() throws Exception {
-        launchDockerContainer();
         if (initScript != null) {
             execute(initScript.toString());
         }
@@ -280,7 +163,6 @@ public void start() throws Exception {
      */
     public void stop() throws IOException, InterruptedException {
         Arrays.stream(ConnectionProperty.values()).forEach(p -> p.clear(this));
-        cleanupDockerContainer();
     }
 
     public void execute(String script) throws IOException, SQLException, ClassNotFoundException {
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/Derby.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/Derby.java
new file mode 100644
index 000000000000..9d55b3f0c274
--- /dev/null
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/Derby.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.externalDB;
+
+import org.apache.commons.io.FileUtils;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class Derby extends AbstractExternalDB {
+
+  public Derby() {
+  }
+
+  private Path getDbPath() {
+    return Paths.get(System.getProperty("test.tmp.dir"), dbName);
+  }
+
+  @Override
+  protected String getJdbcUrl() {
+    // First connection will also create the database
+    return JdbcUrl.CREATE.of(getDbPath().toString());
+  }
+
+  @Override
+  protected String getJdbcDriver() {
+    return "org.apache.derby.jdbc.EmbeddedDriver";
+  }
+
+  @Override
+  protected int getPort() {
+    return -1;
+  }
+
+  /**
+   * Stops the database and deletes the database files. Check the Derby documentation for details on the
+   * shutdown command.
+   * @throws IOException if there is a problem with the deletion of the database files.
+   * @throws InterruptedException never thrown but declared for compatibility with the parent class.
+   */
+  @Override
+  @SuppressWarnings("checkstyle:EmptyBlock")
+  public void stop() throws IOException, InterruptedException {
+    super.stop();
+    try (Connection c = DriverManager.getConnection(JdbcUrl.SHUTDOWN.of(getDbPath().toString()))) {
+    } catch (SQLException e) {
+      if (!isNormalShutdown(e)) {
+        throw new IllegalStateException(e);
+      }
+    } finally {
+      FileUtils.deleteDirectory(getDbPath().toFile());
+    }
+  }
+
+  /**
+   * Whether the exception corresponds to a normal shutdown of Derby.
+   * @param e the exception to check.
+   * @return Whether the exception corresponds to a normal shutdown of Derby.
+   */
+  private boolean isNormalShutdown(SQLException e) {
+    return "08006".equals(e.getSQLState()) && e.getErrorCode() == 45000;
+  }
+
+  private enum JdbcUrl {
+    CREATE {
+      @Override
+      String of(String dbPath) {
+        return "jdbc:derby:;databaseName=" + dbPath + ";create=true";
+      }
+    }, SHUTDOWN {
+      @Override
+      String of(String dbPath) {
+        return "jdbc:derby:;databaseName=" + dbPath + ";shutdown=true";
+      }
+    };
+
+    abstract String of(String dbPath);
+  }
+}
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/DockerizedDatabase.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/DockerizedDatabase.java
new file mode 100644
index 000000000000..61ab387d866b
--- /dev/null
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/DockerizedDatabase.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.externalDB;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public abstract class DockerizedDatabase extends AbstractExternalDB {
+  protected static final Logger LOG = LoggerFactory.getLogger(DockerizedDatabase.class);
+  private static final int MAX_STARTUP_WAIT = 5 * 60 * 1000;
+
+  protected static class ProcessResults {
+    final String stdout;
+    final String stderr;
+    final int rc;
+
+    public ProcessResults(String stdout, String stderr, int rc) {
+      this.stdout = stdout;
+      this.stderr = stderr;
+      this.rc = rc;
+    }
+  }
+
+  private String getDockerContainerName() {
+    return String.format("qtestExternalDB-%s", getClass().getSimpleName());
+  }
+
+  private String[] buildRunCmd() {
+    List cmd = new ArrayList<>(4 + getDockerAdditionalArgs().length);
+    cmd.add("docker");
+    cmd.add("run");
+    cmd.add("--rm");
+    cmd.add("--name");
+    cmd.add(getDockerContainerName());
+    cmd.addAll(Arrays.asList(getDockerAdditionalArgs()));
+    cmd.add(getDockerImageName());
+    return cmd.toArray(new String[cmd.size()]);
+  }
+
+  private String[] buildRmCmd() {
+    return new String[] {"docker", "rm", "-f", "-v", getDockerContainerName()};
+  }
+
+  private String[] buildLogCmd() {
+    return new String[] {"docker", "logs", getDockerContainerName()};
+  }
+
+  private ProcessResults runCmd(String[] cmd, long secondsToWait)
+      throws IOException, InterruptedException {
+    LOG.info("Going to run: " + String.join(" ", cmd));
+    Process proc = Runtime.getRuntime().exec(cmd);
+    if (!proc.waitFor(Math.abs(secondsToWait), TimeUnit.SECONDS)) {
+      throw new RuntimeException("Process " + cmd[0] + " failed to run in " + secondsToWait + " seconds");
+    }
+    BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+    final StringBuilder lines = new StringBuilder();
+    reader.lines().forEach(s -> lines.append(s).append('\n'));
+
+    reader = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
+    final StringBuilder errLines = new StringBuilder();
+    reader.lines().forEach(s -> errLines.append(s).append('\n'));
+    LOG.info("Result lines#: {}(stdout);{}(stderr)", lines.length(), errLines.length());
+    return new ProcessResults(lines.toString(), errLines.toString(), proc.exitValue());
+  }
+
+  private ProcessResults runCmdAndPrintStreams(String[] cmd, long secondsToWait)
+      throws InterruptedException, IOException {
+    ProcessResults results = runCmd(cmd, secondsToWait);
+    LOG.info("Stdout from proc: " + results.stdout);
+    LOG.info("Stderr from proc: " + results.stderr);
+    return results;
+  }
+
+  public void start() throws Exception {
+    runCmdAndPrintStreams(buildRmCmd(), 600);
+    if (runCmdAndPrintStreams(buildRunCmd(), 600).rc != 0) {
+      printDockerEvents();
+      throw new RuntimeException("Unable to start docker container");
+    }
+    long startTime = System.currentTimeMillis();
+    ProcessResults pr;
+    do {
+      Thread.sleep(1000);
+      pr = runCmdAndPrintStreams(buildLogCmd(), 30);
+      if (pr.rc != 0) {
+        printDockerEvents();
+        throw new RuntimeException("Failed to get docker logs");
+      }
+    } while (startTime + MAX_STARTUP_WAIT >= System.currentTimeMillis() && !isContainerReady(pr));
+    if (startTime + MAX_STARTUP_WAIT < System.currentTimeMillis()) {
+      printDockerEvents();
+      throw new RuntimeException(
+          String.format("Container initialization failed within %d seconds. Please check the hive logs.",
+              MAX_STARTUP_WAIT / 1000));
+    }
+    super.start();
+  }
+
+  protected void printDockerEvents() {
+    try {
+      runCmdAndPrintStreams(new String[] {"docker", "events", "--since", "24h", "--until", "0s"}, 3);
+    } catch (Exception e) {
+      LOG.warn("A problem was encountered while attempting to retrieve Docker events (the system made an analytical"
+          + " best effort to list the events to reveal the root cause). No further actions are necessary.", e);
+    }
+  }
+
+  public void stop() throws IOException, InterruptedException {
+    super.stop();
+    if (runCmdAndPrintStreams(buildRmCmd(), 600).rc != 0) {
+      throw new RuntimeException("Unable to remove docker container");
+    }
+  }
+
+  protected abstract String getDockerImageName();
+
+  protected abstract String[] getDockerAdditionalArgs();
+
+  protected abstract boolean isContainerReady(ProcessResults pr);
+}
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MSSQLServer.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MSSQLServer.java
index f968e070ed7f..9cb159de5b6e 100644
--- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MSSQLServer.java
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MSSQLServer.java
@@ -17,7 +17,7 @@
  */
 package org.apache.hadoop.hive.ql.externalDB;
 
-public class MSSQLServer extends AbstractExternalDB {
+public class MSSQLServer extends DockerizedDatabase {
 
   @Override
   public String getRootUser() {
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MariaDB.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MariaDB.java
index eeeeb06c694b..c3f14264ac88 100644
--- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MariaDB.java
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MariaDB.java
@@ -20,7 +20,7 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-public class MariaDB extends AbstractExternalDB {
+public class MariaDB extends DockerizedDatabase {
 
   @Override
   public String getRootUser() {
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MySQLExternalDB.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MySQLExternalDB.java
index 685ca74fd2d8..2a24e2c26e91 100644
--- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MySQLExternalDB.java
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/MySQLExternalDB.java
@@ -23,7 +23,7 @@
 /**
  * Designed for MySQL external database connection
  */
-public class MySQLExternalDB extends AbstractExternalDB {
+public class MySQLExternalDB extends DockerizedDatabase {
 
     public MySQLExternalDB() {
     }
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/Oracle.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/Oracle.java
index ccd8f2d9f156..e28d8f0b0f0d 100644
--- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/Oracle.java
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/Oracle.java
@@ -17,7 +17,7 @@
  */
 package org.apache.hadoop.hive.ql.externalDB;
 
-public class Oracle extends AbstractExternalDB {
+public class Oracle extends DockerizedDatabase {
   @Override
   public String getRootUser() {
     return "SYS as SYSDBA";
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/PostgresExternalDB.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/PostgresExternalDB.java
index 3e10fd6a1e1a..9939b9627879 100644
--- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/PostgresExternalDB.java
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/externalDB/PostgresExternalDB.java
@@ -21,7 +21,7 @@
  * MySQLExternalDB is a extension of abstractExternalDB
  * Designed for MySQL external database connection
  */
-public class PostgresExternalDB extends AbstractExternalDB {
+public class PostgresExternalDB extends DockerizedDatabase {
 
     public PostgresExternalDB() {
     }
diff --git a/itests/util/src/main/java/org/apache/hadoop/hive/ql/qoption/QTestDatabaseHandler.java b/itests/util/src/main/java/org/apache/hadoop/hive/ql/qoption/QTestDatabaseHandler.java
index a90d63c03dcb..0bd33cff43ae 100644
--- a/itests/util/src/main/java/org/apache/hadoop/hive/ql/qoption/QTestDatabaseHandler.java
+++ b/itests/util/src/main/java/org/apache/hadoop/hive/ql/qoption/QTestDatabaseHandler.java
@@ -19,6 +19,7 @@
 
 import org.apache.hadoop.hive.ql.QTestUtil;
 import org.apache.hadoop.hive.ql.externalDB.AbstractExternalDB;
+import org.apache.hadoop.hive.ql.externalDB.Derby;
 import org.apache.hadoop.hive.ql.externalDB.MSSQLServer;
 import org.apache.hadoop.hive.ql.externalDB.MariaDB;
 import org.apache.hadoop.hive.ql.externalDB.MySQLExternalDB;
@@ -75,6 +76,11 @@ AbstractExternalDB create() {
       AbstractExternalDB create() {
         return new Oracle();
       }
+    }, DERBY {
+      @Override
+      AbstractExternalDB create() {
+        return new Derby();
+      }
     };
 
     abstract AbstractExternalDB create();
diff --git a/ql/src/test/queries/clientnegative/authorization_jdbc_keystore.q b/ql/src/test/queries/clientnegative/authorization_jdbc_keystore.q
index 8aacbd4af6e1..0616e8e8c72c 100644
--- a/ql/src/test/queries/clientnegative/authorization_jdbc_keystore.q
+++ b/ql/src/test/queries/clientnegative/authorization_jdbc_keystore.q
@@ -1,3 +1,4 @@
+--!qt:database:derby:qdb
 --! qt:authorizer
 --! qt:dataset:
 
@@ -16,7 +17,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password.keystore" = "jceks://file/${system:test.tmp.dir}/test.jceks",
                 "hive.sql.dbcp.password.key" = "test_derby_auth1.password",
diff --git a/ql/src/test/queries/clientnegative/dataconnector_authfail_alter.q b/ql/src/test/queries/clientnegative/dataconnector_authfail_alter.q
index 76988dc3015d..eeb78a9a01cc 100644
--- a/ql/src/test/queries/clientnegative/dataconnector_authfail_alter.q
+++ b/ql/src/test/queries/clientnegative/dataconnector_authfail_alter.q
@@ -1,7 +1,8 @@
+--!qt:database:derby:qdb
 -- CREATE IF NOT EXISTS already
 CREATE CONNECTOR IF NOT EXISTS derby_auth
 TYPE 'derby'
-URL 'jdbc:derby:./target/tmp/junit_metastore_db;create=true'
+URL '${system:hive.test.database.qdb.jdbc.url}'
 COMMENT 'test derby connector'
 WITH DCPROPERTIES (
 "hive.sql.dbcp.username"="APP",
diff --git a/ql/src/test/queries/clientnegative/dataconnector_authfail_drop.q b/ql/src/test/queries/clientnegative/dataconnector_authfail_drop.q
index adc1923de736..402fd73b102f 100644
--- a/ql/src/test/queries/clientnegative/dataconnector_authfail_drop.q
+++ b/ql/src/test/queries/clientnegative/dataconnector_authfail_drop.q
@@ -1,7 +1,8 @@
+--!qt:database:derby:qdb
 -- CREATE IF NOT EXISTS already
 CREATE CONNECTOR IF NOT EXISTS derby_auth
 TYPE 'derby'
-URL 'jdbc:derby:./target/tmp/junit_metastore_db;create=true'
+URL '${system:hive.test.database.qdb.jdbc.url}'
 COMMENT 'test derby connector'
 WITH DCPROPERTIES (
 "hive.sql.dbcp.username"="APP",
diff --git a/ql/src/test/queries/clientnegative/dataconnector_authfail_remoteDB.q b/ql/src/test/queries/clientnegative/dataconnector_authfail_remoteDB.q
index 2d81d218d962..44facda3d2e9 100644
--- a/ql/src/test/queries/clientnegative/dataconnector_authfail_remoteDB.q
+++ b/ql/src/test/queries/clientnegative/dataconnector_authfail_remoteDB.q
@@ -1,7 +1,8 @@
+--!qt:database:derby:qdb
 -- CREATE IF NOT EXISTS already
 CREATE CONNECTOR IF NOT EXISTS derby_auth
 TYPE 'derby'
-URL 'jdbc:derby:./target/tmp/junit_metastore_db;create=true'
+URL '${system:hive.test.database.qdb.jdbc.url}'
 COMMENT 'test derby connector'
 WITH DCPROPERTIES (
 "hive.sql.dbcp.username"="APP",
diff --git a/ql/src/test/queries/clientnegative/external_jdbc_negative.q b/ql/src/test/queries/clientnegative/external_jdbc_negative.q
index 3e84bffbd6c1..8de9648883d7 100644
--- a/ql/src/test/queries/clientnegative/external_jdbc_negative.q
+++ b/ql/src/test/queries/clientnegative/external_jdbc_negative.q
@@ -1,13 +1,13 @@
---! qt:disabled:test is unstable HIVE-23690
+--!qt:database:derby:qdb
 --! qt:dataset:src
 
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_negative;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE EXTERNAL_JDBC_NEGATIVE_TABLE1 ("ikey" INTEGER)' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_negative','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_NEGATIVE_TABLE1 ("ikey") VALUES (?,?,?,?)','20')
 limit 1;
 
@@ -20,7 +20,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_negative;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "EXTERNAL_JDBC_NEGATIVE_TABLE1",
diff --git a/ql/src/test/queries/clientpositive/authorization_privilege_objects.q b/ql/src/test/queries/clientpositive/authorization_privilege_objects.q
index 2f80064c7e72..c41ce716a3d0 100644
--- a/ql/src/test/queries/clientpositive/authorization_privilege_objects.q
+++ b/ql/src/test/queries/clientpositive/authorization_privilege_objects.q
@@ -1,3 +1,4 @@
+--!qt:database:derby:qdb
 --! qt:authorizer
 set hive.security.authorization.manager=org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactoryForTest;
 set test.hive.authz.sstd.validator.outputPrivObjs=true;
@@ -26,7 +27,7 @@ set role admin;
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE1 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE)' );
 
 CREATE EXTERNAL TABLE ext_simple_derby_table_src
@@ -40,7 +41,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE1",
@@ -54,7 +55,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE1",
diff --git a/ql/src/test/queries/clientpositive/dataconnector.q b/ql/src/test/queries/clientpositive/dataconnector.q
index 30b0c3942dd1..5518d3719edd 100644
--- a/ql/src/test/queries/clientpositive/dataconnector.q
+++ b/ql/src/test/queries/clientpositive/dataconnector.q
@@ -1,3 +1,4 @@
+--!qt:database:derby:qdb:q_test_author_book_tables.sql
 -- SORT_QUERY_RESULTS
 SHOW CONNECTORS;
 
@@ -24,7 +25,7 @@ SHOW CONNECTORS;
 -- CREATE IF NOT EXISTS already
 CREATE CONNECTOR IF NOT EXISTS derby_test
 TYPE 'derby'
-URL 'jdbc:derby:./target/db_for_connectortest.db;create=true'
+URL '${system:hive.test.database.qdb.jdbc.url}'
 COMMENT 'test derby connector'
 WITH DCPROPERTIES (
 "hive.sql.dbcp.username"="APP",
diff --git a/ql/src/test/queries/clientpositive/explain_jdbc.q b/ql/src/test/queries/clientpositive/explain_jdbc.q
index 5dc94912ea27..53ae35a64ca7 100644
--- a/ql/src/test/queries/clientpositive/explain_jdbc.q
+++ b/ql/src/test/queries/clientpositive/explain_jdbc.q
@@ -1,3 +1,4 @@
+--!qt:database:derby:qdb
 CREATE TABLE explain_jdbc_hive_table (id INT, bigId BIGINT);
 
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
@@ -7,10 +8,10 @@ FROM (select 1 as hello) src
 
 SELECT
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_explain_jdbc_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE DERBY_TABLE ("id" INTEGER, "bigId" BIGINT)' ),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_explain_jdbc_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO DERBY_TABLE ("id","bigId") VALUES (?,?)','20','20')
 limit 1;
 
@@ -23,7 +24,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_explain_jdbc_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "DERBY_TABLE",
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_auth.q b/ql/src/test/queries/clientpositive/external_jdbc_auth.q
index f4cbe94d3d06..df2820c04ff8 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_auth.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_auth.q
@@ -1,3 +1,5 @@
+--!qt:database:derby:qdb
+--!qt:database:derby:qdb2
 --! qt:dataset:src
 
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
@@ -6,31 +8,31 @@ FROM src
 
 SELECT
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1;create=true','user1','passwd1',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE SIMPLE_DERBY_TABLE1 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE)' ),
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1','user1','passwd1',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.connection.requireAuthentication\', \'true\')' ),
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1','user1','passwd1',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.authentication.provider\', \'BUILTIN\')' ),
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1','user1','passwd1',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.user.user1\', \'passwd1\')' ),
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1','user1','passwd1',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.database.propertiesOnly\', \'true\')' ),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO SIMPLE_DERBY_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO SIMPLE_DERBY_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','-20','-20.0','-20.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO SIMPLE_DERBY_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','100','-15','65.0','-74.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO SIMPLE_DERBY_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','44','53','-455.454','330.76')
 
 limit 1;
@@ -39,31 +41,31 @@ FROM src
 
 SELECT
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2;create=true','user2','passwd2',
+dboutput ( '${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE )' ),
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2','user2','passwd2',
+dboutput ( '${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.connection.requireAuthentication\', \'true\')' ),
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2','user2','passwd2',
+dboutput ( '${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.authentication.provider\', \'BUILTIN\')' ),
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2','user2','passwd2',
+dboutput ( '${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.user.user2\', \'passwd2\')' ),
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2','user2','passwd2',
+dboutput ( '${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(\'derby.database.propertiesOnly\', \'true\')' ),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','8','9.0','11.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','101','-16','66.0','-75.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','40','50','-455.4543','330.767')
 
 limit 1;
@@ -80,7 +82,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password.keystore" = "jceks://file/${system:test.tmp.dir}/../../../data/files/test.jceks",
                 "hive.sql.dbcp.password.key" = "test_derby_auth1.password",
@@ -100,7 +102,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb2.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user2",
                 "hive.sql.dbcp.password.keystore" = "jceks://file/${system:test.tmp.dir}/../../../data/files/test.jceks",
                 "hive.sql.dbcp.password.key" = "test_derby_auth2.password",
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_join_mv.q b/ql/src/test/queries/clientpositive/external_jdbc_join_mv.q
index fde2383458de..2a2844f9d5b4 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_join_mv.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_join_mv.q
@@ -1,14 +1,15 @@
+--!qt:database:derby:qdb
 set hive.support.concurrency=true;
 set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
 
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_join_mv;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE person ("id" INTEGER, "name" VARCHAR(25), "jid" INTEGER, "cid" INTEGER)' );
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_join_mv;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE country ("id" INTEGER, "name" VARCHAR(25))' );
 
 CREATE EXTERNAL TABLE person
@@ -22,7 +23,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_join_mv;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "PERSON",
@@ -38,7 +39,7 @@ CREATE EXTERNAL TABLE country
     TBLPROPERTIES (
         "hive.sql.database.type" = "DERBY",
         "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-        "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_join_mv;create=true;collation=TERRITORY_BASED:PRIMARY",
+        "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
         "hive.sql.dbcp.username" = "APP",
         "hive.sql.dbcp.password" = "mine",
         "hive.sql.table" = "COUNTRY",
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_rowcount.q b/ql/src/test/queries/clientpositive/external_jdbc_rowcount.q
index aa4c98b8f09f..4865235a1719 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_rowcount.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_rowcount.q
@@ -1,19 +1,20 @@
+--!qt:database:derby:qdb
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE11 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE)' );
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE12 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE, "datekey" DATE)' );
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE13 ("ikey2" INTEGER, "bkey2" BIGINT, "fkey2" REAL, "dkey2" DOUBLE)' );
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE14 ("ikey2" INTEGER, "bkey2" BIGINT, "fkey2" REAL, "dkey2" DOUBLE, "datekey2" DATE)' );
 
 CREATE EXTERNAL TABLE ext_simple_derby_table11
@@ -27,7 +28,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE11",
@@ -47,7 +48,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE12",
@@ -65,7 +66,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE13",
@@ -85,7 +86,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE14",
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_table.q b/ql/src/test/queries/clientpositive/external_jdbc_table.q
index 05b47628e081..32eeade2076b 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_table.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_table.q
@@ -1,4 +1,4 @@
---! qt:disabled:HIVE-25379
+--!qt:database:derby:qdb
 --! qt:dataset:src
 
 set hive.strict.checks.cartesian.product= false;
@@ -13,19 +13,19 @@ FROM src
 
 SELECT
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE1 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE)' ),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','-20','-20.0','-20.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','100','-15','65.0','-74.0'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','44','53','-455.454','330.76')
 
 limit 1;
@@ -34,19 +34,19 @@ FROM src
 
 SELECT
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE, "datekey" DATE)' ),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey") VALUES (?,?,?,?,?)','20','20','20.0','20.0','1999-02-22'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey") VALUES (?,?,?,?,?)','-20','8','9.0','11.0','2000-03-15'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey") VALUES (?,?,?,?,?)','101','-16','66.0','-75.0','2010-04-01'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE2 ("ikey","bkey","fkey","dkey","datekey") VALUES (?,?,?,?,?)','40','50','-455.4543','330.767','2010-04-02')
 
 limit 1;
@@ -63,7 +63,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE1",
@@ -83,7 +83,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE2",
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_table2.q b/ql/src/test/queries/clientpositive/external_jdbc_table2.q
index 335e97dbcbb1..211eccd4d27b 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_table2.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_table2.q
@@ -1,3 +1,4 @@
+--!qt:database:derby:qdb
 --! qt:dataset:src
 
 -- SORT_QUERY_RESULTS
@@ -6,43 +7,43 @@ CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE)' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','-20','-20.0','-20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','100','-15','65.0','-74.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','44','53','-455.454','330.76')
 limit 1;
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_1;create=true','user2','passwd2',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user2','passwd2',
 'CREATE TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE )' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_1','user2','passwd2',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user2','passwd2',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_1','user2','passwd2',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user2','passwd2',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','8','9.0','11.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_1','user2','passwd2',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user2','passwd2',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','101','-16','66.0','-75.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_1','user2','passwd2',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user2','passwd2',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','40','50','-455.4543','330.767')
 limit 1;
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE )' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','8','9.0','11.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','101','-16','66.0','-75.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','40','50','-455.4543','330.767')
 limit 1;
 
@@ -59,7 +60,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url}",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1",
@@ -77,7 +78,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_1;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url}",
                 "hive.sql.dbcp.username" = "user2",
                 "hive.sql.dbcp.password" = "passwd2",
                 "hive.sql.table" = "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2",
@@ -95,7 +96,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url}",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2",
@@ -183,10 +184,10 @@ DROP TABLE db1_ext_auth2;
 
 FROM src
 SELECT
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_1','user2','passwd2',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user2','passwd2',
 'DROP TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2' )
 limit 1;
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_table3.q b/ql/src/test/queries/clientpositive/external_jdbc_table3.q
index 3b6092a38d5a..7884081cadc5 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_table3.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_table3.q
@@ -1,3 +1,4 @@
+--!qt:database:derby:qdb
 --! qt:dataset:src
 
 -- SORT_QUERY_RESULTS
@@ -9,29 +10,29 @@ CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE)' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','-20','-20.0','-20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','100','-15','65.0','-74.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','44','53','-455.454','330.76')
 limit 1;
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE )' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','8','9.0','11.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','101','-16','66.0','-75.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","fkey","dkey") VALUES (?,?,?,?)','40','50','-455.4543','330.767')
 limit 1;
 
@@ -48,7 +49,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1",
@@ -66,7 +67,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2",
@@ -93,8 +94,8 @@ DROP TABLE db1_ext_auth3_2;
 
 FROM src
 SELECT
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth3_1','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2' )
 limit 1;
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_table4.q b/ql/src/test/queries/clientpositive/external_jdbc_table4.q
index ca29b0ce2e8c..c5bfa0681fde 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_table4.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_table4.q
@@ -1,3 +1,5 @@
+--!qt:database:derby:qdb
+--!qt:database:derby:qdb2
 --! qt:dataset:src
 
 -- SORT_QUERY_RESULTS
@@ -6,43 +8,43 @@ CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("IKEY" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE)' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("IKEY","bkey","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("IKEY","bkey","fkey","dkey") VALUES (?,?,?,?)','-20','-20','-20.0','-20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("IKEY","bkey","fkey","dkey") VALUES (?,?,?,?)','100','-15','65.0','-74.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1 ("IKEY","bkey","fkey","dkey") VALUES (?,?,?,?)','44','53','-455.454','330.76')
 limit 1;
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_3;create=true','user2','passwd2',
+dboutput ('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'CREATE TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey" INTEGER, "BKEY" BIGINT, "fkey" REAL, "dkey" DOUBLE )' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_3','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","BKEY","fkey","dkey") VALUES (?,?,?,?)','20','20','20.0','20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_3','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","BKEY","fkey","dkey") VALUES (?,?,?,?)','-20','8','9.0','11.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_3','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","BKEY","fkey","dkey") VALUES (?,?,?,?)','101','-16','66.0','-75.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_3','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","BKEY","fkey","dkey") VALUES (?,?,?,?)','40','50','-455.4543','330.767')
 limit 1;
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "FKEY" REAL, "DKEY" DOUBLE )' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","FKEY","DKEY") VALUES (?,?,?,?)','20','20','20.0','20.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","FKEY","DKEY") VALUES (?,?,?,?)','-20','8','9.0','11.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","FKEY","DKEY") VALUES (?,?,?,?)','101','-16','66.0','-75.0'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'INSERT INTO EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2 ("ikey","bkey","FKEY","DKEY") VALUES (?,?,?,?)','40','50','-455.4543','330.767')
 limit 1;
 
@@ -59,7 +61,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1",
@@ -77,7 +79,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_3;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb2.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user2",
                 "hive.sql.dbcp.password" = "passwd2",
                 "hive.sql.table" = "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2",
@@ -95,7 +97,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2",
@@ -151,10 +153,10 @@ DROP TABLE db1_ext_auth2;
 
 FROM src
 SELECT
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE1' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth1_3','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_auth2_3','user2','passwd2',
+dboutput('${system:hive.test.database.qdb2.jdbc.url}','user2','passwd2',
 'DROP TABLE EXTERNAL_JDBC_SIMPLE_DERBY2_TABLE2' )
 limit 1;
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_table_partition.q b/ql/src/test/queries/clientpositive/external_jdbc_table_partition.q
index 4759af83be30..5789d19ade93 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_table_partition.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_table_partition.q
@@ -1,20 +1,21 @@
+--!qt:database:derby:qdb
 --! qt:dataset:src
 
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2;create=true','user','passwd',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'CREATE TABLE EXTERNAL_JDBC_PARTITION_TABLE1 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE, "chkey" VARCHAR(20), "dekey" DECIMAL(6,4), "dtkey" DATE, "tkey" TIMESTAMP)' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_PARTITION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','1','1000','20.0','40.0','aaa','3.1415','2010-01-01','2018-01-01 12:00:00.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_PARTITION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','5','9000',null,'10.0','bbb','2.7182','2018-01-01','2010-06-01 14:00:00.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_PARTITION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','3','4000','120.0','25.4','hello','2.7182','2017-06-05','2011-11-10 18:00:08.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_PARTITION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','8','3000','180.0','35.8','world','3.1415','2014-03-03','2016-07-04 13:00:00.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_PARTITION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','4','8000','120.4','31.3','ccc',null,'2014-03-04','2018-07-08 11:00:00.000000000')
 limit 1;
 
@@ -35,7 +36,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_PARTITION_TABLE1",
@@ -63,7 +64,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_PARTITION_TABLE1",
@@ -91,7 +92,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_PARTITION_TABLE1",
@@ -120,7 +121,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.query" = "SELECT \"ikey\",\"bkey\",\"fkey\",\"dkey\" FROM EXTERNAL_JDBC_PARTITION_TABLE1 WHERE \"ikey\">1",
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_table_perf.q b/ql/src/test/queries/clientpositive/external_jdbc_table_perf.q
index 25d9d12fda93..62e29695d138 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_table_perf.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_table_perf.q
@@ -1,11 +1,11 @@
---! qt:disabled:HIVE-25379
+--!qt:database:derby:qdb
 --! qt:dataset:src
 
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE CATALOG_SALES ("cs_sold_date_sk" INTEGER, "cs_sold_time_sk" INTEGER, "cs_ship_date_sk" INTEGER, "cs_bill_customer_sk" INTEGER,
   "cs_bill_cdemo_sk" INTEGER, "cs_bill_hdemo_sk" INTEGER, "cs_bill_addr_sk" INTEGER, "cs_ship_customer_sk" INTEGER, "cs_ship_cdemo_sk" INTEGER,
   "cs_ship_hdemo_sk" INTEGER, "cs_ship_addr_sk" INTEGER, "cs_call_center_sk" INTEGER, "cs_catalog_page_sk" INTEGER, "cs_ship_mode_sk" INTEGER,
@@ -14,7 +14,7 @@ dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;creat
   "cs_ext_wholesale_cost" DECIMAL(7,2), "cs_ext_list_price" DECIMAL(7,2), "cs_ext_tax" DECIMAL(7,2), "cs_coupon_amt" DECIMAL(7,2),
   "cs_ext_ship_cost" DECIMAL(7,2), "cs_net_paid" DECIMAL(7,2), "cs_net_paid_inc_tax" DECIMAL(7,2), "cs_net_paid_inc_ship" DECIMAL(7,2),
   "cs_net_paid_inc_ship_tax" DECIMAL(7,2), "cs_net_profit" DECIMAL(7,2))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE CATALOG_RETURNS ("cr_returned_date_sk" INTEGER, "cr_returned_time_sk" INTEGER, "cr_item_sk" INTEGER, "cr_refunded_customer_sk" INTEGER,
   "cr_refunded_cdemo_sk" INTEGER, "cr_refunded_hdemo_sk" INTEGER, "cr_refunded_addr_sk" INTEGER, "cr_returning_customer_sk" INTEGER,
   "cr_returning_cdemo_sk" INTEGER, "cr_returning_hdemo_sk" INTEGER, "cr_returning_addr_sk" INTEGER, "cr_call_center_sk" INTEGER,
@@ -22,19 +22,19 @@ dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;creat
   "cr_return_quantity" INTEGER, "cr_return_amount" DECIMAL(7,2), "cr_return_tax" DECIMAL(7,2), "cr_return_amt_inc_tax" DECIMAL(7,2),
   "cr_fee" DECIMAL(7,2), "cr_return_ship_cost" DECIMAL(7,2), "cr_refunded_cash" DECIMAL(7,2), "cr_reversed_charge" DECIMAL(7,2),
   "cr_store_credit" DECIMAL(7,2), "cr_net_loss" DECIMAL(7,2))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE STORE_SALES ("ss_sold_date_sk" INTEGER, "ss_sold_time_sk" INTEGER, "ss_item_sk" INTEGER, "ss_customer_sk" INTEGER, "ss_cdemo_sk" INTEGER,
   "ss_hdemo_sk" INTEGER, "ss_addr_sk" INTEGER, "ss_store_sk" INTEGER, "ss_promo_sk" INTEGER, "ss_ticket_number" INTEGER, "ss_quantity" INTEGER,
   "ss_wholesale_cost" DECIMAL(7,2), "ss_list_price" DECIMAL(7,2), "ss_sales_price" DECIMAL(7,2), "ss_ext_discount_amt" DECIMAL(7,2),
   "ss_ext_sales_price" DECIMAL(7,2), "ss_ext_wholesale_cost" DECIMAL(7,2), "ss_ext_list_price" DECIMAL(7,2), "ss_ext_tax" DECIMAL(7,2),
   "ss_coupon_amt" DECIMAL(7,2), "ss_net_paid" DECIMAL(7,2), "ss_net_paid_inc_tax" DECIMAL(7,2), "ss_net_profit" DECIMAL(7,2))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE STORE_RETURNS ("sr_returned_date_sk" INTEGER, "sr_return_time_sk" INTEGER, "sr_item_sk" INTEGER, "sr_customer_sk" INTEGER,
   "sr_cdemo_sk" INTEGER, "sr_hdemo_sk" INTEGER, "sr_addr_sk" INTEGER, "sr_store_sk" INTEGER, "sr_reason_sk" INTEGER, "sr_ticket_number" INTEGER,
   "sr_return_quantity" INTEGER, "sr_return_amt" DECIMAL(7,2), "sr_return_tax" DECIMAL(7,2), "sr_return_amt_inc_tax" DECIMAL(7,2),
   "sr_fee" DECIMAL(7,2), "sr_return_ship_cost" DECIMAL(7,2), "sr_refunded_cash" DECIMAL(7,2), "sr_reversed_charge" DECIMAL(7,2),
   "sr_store_credit" DECIMAL(7,2), "sr_net_loss" DECIMAL(7,2))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE WEB_SALES ("ws_sold_date_sk" INTEGER, "ws_sold_time_sk" INTEGER, "ws_ship_date_sk" INTEGER, "ws_item_sk" INTEGER,
   "ws_bill_customer_sk" INTEGER, "ws_bill_cdemo_sk" INTEGER, "ws_bill_hdemo_sk" INTEGER, "ws_bill_addr_sk" INTEGER, "ws_ship_customer_sk" INTEGER,
   "ws_ship_cdemo_sk" INTEGER, "ws_ship_hdemo_sk" INTEGER, "ws_ship_addr_sk" INTEGER, "ws_web_page_sk" INTEGER, "ws_web_site_sk" INTEGER,
@@ -43,47 +43,47 @@ dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;creat
   "ws_ext_sales_price" DECIMAL(7,2), "ws_ext_wholesale_cost" DECIMAL(7,2), "ws_ext_list_price" DECIMAL(7,2), "ws_ext_tax" DECIMAL(7,2),
   "ws_coupon_amt" DECIMAL(7,2), "ws_ext_ship_cost" DECIMAL(7,2), "ws_net_paid" DECIMAL(7,2), "ws_net_paid_inc_tax" DECIMAL(7,2),
   "ws_net_paid_inc_ship" DECIMAL(7,2), "ws_net_paid_inc_ship_tax" DECIMAL(7,2), "ws_net_profit" DECIMAL(7,2))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE WEB_RETURNS ("wr_returned_date_sk" INTEGER, "wr_returned_time_sk" INTEGER, "wr_item_sk" INTEGER, "wr_refunded_customer_sk" INTEGER,
   "wr_refunded_cdemo_sk" INTEGER, "wr_refunded_hdemo_sk" INTEGER, "wr_refunded_addr_sk" INTEGER, "wr_returning_customer_sk" INTEGER,
   "wr_returning_cdemo_sk" INTEGER, "wr_returning_hdemo_sk" INTEGER, "wr_returning_addr_sk" INTEGER, "wr_web_page_sk" INTEGER,
   "wr_reason_sk" INTEGER, "wr_order_number" INTEGER, "wr_return_quantity" INTEGER, "wr_return_amt" DECIMAL(7,2), "wr_return_tax" DECIMAL(7,2),
   "wr_return_amt_inc_tax" DECIMAL(7,2), "wr_fee" DECIMAL(7,2), "wr_return_ship_cost" DECIMAL(7,2), "wr_refunded_cash" DECIMAL(7,2),
   "wr_reversed_charge" DECIMAL(7,2), "wr_account_credit" DECIMAL(7,2), "wr_net_loss" DECIMAL(7,2))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE CUSTOMER ("c_customer_sk" INTEGER, "c_customer_id" CHAR(16), "c_current_cdemo_sk" INTEGER, "c_current_hdemo_sk" INTEGER,
   "c_current_addr_sk" INTEGER, "c_first_shipto_date_sk" INTEGER, "c_first_sales_date_sk" INTEGER, "c_salutation" CHAR(10),
   "c_first_name" CHAR(20), "c_last_name" CHAR(30), "c_preferred_cust_flag" CHAR(1), "c_birth_day" INTEGER, "c_birth_month" INTEGER,
   "c_birth_year" INTEGER, "c_birth_country" VARCHAR(20), "c_login" CHAR(13), "c_email_address" CHAR(50), "c_last_review_date" CHAR(10))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE CUSTOMER_ADDRESS ("ca_address_sk" INTEGER, "ca_address_id" CHAR(16), "ca_street_number" CHAR(10), "ca_street_name" VARCHAR(60),
   "ca_street_type" CHAR(15), "ca_suite_number" CHAR(10), "ca_city" VARCHAR(60), "ca_county" VARCHAR(30), "ca_state" CHAR(2),
   "ca_zip" CHAR(10), "ca_country" VARCHAR(20), "ca_gmt_offset" DECIMAL(5,2), "ca_location_type" CHAR(20))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE CUSTOMER_DEMOGRAPHICS ("cd_demo_sk" INTEGER, "cd_gender" CHAR(1), "cd_marital_status" CHAR(1), "cd_education_status" CHAR(20),
   "cd_purchase_estimate" INTEGER, "cd_credit_rating" CHAR(10), "cd_dep_count" INTEGER, "cd_dep_employed_count" INTEGER,
   "cd_dep_college_count" INTEGER)' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE INVENTORY ("inv_date_sk" INTEGER, "inv_item_sk" INTEGER, "inv_warehouse_sk" INTEGER, "inv_quantity_on_hand" INTEGER)' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE ITEM ("i_item_sk" INTEGER, "i_item_id" CHAR(16), "i_rec_start_date" DATE, "i_rec_end_date" DATE,
   "i_item_desc" VARCHAR(200), "i_current_price" DECIMAL(7,2), "i_wholesale_cost" DECIMAL(7,2), "i_brand_id" INTEGER,
   "i_brand" CHAR(50), "i_class_id" INTEGER, "i_class" CHAR(50), "i_category_id" INTEGER, "i_category" CHAR(50),
   "i_manufact_id" INTEGER, "i_manufact" CHAR(50), "i_size" CHAR(20), "i_formulation" CHAR(20), "i_color" CHAR(20),
   "i_units" CHAR(10), "i_container" CHAR(10), "i_manager_id" INTEGER, "i_product_name" CHAR(50))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE WAREHOUSE ("w_warehouse_sk" INTEGER, "w_warehouse_id" CHAR(16), "w_warehouse_name" VARCHAR(20),
   "w_warehouse_sq_ft" INTEGER, "w_street_number" CHAR(10), "w_street_name" VARCHAR(60), "w_street_type" CHAR(15),
   "w_suite_number" CHAR(10), "w_city" VARCHAR(60), "w_county" VARCHAR(30), "w_state" CHAR(2), "w_zip" CHAR(10),
   "w_country" VARCHAR(20), "w_gmt_offset" DECIMAL(5,2))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE DATE_DIM ("d_date_sk" INTEGER, "d_date_id" CHAR(16), "d_date" DATE, "d_month_seq" INTEGER, "d_week_seq" INTEGER,
   "d_quarter_seq" INTEGER, "d_year" INTEGER, "d_dow" INTEGER, "d_moy" INTEGER, "d_dom" INTEGER, "d_qoy" INTEGER,
   "d_fy_year" INTEGER, "d_fy_quarter_seq" INTEGER, "d_fy_week_seq" INTEGER, "d_day_name" CHAR(9), "d_quarter_name" CHAR(6),
   "d_holiday" CHAR(1), "d_weekend" CHAR(1), "d_following_holiday" CHAR(1), "d_first_dom" INTEGER, "d_last_dom" INTEGER,
   "d_same_day_ly" INTEGER, "d_same_day_lq" INTEGER, "d_current_day" CHAR(1), "d_current_week" CHAR(1), "d_current_month" CHAR(1),
   "d_current_quarter" CHAR(1), "d_current_year" CHAR(1))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE STORE ("s_store_sk" INTEGER, "s_store_id" CHAR(16), "s_rec_start_date" DATE, "s_rec_end_date" DATE,
   "s_closed_date_sk" INTEGER, "s_store_name" VARCHAR(50), "s_number_employees" INTEGER, "s_floor_space" INTEGER,
   "s_hours" CHAR(20), "s_manager" VARCHAR(40), "s_market_id" INTEGER, "s_geography_class" VARCHAR(100),
@@ -91,14 +91,14 @@ dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;creat
   "s_company_id" INTEGER, "s_company_name" VARCHAR(50), "s_street_number" VARCHAR(10), "s_street_name" VARCHAR(60),
   "s_street_type" CHAR(15), "s_suite_number" CHAR(10), "s_city" VARCHAR(60), "s_county" VARCHAR(30),
   "s_state" CHAR(2), "s_zip" CHAR(10), "s_country" VARCHAR(20), "s_gmt_offset" DECIMAL(5,2), "s_tax_precentage" DECIMAL(5,2))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE HOUSEHOLD_DEMOGRAPHICS ("hd_demo_sk" INTEGER, "hd_income_band_sk" INTEGER, "hd_buy_potential" CHAR(15),
   "hd_dep_count" INTEGER, "hd_vehicle_count" INTEGER)' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE TIME_DIM ("t_time_sk" INTEGER, "t_time_id" CHAR(16), "t_time" INTEGER, "t_hour" INTEGER,
   "t_minute" INTEGER, "t_second" INTEGER, "t_am_pm" CHAR(2), "t_shift" CHAR(20), "t_sub_shift" CHAR(20),
   "t_meal_time" CHAR(20))' ),
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;create=true','user1','passwd1',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'CREATE TABLE REASON ("r_reason_sk" INTEGER, "r_reason_id" CHAR(16), "r_reason_desc" CHAR(100))' )
 limit 1;
 
@@ -144,7 +144,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "CATALOG_SALES",
@@ -185,7 +185,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "CATALOG_RETURNS",
@@ -222,7 +222,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "STORE_SALES",
@@ -256,7 +256,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "STORE_RETURNS",
@@ -304,7 +304,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "WEB_SALES",
@@ -342,7 +342,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "WEB_RETURNS",
@@ -374,7 +374,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "CUSTOMER",
@@ -401,7 +401,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "CUSTOMER_ADDRESS",
@@ -424,7 +424,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "CUSTOMER_DEMOGRAPHICS",
@@ -442,7 +442,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "INVENTORY",
@@ -478,7 +478,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "ITEM",
@@ -506,7 +506,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "WAREHOUSE",
@@ -548,7 +548,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "DATE_DIM",
@@ -591,7 +591,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "STORE",
@@ -610,7 +610,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "HOUSEHOLD_DEMOGRAPHICS",
@@ -634,7 +634,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "TIME_DIM",
@@ -651,7 +651,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user1",
                 "hive.sql.dbcp.password" = "passwd1",
                 "hive.sql.table" = "REASON",
@@ -1981,38 +1981,38 @@ DROP TABLE reason;
 
 FROM src
 SELECT
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE CATALOG_SALES' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE CATALOG_RETURNS' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE STORE_SALES' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE STORE_RETURNS' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE WEB_SALES' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE WEB_RETURNS' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE CUSTOMER' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE CUSTOMER_ADDRESS' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE CUSTOMER_DEMOGRAPHICS' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE INVENTORY' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE ITEM' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE WAREHOUSE' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE DATE_DIM' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE STORE' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE HOUSEHOLD_DEMOGRAPHICS' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE TIME_DIM' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_perf','user1','passwd1',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user1','passwd1',
 'DROP TABLE REASON' )
 limit 1;
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_table_typeconversion.q b/ql/src/test/queries/clientpositive/external_jdbc_table_typeconversion.q
index 9342aa325ba0..eac48611c8ff 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_table_typeconversion.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_table_typeconversion.q
@@ -1,3 +1,4 @@
+--!qt:database:derby:qdb
 --! qt:dataset:src
 
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
@@ -5,17 +6,17 @@ CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf
 -- convert varchar to numeric/decimal/date/timestamp
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;create=true','user','passwd',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'CREATE TABLE EXTERNAL_JDBC_TYPE_CONVERSION_TABLE1 ("ikey" VARCHAR(20), "bkey" VARCHAR(20), "fkey" VARCHAR(20), "dkey" VARCHAR(20), "chkey" VARCHAR(20), "dekey" VARCHAR(20), "dtkey" VARCHAR(20), "tkey" VARCHAR(50))' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','1','1000','20.0','40.0','aaa','3.1415','2010-01-01','2018-01-01 12:00:00.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','5','9000',null,'10.0','bbb','2.7182','2018-01-01','2010-06-01 14:00:00.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','3','4000','120.0','25.4','hello','2.7182','2017-06-05','2011-11-10 18:00:08.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','8','3000','180.0','35.8','world','3.1415','2014-03-03','2016-07-04 13:00:00.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE1 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey") VALUES (?,?,?,?,?,?,?,?)','4','8000','120.4','31.3','ccc',null,'2014-03-04','2018-07-08 11:00:00.000000000')
 limit 1;
 
@@ -34,7 +35,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE1",
@@ -51,19 +52,19 @@ SELECT * FROM jdbc_type_conversion_table1;
 
 FROM src
 SELECT
-dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;create=true','user','passwd',
+dboutput ('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'CREATE TABLE EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE, "chkey" VARCHAR(20), "dekey" DECIMAL(6,4), "dtkey" DATE, "tkey" TIMESTAMP, "mixkey" VARCHAR(50))' ),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey", "mixkey") VALUES (?,?,?,?,?,?,?,?,?)','1','1000','20.0','40.0','aaa','3.1415','2010-01-01','2018-01-01 12:00:00.000000000','10'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey", "mixkey") VALUES (?,?,?,?,?,?,?,?,?)','5','9000',null,'10.0','bbb','2.7182','2018-01-01','2010-06-01 14:00:00.000000000','100000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey", "mixkey") VALUES (?,?,?,?,?,?,?,?,?)','3','4000','120.0','25.4','hello','2.7182','2017-06-05','2011-11-10 18:00:08.000000000','10.582'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey", "mixkey") VALUES (?,?,?,?,?,?,?,?,?)','8','3000','180.0','35.8','world','3.1415','2014-03-03','2016-07-04 13:00:00.000000000','2024-03-03'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey", "mixkey") VALUES (?,?,?,?,?,?,?,?,?)','4','8000','120.4','31.3','ccc',null,'2014-03-04','2018-07-08 11:00:00.000000000','2018-07-08 11:00:00.000000000'),
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300','user','passwd',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','user','passwd',
 'INSERT INTO EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2 ("ikey","bkey","fkey","dkey","chkey","dekey","dtkey","tkey", "mixkey") VALUES (?,?,?,?,?,?,?,?,?)','6','6000','80.4','5.3','ddd',null,'2024-05-31','2024-05-31 13:22:34.000000123','ddd')
 limit 1;
 
@@ -83,7 +84,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
@@ -110,7 +111,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
@@ -137,7 +138,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
@@ -164,7 +165,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
@@ -191,7 +192,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
@@ -218,7 +219,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
@@ -245,7 +246,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
@@ -272,7 +273,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
@@ -299,7 +300,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby2_300;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "user",
                 "hive.sql.dbcp.password" = "passwd",
                 "hive.sql.table" = "EXTERNAL_JDBC_TYPE_CONVERSION_TABLE2",
diff --git a/ql/src/test/queries/clientpositive/external_jdbc_view.q b/ql/src/test/queries/clientpositive/external_jdbc_view.q
index 9575cabaac09..e254a792fb96 100644
--- a/ql/src/test/queries/clientpositive/external_jdbc_view.q
+++ b/ql/src/test/queries/clientpositive/external_jdbc_view.q
@@ -1,15 +1,16 @@
+--!qt:database:derby:qdb
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_view;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE person ("id" INTEGER, "name" VARCHAR(25), "jid" INTEGER, "cid" INTEGER)' );
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_view;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE country ("id" INTEGER, "name" VARCHAR(25))' );
 
 SELECT
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_view;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE job ("id" INTEGER, "title" VARCHAR(20))' );
 
 
@@ -24,7 +25,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
     "hive.sql.database.type" = "DERBY",
     "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-    "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_view;create=true;collation=TERRITORY_BASED:PRIMARY",
+    "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
     "hive.sql.dbcp.username" = "APP",
     "hive.sql.dbcp.password" = "mine",
     "hive.sql.table" = "PERSON",
@@ -41,7 +42,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
     "hive.sql.database.type" = "DERBY",
     "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-    "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_view;create=true;collation=TERRITORY_BASED:PRIMARY",
+    "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
     "hive.sql.dbcp.username" = "APP",
     "hive.sql.dbcp.password" = "mine",
     "hive.sql.table" = "COUNTRY",
@@ -62,7 +63,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
     "hive.sql.database.type" = "DERBY",
     "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-    "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_jdbc_view;create=true;collation=TERRITORY_BASED:PRIMARY",
+    "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
     "hive.sql.dbcp.username" = "APP",
     "hive.sql.dbcp.password" = "mine",
     "hive.sql.schema" = "APP",
diff --git a/ql/src/test/queries/clientpositive/jdbc_handler.q b/ql/src/test/queries/clientpositive/jdbc_handler.q
index 55de3bdefab0..b2ed0b095c4d 100644
--- a/ql/src/test/queries/clientpositive/jdbc_handler.q
+++ b/ql/src/test/queries/clientpositive/jdbc_handler.q
@@ -1,5 +1,5 @@
+--!qt:database:derby:qdb
 --! qt:dataset:src
---! qt:disabled:flaky HIVE-23709
 
 set hive.strict.checks.cartesian.product= false;
 
@@ -9,13 +9,13 @@ CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf
 
 FROM src
 
-SELECT dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+SELECT dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE ("kkey" INTEGER NOT NULL )' ),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE ("kkey") VALUES (?)','20'),
 
-dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput('${system:hive.test.database.qdb.jdbc.url}','','',
 'INSERT INTO SIMPLE_DERBY_TABLE ("kkey") VALUES (?)','200')
 
 limit 1;
@@ -28,7 +28,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE",
@@ -97,7 +97,7 @@ describe tables;
 
 FROM src
 
-SELECT dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_insert_derby_as_external_table_db;create=true','','',
+SELECT dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE INSERT_TO_DERBY_TABLE (a BOOLEAN, b  INTEGER, c BIGINT, d FLOAT, e DOUBLE, f DATE, g VARCHAR(27),
                                   h VARCHAR(27), i CHAR(2), j TIMESTAMP, k DECIMAL(5,4), l SMALLINT, m SMALLINT, b1 CHAR(10))' )
 
@@ -124,7 +124,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_insert_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "INSERT_TO_DERBY_TABLE",
diff --git a/ql/src/test/queries/clientpositive/jdbc_split_filter.q b/ql/src/test/queries/clientpositive/jdbc_split_filter.q
index 4ff19b01c1c8..d624f938d77d 100644
--- a/ql/src/test/queries/clientpositive/jdbc_split_filter.q
+++ b/ql/src/test/queries/clientpositive/jdbc_split_filter.q
@@ -1,16 +1,16 @@
---! qt:disabled:flaky HIVE-25462
+--!qt:database:derby:qdb
 
 CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
 
 
 SELECT
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE1 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE)' );
 
 SELECT
 
-dboutput ( 'jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true','','',
+dboutput ( '${system:hive.test.database.qdb.jdbc.url}','','',
 'CREATE TABLE SIMPLE_DERBY_TABLE2 ("ikey" INTEGER, "bkey" BIGINT, "fkey" REAL, "dkey" DOUBLE, "datekey" DATE)' );
 
 CREATE EXTERNAL TABLE ext_simple_derby_table1
@@ -24,7 +24,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE1",
@@ -44,7 +44,7 @@ STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
 TBLPROPERTIES (
                 "hive.sql.database.type" = "DERBY",
                 "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
-                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_as_external_table_db;create=true;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url};collation=TERRITORY_BASED:PRIMARY",
                 "hive.sql.dbcp.username" = "APP",
                 "hive.sql.dbcp.password" = "mine",
                 "hive.sql.table" = "SIMPLE_DERBY_TABLE2",
diff --git a/ql/src/test/queries/clientpositive/qt_database_derby.q b/ql/src/test/queries/clientpositive/qt_database_derby.q
new file mode 100644
index 000000000000..80e93aa70dae
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/qt_database_derby.q
@@ -0,0 +1,17 @@
+--!qt:database:derby:qdb:q_test_country_table.sql
+CREATE EXTERNAL TABLE country
+(
+    id int,
+    name varchar(20)
+)
+    STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
+    TBLPROPERTIES (
+        "hive.sql.database.type" = "DERBY",
+        "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
+        "hive.sql.jdbc.url" = "${system:hive.test.database.qdb.jdbc.url}",
+        "hive.sql.dbcp.username" = "${system:hive.test.database.qdb.jdbc.username}",
+        "hive.sql.dbcp.password" = "${system:hive.test.database.qdb.jdbc.password}",
+        "hive.sql.dbcp.maxActive" = "1",
+        "hive.sql.table" = "COUNTRY"
+        );
+SELECT * FROM country;
diff --git a/ql/src/test/results/clientnegative/external_jdbc_negative.q.out b/ql/src/test/results/clientnegative/external_jdbc_negative.q.out
index c9d296b0599b..485a742fa447 100644
--- a/ql/src/test/results/clientnegative/external_jdbc_negative.q.out
+++ b/ql/src/test/results/clientnegative/external_jdbc_negative.q.out
@@ -43,4 +43,4 @@ TBLPROPERTIES (
 PREHOOK: type: CREATETABLE
 PREHOOK: Output: database:default
 PREHOOK: Output: default@db1_ext_negative1
-FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.ddl.DDLTask. java.lang.RuntimeException: MetaException(message:org.apache.hadoop.hive.serde2.SerDeException org.apache.hadoop.hive.serde2.SerDeException: Column numbers do not match. Remote table columns are [ikey] and declared table columns in Hive external table are [ikey, bkey])
+FAILED: Execution Error, return code 40000 from org.apache.hadoop.hive.ql.ddl.DDLTask. java.lang.RuntimeException: MetaException(message:org.apache.hadoop.hive.serde2.SerDeException Caught exception while initializing the SqlSerDe: Column numbers do not match. Remote table columns are [ikey] and declared table columns in Hive external table are [ikey, bkey])
diff --git a/ql/src/test/results/clientpositive/llap/dataconnector.q.out b/ql/src/test/results/clientpositive/llap/dataconnector.q.out
index d6e162a4ab1f..3582a519ee56 100644
--- a/ql/src/test/results/clientpositive/llap/dataconnector.q.out
+++ b/ql/src/test/results/clientpositive/llap/dataconnector.q.out
@@ -50,7 +50,7 @@ POSTHOOK: type: SHOWDATACONNECTORS
 mysql_test
 PREHOOK: query: CREATE CONNECTOR IF NOT EXISTS derby_test
 TYPE 'derby'
-URL 'jdbc:derby:./target/db_for_connectortest.db;create=true'
+#### A masked pattern was here ####
 COMMENT 'test derby connector'
 WITH DCPROPERTIES (
 "hive.sql.dbcp.username"="APP",
@@ -59,7 +59,7 @@ PREHOOK: type: CREATEDATACONNECTOR
 PREHOOK: Output: connector:derby_test
 POSTHOOK: query: CREATE CONNECTOR IF NOT EXISTS derby_test
 TYPE 'derby'
-URL 'jdbc:derby:./target/db_for_connectortest.db;create=true'
+#### A masked pattern was here ####
 COMMENT 'test derby connector'
 WITH DCPROPERTIES (
 "hive.sql.dbcp.username"="APP",
@@ -138,8 +138,8 @@ PREHOOK: Input: database:db_derby
 POSTHOOK: query: SHOW TABLES
 POSTHOOK: type: SHOWTABLES
 POSTHOOK: Input: database:db_derby
-TESTTABLE1
-TESTTABLE2
+AUTHOR
+BOOK
 PREHOOK: query: alter connector mysql_test set URL 'jdbc:mysql://nightly1.apache.org:3306/hive2'
 PREHOOK: type: ALTERDATACONNECTOR_
 PREHOOK: Output: connector:mysql_test
diff --git a/ql/src/test/results/clientpositive/llap/external_jdbc_table.q.out b/ql/src/test/results/clientpositive/llap/external_jdbc_table.q.out
index 5f8f9caa3131..ac99bb17dd50 100644
--- a/ql/src/test/results/clientpositive/llap/external_jdbc_table.q.out
+++ b/ql/src/test/results/clientpositive/llap/external_jdbc_table.q.out
@@ -319,7 +319,8 @@ STAGE PLANS:
           alias: ext_simple_derby_table1
           properties:
             hive.sql.query SELECT "bkey"
-FROM "SIMPLE_DERBY_TABLE1"
+FROM (SELECT "ikey", "bkey"
+FROM "SIMPLE_DERBY_TABLE1") AS "t"
 WHERE 100 < "ikey"
             hive.sql.query.fieldNames bkey
             hive.sql.query.fieldTypes bigint
@@ -395,13 +396,15 @@ STAGE PLANS:
         TableScan
           alias: ext_simple_derby_table1
           properties:
-            hive.sql.query SELECT "t0"."fkey", "t2"."dkey"
+            hive.sql.query SELECT "t1"."fkey", "t4"."dkey"
 FROM (SELECT "ikey", "fkey"
-FROM "SIMPLE_DERBY_TABLE1"
-WHERE "ikey" IS NOT NULL) AS "t0"
+FROM (SELECT "ikey", "fkey"
+FROM "SIMPLE_DERBY_TABLE1") AS "t"
+WHERE "ikey" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "ikey", "dkey"
-FROM "SIMPLE_DERBY_TABLE2"
-WHERE "ikey" IS NOT NULL) AS "t2" ON "t0"."ikey" = "t2"."ikey"
+FROM (SELECT "ikey", "dkey"
+FROM "SIMPLE_DERBY_TABLE2") AS "t2"
+WHERE "ikey" IS NOT NULL) AS "t4" ON "t1"."ikey" = "t4"."ikey"
             hive.sql.query.fieldNames fkey,dkey
             hive.sql.query.fieldTypes float,double
             hive.sql.query.split false
@@ -476,7 +479,8 @@ STAGE PLANS:
                   alias: ext_simple_derby_table2
                   properties:
                     hive.sql.query SELECT "ikey", "dkey"
-FROM "SIMPLE_DERBY_TABLE2"
+FROM (SELECT "ikey", "dkey"
+FROM "SIMPLE_DERBY_TABLE2") AS "t"
 WHERE "ikey" IS NOT NULL
                     hive.sql.query.fieldNames ikey,dkey
                     hive.sql.query.fieldTypes int,double
@@ -572,10 +576,12 @@ CBO PLAN:
 HiveJdbcConverter(convention=[JDBC.DERBY])
   JdbcProject(fkey=[$1], dkey=[$3])
     JdbcJoin(condition=[=($0, $2)], joinType=[inner])
-      JdbcProject(ikey=[$0], fkey=[$2])
+      JdbcProject(ikey=[$0], fkey=[$1])
         JdbcFilter(condition=[IS NOT NULL($0)])
-          JdbcHiveTableScan(table=[[default, ext_simple_derby_table1]], table:alias=[ext_simple_derby_table1])
-      JdbcProject(ikey=[$0], dkey=[$3])
+          JdbcProject(ikey=[$0], fkey=[$2])
+            JdbcHiveTableScan(table=[[default, ext_simple_derby_table1]], table:alias=[ext_simple_derby_table1])
+      JdbcProject(ikey=[$0], dkey=[$1])
         JdbcFilter(condition=[IS NOT NULL($0)])
-          JdbcHiveTableScan(table=[[default, ext_simple_derby_table2]], table:alias=[ext_simple_derby_table2])
+          JdbcProject(ikey=[$0], dkey=[$3])
+            JdbcHiveTableScan(table=[[default, ext_simple_derby_table2]], table:alias=[ext_simple_derby_table2])
 
diff --git a/ql/src/test/results/clientpositive/llap/external_jdbc_table_perf.q.out b/ql/src/test/results/clientpositive/llap/external_jdbc_table_perf.q.out
index cb078e66e921..183069a25b9e 100644
--- a/ql/src/test/results/clientpositive/llap/external_jdbc_table_perf.q.out
+++ b/ql/src/test/results/clientpositive/llap/external_jdbc_table_perf.q.out
@@ -1480,41 +1480,47 @@ STAGE PLANS:
         TableScan
           alias: inventory
           properties:
-            hive.sql.query SELECT "t23"."w_warehouse_sk", "t23"."i_item_sk", CAST(1 AS INTEGER) AS "d_moy", "t23"."mean", "t23"."cov", "t23"."w_warehouse_sk0" AS "w_warehouse_sk1", "t23"."i_item_sk0" AS "i_item_sk1", CAST(2 AS INTEGER) AS "d_moy1", "t23"."mean0" AS "mean1", "t23"."cov0" AS "cov1"
-FROM (SELECT "t10"."w_warehouse_sk", "t10"."i_item_sk", "t10"."mean", "t10"."cov", "t22"."w_warehouse_sk" AS "w_warehouse_sk0", "t22"."i_item_sk" AS "i_item_sk0", "t22"."mean" AS "mean0", "t22"."cov" AS "cov0"
+            hive.sql.query SELECT "t29"."w_warehouse_sk", "t29"."i_item_sk", CAST(1 AS INTEGER) AS "d_moy", "t29"."mean", "t29"."cov", "t29"."w_warehouse_sk0" AS "w_warehouse_sk1", "t29"."i_item_sk0" AS "i_item_sk1", CAST(2 AS INTEGER) AS "d_moy1", "t29"."mean0" AS "mean1", "t29"."cov0" AS "cov1"
+FROM (SELECT "t13"."w_warehouse_sk", "t13"."i_item_sk", "t13"."mean", "t13"."cov", "t28"."w_warehouse_sk" AS "w_warehouse_sk0", "t28"."i_item_sk" AS "i_item_sk0", "t28"."mean" AS "mean0", "t28"."cov" AS "cov0"
 FROM (SELECT "w_warehouse_sk", "i_item_sk", CAST("$f3" AS DOUBLE) / "$f4" AS "mean", CASE WHEN CAST("$f3" AS DOUBLE) / "$f4" = 0 THEN NULL ELSE CAST("$f3" AS DOUBLE) / (CAST("$f3" AS DOUBLE) / "$f4") END AS "cov"
-FROM (SELECT "t6"."w_warehouse_name", "t6"."w_warehouse_sk", "t2"."i_item_sk", SUM("t0"."inv_quantity_on_hand") AS "$f3", COUNT("t0"."inv_quantity_on_hand") AS "$f4"
+FROM (SELECT "t9"."w_warehouse_name", "t9"."w_warehouse_sk", "t3"."i_item_sk", SUM("t0"."inv_quantity_on_hand") AS "$f3", COUNT("t0"."inv_quantity_on_hand") AS "$f4"
 FROM (SELECT "inv_date_sk", "inv_item_sk", "inv_warehouse_sk", "inv_quantity_on_hand"
 FROM "INVENTORY"
-WHERE "inv_item_sk" IS NOT NULL AND ("inv_warehouse_sk" IS NOT NULL AND "inv_date_sk" IS NOT NULL)) AS "t0"
+WHERE "inv_item_sk" IS NOT NULL AND "inv_warehouse_sk" IS NOT NULL AND "inv_date_sk" IS NOT NULL) AS "t0"
 INNER JOIN (SELECT "i_item_sk"
-FROM "ITEM"
-WHERE "i_item_sk" IS NOT NULL) AS "t2" ON "t0"."inv_item_sk" = "t2"."i_item_sk"
+FROM (SELECT "i_item_sk"
+FROM "ITEM") AS "t1"
+WHERE "i_item_sk" IS NOT NULL) AS "t3" ON "t0"."inv_item_sk" = "t3"."i_item_sk"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 2001 AND ("d_moy" = 1 AND "d_date_sk" IS NOT NULL)) AS "t4" ON "t0"."inv_date_sk" = "t4"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t4"
+WHERE "d_year" = 2001 AND "d_moy" = 1 AND "d_date_sk" IS NOT NULL) AS "t6" ON "t0"."inv_date_sk" = "t6"."d_date_sk"
 INNER JOIN (SELECT "w_warehouse_sk", "w_warehouse_name"
-FROM "WAREHOUSE"
-WHERE "w_warehouse_sk" IS NOT NULL) AS "t6" ON "t0"."inv_warehouse_sk" = "t6"."w_warehouse_sk"
-GROUP BY "t2"."i_item_sk", "t6"."w_warehouse_sk", "t6"."w_warehouse_name") AS "t8"
-WHERE CASE WHEN CAST("t8"."$f3" AS DOUBLE) / "t8"."$f4" = 0 THEN FALSE ELSE CAST("t8"."$f3" AS DOUBLE) / (CAST("t8"."$f3" AS DOUBLE) / "t8"."$f4") > 1 END) AS "t10"
+FROM (SELECT "w_warehouse_sk", "w_warehouse_name"
+FROM "WAREHOUSE") AS "t7"
+WHERE "w_warehouse_sk" IS NOT NULL) AS "t9" ON "t0"."inv_warehouse_sk" = "t9"."w_warehouse_sk"
+GROUP BY "t3"."i_item_sk", "t9"."w_warehouse_sk", "t9"."w_warehouse_name") AS "t11"
+WHERE CASE WHEN CAST("t11"."$f3" AS DOUBLE) / "t11"."$f4" = 0 THEN FALSE ELSE CAST("t11"."$f3" AS DOUBLE) / (CAST("t11"."$f3" AS DOUBLE) / "t11"."$f4") > 1 END) AS "t13"
 INNER JOIN (SELECT "w_warehouse_sk", "i_item_sk", CAST("$f3" AS DOUBLE) / "$f4" AS "mean", CASE WHEN CAST("$f3" AS DOUBLE) / "$f4" = 0 THEN NULL ELSE CAST("$f3" AS DOUBLE) / (CAST("$f3" AS DOUBLE) / "$f4") END AS "cov"
-FROM (SELECT "t18"."w_warehouse_name", "t18"."w_warehouse_sk", "t14"."i_item_sk", SUM("t12"."inv_quantity_on_hand") AS "$f3", COUNT("t12"."inv_quantity_on_hand") AS "$f4"
+FROM (SELECT "t24"."w_warehouse_name", "t24"."w_warehouse_sk", "t18"."i_item_sk", SUM("t15"."inv_quantity_on_hand") AS "$f3", COUNT("t15"."inv_quantity_on_hand") AS "$f4"
 FROM (SELECT "inv_date_sk", "inv_item_sk", "inv_warehouse_sk", "inv_quantity_on_hand"
 FROM "INVENTORY"
-WHERE "inv_item_sk" IS NOT NULL AND ("inv_warehouse_sk" IS NOT NULL AND "inv_date_sk" IS NOT NULL)) AS "t12"
+WHERE "inv_item_sk" IS NOT NULL AND "inv_warehouse_sk" IS NOT NULL AND "inv_date_sk" IS NOT NULL) AS "t15"
 INNER JOIN (SELECT "i_item_sk"
-FROM "ITEM"
-WHERE "i_item_sk" IS NOT NULL) AS "t14" ON "t12"."inv_item_sk" = "t14"."i_item_sk"
+FROM (SELECT "i_item_sk"
+FROM "ITEM") AS "t16"
+WHERE "i_item_sk" IS NOT NULL) AS "t18" ON "t15"."inv_item_sk" = "t18"."i_item_sk"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 2001 AND ("d_moy" = 2 AND "d_date_sk" IS NOT NULL)) AS "t16" ON "t12"."inv_date_sk" = "t16"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t19"
+WHERE "d_year" = 2001 AND "d_moy" = 2 AND "d_date_sk" IS NOT NULL) AS "t21" ON "t15"."inv_date_sk" = "t21"."d_date_sk"
 INNER JOIN (SELECT "w_warehouse_sk", "w_warehouse_name"
-FROM "WAREHOUSE"
-WHERE "w_warehouse_sk" IS NOT NULL) AS "t18" ON "t12"."inv_warehouse_sk" = "t18"."w_warehouse_sk"
-GROUP BY "t14"."i_item_sk", "t18"."w_warehouse_sk", "t18"."w_warehouse_name") AS "t20"
-WHERE CASE WHEN CAST("t20"."$f3" AS DOUBLE) / "t20"."$f4" = 0 THEN FALSE ELSE CAST("t20"."$f3" AS DOUBLE) / (CAST("t20"."$f3" AS DOUBLE) / "t20"."$f4") > 1 END) AS "t22" ON "t10"."i_item_sk" = "t22"."i_item_sk" AND "t10"."w_warehouse_sk" = "t22"."w_warehouse_sk"
-ORDER BY "t10"."w_warehouse_sk", "t10"."i_item_sk", "t10"."mean", "t10"."cov", "t22"."mean", "t22"."cov") AS "t23"
+FROM (SELECT "w_warehouse_sk", "w_warehouse_name"
+FROM "WAREHOUSE") AS "t22"
+WHERE "w_warehouse_sk" IS NOT NULL) AS "t24" ON "t15"."inv_warehouse_sk" = "t24"."w_warehouse_sk"
+GROUP BY "t18"."i_item_sk", "t24"."w_warehouse_sk", "t24"."w_warehouse_name") AS "t26"
+WHERE CASE WHEN CAST("t26"."$f3" AS DOUBLE) / "t26"."$f4" = 0 THEN FALSE ELSE CAST("t26"."$f3" AS DOUBLE) / (CAST("t26"."$f3" AS DOUBLE) / "t26"."$f4") > 1 END) AS "t28" ON "t13"."i_item_sk" = "t28"."i_item_sk" AND "t13"."w_warehouse_sk" = "t28"."w_warehouse_sk"
+ORDER BY "t13"."w_warehouse_sk", "t13"."i_item_sk", "t13"."mean", "t13"."cov", "t28"."mean", "t28"."cov") AS "t29"
             hive.sql.query.fieldNames w_warehouse_sk,i_item_sk,d_moy,mean,cov,w_warehouse_sk1,i_item_sk1,d_moy1,mean1,cov1
             hive.sql.query.fieldTypes int,int,int,double,double,int,int,int,double,double
             hive.sql.query.split false
@@ -1738,23 +1744,26 @@ STAGE PLANS:
                 TableScan
                   alias: c
                   properties:
-                    hive.sql.query SELECT "t0"."c_customer_sk", "t0"."c_customer_id", "t0"."c_current_cdemo_sk", "t0"."c_current_hdemo_sk", "t0"."c_current_addr_sk", "t0"."c_first_shipto_date_sk", "t0"."c_first_sales_date_sk", "t0"."c_salutation", "t0"."c_first_name", "t0"."c_last_name", "t0"."c_preferred_cust_flag", "t0"."c_birth_day", "t0"."c_birth_month", "t0"."c_birth_year", "t0"."c_birth_country", "t0"."c_login", "t0"."c_email_address", "t0"."c_last_review_date", "t4"."ca_address_sk", "t4"."ca_address_id", "t4"."ca_street_number", "t4"."ca_street_name", "t4"."ca_street_type", "t4"."ca_suite_number", "t4"."ca_city", "t4"."ca_county", "t4"."ca_state", "t4"."ca_zip", "t4"."ca_country", "t4"."ca_gmt_offset", "t4"."ca_location_type", "t2"."cd_demo_sk", "t2"."cd_gender", "t2"."cd_marital_status", "t2"."cd_education_status", "t2"."cd_purchase_estimate", "t2"."cd_credit_rating", "t2"."cd_dep_count", "t2"."cd_dep_employed_count", "t2"."cd_dep_college_count"
-FROM (SELECT "c_customer_sk", "c_customer_id", "c_current_cdemo_sk", "c_current_hdemo_sk", "c_current_addr_sk", "c_first_shipto_date_sk", "c_first_sales_date_sk", "c_salutation", "c_first_name", "c_last_name", "c_preferred_cust_flag", "c_birth_day", "c_birth_month", "c_birth_year", "c_birth_country", "c_login", "c_email_address", "c_last_review_date"
-FROM "CUSTOMER"
-WHERE "c_current_addr_sk" IS NOT NULL AND ("c_current_cdemo_sk" IS NOT NULL AND "c_customer_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating", "cd_dep_count", "cd_dep_employed_count", "cd_dep_college_count"
-FROM "CUSTOMER_DEMOGRAPHICS"
-WHERE "cd_demo_sk" IS NOT NULL) AS "t2" ON "t0"."c_current_cdemo_sk" = "t2"."cd_demo_sk"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t0"."c_current_addr_sk" = "t4"."ca_address_sk"
-                    hive.sql.query.fieldNames c_customer_sk,c_customer_id,c_current_cdemo_sk,c_current_hdemo_sk,c_current_addr_sk,c_first_shipto_date_sk,c_first_sales_date_sk,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address,c_last_review_date,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,cd_demo_sk,cd_gender,cd_marital_status,cd_education_status,cd_purchase_estimate,cd_credit_rating,cd_dep_count,cd_dep_employed_count,cd_dep_college_count
-                    hive.sql.query.fieldTypes int,char(16),int,int,int,int,int,char(10),char(20),char(30),char(1),int,int,int,varchar(20),char(13),char(50),char(10),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(1),char(1),char(20),int,char(10),int,int,int
+                    hive.sql.query SELECT "t1"."c_customer_sk", "t1"."c_current_cdemo_sk", "t1"."c_current_addr_sk", "t4"."ca_address_sk", "t4"."ca_state", "t7"."cd_demo_sk", "t7"."cd_gender", "t7"."cd_marital_status", "t7"."cd_education_status", "t7"."cd_purchase_estimate", "t7"."cd_credit_rating"
+FROM (SELECT "c_customer_sk", "c_current_cdemo_sk", "c_current_addr_sk"
+FROM (SELECT "c_customer_sk", "c_current_cdemo_sk", "c_current_addr_sk"
+FROM "CUSTOMER") AS "t"
+WHERE "c_current_addr_sk" IS NOT NULL AND "c_current_cdemo_sk" IS NOT NULL AND "c_customer_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_state"
+FROM (SELECT "ca_address_sk", "ca_state"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."c_current_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating"
+FROM (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating"
+FROM "CUSTOMER_DEMOGRAPHICS") AS "t5"
+WHERE "cd_demo_sk" IS NOT NULL) AS "t7" ON "t1"."c_current_cdemo_sk" = "t7"."cd_demo_sk"
+                    hive.sql.query.fieldNames c_customer_sk,c_current_cdemo_sk,c_current_addr_sk,ca_address_sk,ca_state,cd_demo_sk,cd_gender,cd_marital_status,cd_education_status,cd_purchase_estimate,cd_credit_rating
+                    hive.sql.query.fieldTypes int,int,int,int,char(2),int,char(1),char(1),char(20),int,char(10)
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: c_customer_sk (type: int), cd_gender (type: char(1)), cd_marital_status (type: char(1)), cd_education_status (type: char(20)), cd_purchase_estimate (type: int), cd_credit_rating (type: char(10))
-                    outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                    outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                     Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col0 (type: int)
@@ -1762,7 +1771,7 @@ WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4"
                       sort order: +
                       Map-reduce partition columns: _col0 (type: int)
                       Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                      value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 7 
@@ -1770,13 +1779,15 @@ WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4"
                 TableScan
                   alias: store_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ss_customer_sk"
+                    hive.sql.query SELECT "t1"."ss_customer_sk"
 FROM (SELECT "ss_sold_date_sk", "ss_customer_sk"
-FROM "STORE_SALES"
-WHERE "ss_customer_sk" IS NOT NULL AND "ss_sold_date_sk" IS NOT NULL) AS "t0"
+FROM (SELECT "ss_sold_date_sk", "ss_customer_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_customer_sk" IS NOT NULL AND "ss_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_sold_date_sk" = "t2"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."ss_sold_date_sk" = "t4"."d_date_sk"
                     hive.sql.query.fieldNames ss_customer_sk
                     hive.sql.query.fieldTypes int
                     hive.sql.query.split false
@@ -1804,13 +1815,15 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 TableScan
                   alias: web_sales
                   properties:
-                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."ws_bill_customer_sk"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t1"."ws_bill_customer_sk"
 FROM (SELECT "ws_sold_date_sk", "ws_bill_customer_sk"
-FROM "WEB_SALES"
-WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t0"
+FROM (SELECT "ws_sold_date_sk", "ws_bill_customer_sk"
+FROM "WEB_SALES") AS "t"
+WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."ws_sold_date_sk" = "t2"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."ws_sold_date_sk" = "t4"."d_date_sk"
                     hive.sql.query.fieldNames literalTrue,ws_bill_customer_sk
                     hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
@@ -1833,13 +1846,15 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 TableScan
                   alias: catalog_sales
                   properties:
-                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."cs_ship_customer_sk"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t1"."cs_ship_customer_sk"
+FROM (SELECT "cs_sold_date_sk", "cs_ship_customer_sk"
 FROM (SELECT "cs_sold_date_sk", "cs_ship_customer_sk"
-FROM "CATALOG_SALES"
-WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t0"
+FROM "CATALOG_SALES") AS "t"
+WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."cs_sold_date_sk" = "t2"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."cs_sold_date_sk" = "t4"."d_date_sk"
                     hive.sql.query.fieldNames literalTrue,cs_ship_customer_sk
                     hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
@@ -1871,7 +1886,7 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                 Statistics: Num rows: 1 Data size: 413 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
                   key expressions: _col0 (type: int)
@@ -1879,7 +1894,7 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                   sort order: +
                   Map-reduce partition columns: _col0 (type: int)
                   Statistics: Num rows: 1 Data size: 413 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                  value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
         Reducer 3 
             Execution mode: llap
             Reduce Operator Tree:
@@ -1889,14 +1904,14 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 keys:
                   0 _col0 (type: int)
                   1 _col1 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36, _col40
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10, _col11
                 Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col40 is null (type: boolean)
+                  predicate: _col11 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col0 (type: int), _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
-                    outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                    expressions: _col0 (type: int), _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
+                    outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                     Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col0 (type: int)
@@ -1904,7 +1919,7 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                       sort order: +
                       Map-reduce partition columns: _col0 (type: int)
                       Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                      value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
         Reducer 4 
             Execution mode: llap
             Reduce Operator Tree:
@@ -1914,17 +1929,17 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col32, _col33, _col34, _col35, _col36
+                outputColumnNames: _col6, _col7, _col8, _col9, _col10
                 Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                 Top N Key Operator
                   sort order: +++++
-                  keys: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                  keys: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
                   null sort order: zzzzz
                   Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                   top n: 100
                   Group By Operator
                     aggregations: count()
-                    keys: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                    keys: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
                     minReductionHashAggr: 0.99
                     mode: hash
                     outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -2222,23 +2237,26 @@ STAGE PLANS:
                 TableScan
                   alias: c
                   properties:
-                    hive.sql.query SELECT "t0"."c_customer_sk", "t0"."c_customer_id", "t0"."c_current_cdemo_sk", "t0"."c_current_hdemo_sk", "t0"."c_current_addr_sk", "t0"."c_first_shipto_date_sk", "t0"."c_first_sales_date_sk", "t0"."c_salutation", "t0"."c_first_name", "t0"."c_last_name", "t0"."c_preferred_cust_flag", "t0"."c_birth_day", "t0"."c_birth_month", "t0"."c_birth_year", "t0"."c_birth_country", "t0"."c_login", "t0"."c_email_address", "t0"."c_last_review_date", "t4"."ca_address_sk", "t4"."ca_address_id", "t4"."ca_street_number", "t4"."ca_street_name", "t4"."ca_street_type", "t4"."ca_suite_number", "t4"."ca_city", "t4"."ca_county", "t4"."ca_state", "t4"."ca_zip", "t4"."ca_country", "t4"."ca_gmt_offset", "t4"."ca_location_type", "t2"."cd_demo_sk", "t2"."cd_gender", "t2"."cd_marital_status", "t2"."cd_education_status", "t2"."cd_purchase_estimate", "t2"."cd_credit_rating", "t2"."cd_dep_count", "t2"."cd_dep_employed_count", "t2"."cd_dep_college_count"
-FROM (SELECT "c_customer_sk", "c_customer_id", "c_current_cdemo_sk", "c_current_hdemo_sk", "c_current_addr_sk", "c_first_shipto_date_sk", "c_first_sales_date_sk", "c_salutation", "c_first_name", "c_last_name", "c_preferred_cust_flag", "c_birth_day", "c_birth_month", "c_birth_year", "c_birth_country", "c_login", "c_email_address", "c_last_review_date"
-FROM "CUSTOMER"
-WHERE "c_current_addr_sk" IS NOT NULL AND ("c_current_cdemo_sk" IS NOT NULL AND "c_customer_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating", "cd_dep_count", "cd_dep_employed_count", "cd_dep_college_count"
-FROM "CUSTOMER_DEMOGRAPHICS"
-WHERE "cd_demo_sk" IS NOT NULL) AS "t2" ON "t0"."c_current_cdemo_sk" = "t2"."cd_demo_sk"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t0"."c_current_addr_sk" = "t4"."ca_address_sk"
-                    hive.sql.query.fieldNames c_customer_sk,c_customer_id,c_current_cdemo_sk,c_current_hdemo_sk,c_current_addr_sk,c_first_shipto_date_sk,c_first_sales_date_sk,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address,c_last_review_date,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,cd_demo_sk,cd_gender,cd_marital_status,cd_education_status,cd_purchase_estimate,cd_credit_rating,cd_dep_count,cd_dep_employed_count,cd_dep_college_count
-                    hive.sql.query.fieldTypes int,char(16),int,int,int,int,int,char(10),char(20),char(30),char(1),int,int,int,varchar(20),char(13),char(50),char(10),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(1),char(1),char(20),int,char(10),int,int,int
+                    hive.sql.query SELECT "t1"."c_customer_sk", "t1"."c_current_cdemo_sk", "t1"."c_current_addr_sk", "t4"."ca_address_sk", "t4"."ca_state", "t7"."cd_demo_sk", "t7"."cd_gender", "t7"."cd_marital_status", "t7"."cd_education_status", "t7"."cd_purchase_estimate", "t7"."cd_credit_rating"
+FROM (SELECT "c_customer_sk", "c_current_cdemo_sk", "c_current_addr_sk"
+FROM (SELECT "c_customer_sk", "c_current_cdemo_sk", "c_current_addr_sk"
+FROM "CUSTOMER") AS "t"
+WHERE "c_current_addr_sk" IS NOT NULL AND "c_current_cdemo_sk" IS NOT NULL AND "c_customer_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_state"
+FROM (SELECT "ca_address_sk", "ca_state"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."c_current_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating"
+FROM (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating"
+FROM "CUSTOMER_DEMOGRAPHICS") AS "t5"
+WHERE "cd_demo_sk" IS NOT NULL) AS "t7" ON "t1"."c_current_cdemo_sk" = "t7"."cd_demo_sk"
+                    hive.sql.query.fieldNames c_customer_sk,c_current_cdemo_sk,c_current_addr_sk,ca_address_sk,ca_state,cd_demo_sk,cd_gender,cd_marital_status,cd_education_status,cd_purchase_estimate,cd_credit_rating
+                    hive.sql.query.fieldTypes int,int,int,int,char(2),int,char(1),char(1),char(20),int,char(10)
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: c_customer_sk (type: int), cd_gender (type: char(1)), cd_marital_status (type: char(1)), cd_education_status (type: char(20)), cd_purchase_estimate (type: int), cd_credit_rating (type: char(10))
-                    outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                    outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                     Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col0 (type: int)
@@ -2246,7 +2264,7 @@ WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4"
                       sort order: +
                       Map-reduce partition columns: _col0 (type: int)
                       Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                      value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 7 
@@ -2254,13 +2272,15 @@ WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4"
                 TableScan
                   alias: store_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ss_customer_sk"
+                    hive.sql.query SELECT "t1"."ss_customer_sk"
 FROM (SELECT "ss_sold_date_sk", "ss_customer_sk"
-FROM "STORE_SALES"
-WHERE "ss_customer_sk" IS NOT NULL AND "ss_sold_date_sk" IS NOT NULL) AS "t0"
+FROM (SELECT "ss_sold_date_sk", "ss_customer_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_customer_sk" IS NOT NULL AND "ss_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_sold_date_sk" = "t2"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE ("d_moy" < 1 OR "d_moy" > 3) AND "d_year" = 1999 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."ss_sold_date_sk" = "t4"."d_date_sk"
                     hive.sql.query.fieldNames ss_customer_sk
                     hive.sql.query.fieldTypes int
                     hive.sql.query.split false
@@ -2288,13 +2308,15 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 TableScan
                   alias: web_sales
                   properties:
-                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."ws_bill_customer_sk"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t1"."ws_bill_customer_sk"
+FROM (SELECT "ws_sold_date_sk", "ws_bill_customer_sk"
 FROM (SELECT "ws_sold_date_sk", "ws_bill_customer_sk"
-FROM "WEB_SALES"
-WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t0"
+FROM "WEB_SALES") AS "t"
+WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."ws_sold_date_sk" = "t2"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE ("d_moy" < 1 OR "d_moy" > 3) AND "d_year" = 1999 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."ws_sold_date_sk" = "t4"."d_date_sk"
                     hive.sql.query.fieldNames literalTrue,ws_bill_customer_sk
                     hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
@@ -2317,13 +2339,15 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 TableScan
                   alias: catalog_sales
                   properties:
-                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."cs_ship_customer_sk"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t1"."cs_ship_customer_sk"
 FROM (SELECT "cs_sold_date_sk", "cs_ship_customer_sk"
-FROM "CATALOG_SALES"
-WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t0"
+FROM (SELECT "cs_sold_date_sk", "cs_ship_customer_sk"
+FROM "CATALOG_SALES") AS "t"
+WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."cs_sold_date_sk" = "t2"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE ("d_moy" < 1 OR "d_moy" > 3) AND "d_year" = 1999 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."cs_sold_date_sk" = "t4"."d_date_sk"
                     hive.sql.query.fieldNames literalTrue,cs_ship_customer_sk
                     hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
@@ -2355,7 +2379,7 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                 Statistics: Num rows: 1 Data size: 413 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
                   key expressions: _col0 (type: int)
@@ -2363,7 +2387,7 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                   sort order: +
                   Map-reduce partition columns: _col0 (type: int)
                   Statistics: Num rows: 1 Data size: 413 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                  value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
         Reducer 3 
             Execution mode: llap
             Reduce Operator Tree:
@@ -2373,14 +2397,14 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 keys:
                   0 _col0 (type: int)
                   1 _col1 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36, _col40
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10, _col11
                 Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col40 is null (type: boolean)
+                  predicate: _col11 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col0 (type: int), _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
-                    outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                    expressions: _col0 (type: int), _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
+                    outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                     Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col0 (type: int)
@@ -2388,7 +2412,7 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                       sort order: +
                       Map-reduce partition columns: _col0 (type: int)
                       Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                      value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
         Reducer 4 
             Execution mode: llap
             Reduce Operator Tree:
@@ -2398,17 +2422,17 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col32, _col33, _col34, _col35, _col36
+                outputColumnNames: _col6, _col7, _col8, _col9, _col10
                 Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                 Top N Key Operator
                   sort order: +++++
-                  keys: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                  keys: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
                   null sort order: zzzzz
                   Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                   top n: 100
                   Group By Operator
                     aggregations: count()
-                    keys: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                    keys: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
                     minReductionHashAggr: 0.99
                     mode: hash
                     outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -3068,34 +3092,38 @@ STAGE PLANS:
                 TableScan
                   alias: store_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ss_sold_date_sk", "t0"."ss_sold_time_sk", "t0"."ss_item_sk", "t0"."ss_customer_sk", "t0"."ss_cdemo_sk", "t0"."ss_hdemo_sk", "t0"."ss_addr_sk", "t0"."ss_store_sk", "t0"."ss_promo_sk", "t0"."ss_ticket_number", "t0"."ss_quantity", "t0"."ss_wholesale_cost", "t0"."ss_list_price", "t0"."ss_sales_price", "t0"."ss_ext_discount_amt", "t0"."ss_ext_sales_price", "t0"."ss_ext_wholesale_cost", "t0"."ss_ext_list_price", "t0"."ss_ext_tax", "t0"."ss_coupon_amt", "t0"."ss_net_paid", "t0"."ss_net_paid_inc_tax", "t0"."ss_net_profit", "t6"."d_date_sk", "t6"."d_date_id", "t6"."d_date", "t6"."d_month_seq", "t6"."d_week_seq", "t6"."d_quarter_seq", "t6"."d_year", "t6"."d_dow", "t6"."d_moy", "t6"."d_dom", "t6"."d_qoy", "t6"."d_fy_year", "t6"."d_fy_quarter_seq", "t6"."d_fy_week_seq", "t6"."d_day_name", "t6"."d_quarter_name", "t6"."d_holiday", "t6"."d_weekend", "t6"."d_following_holiday", "t6"."d_first_dom", "t6"."d_last_dom", "t6"."d_same_day_ly", "t6"."d_same_day_lq", "t6"."d_current_day", "t6"."d_current_week", "t6"."d_current_month", "t6"."d_current_quarter", "t6"."d_current_year", "t2"."ca_address_sk", "t2"."ca_address_id", "t2"."ca_street_number", "t2"."ca_street_name", "t2"."ca_street_type", "t2"."ca_suite_number", "t2"."ca_city", "t2"."ca_county", "t2"."ca_state", "t2"."ca_zip", "t2"."ca_country", "t2"."ca_gmt_offset", "t2"."ca_location_type", "t4"."i_item_sk", "t4"."i_item_id", "t4"."i_rec_start_date", "t4"."i_rec_end_date", "t4"."i_item_desc", "t4"."i_current_price", "t4"."i_wholesale_cost", "t4"."i_brand_id", "t4"."i_brand", "t4"."i_class_id", "t4"."i_class", "t4"."i_category_id", "t4"."i_category", "t4"."i_manufact_id", "t4"."i_manufact", "t4"."i_size", "t4"."i_formulation", "t4"."i_color", "t4"."i_units", "t4"."i_container", "t4"."i_manager_id", "t4"."i_product_name"
-FROM (SELECT "ss_sold_date_sk", "ss_sold_time_sk", "ss_item_sk", "ss_customer_sk", "ss_cdemo_sk", "ss_hdemo_sk", "ss_addr_sk", "ss_store_sk", "ss_promo_sk", "ss_ticket_number", "ss_quantity", "ss_wholesale_cost", "ss_list_price", "ss_sales_price", "ss_ext_discount_amt", "ss_ext_sales_price", "ss_ext_wholesale_cost", "ss_ext_list_price", "ss_ext_tax", "ss_coupon_amt", "ss_net_paid", "ss_net_paid_inc_tax", "ss_net_profit"
-FROM "STORE_SALES"
-WHERE "ss_sold_date_sk" IS NOT NULL AND ("ss_addr_sk" IS NOT NULL AND "ss_item_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_gmt_offset" = -8 AND "ca_address_sk" IS NOT NULL) AS "t2" ON "t0"."ss_addr_sk" = "t2"."ca_address_sk"
-INNER JOIN (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_item_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t4" ON "t0"."ss_item_sk" = "t4"."i_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_year" = 2000 AND ("d_moy" = 1 AND "d_date_sk" IS NOT NULL)) AS "t6" ON "t0"."ss_sold_date_sk" = "t6"."d_date_sk"
-                    hive.sql.query.fieldNames ss_sold_date_sk,ss_sold_time_sk,ss_item_sk,ss_customer_sk,ss_cdemo_sk,ss_hdemo_sk,ss_addr_sk,ss_store_sk,ss_promo_sk,ss_ticket_number,ss_quantity,ss_wholesale_cost,ss_list_price,ss_sales_price,ss_ext_discount_amt,ss_ext_sales_price,ss_ext_wholesale_cost,ss_ext_list_price,ss_ext_tax,ss_coupon_amt,ss_net_paid,ss_net_paid_inc_tax,ss_net_profit,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50)
+                    hive.sql.query SELECT "t1"."ss_sold_date_sk", "t1"."ss_item_sk", "t1"."ss_addr_sk", "t1"."ss_ext_sales_price", "t10"."d_date_sk", "t10"."d_year", "t10"."d_moy", "t4"."ca_address_sk", "t4"."ca_gmt_offset", "t7"."i_item_sk", "t7"."i_item_id"
+FROM (SELECT "ss_sold_date_sk", "ss_item_sk", "ss_addr_sk", "ss_ext_sales_price"
+FROM (SELECT "ss_sold_date_sk", "ss_item_sk", "ss_addr_sk", "ss_ext_sales_price"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_sold_date_sk" IS NOT NULL AND "ss_addr_sk" IS NOT NULL AND "ss_item_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_gmt_offset" = -8 AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."ss_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "i_item_sk", "i_item_id"
+FROM (SELECT "i_item_sk", "i_item_id"
+FROM "ITEM") AS "t5"
+WHERE "i_item_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t7" ON "t1"."ss_item_sk" = "t7"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_year", "d_moy"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t8"
+WHERE "d_year" = 2000 AND "d_moy" = 1 AND "d_date_sk" IS NOT NULL) AS "t10" ON "t1"."ss_sold_date_sk" = "t10"."d_date_sk"
+                    hive.sql.query.fieldNames ss_sold_date_sk,ss_item_sk,ss_addr_sk,ss_ext_sales_price,d_date_sk,d_year,d_moy,ca_address_sk,ca_gmt_offset,i_item_sk,i_item_id
+                    hive.sql.query.fieldTypes int,int,int,decimal(7,2),int,int,int,int,decimal(5,2),int,char(16)
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: ss_ext_sales_price (type: decimal(7,2)), i_item_id (type: char(16))
-                    outputColumnNames: _col15, _col65
+                    outputColumnNames: _col3, _col10
                     Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col65 (type: char(16))
+                      key expressions: _col10 (type: char(16))
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col65 (type: char(16))
+                      Map-reduce partition columns: _col10 (type: char(16))
                       Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col15 (type: decimal(7,2))
+                      value expressions: _col3 (type: decimal(7,2))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 12 
@@ -3103,34 +3131,38 @@ WHERE "d_year" = 2000 AND ("d_moy" = 1 AND "d_date_sk" IS NOT NULL)) AS "t6" ON
                 TableScan
                   alias: catalog_sales
                   properties:
-                    hive.sql.query SELECT "t0"."cs_sold_date_sk", "t0"."cs_sold_time_sk", "t0"."cs_ship_date_sk", "t0"."cs_bill_customer_sk", "t0"."cs_bill_cdemo_sk", "t0"."cs_bill_hdemo_sk", "t0"."cs_bill_addr_sk", "t0"."cs_ship_customer_sk", "t0"."cs_ship_cdemo_sk", "t0"."cs_ship_hdemo_sk", "t0"."cs_ship_addr_sk", "t0"."cs_call_center_sk", "t0"."cs_catalog_page_sk", "t0"."cs_ship_mode_sk", "t0"."cs_warehouse_sk", "t0"."cs_item_sk", "t0"."cs_promo_sk", "t0"."cs_order_number", "t0"."cs_quantity", "t0"."cs_wholesale_cost", "t0"."cs_list_price", "t0"."cs_sales_price", "t0"."cs_ext_discount_amt", "t0"."cs_ext_sales_price", "t0"."cs_ext_wholesale_cost", "t0"."cs_ext_list_price", "t0"."cs_ext_tax", "t0"."cs_coupon_amt", "t0"."cs_ext_ship_cost", "t0"."cs_net_paid", "t0"."cs_net_paid_inc_tax", "t0"."cs_net_paid_inc_ship", "t0"."cs_net_paid_inc_ship_tax", "t0"."cs_net_profit", "t6"."d_date_sk", "t6"."d_date_id", "t6"."d_date", "t6"."d_month_seq", "t6"."d_week_seq", "t6"."d_quarter_seq", "t6"."d_year", "t6"."d_dow", "t6"."d_moy", "t6"."d_dom", "t6"."d_qoy", "t6"."d_fy_year", "t6"."d_fy_quarter_seq", "t6"."d_fy_week_seq", "t6"."d_day_name", "t6"."d_quarter_name", "t6"."d_holiday", "t6"."d_weekend", "t6"."d_following_holiday", "t6"."d_first_dom", "t6"."d_last_dom", "t6"."d_same_day_ly", "t6"."d_same_day_lq", "t6"."d_current_day", "t6"."d_current_week", "t6"."d_current_month", "t6"."d_current_quarter", "t6"."d_current_year", "t2"."ca_address_sk", "t2"."ca_address_id", "t2"."ca_street_number", "t2"."ca_street_name", "t2"."ca_street_type", "t2"."ca_suite_number", "t2"."ca_city", "t2"."ca_county", "t2"."ca_state", "t2"."ca_zip", "t2"."ca_country", "t2"."ca_gmt_offset", "t2"."ca_location_type", "t4"."i_item_sk", "t4"."i_item_id", "t4"."i_rec_start_date", "t4"."i_rec_end_date", "t4"."i_item_desc", "t4"."i_current_price", "t4"."i_wholesale_cost", "t4"."i_brand_id", "t4"."i_brand", "t4"."i_class_id", "t4"."i_class", "t4"."i_category_id", "t4"."i_category", "t4"."i_manufact_id", "t4"."i_manufact", "t4"."i_size", "t4"."i_formulation", "t4"."i_color", "t4"."i_units", "t4"."i_container", "t4"."i_manager_id", "t4"."i_product_name"
-FROM (SELECT "cs_sold_date_sk", "cs_sold_time_sk", "cs_ship_date_sk", "cs_bill_customer_sk", "cs_bill_cdemo_sk", "cs_bill_hdemo_sk", "cs_bill_addr_sk", "cs_ship_customer_sk", "cs_ship_cdemo_sk", "cs_ship_hdemo_sk", "cs_ship_addr_sk", "cs_call_center_sk", "cs_catalog_page_sk", "cs_ship_mode_sk", "cs_warehouse_sk", "cs_item_sk", "cs_promo_sk", "cs_order_number", "cs_quantity", "cs_wholesale_cost", "cs_list_price", "cs_sales_price", "cs_ext_discount_amt", "cs_ext_sales_price", "cs_ext_wholesale_cost", "cs_ext_list_price", "cs_ext_tax", "cs_coupon_amt", "cs_ext_ship_cost", "cs_net_paid", "cs_net_paid_inc_tax", "cs_net_paid_inc_ship", "cs_net_paid_inc_ship_tax", "cs_net_profit"
-FROM "CATALOG_SALES"
-WHERE "cs_sold_date_sk" IS NOT NULL AND ("cs_bill_addr_sk" IS NOT NULL AND "cs_item_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_gmt_offset" = -8 AND "ca_address_sk" IS NOT NULL) AS "t2" ON "t0"."cs_bill_addr_sk" = "t2"."ca_address_sk"
-INNER JOIN (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_item_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t4" ON "t0"."cs_item_sk" = "t4"."i_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_year" = 2000 AND ("d_moy" = 1 AND "d_date_sk" IS NOT NULL)) AS "t6" ON "t0"."cs_sold_date_sk" = "t6"."d_date_sk"
-                    hive.sql.query.fieldNames cs_sold_date_sk,cs_sold_time_sk,cs_ship_date_sk,cs_bill_customer_sk,cs_bill_cdemo_sk,cs_bill_hdemo_sk,cs_bill_addr_sk,cs_ship_customer_sk,cs_ship_cdemo_sk,cs_ship_hdemo_sk,cs_ship_addr_sk,cs_call_center_sk,cs_catalog_page_sk,cs_ship_mode_sk,cs_warehouse_sk,cs_item_sk,cs_promo_sk,cs_order_number,cs_quantity,cs_wholesale_cost,cs_list_price,cs_sales_price,cs_ext_discount_amt,cs_ext_sales_price,cs_ext_wholesale_cost,cs_ext_list_price,cs_ext_tax,cs_coupon_amt,cs_ext_ship_cost,cs_net_paid,cs_net_paid_inc_tax,cs_net_paid_inc_ship,cs_net_paid_inc_ship_tax,cs_net_profit,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50)
+                    hive.sql.query SELECT "t1"."cs_sold_date_sk", "t1"."cs_bill_addr_sk", "t1"."cs_item_sk", "t1"."cs_ext_sales_price", "t10"."d_date_sk", "t10"."d_year", "t10"."d_moy", "t4"."ca_address_sk", "t4"."ca_gmt_offset", "t7"."i_item_sk", "t7"."i_item_id"
+FROM (SELECT "cs_sold_date_sk", "cs_bill_addr_sk", "cs_item_sk", "cs_ext_sales_price"
+FROM (SELECT "cs_sold_date_sk", "cs_bill_addr_sk", "cs_item_sk", "cs_ext_sales_price"
+FROM "CATALOG_SALES") AS "t"
+WHERE "cs_sold_date_sk" IS NOT NULL AND "cs_bill_addr_sk" IS NOT NULL AND "cs_item_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_gmt_offset" = -8 AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."cs_bill_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "i_item_sk", "i_item_id"
+FROM (SELECT "i_item_sk", "i_item_id"
+FROM "ITEM") AS "t5"
+WHERE "i_item_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t7" ON "t1"."cs_item_sk" = "t7"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_year", "d_moy"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t8"
+WHERE "d_year" = 2000 AND "d_moy" = 1 AND "d_date_sk" IS NOT NULL) AS "t10" ON "t1"."cs_sold_date_sk" = "t10"."d_date_sk"
+                    hive.sql.query.fieldNames cs_sold_date_sk,cs_bill_addr_sk,cs_item_sk,cs_ext_sales_price,d_date_sk,d_year,d_moy,ca_address_sk,ca_gmt_offset,i_item_sk,i_item_id
+                    hive.sql.query.fieldTypes int,int,int,decimal(7,2),int,int,int,int,decimal(5,2),int,char(16)
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: cs_ext_sales_price (type: decimal(7,2)), i_item_id (type: char(16))
-                    outputColumnNames: _col23, _col76
+                    outputColumnNames: _col3, _col10
                     Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col76 (type: char(16))
+                      key expressions: _col10 (type: char(16))
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col76 (type: char(16))
+                      Map-reduce partition columns: _col10 (type: char(16))
                       Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col23 (type: decimal(7,2))
+                      value expressions: _col3 (type: decimal(7,2))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 13 
@@ -3138,34 +3170,38 @@ WHERE "d_year" = 2000 AND ("d_moy" = 1 AND "d_date_sk" IS NOT NULL)) AS "t6" ON
                 TableScan
                   alias: web_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ws_sold_date_sk", "t0"."ws_sold_time_sk", "t0"."ws_ship_date_sk", "t0"."ws_item_sk", "t0"."ws_bill_customer_sk", "t0"."ws_bill_cdemo_sk", "t0"."ws_bill_hdemo_sk", "t0"."ws_bill_addr_sk", "t0"."ws_ship_customer_sk", "t0"."ws_ship_cdemo_sk", "t0"."ws_ship_hdemo_sk", "t0"."ws_ship_addr_sk", "t0"."ws_web_page_sk", "t0"."ws_web_site_sk", "t0"."ws_ship_mode_sk", "t0"."ws_warehouse_sk", "t0"."ws_promo_sk", "t0"."ws_order_number", "t0"."ws_quantity", "t0"."ws_wholesale_cost", "t0"."ws_list_price", "t0"."ws_sales_price", "t0"."ws_ext_discount_amt", "t0"."ws_ext_sales_price", "t0"."ws_ext_wholesale_cost", "t0"."ws_ext_list_price", "t0"."ws_ext_tax", "t0"."ws_coupon_amt", "t0"."ws_ext_ship_cost", "t0"."ws_net_paid", "t0"."ws_net_paid_inc_tax", "t0"."ws_net_paid_inc_ship", "t0"."ws_net_paid_inc_ship_tax", "t0"."ws_net_profit", "t6"."d_date_sk", "t6"."d_date_id", "t6"."d_date", "t6"."d_month_seq", "t6"."d_week_seq", "t6"."d_quarter_seq", "t6"."d_year", "t6"."d_dow", "t6"."d_moy", "t6"."d_dom", "t6"."d_qoy", "t6"."d_fy_year", "t6"."d_fy_quarter_seq", "t6"."d_fy_week_seq", "t6"."d_day_name", "t6"."d_quarter_name", "t6"."d_holiday", "t6"."d_weekend", "t6"."d_following_holiday", "t6"."d_first_dom", "t6"."d_last_dom", "t6"."d_same_day_ly", "t6"."d_same_day_lq", "t6"."d_current_day", "t6"."d_current_week", "t6"."d_current_month", "t6"."d_current_quarter", "t6"."d_current_year", "t2"."ca_address_sk", "t2"."ca_address_id", "t2"."ca_street_number", "t2"."ca_street_name", "t2"."ca_street_type", "t2"."ca_suite_number", "t2"."ca_city", "t2"."ca_county", "t2"."ca_state", "t2"."ca_zip", "t2"."ca_country", "t2"."ca_gmt_offset", "t2"."ca_location_type", "t4"."i_item_sk", "t4"."i_item_id", "t4"."i_rec_start_date", "t4"."i_rec_end_date", "t4"."i_item_desc", "t4"."i_current_price", "t4"."i_wholesale_cost", "t4"."i_brand_id", "t4"."i_brand", "t4"."i_class_id", "t4"."i_class", "t4"."i_category_id", "t4"."i_category", "t4"."i_manufact_id", "t4"."i_manufact", "t4"."i_size", "t4"."i_formulation", "t4"."i_color", "t4"."i_units", "t4"."i_container", "t4"."i_manager_id", "t4"."i_product_name"
-FROM (SELECT "ws_sold_date_sk", "ws_sold_time_sk", "ws_ship_date_sk", "ws_item_sk", "ws_bill_customer_sk", "ws_bill_cdemo_sk", "ws_bill_hdemo_sk", "ws_bill_addr_sk", "ws_ship_customer_sk", "ws_ship_cdemo_sk", "ws_ship_hdemo_sk", "ws_ship_addr_sk", "ws_web_page_sk", "ws_web_site_sk", "ws_ship_mode_sk", "ws_warehouse_sk", "ws_promo_sk", "ws_order_number", "ws_quantity", "ws_wholesale_cost", "ws_list_price", "ws_sales_price", "ws_ext_discount_amt", "ws_ext_sales_price", "ws_ext_wholesale_cost", "ws_ext_list_price", "ws_ext_tax", "ws_coupon_amt", "ws_ext_ship_cost", "ws_net_paid", "ws_net_paid_inc_tax", "ws_net_paid_inc_ship", "ws_net_paid_inc_ship_tax", "ws_net_profit"
-FROM "WEB_SALES"
-WHERE "ws_sold_date_sk" IS NOT NULL AND ("ws_bill_addr_sk" IS NOT NULL AND "ws_item_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_gmt_offset" = -8 AND "ca_address_sk" IS NOT NULL) AS "t2" ON "t0"."ws_bill_addr_sk" = "t2"."ca_address_sk"
-INNER JOIN (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_item_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t4" ON "t0"."ws_item_sk" = "t4"."i_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_year" = 2000 AND ("d_moy" = 1 AND "d_date_sk" IS NOT NULL)) AS "t6" ON "t0"."ws_sold_date_sk" = "t6"."d_date_sk"
-                    hive.sql.query.fieldNames ws_sold_date_sk,ws_sold_time_sk,ws_ship_date_sk,ws_item_sk,ws_bill_customer_sk,ws_bill_cdemo_sk,ws_bill_hdemo_sk,ws_bill_addr_sk,ws_ship_customer_sk,ws_ship_cdemo_sk,ws_ship_hdemo_sk,ws_ship_addr_sk,ws_web_page_sk,ws_web_site_sk,ws_ship_mode_sk,ws_warehouse_sk,ws_promo_sk,ws_order_number,ws_quantity,ws_wholesale_cost,ws_list_price,ws_sales_price,ws_ext_discount_amt,ws_ext_sales_price,ws_ext_wholesale_cost,ws_ext_list_price,ws_ext_tax,ws_coupon_amt,ws_ext_ship_cost,ws_net_paid,ws_net_paid_inc_tax,ws_net_paid_inc_ship,ws_net_paid_inc_ship_tax,ws_net_profit,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50)
+                    hive.sql.query SELECT "t1"."ws_sold_date_sk", "t1"."ws_item_sk", "t1"."ws_bill_addr_sk", "t1"."ws_ext_sales_price", "t10"."d_date_sk", "t10"."d_year", "t10"."d_moy", "t4"."ca_address_sk", "t4"."ca_gmt_offset", "t7"."i_item_sk", "t7"."i_item_id"
+FROM (SELECT "ws_sold_date_sk", "ws_item_sk", "ws_bill_addr_sk", "ws_ext_sales_price"
+FROM (SELECT "ws_sold_date_sk", "ws_item_sk", "ws_bill_addr_sk", "ws_ext_sales_price"
+FROM "WEB_SALES") AS "t"
+WHERE "ws_sold_date_sk" IS NOT NULL AND "ws_bill_addr_sk" IS NOT NULL AND "ws_item_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_gmt_offset" = -8 AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."ws_bill_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "i_item_sk", "i_item_id"
+FROM (SELECT "i_item_sk", "i_item_id"
+FROM "ITEM") AS "t5"
+WHERE "i_item_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t7" ON "t1"."ws_item_sk" = "t7"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_year", "d_moy"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t8"
+WHERE "d_year" = 2000 AND "d_moy" = 1 AND "d_date_sk" IS NOT NULL) AS "t10" ON "t1"."ws_sold_date_sk" = "t10"."d_date_sk"
+                    hive.sql.query.fieldNames ws_sold_date_sk,ws_item_sk,ws_bill_addr_sk,ws_ext_sales_price,d_date_sk,d_year,d_moy,ca_address_sk,ca_gmt_offset,i_item_sk,i_item_id
+                    hive.sql.query.fieldTypes int,int,int,decimal(7,2),int,int,int,int,decimal(5,2),int,char(16)
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: ws_ext_sales_price (type: decimal(7,2)), i_item_id (type: char(16))
-                    outputColumnNames: _col23, _col76
+                    outputColumnNames: _col3, _col10
                     Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col76 (type: char(16))
+                      key expressions: _col10 (type: char(16))
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col76 (type: char(16))
+                      Map-reduce partition columns: _col10 (type: char(16))
                       Statistics: Num rows: 1 Data size: 212 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col23 (type: decimal(7,2))
+                      value expressions: _col3 (type: decimal(7,2))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 7 
@@ -3174,8 +3210,9 @@ WHERE "d_year" = 2000 AND ("d_moy" = 1 AND "d_date_sk" IS NOT NULL)) AS "t6" ON
                   alias: item
                   properties:
                     hive.sql.query SELECT "i_item_id"
-FROM "ITEM"
-WHERE "i_color" IN ('orchid              ', 'chiffon             ', 'lace                ') AND "i_item_id" IS NOT NULL
+FROM (SELECT "i_item_id", "i_color"
+FROM "ITEM") AS "t"
+WHERE "i_color" IN ('chiffon', 'lace', 'orchid') AND "i_item_id" IS NOT NULL
                     hive.sql.query.fieldNames i_item_id
                     hive.sql.query.fieldTypes char(16)
                     hive.sql.query.split true
@@ -3217,13 +3254,13 @@ WHERE "i_color" IN ('orchid              ', 'chiffon             ', 'lace
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col76 (type: char(16))
+                  0 _col10 (type: char(16))
                   1 _col0 (type: char(16))
-                outputColumnNames: _col23, _col76
+                outputColumnNames: _col3, _col10
                 Statistics: Num rows: 1 Data size: 233 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col23)
-                  keys: _col76 (type: char(16))
+                  aggregations: sum(_col3)
+                  keys: _col10 (type: char(16))
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -3265,13 +3302,13 @@ WHERE "i_color" IN ('orchid              ', 'chiffon             ', 'lace
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col65 (type: char(16))
+                  0 _col10 (type: char(16))
                   1 _col0 (type: char(16))
-                outputColumnNames: _col15, _col65
+                outputColumnNames: _col3, _col10
                 Statistics: Num rows: 1 Data size: 233 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col15)
-                  keys: _col65 (type: char(16))
+                  aggregations: sum(_col3)
+                  keys: _col10 (type: char(16))
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -3351,13 +3388,13 @@ WHERE "i_color" IN ('orchid              ', 'chiffon             ', 'lace
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col76 (type: char(16))
+                  0 _col10 (type: char(16))
                   1 _col0 (type: char(16))
-                outputColumnNames: _col23, _col76
+                outputColumnNames: _col3, _col10
                 Statistics: Num rows: 1 Data size: 233 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col23)
-                  keys: _col76 (type: char(16))
+                  aggregations: sum(_col3)
+                  keys: _col10 (type: char(16))
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -3763,33 +3800,36 @@ STAGE PLANS:
         Map 1 
             Map Operator Tree:
                 TableScan
-                  alias: item
+                  alias: store_returns
                   properties:
-                    hive.sql.query SELECT "t2"."sr_returned_date_sk", "t2"."sr_return_time_sk", "t2"."sr_item_sk", "t2"."sr_customer_sk", "t2"."sr_cdemo_sk", "t2"."sr_hdemo_sk", "t2"."sr_addr_sk", "t2"."sr_store_sk", "t2"."sr_reason_sk", "t2"."sr_ticket_number", "t2"."sr_return_quantity", "t2"."sr_return_amt", "t2"."sr_return_tax", "t2"."sr_return_amt_inc_tax", "t2"."sr_fee", "t2"."sr_return_ship_cost", "t2"."sr_refunded_cash", "t2"."sr_reversed_charge", "t2"."sr_store_credit", "t2"."sr_net_loss", "t0"."i_item_sk", "t0"."i_item_id", "t0"."i_rec_start_date", "t0"."i_rec_end_date", "t0"."i_item_desc", "t0"."i_current_price", "t0"."i_wholesale_cost", "t0"."i_brand_id", "t0"."i_brand", "t0"."i_class_id", "t0"."i_class", "t0"."i_category_id", "t0"."i_category", "t0"."i_manufact_id", "t0"."i_manufact", "t0"."i_size", "t0"."i_formulation", "t0"."i_color", "t0"."i_units", "t0"."i_container", "t0"."i_manager_id", "t0"."i_product_name", "t4"."d_date_sk", "t4"."d_date_id", "t4"."d_date", "t4"."d_month_seq", "t4"."d_week_seq", "t4"."d_quarter_seq", "t4"."d_year", "t4"."d_dow", "t4"."d_moy", "t4"."d_dom", "t4"."d_qoy", "t4"."d_fy_year", "t4"."d_fy_quarter_seq", "t4"."d_fy_week_seq", "t4"."d_day_name", "t4"."d_quarter_name", "t4"."d_holiday", "t4"."d_weekend", "t4"."d_following_holiday", "t4"."d_first_dom", "t4"."d_last_dom", "t4"."d_same_day_ly", "t4"."d_same_day_lq", "t4"."d_current_day", "t4"."d_current_week", "t4"."d_current_month", "t4"."d_current_quarter", "t4"."d_current_year"
-FROM (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_item_sk" IS NOT NULL AND "i_item_id" IS NOT NULL) AS "t0"
-INNER JOIN (SELECT "sr_returned_date_sk", "sr_return_time_sk", "sr_item_sk", "sr_customer_sk", "sr_cdemo_sk", "sr_hdemo_sk", "sr_addr_sk", "sr_store_sk", "sr_reason_sk", "sr_ticket_number", "sr_return_quantity", "sr_return_amt", "sr_return_tax", "sr_return_amt_inc_tax", "sr_fee", "sr_return_ship_cost", "sr_refunded_cash", "sr_reversed_charge", "sr_store_credit", "sr_net_loss"
-FROM "STORE_RETURNS"
-WHERE "sr_item_sk" IS NOT NULL AND "sr_returned_date_sk" IS NOT NULL) AS "t2" ON "t0"."i_item_sk" = "t2"."sr_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t4" ON "t2"."sr_returned_date_sk" = "t4"."d_date_sk"
-                    hive.sql.query.fieldNames sr_returned_date_sk,sr_return_time_sk,sr_item_sk,sr_customer_sk,sr_cdemo_sk,sr_hdemo_sk,sr_addr_sk,sr_store_sk,sr_reason_sk,sr_ticket_number,sr_return_quantity,sr_return_amt,sr_return_tax,sr_return_amt_inc_tax,sr_fee,sr_return_ship_cost,sr_refunded_cash,sr_reversed_charge,sr_store_credit,sr_net_loss,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1)
+                    hive.sql.query SELECT "t1"."sr_returned_date_sk", "t1"."sr_item_sk", "t1"."sr_return_quantity", "t4"."i_item_sk", "t4"."i_item_id", "t7"."d_date_sk", "t7"."d_date"
+FROM (SELECT "sr_returned_date_sk", "sr_item_sk", "sr_return_quantity"
+FROM (SELECT "sr_returned_date_sk", "sr_item_sk", "sr_return_quantity"
+FROM "STORE_RETURNS") AS "t"
+WHERE "sr_item_sk" IS NOT NULL AND "sr_returned_date_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "i_item_sk", "i_item_id"
+FROM (SELECT "i_item_sk", "i_item_id"
+FROM "ITEM") AS "t2"
+WHERE "i_item_sk" IS NOT NULL AND "i_item_id" IS NOT NULL) AS "t4" ON "t1"."sr_item_sk" = "t4"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_date"
+FROM (SELECT "d_date_sk", "d_date"
+FROM "DATE_DIM") AS "t5"
+WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t7" ON "t1"."sr_returned_date_sk" = "t7"."d_date_sk"
+                    hive.sql.query.fieldNames sr_returned_date_sk,sr_item_sk,sr_return_quantity,i_item_sk,i_item_id,d_date_sk,d_date
+                    hive.sql.query.fieldTypes int,int,int,int,char(16),int,date
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: sr_return_quantity (type: int), i_item_id (type: char(16)), d_date (type: date)
-                    outputColumnNames: _col10, _col21, _col44
+                    outputColumnNames: _col2, _col4, _col6
                     Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col44 (type: date)
+                      key expressions: _col6 (type: date)
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col44 (type: date)
+                      Map-reduce partition columns: _col6 (type: date)
                       Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col10 (type: int), _col21 (type: char(16))
+                      value expressions: _col2 (type: int), _col4 (type: char(16))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 13 
@@ -3798,7 +3838,8 @@ WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t4" ON "t2"."sr_retu
                   alias: date_dim
                   properties:
                     hive.sql.query SELECT "d_week_seq"
-FROM "DATE_DIM"
+FROM (SELECT "d_date", "d_week_seq"
+FROM "DATE_DIM") AS "t"
 WHERE "d_date" IN (DATE '1998-01-02', DATE '1998-10-15', DATE '1998-11-10') AND "d_week_seq" IS NOT NULL
                     hive.sql.query.fieldNames d_week_seq
                     hive.sql.query.fieldTypes int
@@ -3827,31 +3868,34 @@ WHERE "d_date" IN (DATE '1998-01-02', DATE '1998-10-15', DATE '1998-11-10') AND
                 TableScan
                   alias: catalog_returns
                   properties:
-                    hive.sql.query SELECT "t0"."cr_returned_date_sk", "t0"."cr_returned_time_sk", "t0"."cr_item_sk", "t0"."cr_refunded_customer_sk", "t0"."cr_refunded_cdemo_sk", "t0"."cr_refunded_hdemo_sk", "t0"."cr_refunded_addr_sk", "t0"."cr_returning_customer_sk", "t0"."cr_returning_cdemo_sk", "t0"."cr_returning_hdemo_sk", "t0"."cr_returning_addr_sk", "t0"."cr_call_center_sk", "t0"."cr_catalog_page_sk", "t0"."cr_ship_mode_sk", "t0"."cr_warehouse_sk", "t0"."cr_reason_sk", "t0"."cr_order_number", "t0"."cr_return_quantity", "t0"."cr_return_amount", "t0"."cr_return_tax", "t0"."cr_return_amt_inc_tax", "t0"."cr_fee", "t0"."cr_return_ship_cost", "t0"."cr_refunded_cash", "t0"."cr_reversed_charge", "t0"."cr_store_credit", "t0"."cr_net_loss", "t2"."i_item_sk", "t2"."i_item_id", "t2"."i_rec_start_date", "t2"."i_rec_end_date", "t2"."i_item_desc", "t2"."i_current_price", "t2"."i_wholesale_cost", "t2"."i_brand_id", "t2"."i_brand", "t2"."i_class_id", "t2"."i_class", "t2"."i_category_id", "t2"."i_category", "t2"."i_manufact_id", "t2"."i_manufact", "t2"."i_size", "t2"."i_formulation", "t2"."i_color", "t2"."i_units", "t2"."i_container", "t2"."i_manager_id", "t2"."i_product_name", "t4"."d_date_sk", "t4"."d_date_id", "t4"."d_date", "t4"."d_month_seq", "t4"."d_week_seq", "t4"."d_quarter_seq", "t4"."d_year", "t4"."d_dow", "t4"."d_moy", "t4"."d_dom", "t4"."d_qoy", "t4"."d_fy_year", "t4"."d_fy_quarter_seq", "t4"."d_fy_week_seq", "t4"."d_day_name", "t4"."d_quarter_name", "t4"."d_holiday", "t4"."d_weekend", "t4"."d_following_holiday", "t4"."d_first_dom", "t4"."d_last_dom", "t4"."d_same_day_ly", "t4"."d_same_day_lq", "t4"."d_current_day", "t4"."d_current_week", "t4"."d_current_month", "t4"."d_current_quarter", "t4"."d_current_year"
-FROM (SELECT "cr_returned_date_sk", "cr_returned_time_sk", "cr_item_sk", "cr_refunded_customer_sk", "cr_refunded_cdemo_sk", "cr_refunded_hdemo_sk", "cr_refunded_addr_sk", "cr_returning_customer_sk", "cr_returning_cdemo_sk", "cr_returning_hdemo_sk", "cr_returning_addr_sk", "cr_call_center_sk", "cr_catalog_page_sk", "cr_ship_mode_sk", "cr_warehouse_sk", "cr_reason_sk", "cr_order_number", "cr_return_quantity", "cr_return_amount", "cr_return_tax", "cr_return_amt_inc_tax", "cr_fee", "cr_return_ship_cost", "cr_refunded_cash", "cr_reversed_charge", "cr_store_credit", "cr_net_loss"
-FROM "CATALOG_RETURNS"
-WHERE "cr_item_sk" IS NOT NULL AND "cr_returned_date_sk" IS NOT NULL) AS "t0"
-INNER JOIN (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_item_sk" IS NOT NULL AND "i_item_id" IS NOT NULL) AS "t2" ON "t0"."cr_item_sk" = "t2"."i_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t4" ON "t0"."cr_returned_date_sk" = "t4"."d_date_sk"
-                    hive.sql.query.fieldNames cr_returned_date_sk,cr_returned_time_sk,cr_item_sk,cr_refunded_customer_sk,cr_refunded_cdemo_sk,cr_refunded_hdemo_sk,cr_refunded_addr_sk,cr_returning_customer_sk,cr_returning_cdemo_sk,cr_returning_hdemo_sk,cr_returning_addr_sk,cr_call_center_sk,cr_catalog_page_sk,cr_ship_mode_sk,cr_warehouse_sk,cr_reason_sk,cr_order_number,cr_return_quantity,cr_return_amount,cr_return_tax,cr_return_amt_inc_tax,cr_fee,cr_return_ship_cost,cr_refunded_cash,cr_reversed_charge,cr_store_credit,cr_net_loss,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1)
+                    hive.sql.query SELECT "t1"."cr_returned_date_sk", "t1"."cr_item_sk", "t1"."cr_return_quantity", "t4"."i_item_sk", "t4"."i_item_id", "t7"."d_date_sk", "t7"."d_date"
+FROM (SELECT "cr_returned_date_sk", "cr_item_sk", "cr_return_quantity"
+FROM (SELECT "cr_returned_date_sk", "cr_item_sk", "cr_return_quantity"
+FROM "CATALOG_RETURNS") AS "t"
+WHERE "cr_item_sk" IS NOT NULL AND "cr_returned_date_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "i_item_sk", "i_item_id"
+FROM (SELECT "i_item_sk", "i_item_id"
+FROM "ITEM") AS "t2"
+WHERE "i_item_sk" IS NOT NULL AND "i_item_id" IS NOT NULL) AS "t4" ON "t1"."cr_item_sk" = "t4"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_date"
+FROM (SELECT "d_date_sk", "d_date"
+FROM "DATE_DIM") AS "t5"
+WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t7" ON "t1"."cr_returned_date_sk" = "t7"."d_date_sk"
+                    hive.sql.query.fieldNames cr_returned_date_sk,cr_item_sk,cr_return_quantity,i_item_sk,i_item_id,d_date_sk,d_date
+                    hive.sql.query.fieldTypes int,int,int,int,char(16),int,date
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: cr_return_quantity (type: int), i_item_id (type: char(16)), d_date (type: date)
-                    outputColumnNames: _col17, _col28, _col51
+                    outputColumnNames: _col2, _col4, _col6
                     Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col51 (type: date)
+                      key expressions: _col6 (type: date)
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col51 (type: date)
+                      Map-reduce partition columns: _col6 (type: date)
                       Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col17 (type: int), _col28 (type: char(16))
+                      value expressions: _col2 (type: int), _col4 (type: char(16))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 15 
@@ -3859,31 +3903,34 @@ WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t4" ON "t0"."cr_retu
                 TableScan
                   alias: web_returns
                   properties:
-                    hive.sql.query SELECT "t0"."wr_returned_date_sk", "t0"."wr_returned_time_sk", "t0"."wr_item_sk", "t0"."wr_refunded_customer_sk", "t0"."wr_refunded_cdemo_sk", "t0"."wr_refunded_hdemo_sk", "t0"."wr_refunded_addr_sk", "t0"."wr_returning_customer_sk", "t0"."wr_returning_cdemo_sk", "t0"."wr_returning_hdemo_sk", "t0"."wr_returning_addr_sk", "t0"."wr_web_page_sk", "t0"."wr_reason_sk", "t0"."wr_order_number", "t0"."wr_return_quantity", "t0"."wr_return_amt", "t0"."wr_return_tax", "t0"."wr_return_amt_inc_tax", "t0"."wr_fee", "t0"."wr_return_ship_cost", "t0"."wr_refunded_cash", "t0"."wr_reversed_charge", "t0"."wr_account_credit", "t0"."wr_net_loss", "t2"."i_item_sk", "t2"."i_item_id", "t2"."i_rec_start_date", "t2"."i_rec_end_date", "t2"."i_item_desc", "t2"."i_current_price", "t2"."i_wholesale_cost", "t2"."i_brand_id", "t2"."i_brand", "t2"."i_class_id", "t2"."i_class", "t2"."i_category_id", "t2"."i_category", "t2"."i_manufact_id", "t2"."i_manufact", "t2"."i_size", "t2"."i_formulation", "t2"."i_color", "t2"."i_units", "t2"."i_container", "t2"."i_manager_id", "t2"."i_product_name", "t4"."d_date_sk", "t4"."d_date_id", "t4"."d_date", "t4"."d_month_seq", "t4"."d_week_seq", "t4"."d_quarter_seq", "t4"."d_year", "t4"."d_dow", "t4"."d_moy", "t4"."d_dom", "t4"."d_qoy", "t4"."d_fy_year", "t4"."d_fy_quarter_seq", "t4"."d_fy_week_seq", "t4"."d_day_name", "t4"."d_quarter_name", "t4"."d_holiday", "t4"."d_weekend", "t4"."d_following_holiday", "t4"."d_first_dom", "t4"."d_last_dom", "t4"."d_same_day_ly", "t4"."d_same_day_lq", "t4"."d_current_day", "t4"."d_current_week", "t4"."d_current_month", "t4"."d_current_quarter", "t4"."d_current_year"
-FROM (SELECT "wr_returned_date_sk", "wr_returned_time_sk", "wr_item_sk", "wr_refunded_customer_sk", "wr_refunded_cdemo_sk", "wr_refunded_hdemo_sk", "wr_refunded_addr_sk", "wr_returning_customer_sk", "wr_returning_cdemo_sk", "wr_returning_hdemo_sk", "wr_returning_addr_sk", "wr_web_page_sk", "wr_reason_sk", "wr_order_number", "wr_return_quantity", "wr_return_amt", "wr_return_tax", "wr_return_amt_inc_tax", "wr_fee", "wr_return_ship_cost", "wr_refunded_cash", "wr_reversed_charge", "wr_account_credit", "wr_net_loss"
-FROM "WEB_RETURNS"
-WHERE "wr_item_sk" IS NOT NULL AND "wr_returned_date_sk" IS NOT NULL) AS "t0"
-INNER JOIN (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_item_sk" IS NOT NULL AND "i_item_id" IS NOT NULL) AS "t2" ON "t0"."wr_item_sk" = "t2"."i_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t4" ON "t0"."wr_returned_date_sk" = "t4"."d_date_sk"
-                    hive.sql.query.fieldNames wr_returned_date_sk,wr_returned_time_sk,wr_item_sk,wr_refunded_customer_sk,wr_refunded_cdemo_sk,wr_refunded_hdemo_sk,wr_refunded_addr_sk,wr_returning_customer_sk,wr_returning_cdemo_sk,wr_returning_hdemo_sk,wr_returning_addr_sk,wr_web_page_sk,wr_reason_sk,wr_order_number,wr_return_quantity,wr_return_amt,wr_return_tax,wr_return_amt_inc_tax,wr_fee,wr_return_ship_cost,wr_refunded_cash,wr_reversed_charge,wr_account_credit,wr_net_loss,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1)
+                    hive.sql.query SELECT "t1"."wr_returned_date_sk", "t1"."wr_item_sk", "t1"."wr_return_quantity", "t4"."i_item_sk", "t4"."i_item_id", "t7"."d_date_sk", "t7"."d_date"
+FROM (SELECT "wr_returned_date_sk", "wr_item_sk", "wr_return_quantity"
+FROM (SELECT "wr_returned_date_sk", "wr_item_sk", "wr_return_quantity"
+FROM "WEB_RETURNS") AS "t"
+WHERE "wr_item_sk" IS NOT NULL AND "wr_returned_date_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "i_item_sk", "i_item_id"
+FROM (SELECT "i_item_sk", "i_item_id"
+FROM "ITEM") AS "t2"
+WHERE "i_item_sk" IS NOT NULL AND "i_item_id" IS NOT NULL) AS "t4" ON "t1"."wr_item_sk" = "t4"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_date"
+FROM (SELECT "d_date_sk", "d_date"
+FROM "DATE_DIM") AS "t5"
+WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t7" ON "t1"."wr_returned_date_sk" = "t7"."d_date_sk"
+                    hive.sql.query.fieldNames wr_returned_date_sk,wr_item_sk,wr_return_quantity,i_item_sk,i_item_id,d_date_sk,d_date
+                    hive.sql.query.fieldTypes int,int,int,int,char(16),int,date
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: wr_return_quantity (type: int), i_item_id (type: char(16)), d_date (type: date)
-                    outputColumnNames: _col14, _col25, _col48
+                    outputColumnNames: _col2, _col4, _col6
                     Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col48 (type: date)
+                      key expressions: _col6 (type: date)
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col48 (type: date)
+                      Map-reduce partition columns: _col6 (type: date)
                       Statistics: Num rows: 1 Data size: 160 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col14 (type: int), _col25 (type: char(16))
+                      value expressions: _col2 (type: int), _col4 (type: char(16))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 7 
@@ -3891,24 +3938,25 @@ WHERE "d_date" IS NOT NULL AND "d_date_sk" IS NOT NULL) AS "t4" ON "t0"."wr_retu
                 TableScan
                   alias: date_dim
                   properties:
-                    hive.sql.query SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
+                    hive.sql.query SELECT "d_date", "d_week_seq"
+FROM (SELECT "d_date", "d_week_seq"
+FROM "DATE_DIM") AS "t"
 WHERE "d_week_seq" IS NOT NULL AND "d_date" IS NOT NULL
-                    hive.sql.query.fieldNames d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year
-                    hive.sql.query.fieldTypes int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1)
+                    hive.sql.query.fieldNames d_date,d_week_seq
+                    hive.sql.query.fieldTypes date,int
                     hive.sql.query.split true
                   Statistics: Num rows: 1 Data size: 60 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: d_date (type: date), d_week_seq (type: int)
-                    outputColumnNames: _col2, _col4
+                    outputColumnNames: _col0, _col1
                     Statistics: Num rows: 1 Data size: 60 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col4 (type: int)
+                      key expressions: _col1 (type: int)
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col4 (type: int)
+                      Map-reduce partition columns: _col1 (type: int)
                       Statistics: Num rows: 1 Data size: 60 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col2 (type: date)
+                      value expressions: _col0 (type: date)
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Reducer 10 
@@ -3938,13 +3986,13 @@ WHERE "d_week_seq" IS NOT NULL AND "d_date" IS NOT NULL
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col48 (type: date)
+                  0 _col6 (type: date)
                   1 _col0 (type: date)
-                outputColumnNames: _col14, _col25
+                outputColumnNames: _col2, _col4
                 Statistics: Num rows: 1 Data size: 176 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col14)
-                  keys: _col25 (type: char(16))
+                  aggregations: sum(_col2)
+                  keys: _col4 (type: char(16))
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -3983,13 +4031,13 @@ WHERE "d_week_seq" IS NOT NULL AND "d_date" IS NOT NULL
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col44 (type: date)
+                  0 _col6 (type: date)
                   1 _col0 (type: date)
-                outputColumnNames: _col10, _col21
+                outputColumnNames: _col2, _col4
                 Statistics: Num rows: 1 Data size: 176 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col10)
-                  keys: _col21 (type: char(16))
+                  aggregations: sum(_col2)
+                  keys: _col4 (type: char(16))
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -4090,38 +4138,34 @@ WHERE "d_week_seq" IS NOT NULL AND "d_date" IS NOT NULL
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col4 (type: int)
+                  0 _col1 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col2
+                outputColumnNames: _col0
                 Statistics: Num rows: 1 Data size: 66 Basic stats: COMPLETE Column stats: NONE
-                Select Operator
-                  expressions: _col2 (type: date)
+                Group By Operator
+                  keys: _col0 (type: date)
+                  minReductionHashAggr: 0.99
+                  mode: hash
                   outputColumnNames: _col0
                   Statistics: Num rows: 1 Data size: 66 Basic stats: COMPLETE Column stats: NONE
-                  Group By Operator
-                    keys: _col0 (type: date)
-                    minReductionHashAggr: 0.99
-                    mode: hash
-                    outputColumnNames: _col0
+                  Reduce Output Operator
+                    key expressions: _col0 (type: date)
+                    null sort order: z
+                    sort order: +
+                    Map-reduce partition columns: _col0 (type: date)
+                    Statistics: Num rows: 1 Data size: 66 Basic stats: COMPLETE Column stats: NONE
+                  Reduce Output Operator
+                    key expressions: _col0 (type: date)
+                    null sort order: z
+                    sort order: +
+                    Map-reduce partition columns: _col0 (type: date)
+                    Statistics: Num rows: 1 Data size: 66 Basic stats: COMPLETE Column stats: NONE
+                  Reduce Output Operator
+                    key expressions: _col0 (type: date)
+                    null sort order: z
+                    sort order: +
+                    Map-reduce partition columns: _col0 (type: date)
                     Statistics: Num rows: 1 Data size: 66 Basic stats: COMPLETE Column stats: NONE
-                    Reduce Output Operator
-                      key expressions: _col0 (type: date)
-                      null sort order: z
-                      sort order: +
-                      Map-reduce partition columns: _col0 (type: date)
-                      Statistics: Num rows: 1 Data size: 66 Basic stats: COMPLETE Column stats: NONE
-                    Reduce Output Operator
-                      key expressions: _col0 (type: date)
-                      null sort order: z
-                      sort order: +
-                      Map-reduce partition columns: _col0 (type: date)
-                      Statistics: Num rows: 1 Data size: 66 Basic stats: COMPLETE Column stats: NONE
-                    Reduce Output Operator
-                      key expressions: _col0 (type: date)
-                      null sort order: z
-                      sort order: +
-                      Map-reduce partition columns: _col0 (type: date)
-                      Statistics: Num rows: 1 Data size: 66 Basic stats: COMPLETE Column stats: NONE
         Reducer 9 
             Execution mode: llap
             Reduce Operator Tree:
@@ -4129,13 +4173,13 @@ WHERE "d_week_seq" IS NOT NULL AND "d_date" IS NOT NULL
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col51 (type: date)
+                  0 _col6 (type: date)
                   1 _col0 (type: date)
-                outputColumnNames: _col17, _col28
+                outputColumnNames: _col2, _col4
                 Statistics: Num rows: 1 Data size: 176 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col17)
-                  keys: _col28 (type: char(16))
+                  aggregations: sum(_col2)
+                  keys: _col4 (type: char(16))
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -4340,34 +4384,38 @@ STAGE PLANS:
                 TableScan
                   alias: store_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ss_sold_date_sk", "t0"."ss_sold_time_sk", "t0"."ss_item_sk", "t0"."ss_customer_sk", "t0"."ss_cdemo_sk", "t0"."ss_hdemo_sk", "t0"."ss_addr_sk", "t0"."ss_store_sk", "t0"."ss_promo_sk", "t0"."ss_ticket_number", "t0"."ss_quantity", "t0"."ss_wholesale_cost", "t0"."ss_list_price", "t0"."ss_sales_price", "t0"."ss_ext_discount_amt", "t0"."ss_ext_sales_price", "t0"."ss_ext_wholesale_cost", "t0"."ss_ext_list_price", "t0"."ss_ext_tax", "t0"."ss_coupon_amt", "t0"."ss_net_paid", "t0"."ss_net_paid_inc_tax", "t0"."ss_net_profit", "t6"."d_date_sk", "t6"."d_date_id", "t6"."d_date", "t6"."d_month_seq", "t6"."d_week_seq", "t6"."d_quarter_seq", "t6"."d_year", "t6"."d_dow", "t6"."d_moy", "t6"."d_dom", "t6"."d_qoy", "t6"."d_fy_year", "t6"."d_fy_quarter_seq", "t6"."d_fy_week_seq", "t6"."d_day_name", "t6"."d_quarter_name", "t6"."d_holiday", "t6"."d_weekend", "t6"."d_following_holiday", "t6"."d_first_dom", "t6"."d_last_dom", "t6"."d_same_day_ly", "t6"."d_same_day_lq", "t6"."d_current_day", "t6"."d_current_week", "t6"."d_current_month", "t6"."d_current_quarter", "t6"."d_current_year", "t2"."ca_address_sk", "t2"."ca_address_id", "t2"."ca_street_number", "t2"."ca_street_name", "t2"."ca_street_type", "t2"."ca_suite_number", "t2"."ca_city", "t2"."ca_county", "t2"."ca_state", "t2"."ca_zip", "t2"."ca_country", "t2"."ca_gmt_offset", "t2"."ca_location_type", "t4"."i_item_sk", "t4"."i_item_id", "t4"."i_rec_start_date", "t4"."i_rec_end_date", "t4"."i_item_desc", "t4"."i_current_price", "t4"."i_wholesale_cost", "t4"."i_brand_id", "t4"."i_brand", "t4"."i_class_id", "t4"."i_class", "t4"."i_category_id", "t4"."i_category", "t4"."i_manufact_id", "t4"."i_manufact", "t4"."i_size", "t4"."i_formulation", "t4"."i_color", "t4"."i_units", "t4"."i_container", "t4"."i_manager_id", "t4"."i_product_name"
-FROM (SELECT "ss_sold_date_sk", "ss_sold_time_sk", "ss_item_sk", "ss_customer_sk", "ss_cdemo_sk", "ss_hdemo_sk", "ss_addr_sk", "ss_store_sk", "ss_promo_sk", "ss_ticket_number", "ss_quantity", "ss_wholesale_cost", "ss_list_price", "ss_sales_price", "ss_ext_discount_amt", "ss_ext_sales_price", "ss_ext_wholesale_cost", "ss_ext_list_price", "ss_ext_tax", "ss_coupon_amt", "ss_net_paid", "ss_net_paid_inc_tax", "ss_net_profit"
-FROM "STORE_SALES"
-WHERE "ss_sold_date_sk" IS NOT NULL AND ("ss_addr_sk" IS NOT NULL AND "ss_item_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_gmt_offset" = -6 AND "ca_address_sk" IS NOT NULL) AS "t2" ON "t0"."ss_addr_sk" = "t2"."ca_address_sk"
-INNER JOIN (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_manufact_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t4" ON "t0"."ss_item_sk" = "t4"."i_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" = 3 AND "d_date_sk" IS NOT NULL)) AS "t6" ON "t0"."ss_sold_date_sk" = "t6"."d_date_sk"
-                    hive.sql.query.fieldNames ss_sold_date_sk,ss_sold_time_sk,ss_item_sk,ss_customer_sk,ss_cdemo_sk,ss_hdemo_sk,ss_addr_sk,ss_store_sk,ss_promo_sk,ss_ticket_number,ss_quantity,ss_wholesale_cost,ss_list_price,ss_sales_price,ss_ext_discount_amt,ss_ext_sales_price,ss_ext_wholesale_cost,ss_ext_list_price,ss_ext_tax,ss_coupon_amt,ss_net_paid,ss_net_paid_inc_tax,ss_net_profit,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50)
+                    hive.sql.query SELECT "t1"."ss_sold_date_sk", "t1"."ss_item_sk", "t1"."ss_addr_sk", "t1"."ss_ext_sales_price", "t10"."d_date_sk", "t10"."d_year", "t10"."d_moy", "t4"."ca_address_sk", "t4"."ca_gmt_offset", "t7"."i_item_sk", "t7"."i_manufact_id"
+FROM (SELECT "ss_sold_date_sk", "ss_item_sk", "ss_addr_sk", "ss_ext_sales_price"
+FROM (SELECT "ss_sold_date_sk", "ss_item_sk", "ss_addr_sk", "ss_ext_sales_price"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_sold_date_sk" IS NOT NULL AND "ss_addr_sk" IS NOT NULL AND "ss_item_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_gmt_offset" = -6 AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."ss_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "i_item_sk", "i_manufact_id"
+FROM (SELECT "i_item_sk", "i_manufact_id"
+FROM "ITEM") AS "t5"
+WHERE "i_manufact_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t7" ON "t1"."ss_item_sk" = "t7"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_year", "d_moy"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t8"
+WHERE "d_year" = 1999 AND "d_moy" = 3 AND "d_date_sk" IS NOT NULL) AS "t10" ON "t1"."ss_sold_date_sk" = "t10"."d_date_sk"
+                    hive.sql.query.fieldNames ss_sold_date_sk,ss_item_sk,ss_addr_sk,ss_ext_sales_price,d_date_sk,d_year,d_moy,ca_address_sk,ca_gmt_offset,i_item_sk,i_manufact_id
+                    hive.sql.query.fieldTypes int,int,int,decimal(7,2),int,int,int,int,decimal(5,2),int,int
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: ss_ext_sales_price (type: decimal(7,2)), i_manufact_id (type: int)
-                    outputColumnNames: _col15, _col77
+                    outputColumnNames: _col3, _col10
                     Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col77 (type: int)
+                      key expressions: _col10 (type: int)
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col77 (type: int)
+                      Map-reduce partition columns: _col10 (type: int)
                       Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col15 (type: decimal(7,2))
+                      value expressions: _col3 (type: decimal(7,2))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 12 
@@ -4375,34 +4423,38 @@ WHERE "d_year" = 1999 AND ("d_moy" = 3 AND "d_date_sk" IS NOT NULL)) AS "t6" ON
                 TableScan
                   alias: catalog_sales
                   properties:
-                    hive.sql.query SELECT "t0"."cs_sold_date_sk", "t0"."cs_sold_time_sk", "t0"."cs_ship_date_sk", "t0"."cs_bill_customer_sk", "t0"."cs_bill_cdemo_sk", "t0"."cs_bill_hdemo_sk", "t0"."cs_bill_addr_sk", "t0"."cs_ship_customer_sk", "t0"."cs_ship_cdemo_sk", "t0"."cs_ship_hdemo_sk", "t0"."cs_ship_addr_sk", "t0"."cs_call_center_sk", "t0"."cs_catalog_page_sk", "t0"."cs_ship_mode_sk", "t0"."cs_warehouse_sk", "t0"."cs_item_sk", "t0"."cs_promo_sk", "t0"."cs_order_number", "t0"."cs_quantity", "t0"."cs_wholesale_cost", "t0"."cs_list_price", "t0"."cs_sales_price", "t0"."cs_ext_discount_amt", "t0"."cs_ext_sales_price", "t0"."cs_ext_wholesale_cost", "t0"."cs_ext_list_price", "t0"."cs_ext_tax", "t0"."cs_coupon_amt", "t0"."cs_ext_ship_cost", "t0"."cs_net_paid", "t0"."cs_net_paid_inc_tax", "t0"."cs_net_paid_inc_ship", "t0"."cs_net_paid_inc_ship_tax", "t0"."cs_net_profit", "t6"."d_date_sk", "t6"."d_date_id", "t6"."d_date", "t6"."d_month_seq", "t6"."d_week_seq", "t6"."d_quarter_seq", "t6"."d_year", "t6"."d_dow", "t6"."d_moy", "t6"."d_dom", "t6"."d_qoy", "t6"."d_fy_year", "t6"."d_fy_quarter_seq", "t6"."d_fy_week_seq", "t6"."d_day_name", "t6"."d_quarter_name", "t6"."d_holiday", "t6"."d_weekend", "t6"."d_following_holiday", "t6"."d_first_dom", "t6"."d_last_dom", "t6"."d_same_day_ly", "t6"."d_same_day_lq", "t6"."d_current_day", "t6"."d_current_week", "t6"."d_current_month", "t6"."d_current_quarter", "t6"."d_current_year", "t2"."ca_address_sk", "t2"."ca_address_id", "t2"."ca_street_number", "t2"."ca_street_name", "t2"."ca_street_type", "t2"."ca_suite_number", "t2"."ca_city", "t2"."ca_county", "t2"."ca_state", "t2"."ca_zip", "t2"."ca_country", "t2"."ca_gmt_offset", "t2"."ca_location_type", "t4"."i_item_sk", "t4"."i_item_id", "t4"."i_rec_start_date", "t4"."i_rec_end_date", "t4"."i_item_desc", "t4"."i_current_price", "t4"."i_wholesale_cost", "t4"."i_brand_id", "t4"."i_brand", "t4"."i_class_id", "t4"."i_class", "t4"."i_category_id", "t4"."i_category", "t4"."i_manufact_id", "t4"."i_manufact", "t4"."i_size", "t4"."i_formulation", "t4"."i_color", "t4"."i_units", "t4"."i_container", "t4"."i_manager_id", "t4"."i_product_name"
-FROM (SELECT "cs_sold_date_sk", "cs_sold_time_sk", "cs_ship_date_sk", "cs_bill_customer_sk", "cs_bill_cdemo_sk", "cs_bill_hdemo_sk", "cs_bill_addr_sk", "cs_ship_customer_sk", "cs_ship_cdemo_sk", "cs_ship_hdemo_sk", "cs_ship_addr_sk", "cs_call_center_sk", "cs_catalog_page_sk", "cs_ship_mode_sk", "cs_warehouse_sk", "cs_item_sk", "cs_promo_sk", "cs_order_number", "cs_quantity", "cs_wholesale_cost", "cs_list_price", "cs_sales_price", "cs_ext_discount_amt", "cs_ext_sales_price", "cs_ext_wholesale_cost", "cs_ext_list_price", "cs_ext_tax", "cs_coupon_amt", "cs_ext_ship_cost", "cs_net_paid", "cs_net_paid_inc_tax", "cs_net_paid_inc_ship", "cs_net_paid_inc_ship_tax", "cs_net_profit"
-FROM "CATALOG_SALES"
-WHERE "cs_sold_date_sk" IS NOT NULL AND ("cs_bill_addr_sk" IS NOT NULL AND "cs_item_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_gmt_offset" = -6 AND "ca_address_sk" IS NOT NULL) AS "t2" ON "t0"."cs_bill_addr_sk" = "t2"."ca_address_sk"
-INNER JOIN (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_manufact_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t4" ON "t0"."cs_item_sk" = "t4"."i_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" = 3 AND "d_date_sk" IS NOT NULL)) AS "t6" ON "t0"."cs_sold_date_sk" = "t6"."d_date_sk"
-                    hive.sql.query.fieldNames cs_sold_date_sk,cs_sold_time_sk,cs_ship_date_sk,cs_bill_customer_sk,cs_bill_cdemo_sk,cs_bill_hdemo_sk,cs_bill_addr_sk,cs_ship_customer_sk,cs_ship_cdemo_sk,cs_ship_hdemo_sk,cs_ship_addr_sk,cs_call_center_sk,cs_catalog_page_sk,cs_ship_mode_sk,cs_warehouse_sk,cs_item_sk,cs_promo_sk,cs_order_number,cs_quantity,cs_wholesale_cost,cs_list_price,cs_sales_price,cs_ext_discount_amt,cs_ext_sales_price,cs_ext_wholesale_cost,cs_ext_list_price,cs_ext_tax,cs_coupon_amt,cs_ext_ship_cost,cs_net_paid,cs_net_paid_inc_tax,cs_net_paid_inc_ship,cs_net_paid_inc_ship_tax,cs_net_profit,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50)
+                    hive.sql.query SELECT "t1"."cs_sold_date_sk", "t1"."cs_bill_addr_sk", "t1"."cs_item_sk", "t1"."cs_ext_sales_price", "t10"."d_date_sk", "t10"."d_year", "t10"."d_moy", "t4"."ca_address_sk", "t4"."ca_gmt_offset", "t7"."i_item_sk", "t7"."i_manufact_id"
+FROM (SELECT "cs_sold_date_sk", "cs_bill_addr_sk", "cs_item_sk", "cs_ext_sales_price"
+FROM (SELECT "cs_sold_date_sk", "cs_bill_addr_sk", "cs_item_sk", "cs_ext_sales_price"
+FROM "CATALOG_SALES") AS "t"
+WHERE "cs_sold_date_sk" IS NOT NULL AND "cs_bill_addr_sk" IS NOT NULL AND "cs_item_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_gmt_offset" = -6 AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."cs_bill_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "i_item_sk", "i_manufact_id"
+FROM (SELECT "i_item_sk", "i_manufact_id"
+FROM "ITEM") AS "t5"
+WHERE "i_manufact_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t7" ON "t1"."cs_item_sk" = "t7"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_year", "d_moy"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t8"
+WHERE "d_year" = 1999 AND "d_moy" = 3 AND "d_date_sk" IS NOT NULL) AS "t10" ON "t1"."cs_sold_date_sk" = "t10"."d_date_sk"
+                    hive.sql.query.fieldNames cs_sold_date_sk,cs_bill_addr_sk,cs_item_sk,cs_ext_sales_price,d_date_sk,d_year,d_moy,ca_address_sk,ca_gmt_offset,i_item_sk,i_manufact_id
+                    hive.sql.query.fieldTypes int,int,int,decimal(7,2),int,int,int,int,decimal(5,2),int,int
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: cs_ext_sales_price (type: decimal(7,2)), i_manufact_id (type: int)
-                    outputColumnNames: _col23, _col88
+                    outputColumnNames: _col3, _col10
                     Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col88 (type: int)
+                      key expressions: _col10 (type: int)
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col88 (type: int)
+                      Map-reduce partition columns: _col10 (type: int)
                       Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col23 (type: decimal(7,2))
+                      value expressions: _col3 (type: decimal(7,2))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 13 
@@ -4410,34 +4462,38 @@ WHERE "d_year" = 1999 AND ("d_moy" = 3 AND "d_date_sk" IS NOT NULL)) AS "t6" ON
                 TableScan
                   alias: web_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ws_sold_date_sk", "t0"."ws_sold_time_sk", "t0"."ws_ship_date_sk", "t0"."ws_item_sk", "t0"."ws_bill_customer_sk", "t0"."ws_bill_cdemo_sk", "t0"."ws_bill_hdemo_sk", "t0"."ws_bill_addr_sk", "t0"."ws_ship_customer_sk", "t0"."ws_ship_cdemo_sk", "t0"."ws_ship_hdemo_sk", "t0"."ws_ship_addr_sk", "t0"."ws_web_page_sk", "t0"."ws_web_site_sk", "t0"."ws_ship_mode_sk", "t0"."ws_warehouse_sk", "t0"."ws_promo_sk", "t0"."ws_order_number", "t0"."ws_quantity", "t0"."ws_wholesale_cost", "t0"."ws_list_price", "t0"."ws_sales_price", "t0"."ws_ext_discount_amt", "t0"."ws_ext_sales_price", "t0"."ws_ext_wholesale_cost", "t0"."ws_ext_list_price", "t0"."ws_ext_tax", "t0"."ws_coupon_amt", "t0"."ws_ext_ship_cost", "t0"."ws_net_paid", "t0"."ws_net_paid_inc_tax", "t0"."ws_net_paid_inc_ship", "t0"."ws_net_paid_inc_ship_tax", "t0"."ws_net_profit", "t6"."d_date_sk", "t6"."d_date_id", "t6"."d_date", "t6"."d_month_seq", "t6"."d_week_seq", "t6"."d_quarter_seq", "t6"."d_year", "t6"."d_dow", "t6"."d_moy", "t6"."d_dom", "t6"."d_qoy", "t6"."d_fy_year", "t6"."d_fy_quarter_seq", "t6"."d_fy_week_seq", "t6"."d_day_name", "t6"."d_quarter_name", "t6"."d_holiday", "t6"."d_weekend", "t6"."d_following_holiday", "t6"."d_first_dom", "t6"."d_last_dom", "t6"."d_same_day_ly", "t6"."d_same_day_lq", "t6"."d_current_day", "t6"."d_current_week", "t6"."d_current_month", "t6"."d_current_quarter", "t6"."d_current_year", "t2"."ca_address_sk", "t2"."ca_address_id", "t2"."ca_street_number", "t2"."ca_street_name", "t2"."ca_street_type", "t2"."ca_suite_number", "t2"."ca_city", "t2"."ca_county", "t2"."ca_state", "t2"."ca_zip", "t2"."ca_country", "t2"."ca_gmt_offset", "t2"."ca_location_type", "t4"."i_item_sk", "t4"."i_item_id", "t4"."i_rec_start_date", "t4"."i_rec_end_date", "t4"."i_item_desc", "t4"."i_current_price", "t4"."i_wholesale_cost", "t4"."i_brand_id", "t4"."i_brand", "t4"."i_class_id", "t4"."i_class", "t4"."i_category_id", "t4"."i_category", "t4"."i_manufact_id", "t4"."i_manufact", "t4"."i_size", "t4"."i_formulation", "t4"."i_color", "t4"."i_units", "t4"."i_container", "t4"."i_manager_id", "t4"."i_product_name"
-FROM (SELECT "ws_sold_date_sk", "ws_sold_time_sk", "ws_ship_date_sk", "ws_item_sk", "ws_bill_customer_sk", "ws_bill_cdemo_sk", "ws_bill_hdemo_sk", "ws_bill_addr_sk", "ws_ship_customer_sk", "ws_ship_cdemo_sk", "ws_ship_hdemo_sk", "ws_ship_addr_sk", "ws_web_page_sk", "ws_web_site_sk", "ws_ship_mode_sk", "ws_warehouse_sk", "ws_promo_sk", "ws_order_number", "ws_quantity", "ws_wholesale_cost", "ws_list_price", "ws_sales_price", "ws_ext_discount_amt", "ws_ext_sales_price", "ws_ext_wholesale_cost", "ws_ext_list_price", "ws_ext_tax", "ws_coupon_amt", "ws_ext_ship_cost", "ws_net_paid", "ws_net_paid_inc_tax", "ws_net_paid_inc_ship", "ws_net_paid_inc_ship_tax", "ws_net_profit"
-FROM "WEB_SALES"
-WHERE "ws_sold_date_sk" IS NOT NULL AND ("ws_bill_addr_sk" IS NOT NULL AND "ws_item_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_gmt_offset" = -6 AND "ca_address_sk" IS NOT NULL) AS "t2" ON "t0"."ws_bill_addr_sk" = "t2"."ca_address_sk"
-INNER JOIN (SELECT "i_item_sk", "i_item_id", "i_rec_start_date", "i_rec_end_date", "i_item_desc", "i_current_price", "i_wholesale_cost", "i_brand_id", "i_brand", "i_class_id", "i_class", "i_category_id", "i_category", "i_manufact_id", "i_manufact", "i_size", "i_formulation", "i_color", "i_units", "i_container", "i_manager_id", "i_product_name"
-FROM "ITEM"
-WHERE "i_manufact_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t4" ON "t0"."ws_item_sk" = "t4"."i_item_sk"
-INNER JOIN (SELECT "d_date_sk", "d_date_id", "d_date", "d_month_seq", "d_week_seq", "d_quarter_seq", "d_year", "d_dow", "d_moy", "d_dom", "d_qoy", "d_fy_year", "d_fy_quarter_seq", "d_fy_week_seq", "d_day_name", "d_quarter_name", "d_holiday", "d_weekend", "d_following_holiday", "d_first_dom", "d_last_dom", "d_same_day_ly", "d_same_day_lq", "d_current_day", "d_current_week", "d_current_month", "d_current_quarter", "d_current_year"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" = 3 AND "d_date_sk" IS NOT NULL)) AS "t6" ON "t0"."ws_sold_date_sk" = "t6"."d_date_sk"
-                    hive.sql.query.fieldNames ws_sold_date_sk,ws_sold_time_sk,ws_ship_date_sk,ws_item_sk,ws_bill_customer_sk,ws_bill_cdemo_sk,ws_bill_hdemo_sk,ws_bill_addr_sk,ws_ship_customer_sk,ws_ship_cdemo_sk,ws_ship_hdemo_sk,ws_ship_addr_sk,ws_web_page_sk,ws_web_site_sk,ws_ship_mode_sk,ws_warehouse_sk,ws_promo_sk,ws_order_number,ws_quantity,ws_wholesale_cost,ws_list_price,ws_sales_price,ws_ext_discount_amt,ws_ext_sales_price,ws_ext_wholesale_cost,ws_ext_list_price,ws_ext_tax,ws_coupon_amt,ws_ext_ship_cost,ws_net_paid,ws_net_paid_inc_tax,ws_net_paid_inc_ship,ws_net_paid_inc_ship_tax,ws_net_profit,d_date_sk,d_date_id,d_date,d_month_seq,d_week_seq,d_quarter_seq,d_year,d_dow,d_moy,d_dom,d_qoy,d_fy_year,d_fy_quarter_seq,d_fy_week_seq,d_day_name,d_quarter_name,d_holiday,d_weekend,d_following_holiday,d_first_dom,d_last_dom,d_same_day_ly,d_same_day_lq,d_current_day,d_current_week,d_current_month,d_current_quarter,d_current_year,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,i_item_sk,i_item_id,i_rec_start_date,i_rec_end_date,i_item_desc,i_current_price,i_wholesale_cost,i_brand_id,i_brand,i_class_id,i_class,i_category_id,i_category,i_manufact_id,i_manufact,i_size,i_formulation,i_color,i_units,i_container,i_manager_id,i_product_name
-                    hive.sql.query.fieldTypes int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),decimal(7,2),int,char(16),date,int,int,int,int,int,int,int,int,int,int,int,char(9),char(6),char(1),char(1),char(1),int,int,int,int,char(1),char(1),char(1),char(1),char(1),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(16),date,date,varchar(200),decimal(7,2),decimal(7,2),int,char(50),int,char(50),int,char(50),int,char(50),char(20),char(20),char(20),char(10),char(10),int,char(50)
+                    hive.sql.query SELECT "t1"."ws_sold_date_sk", "t1"."ws_item_sk", "t1"."ws_bill_addr_sk", "t1"."ws_ext_sales_price", "t10"."d_date_sk", "t10"."d_year", "t10"."d_moy", "t4"."ca_address_sk", "t4"."ca_gmt_offset", "t7"."i_item_sk", "t7"."i_manufact_id"
+FROM (SELECT "ws_sold_date_sk", "ws_item_sk", "ws_bill_addr_sk", "ws_ext_sales_price"
+FROM (SELECT "ws_sold_date_sk", "ws_item_sk", "ws_bill_addr_sk", "ws_ext_sales_price"
+FROM "WEB_SALES") AS "t"
+WHERE "ws_sold_date_sk" IS NOT NULL AND "ws_bill_addr_sk" IS NOT NULL AND "ws_item_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM (SELECT "ca_address_sk", "ca_gmt_offset"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_gmt_offset" = -6 AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."ws_bill_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "i_item_sk", "i_manufact_id"
+FROM (SELECT "i_item_sk", "i_manufact_id"
+FROM "ITEM") AS "t5"
+WHERE "i_manufact_id" IS NOT NULL AND "i_item_sk" IS NOT NULL) AS "t7" ON "t1"."ws_item_sk" = "t7"."i_item_sk"
+INNER JOIN (SELECT "d_date_sk", "d_year", "d_moy"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t8"
+WHERE "d_year" = 1999 AND "d_moy" = 3 AND "d_date_sk" IS NOT NULL) AS "t10" ON "t1"."ws_sold_date_sk" = "t10"."d_date_sk"
+                    hive.sql.query.fieldNames ws_sold_date_sk,ws_item_sk,ws_bill_addr_sk,ws_ext_sales_price,d_date_sk,d_year,d_moy,ca_address_sk,ca_gmt_offset,i_item_sk,i_manufact_id
+                    hive.sql.query.fieldTypes int,int,int,decimal(7,2),int,int,int,int,decimal(5,2),int,int
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: ws_ext_sales_price (type: decimal(7,2)), i_manufact_id (type: int)
-                    outputColumnNames: _col23, _col88
+                    outputColumnNames: _col3, _col10
                     Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
-                      key expressions: _col88 (type: int)
+                      key expressions: _col10 (type: int)
                       null sort order: z
                       sort order: +
-                      Map-reduce partition columns: _col88 (type: int)
+                      Map-reduce partition columns: _col10 (type: int)
                       Statistics: Num rows: 1 Data size: 116 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col23 (type: decimal(7,2))
+                      value expressions: _col3 (type: decimal(7,2))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 7 
@@ -4446,7 +4502,8 @@ WHERE "d_year" = 1999 AND ("d_moy" = 3 AND "d_date_sk" IS NOT NULL)) AS "t6" ON
                   alias: item
                   properties:
                     hive.sql.query SELECT "i_manufact_id"
-FROM "ITEM"
+FROM (SELECT "i_category", "i_manufact_id"
+FROM "ITEM") AS "t"
 WHERE "i_category" = 'Books                                             ' AND "i_manufact_id" IS NOT NULL
                     hive.sql.query.fieldNames i_manufact_id
                     hive.sql.query.fieldTypes int
@@ -4489,13 +4546,13 @@ WHERE "i_category" = 'Books                                             ' AND "i
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col88 (type: int)
+                  0 _col10 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col23, _col88
+                outputColumnNames: _col3, _col10
                 Statistics: Num rows: 1 Data size: 127 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col23)
-                  keys: _col88 (type: int)
+                  aggregations: sum(_col3)
+                  keys: _col10 (type: int)
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -4537,13 +4594,13 @@ WHERE "i_category" = 'Books                                             ' AND "i
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col77 (type: int)
+                  0 _col10 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col15, _col77
+                outputColumnNames: _col3, _col10
                 Statistics: Num rows: 1 Data size: 127 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col15)
-                  keys: _col77 (type: int)
+                  aggregations: sum(_col3)
+                  keys: _col10 (type: int)
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -4623,13 +4680,13 @@ WHERE "i_category" = 'Books                                             ' AND "i
                 condition map:
                      Left Semi Join 0 to 1
                 keys:
-                  0 _col88 (type: int)
+                  0 _col10 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col23, _col88
+                outputColumnNames: _col3, _col10
                 Statistics: Num rows: 1 Data size: 127 Basic stats: COMPLETE Column stats: NONE
                 Group By Operator
-                  aggregations: sum(_col23)
-                  keys: _col88 (type: int)
+                  aggregations: sum(_col3)
+                  keys: _col10 (type: int)
                   minReductionHashAggr: 0.99
                   mode: hash
                   outputColumnNames: _col0, _col1
@@ -4833,13 +4890,13 @@ POSTHOOK: Input: default@item
 POSTHOOK: Input: default@store_sales
 POSTHOOK: Input: default@web_sales
 #### A masked pattern was here ####
-Warning: Shuffle Join MERGEJOIN[40][tables = [$hdt$_0, $hdt$_1]] in Stage 'Reducer 2' is a cross product
-Warning: Shuffle Join MERGEJOIN[41][tables = [$hdt$_0, $hdt$_1, $hdt$_2]] in Stage 'Reducer 3' is a cross product
-Warning: Shuffle Join MERGEJOIN[42][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3]] in Stage 'Reducer 4' is a cross product
-Warning: Shuffle Join MERGEJOIN[43][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4]] in Stage 'Reducer 5' is a cross product
-Warning: Shuffle Join MERGEJOIN[44][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5]] in Stage 'Reducer 6' is a cross product
-Warning: Shuffle Join MERGEJOIN[45][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5, $hdt$_6]] in Stage 'Reducer 7' is a cross product
-Warning: Shuffle Join MERGEJOIN[46][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5, $hdt$_6, $hdt$_7]] in Stage 'Reducer 8' is a cross product
+Warning: Shuffle Join MERGEJOIN[39][tables = [$hdt$_0, $hdt$_1]] in Stage 'Reducer 2' is a cross product
+Warning: Shuffle Join MERGEJOIN[40][tables = [$hdt$_0, $hdt$_1, $hdt$_2]] in Stage 'Reducer 3' is a cross product
+Warning: Shuffle Join MERGEJOIN[41][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3]] in Stage 'Reducer 4' is a cross product
+Warning: Shuffle Join MERGEJOIN[42][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4]] in Stage 'Reducer 5' is a cross product
+Warning: Shuffle Join MERGEJOIN[43][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5]] in Stage 'Reducer 6' is a cross product
+Warning: Shuffle Join MERGEJOIN[44][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5, $hdt$_6]] in Stage 'Reducer 7' is a cross product
+Warning: Shuffle Join MERGEJOIN[45][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5, $hdt$_6, $hdt$_7]] in Stage 'Reducer 8' is a cross product
 PREHOOK: query: explain
 select *
                           from (select count(*) as h8_30_to_9
@@ -5153,17 +5210,21 @@ STAGE PLANS:
                   properties:
                     hive.sql.query SELECT COUNT(*) AS "$f0"
 FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
-FROM "STORE_SALES"
-WHERE "ss_hdemo_sk" IS NOT NULL AND ("ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL)) AS "t0"
+FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_hdemo_sk" IS NOT NULL AND "ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "hd_demo_sk"
-FROM "HOUSEHOLD_DEMOGRAPHICS"
-WHERE ("hd_vehicle_count" <= 5 OR ("hd_vehicle_count" <= 2 OR "hd_vehicle_count" <= 3)) AND ("hd_dep_count" = 4 AND "hd_vehicle_count" <= 5 OR ("hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3)) AND ("hd_dep_count" IN (4, 2, 0) AND "hd_demo_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_hdemo_sk" = "t2"."hd_demo_sk"
+FROM (SELECT "hd_demo_sk", "hd_dep_count", "hd_vehicle_count"
+FROM "HOUSEHOLD_DEMOGRAPHICS") AS "t2"
+WHERE "hd_vehicle_count" <= 5 AND ("hd_dep_count" = 4 AND "hd_vehicle_count" IS NOT NULL OR "hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3) AND "hd_dep_count" IN (0, 2, 4) AND "hd_demo_sk" IS NOT NULL) AS "t4" ON "t1"."ss_hdemo_sk" = "t4"."hd_demo_sk"
 INNER JOIN (SELECT "t_time_sk"
-FROM "TIME_DIM"
-WHERE "t_minute" >= 30 AND ("t_hour" = 8 AND "t_time_sk" IS NOT NULL)) AS "t4" ON "t0"."ss_sold_time_sk" = "t4"."t_time_sk"
+FROM (SELECT "t_time_sk", "t_hour", "t_minute"
+FROM "TIME_DIM") AS "t5"
+WHERE "t_minute" >= 30 AND "t_hour" = 8 AND "t_time_sk" IS NOT NULL) AS "t7" ON "t1"."ss_sold_time_sk" = "t7"."t_time_sk"
 INNER JOIN (SELECT "s_store_sk"
-FROM "STORE"
-WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_store_sk" = "t6"."s_store_sk"
+FROM (SELECT "s_store_sk", "s_store_name"
+FROM "STORE") AS "t8"
+WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t10" ON "t1"."ss_store_sk" = "t10"."s_store_sk"
                     hive.sql.query.fieldNames $f0
                     hive.sql.query.fieldTypes bigint
                     hive.sql.query.split false
@@ -5186,17 +5247,21 @@ WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_s
                   properties:
                     hive.sql.query SELECT COUNT(*) AS "$f0"
 FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
-FROM "STORE_SALES"
-WHERE "ss_hdemo_sk" IS NOT NULL AND ("ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL)) AS "t0"
+FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_hdemo_sk" IS NOT NULL AND "ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "hd_demo_sk"
-FROM "HOUSEHOLD_DEMOGRAPHICS"
-WHERE ("hd_vehicle_count" <= 5 OR ("hd_vehicle_count" <= 2 OR "hd_vehicle_count" <= 3)) AND ("hd_dep_count" = 4 AND "hd_vehicle_count" <= 5 OR ("hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3)) AND ("hd_dep_count" IN (4, 2, 0) AND "hd_demo_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_hdemo_sk" = "t2"."hd_demo_sk"
+FROM (SELECT "hd_demo_sk", "hd_dep_count", "hd_vehicle_count"
+FROM "HOUSEHOLD_DEMOGRAPHICS") AS "t2"
+WHERE "hd_vehicle_count" <= 5 AND ("hd_dep_count" = 4 AND "hd_vehicle_count" IS NOT NULL OR "hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3) AND "hd_dep_count" IN (0, 2, 4) AND "hd_demo_sk" IS NOT NULL) AS "t4" ON "t1"."ss_hdemo_sk" = "t4"."hd_demo_sk"
 INNER JOIN (SELECT "t_time_sk"
-FROM "TIME_DIM"
-WHERE "t_minute" >= 30 AND ("t_hour" = 11 AND "t_time_sk" IS NOT NULL)) AS "t4" ON "t0"."ss_sold_time_sk" = "t4"."t_time_sk"
+FROM (SELECT "t_time_sk", "t_hour", "t_minute"
+FROM "TIME_DIM") AS "t5"
+WHERE "t_minute" >= 30 AND "t_hour" = 11 AND "t_time_sk" IS NOT NULL) AS "t7" ON "t1"."ss_sold_time_sk" = "t7"."t_time_sk"
 INNER JOIN (SELECT "s_store_sk"
-FROM "STORE"
-WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_store_sk" = "t6"."s_store_sk"
+FROM (SELECT "s_store_sk", "s_store_name"
+FROM "STORE") AS "t8"
+WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t10" ON "t1"."ss_store_sk" = "t10"."s_store_sk"
                     hive.sql.query.fieldNames $f0
                     hive.sql.query.fieldTypes bigint
                     hive.sql.query.split false
@@ -5219,17 +5284,21 @@ WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_s
                   properties:
                     hive.sql.query SELECT COUNT(*) AS "$f0"
 FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
-FROM "STORE_SALES"
-WHERE "ss_hdemo_sk" IS NOT NULL AND ("ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL)) AS "t0"
+FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_hdemo_sk" IS NOT NULL AND "ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "hd_demo_sk"
-FROM "HOUSEHOLD_DEMOGRAPHICS"
-WHERE ("hd_vehicle_count" <= 5 OR ("hd_vehicle_count" <= 2 OR "hd_vehicle_count" <= 3)) AND ("hd_dep_count" = 4 AND "hd_vehicle_count" <= 5 OR ("hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3)) AND ("hd_dep_count" IN (4, 2, 0) AND "hd_demo_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_hdemo_sk" = "t2"."hd_demo_sk"
+FROM (SELECT "hd_demo_sk", "hd_dep_count", "hd_vehicle_count"
+FROM "HOUSEHOLD_DEMOGRAPHICS") AS "t2"
+WHERE "hd_vehicle_count" <= 5 AND ("hd_dep_count" = 4 AND "hd_vehicle_count" IS NOT NULL OR "hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3) AND "hd_dep_count" IN (0, 2, 4) AND "hd_demo_sk" IS NOT NULL) AS "t4" ON "t1"."ss_hdemo_sk" = "t4"."hd_demo_sk"
 INNER JOIN (SELECT "t_time_sk"
-FROM "TIME_DIM"
-WHERE "t_minute" < 30 AND ("t_hour" = 11 AND "t_time_sk" IS NOT NULL)) AS "t4" ON "t0"."ss_sold_time_sk" = "t4"."t_time_sk"
+FROM (SELECT "t_time_sk", "t_hour", "t_minute"
+FROM "TIME_DIM") AS "t5"
+WHERE "t_minute" < 30 AND "t_hour" = 11 AND "t_time_sk" IS NOT NULL) AS "t7" ON "t1"."ss_sold_time_sk" = "t7"."t_time_sk"
 INNER JOIN (SELECT "s_store_sk"
-FROM "STORE"
-WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_store_sk" = "t6"."s_store_sk"
+FROM (SELECT "s_store_sk", "s_store_name"
+FROM "STORE") AS "t8"
+WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t10" ON "t1"."ss_store_sk" = "t10"."s_store_sk"
                     hive.sql.query.fieldNames $f0
                     hive.sql.query.fieldTypes bigint
                     hive.sql.query.split false
@@ -5252,17 +5321,21 @@ WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_s
                   properties:
                     hive.sql.query SELECT COUNT(*) AS "$f0"
 FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
-FROM "STORE_SALES"
-WHERE "ss_hdemo_sk" IS NOT NULL AND ("ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL)) AS "t0"
+FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_hdemo_sk" IS NOT NULL AND "ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "hd_demo_sk"
-FROM "HOUSEHOLD_DEMOGRAPHICS"
-WHERE ("hd_vehicle_count" <= 5 OR ("hd_vehicle_count" <= 2 OR "hd_vehicle_count" <= 3)) AND ("hd_dep_count" = 4 AND "hd_vehicle_count" <= 5 OR ("hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3)) AND ("hd_dep_count" IN (4, 2, 0) AND "hd_demo_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_hdemo_sk" = "t2"."hd_demo_sk"
+FROM (SELECT "hd_demo_sk", "hd_dep_count", "hd_vehicle_count"
+FROM "HOUSEHOLD_DEMOGRAPHICS") AS "t2"
+WHERE "hd_vehicle_count" <= 5 AND ("hd_dep_count" = 4 AND "hd_vehicle_count" IS NOT NULL OR "hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3) AND "hd_dep_count" IN (0, 2, 4) AND "hd_demo_sk" IS NOT NULL) AS "t4" ON "t1"."ss_hdemo_sk" = "t4"."hd_demo_sk"
 INNER JOIN (SELECT "t_time_sk"
-FROM "TIME_DIM"
-WHERE "t_minute" >= 30 AND ("t_hour" = 10 AND "t_time_sk" IS NOT NULL)) AS "t4" ON "t0"."ss_sold_time_sk" = "t4"."t_time_sk"
+FROM (SELECT "t_time_sk", "t_hour", "t_minute"
+FROM "TIME_DIM") AS "t5"
+WHERE "t_minute" >= 30 AND "t_hour" = 10 AND "t_time_sk" IS NOT NULL) AS "t7" ON "t1"."ss_sold_time_sk" = "t7"."t_time_sk"
 INNER JOIN (SELECT "s_store_sk"
-FROM "STORE"
-WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_store_sk" = "t6"."s_store_sk"
+FROM (SELECT "s_store_sk", "s_store_name"
+FROM "STORE") AS "t8"
+WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t10" ON "t1"."ss_store_sk" = "t10"."s_store_sk"
                     hive.sql.query.fieldNames $f0
                     hive.sql.query.fieldTypes bigint
                     hive.sql.query.split false
@@ -5285,17 +5358,21 @@ WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_s
                   properties:
                     hive.sql.query SELECT COUNT(*) AS "$f0"
 FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
-FROM "STORE_SALES"
-WHERE "ss_hdemo_sk" IS NOT NULL AND ("ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL)) AS "t0"
+FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_hdemo_sk" IS NOT NULL AND "ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "hd_demo_sk"
-FROM "HOUSEHOLD_DEMOGRAPHICS"
-WHERE ("hd_vehicle_count" <= 5 OR ("hd_vehicle_count" <= 2 OR "hd_vehicle_count" <= 3)) AND ("hd_dep_count" = 4 AND "hd_vehicle_count" <= 5 OR ("hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3)) AND ("hd_dep_count" IN (4, 2, 0) AND "hd_demo_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_hdemo_sk" = "t2"."hd_demo_sk"
+FROM (SELECT "hd_demo_sk", "hd_dep_count", "hd_vehicle_count"
+FROM "HOUSEHOLD_DEMOGRAPHICS") AS "t2"
+WHERE "hd_vehicle_count" <= 5 AND ("hd_dep_count" = 4 AND "hd_vehicle_count" IS NOT NULL OR "hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3) AND "hd_dep_count" IN (0, 2, 4) AND "hd_demo_sk" IS NOT NULL) AS "t4" ON "t1"."ss_hdemo_sk" = "t4"."hd_demo_sk"
 INNER JOIN (SELECT "t_time_sk"
-FROM "TIME_DIM"
-WHERE "t_minute" < 30 AND ("t_hour" = 10 AND "t_time_sk" IS NOT NULL)) AS "t4" ON "t0"."ss_sold_time_sk" = "t4"."t_time_sk"
+FROM (SELECT "t_time_sk", "t_hour", "t_minute"
+FROM "TIME_DIM") AS "t5"
+WHERE "t_minute" < 30 AND "t_hour" = 10 AND "t_time_sk" IS NOT NULL) AS "t7" ON "t1"."ss_sold_time_sk" = "t7"."t_time_sk"
 INNER JOIN (SELECT "s_store_sk"
-FROM "STORE"
-WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_store_sk" = "t6"."s_store_sk"
+FROM (SELECT "s_store_sk", "s_store_name"
+FROM "STORE") AS "t8"
+WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t10" ON "t1"."ss_store_sk" = "t10"."s_store_sk"
                     hive.sql.query.fieldNames $f0
                     hive.sql.query.fieldTypes bigint
                     hive.sql.query.split false
@@ -5318,17 +5395,21 @@ WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_s
                   properties:
                     hive.sql.query SELECT COUNT(*) AS "$f0"
 FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
-FROM "STORE_SALES"
-WHERE "ss_hdemo_sk" IS NOT NULL AND ("ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL)) AS "t0"
+FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_hdemo_sk" IS NOT NULL AND "ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "hd_demo_sk"
-FROM "HOUSEHOLD_DEMOGRAPHICS"
-WHERE ("hd_vehicle_count" <= 5 OR ("hd_vehicle_count" <= 2 OR "hd_vehicle_count" <= 3)) AND ("hd_dep_count" = 4 AND "hd_vehicle_count" <= 5 OR ("hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3)) AND ("hd_dep_count" IN (4, 2, 0) AND "hd_demo_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_hdemo_sk" = "t2"."hd_demo_sk"
+FROM (SELECT "hd_demo_sk", "hd_dep_count", "hd_vehicle_count"
+FROM "HOUSEHOLD_DEMOGRAPHICS") AS "t2"
+WHERE "hd_vehicle_count" <= 5 AND ("hd_dep_count" = 4 AND "hd_vehicle_count" IS NOT NULL OR "hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3) AND "hd_dep_count" IN (0, 2, 4) AND "hd_demo_sk" IS NOT NULL) AS "t4" ON "t1"."ss_hdemo_sk" = "t4"."hd_demo_sk"
 INNER JOIN (SELECT "t_time_sk"
-FROM "TIME_DIM"
-WHERE "t_minute" >= 30 AND ("t_hour" = 9 AND "t_time_sk" IS NOT NULL)) AS "t4" ON "t0"."ss_sold_time_sk" = "t4"."t_time_sk"
+FROM (SELECT "t_time_sk", "t_hour", "t_minute"
+FROM "TIME_DIM") AS "t5"
+WHERE "t_minute" >= 30 AND "t_hour" = 9 AND "t_time_sk" IS NOT NULL) AS "t7" ON "t1"."ss_sold_time_sk" = "t7"."t_time_sk"
 INNER JOIN (SELECT "s_store_sk"
-FROM "STORE"
-WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_store_sk" = "t6"."s_store_sk"
+FROM (SELECT "s_store_sk", "s_store_name"
+FROM "STORE") AS "t8"
+WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t10" ON "t1"."ss_store_sk" = "t10"."s_store_sk"
                     hive.sql.query.fieldNames $f0
                     hive.sql.query.fieldTypes bigint
                     hive.sql.query.split false
@@ -5351,17 +5432,21 @@ WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_s
                   properties:
                     hive.sql.query SELECT COUNT(*) AS "$f0"
 FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
-FROM "STORE_SALES"
-WHERE "ss_hdemo_sk" IS NOT NULL AND ("ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL)) AS "t0"
+FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_hdemo_sk" IS NOT NULL AND "ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "hd_demo_sk"
-FROM "HOUSEHOLD_DEMOGRAPHICS"
-WHERE ("hd_vehicle_count" <= 5 OR ("hd_vehicle_count" <= 2 OR "hd_vehicle_count" <= 3)) AND ("hd_dep_count" = 4 AND "hd_vehicle_count" <= 5 OR ("hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3)) AND ("hd_dep_count" IN (4, 2, 0) AND "hd_demo_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_hdemo_sk" = "t2"."hd_demo_sk"
+FROM (SELECT "hd_demo_sk", "hd_dep_count", "hd_vehicle_count"
+FROM "HOUSEHOLD_DEMOGRAPHICS") AS "t2"
+WHERE "hd_vehicle_count" <= 5 AND ("hd_dep_count" = 4 AND "hd_vehicle_count" IS NOT NULL OR "hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3) AND "hd_dep_count" IN (0, 2, 4) AND "hd_demo_sk" IS NOT NULL) AS "t4" ON "t1"."ss_hdemo_sk" = "t4"."hd_demo_sk"
 INNER JOIN (SELECT "t_time_sk"
-FROM "TIME_DIM"
-WHERE "t_minute" < 30 AND ("t_hour" = 9 AND "t_time_sk" IS NOT NULL)) AS "t4" ON "t0"."ss_sold_time_sk" = "t4"."t_time_sk"
+FROM (SELECT "t_time_sk", "t_hour", "t_minute"
+FROM "TIME_DIM") AS "t5"
+WHERE "t_minute" < 30 AND "t_hour" = 9 AND "t_time_sk" IS NOT NULL) AS "t7" ON "t1"."ss_sold_time_sk" = "t7"."t_time_sk"
 INNER JOIN (SELECT "s_store_sk"
-FROM "STORE"
-WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_store_sk" = "t6"."s_store_sk"
+FROM (SELECT "s_store_sk", "s_store_name"
+FROM "STORE") AS "t8"
+WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t10" ON "t1"."ss_store_sk" = "t10"."s_store_sk"
                     hive.sql.query.fieldNames $f0
                     hive.sql.query.fieldTypes bigint
                     hive.sql.query.split false
@@ -5384,17 +5469,21 @@ WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_s
                   properties:
                     hive.sql.query SELECT COUNT(*) AS "$f0"
 FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
-FROM "STORE_SALES"
-WHERE "ss_hdemo_sk" IS NOT NULL AND ("ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL)) AS "t0"
+FROM (SELECT "ss_sold_time_sk", "ss_hdemo_sk", "ss_store_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_hdemo_sk" IS NOT NULL AND "ss_sold_time_sk" IS NOT NULL AND "ss_store_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "hd_demo_sk"
-FROM "HOUSEHOLD_DEMOGRAPHICS"
-WHERE ("hd_vehicle_count" <= 5 OR ("hd_vehicle_count" <= 2 OR "hd_vehicle_count" <= 3)) AND ("hd_dep_count" = 4 AND "hd_vehicle_count" <= 5 OR ("hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3)) AND ("hd_dep_count" IN (4, 2, 0) AND "hd_demo_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_hdemo_sk" = "t2"."hd_demo_sk"
+FROM (SELECT "hd_demo_sk", "hd_dep_count", "hd_vehicle_count"
+FROM "HOUSEHOLD_DEMOGRAPHICS") AS "t2"
+WHERE "hd_vehicle_count" <= 5 AND ("hd_dep_count" = 4 AND "hd_vehicle_count" IS NOT NULL OR "hd_dep_count" = 2 AND "hd_vehicle_count" <= 2 OR "hd_dep_count" = 0 AND "hd_vehicle_count" <= 3) AND "hd_dep_count" IN (0, 2, 4) AND "hd_demo_sk" IS NOT NULL) AS "t4" ON "t1"."ss_hdemo_sk" = "t4"."hd_demo_sk"
 INNER JOIN (SELECT "t_time_sk"
-FROM "TIME_DIM"
-WHERE "t_minute" < 30 AND ("t_hour" = 12 AND "t_time_sk" IS NOT NULL)) AS "t4" ON "t0"."ss_sold_time_sk" = "t4"."t_time_sk"
+FROM (SELECT "t_time_sk", "t_hour", "t_minute"
+FROM "TIME_DIM") AS "t5"
+WHERE "t_minute" < 30 AND "t_hour" = 12 AND "t_time_sk" IS NOT NULL) AS "t7" ON "t1"."ss_sold_time_sk" = "t7"."t_time_sk"
 INNER JOIN (SELECT "s_store_sk"
-FROM "STORE"
-WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_store_sk" = "t6"."s_store_sk"
+FROM (SELECT "s_store_sk", "s_store_name"
+FROM "STORE") AS "t8"
+WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t10" ON "t1"."ss_store_sk" = "t10"."s_store_sk"
                     hive.sql.query.fieldNames $f0
                     hive.sql.query.fieldTypes bigint
                     hive.sql.query.split false
@@ -5535,13 +5624,13 @@ WHERE "s_store_name" = 'ese' AND "s_store_sk" IS NOT NULL) AS "t6" ON "t0"."ss_s
       Processor Tree:
         ListSink
 
-Warning: Shuffle Join MERGEJOIN[40][tables = [$hdt$_0, $hdt$_1]] in Stage 'Reducer 2' is a cross product
-Warning: Shuffle Join MERGEJOIN[41][tables = [$hdt$_0, $hdt$_1, $hdt$_2]] in Stage 'Reducer 3' is a cross product
-Warning: Shuffle Join MERGEJOIN[42][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3]] in Stage 'Reducer 4' is a cross product
-Warning: Shuffle Join MERGEJOIN[43][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4]] in Stage 'Reducer 5' is a cross product
-Warning: Shuffle Join MERGEJOIN[44][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5]] in Stage 'Reducer 6' is a cross product
-Warning: Shuffle Join MERGEJOIN[45][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5, $hdt$_6]] in Stage 'Reducer 7' is a cross product
-Warning: Shuffle Join MERGEJOIN[46][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5, $hdt$_6, $hdt$_7]] in Stage 'Reducer 8' is a cross product
+Warning: Shuffle Join MERGEJOIN[39][tables = [$hdt$_0, $hdt$_1]] in Stage 'Reducer 2' is a cross product
+Warning: Shuffle Join MERGEJOIN[40][tables = [$hdt$_0, $hdt$_1, $hdt$_2]] in Stage 'Reducer 3' is a cross product
+Warning: Shuffle Join MERGEJOIN[41][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3]] in Stage 'Reducer 4' is a cross product
+Warning: Shuffle Join MERGEJOIN[42][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4]] in Stage 'Reducer 5' is a cross product
+Warning: Shuffle Join MERGEJOIN[43][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5]] in Stage 'Reducer 6' is a cross product
+Warning: Shuffle Join MERGEJOIN[44][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5, $hdt$_6]] in Stage 'Reducer 7' is a cross product
+Warning: Shuffle Join MERGEJOIN[45][tables = [$hdt$_0, $hdt$_1, $hdt$_2, $hdt$_3, $hdt$_4, $hdt$_5, $hdt$_6, $hdt$_7]] in Stage 'Reducer 8' is a cross product
 PREHOOK: query: select *
                           from (select count(*) as h8_30_to_9
                                 from store_sales
@@ -5964,30 +6053,37 @@ STAGE PLANS:
                 TableScan
                   alias: web_returns
                   properties:
-                    hive.sql.query SELECT "t2"."r_reason_desc", SUM("t13"."ws_quantity") AS "$f1", COUNT("t13"."ws_quantity") AS "$f2", SUM("t0"."wr_refunded_cash") AS "$f3", COUNT("t0"."wr_refunded_cash") AS "$f4", SUM("t0"."wr_fee") AS "$f5", COUNT("t0"."wr_fee") AS "$f6"
+                    hive.sql.query SELECT "t4"."r_reason_desc", SUM("t20"."ws_quantity") AS "$f1", COUNT("t20"."ws_quantity") AS "$f2", SUM("t1"."wr_refunded_cash") AS "$f3", COUNT("t1"."wr_refunded_cash") AS "$f4", SUM("t1"."wr_fee") AS "$f5", COUNT("t1"."wr_fee") AS "$f6"
+FROM (SELECT "wr_item_sk", "wr_refunded_cdemo_sk", "wr_refunded_addr_sk", "wr_returning_cdemo_sk", "wr_reason_sk", "wr_order_number", "wr_fee", "wr_refunded_cash"
 FROM (SELECT "wr_item_sk", "wr_refunded_cdemo_sk", "wr_refunded_addr_sk", "wr_returning_cdemo_sk", "wr_reason_sk", "wr_order_number", "wr_fee", "wr_refunded_cash"
-FROM "WEB_RETURNS"
-WHERE "wr_item_sk" IS NOT NULL AND ("wr_order_number" IS NOT NULL AND "wr_refunded_cdemo_sk" IS NOT NULL) AND ("wr_returning_cdemo_sk" IS NOT NULL AND ("wr_refunded_addr_sk" IS NOT NULL AND "wr_reason_sk" IS NOT NULL))) AS "t0"
+FROM "WEB_RETURNS") AS "t"
+WHERE "wr_item_sk" IS NOT NULL AND ("wr_order_number" IS NOT NULL AND "wr_refunded_cdemo_sk" IS NOT NULL) AND ("wr_returning_cdemo_sk" IS NOT NULL AND ("wr_refunded_addr_sk" IS NOT NULL AND "wr_reason_sk" IS NOT NULL))) AS "t1"
 INNER JOIN (SELECT "r_reason_sk", "r_reason_desc"
-FROM "REASON"
-WHERE "r_reason_sk" IS NOT NULL) AS "t2" ON "t0"."wr_reason_sk" = "t2"."r_reason_sk"
-INNER JOIN (SELECT "ca_address_sk", "ca_state" IN ('IN', 'OH', 'NJ') AS "IN", "ca_state" IN ('WI', 'CT', 'KY') AS "IN2", "ca_state" IN ('LA', 'IA', 'AR') AS "IN3"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_state" IN ('IN', 'OH', 'NJ', 'WI', 'CT', 'KY', 'LA', 'IA', 'AR') AND ("ca_country" = 'United States' AND "ca_address_sk" IS NOT NULL)) AS "t4" ON "t0"."wr_refunded_addr_sk" = "t4"."ca_address_sk"
-INNER JOIN (SELECT "cd_demo_sk", "cd_marital_status", "cd_education_status", "cd_marital_status" = 'M' AS "=", "cd_education_status" = 'Advanced Degree     ' AS "=4", "cd_marital_status" = 'S' AS "=5", "cd_education_status" = 'College             ' AS "=6", "cd_marital_status" = 'W' AS "=7", "cd_education_status" = '2 yr Degree         ' AS "=8"
-FROM "CUSTOMER_DEMOGRAPHICS"
-WHERE "cd_marital_status" IN ('M', 'S', 'W') AND ("cd_education_status" IN ('Advanced Degree     ', 'College             ', '2 yr Degree         ') AND "cd_demo_sk" IS NOT NULL)) AS "t6" ON "t0"."wr_refunded_cdemo_sk" = "t6"."cd_demo_sk"
+FROM (SELECT "r_reason_sk", "r_reason_desc"
+FROM "REASON") AS "t2"
+WHERE "r_reason_sk" IS NOT NULL) AS "t4" ON "t1"."wr_reason_sk" = "t4"."r_reason_sk"
+INNER JOIN (SELECT "ca_address_sk", "ca_state" IN ('IN', 'NJ', 'OH') AS "EXPR$0", "ca_state" IN ('CT', 'KY', 'WI') AS "EXPR$1", "ca_state" IN ('AR', 'IA', 'LA') AS "EXPR$2"
+FROM (SELECT "ca_address_sk", "ca_state", "ca_country"
+FROM "CUSTOMER_ADDRESS") AS "t5"
+WHERE "ca_state" IN ('AR', 'CT', 'IA', 'IN', 'KY', 'LA', 'NJ', 'OH', 'WI') AND "ca_country" = 'United States' AND "ca_address_sk" IS NOT NULL) AS "t7" ON "t1"."wr_refunded_addr_sk" = "t7"."ca_address_sk"
+INNER JOIN (SELECT "cd_demo_sk", "cd_marital_status", "cd_education_status", "cd_marital_status" = 'M' AS "EXPR$0", "cd_education_status" = 'Advanced Degree' AS "EXPR$1", "cd_marital_status" = 'S' AS "EXPR$2", "cd_education_status" = 'College' AS "EXPR$3", "cd_marital_status" = 'W' AS "EXPR$4", "cd_education_status" = '2 yr Degree' AS "EXPR$5"
+FROM (SELECT "cd_demo_sk", "cd_marital_status", "cd_education_status"
+FROM "CUSTOMER_DEMOGRAPHICS") AS "t8"
+WHERE "cd_marital_status" IN ('M', 'S', 'W') AND "cd_education_status" IN ('2 yr Degree', 'Advanced Degree', 'College') AND "cd_demo_sk" IS NOT NULL) AS "t10" ON "t1"."wr_refunded_cdemo_sk" = "t10"."cd_demo_sk"
 INNER JOIN (SELECT "cd_demo_sk", "cd_marital_status", "cd_education_status"
-FROM "CUSTOMER_DEMOGRAPHICS"
-WHERE "cd_marital_status" IN ('M', 'S', 'W') AND ("cd_education_status" IN ('Advanced Degree     ', 'College             ', '2 yr Degree         ') AND "cd_demo_sk" IS NOT NULL)) AS "t8" ON "t0"."wr_returning_cdemo_sk" = "t8"."cd_demo_sk" AND "t6"."cd_marital_status" = "t8"."cd_marital_status" AND "t6"."cd_education_status" = "t8"."cd_education_status"
-INNER JOIN (SELECT "t10"."ws_sold_date_sk", "t10"."ws_item_sk", "t10"."ws_order_number", "t10"."ws_quantity", "t10"."BETWEEN", "t10"."BETWEEN5", "t10"."BETWEEN6", "t10"."BETWEEN7", "t10"."BETWEEN8", "t10"."BETWEEN9", "t12"."d_date_sk"
-FROM (SELECT "ws_sold_date_sk", "ws_item_sk", "ws_order_number", "ws_quantity", "ws_net_profit" BETWEEN 100 AND 200 AS "BETWEEN", "ws_net_profit" BETWEEN 150 AND 300 AS "BETWEEN5", "ws_net_profit" BETWEEN 50 AND 250 AS "BETWEEN6", "ws_sales_price" BETWEEN 100 AND 150 AS "BETWEEN7", "ws_sales_price" BETWEEN 50 AND 100 AS "BETWEEN8", "ws_sales_price" BETWEEN 150 AND 200 AS "BETWEEN9"
-FROM "WEB_SALES"
-WHERE (100 <= "ws_sales_price" OR ("ws_sales_price" <= 150 OR 50 <= "ws_sales_price") OR ("ws_sales_price" <= 100 OR (150 <= "ws_sales_price" OR "ws_sales_price" <= 200))) AND (100 <= "ws_net_profit" OR ("ws_net_profit" <= 200 OR 150 <= "ws_net_profit") OR ("ws_net_profit" <= 300 OR (50 <= "ws_net_profit" OR "ws_net_profit" <= 250))) AND ("ws_item_sk" IS NOT NULL AND ("ws_order_number" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL))) AS "t10"
+FROM (SELECT "cd_demo_sk", "cd_marital_status", "cd_education_status"
+FROM "CUSTOMER_DEMOGRAPHICS") AS "t11"
+WHERE "cd_marital_status" IN ('M', 'S', 'W') AND "cd_education_status" IN ('2 yr Degree', 'Advanced Degree', 'College') AND "cd_demo_sk" IS NOT NULL) AS "t13" ON "t1"."wr_returning_cdemo_sk" = "t13"."cd_demo_sk" AND "t10"."cd_marital_status" = "t13"."cd_marital_status" AND "t10"."cd_education_status" = "t13"."cd_education_status"
+INNER JOIN (SELECT "t16"."ws_sold_date_sk", "t16"."ws_item_sk", "t16"."ws_order_number", "t16"."ws_quantity", "t16"."EXPR$0", "t16"."EXPR$1", "t16"."EXPR$2", "t16"."EXPR$3", "t16"."EXPR$4", "t16"."EXPR$5", "t19"."d_date_sk"
+FROM (SELECT "ws_sold_date_sk", "ws_item_sk", "ws_order_number", "ws_quantity", "ws_net_profit" BETWEEN 100 AND 200 AS "EXPR$0", "ws_net_profit" BETWEEN 150 AND 300 AS "EXPR$1", "ws_net_profit" BETWEEN 50 AND 250 AS "EXPR$2", "ws_sales_price" BETWEEN 100 AND 150 AS "EXPR$3", "ws_sales_price" BETWEEN 50 AND 100 AS "EXPR$4", "ws_sales_price" BETWEEN 150 AND 200 AS "EXPR$5"
+FROM (SELECT "ws_sold_date_sk", "ws_item_sk", "ws_order_number", "ws_quantity", "ws_sales_price", "ws_net_profit"
+FROM "WEB_SALES") AS "t14"
+WHERE "ws_item_sk" IS NOT NULL AND "ws_order_number" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL AND "ws_sales_price" IS NOT NULL AND "ws_net_profit" IS NOT NULL) AS "t16"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 2000 AND "d_date_sk" IS NOT NULL) AS "t12" ON "t10"."ws_sold_date_sk" = "t12"."d_date_sk") AS "t13" ON "t0"."wr_item_sk" = "t13"."ws_item_sk" AND "t0"."wr_order_number" = "t13"."ws_order_number" AND ("t6"."=" AND "t6"."=4" AND "t13"."BETWEEN7" OR "t6"."=5" AND "t6"."=6" AND "t13"."BETWEEN8" OR "t6"."=7" AND "t6"."=8" AND "t13"."BETWEEN9") AND ("t4"."IN" AND "t13"."BETWEEN" OR "t4"."IN2" AND "t13"."BETWEEN5" OR "t4"."IN3" AND "t13"."BETWEEN6")
-GROUP BY "t2"."r_reason_desc"
+FROM (SELECT "d_date_sk", "d_year"
+FROM "DATE_DIM") AS "t17"
+WHERE "d_year" = 2000 AND "d_date_sk" IS NOT NULL) AS "t19" ON "t16"."ws_sold_date_sk" = "t19"."d_date_sk") AS "t20" ON "t1"."wr_item_sk" = "t20"."ws_item_sk" AND "t1"."wr_order_number" = "t20"."ws_order_number" AND ("t10"."EXPR$0" AND "t10"."EXPR$1" AND "t20"."EXPR$3" OR "t10"."EXPR$2" AND "t10"."EXPR$3" AND "t20"."EXPR$4" OR "t10"."EXPR$4" AND "t10"."EXPR$5" AND "t20"."EXPR$5") AND ("t7"."EXPR$0" AND "t20"."EXPR$0" OR "t7"."EXPR$1" AND "t20"."EXPR$1" OR "t7"."EXPR$2" AND "t20"."EXPR$2")
+GROUP BY "t4"."r_reason_desc"
                     hive.sql.query.fieldNames r_reason_desc,$f1,$f2,$f3,$f4,$f5,$f6
                     hive.sql.query.fieldTypes char(100),bigint,bigint,decimal(17,2),bigint,decimal(17,2),bigint
                     hive.sql.query.split false
@@ -6282,23 +6378,26 @@ STAGE PLANS:
                 TableScan
                   alias: c
                   properties:
-                    hive.sql.query SELECT "t0"."c_customer_sk", "t0"."c_customer_id", "t0"."c_current_cdemo_sk", "t0"."c_current_hdemo_sk", "t0"."c_current_addr_sk", "t0"."c_first_shipto_date_sk", "t0"."c_first_sales_date_sk", "t0"."c_salutation", "t0"."c_first_name", "t0"."c_last_name", "t0"."c_preferred_cust_flag", "t0"."c_birth_day", "t0"."c_birth_month", "t0"."c_birth_year", "t0"."c_birth_country", "t0"."c_login", "t0"."c_email_address", "t0"."c_last_review_date", "t4"."ca_address_sk", "t4"."ca_address_id", "t4"."ca_street_number", "t4"."ca_street_name", "t4"."ca_street_type", "t4"."ca_suite_number", "t4"."ca_city", "t4"."ca_county", "t4"."ca_state", "t4"."ca_zip", "t4"."ca_country", "t4"."ca_gmt_offset", "t4"."ca_location_type", "t2"."cd_demo_sk", "t2"."cd_gender", "t2"."cd_marital_status", "t2"."cd_education_status", "t2"."cd_purchase_estimate", "t2"."cd_credit_rating", "t2"."cd_dep_count", "t2"."cd_dep_employed_count", "t2"."cd_dep_college_count"
-FROM (SELECT "c_customer_sk", "c_customer_id", "c_current_cdemo_sk", "c_current_hdemo_sk", "c_current_addr_sk", "c_first_shipto_date_sk", "c_first_sales_date_sk", "c_salutation", "c_first_name", "c_last_name", "c_preferred_cust_flag", "c_birth_day", "c_birth_month", "c_birth_year", "c_birth_country", "c_login", "c_email_address", "c_last_review_date"
-FROM "CUSTOMER"
-WHERE "c_current_addr_sk" IS NOT NULL AND ("c_current_cdemo_sk" IS NOT NULL AND "c_customer_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating", "cd_dep_count", "cd_dep_employed_count", "cd_dep_college_count"
-FROM "CUSTOMER_DEMOGRAPHICS"
-WHERE "cd_demo_sk" IS NOT NULL) AS "t2" ON "t0"."c_current_cdemo_sk" = "t2"."cd_demo_sk"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t0"."c_current_addr_sk" = "t4"."ca_address_sk"
-                    hive.sql.query.fieldNames c_customer_sk,c_customer_id,c_current_cdemo_sk,c_current_hdemo_sk,c_current_addr_sk,c_first_shipto_date_sk,c_first_sales_date_sk,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address,c_last_review_date,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,cd_demo_sk,cd_gender,cd_marital_status,cd_education_status,cd_purchase_estimate,cd_credit_rating,cd_dep_count,cd_dep_employed_count,cd_dep_college_count
-                    hive.sql.query.fieldTypes int,char(16),int,int,int,int,int,char(10),char(20),char(30),char(1),int,int,int,varchar(20),char(13),char(50),char(10),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(1),char(1),char(20),int,char(10),int,int,int
+                    hive.sql.query SELECT "t1"."c_customer_sk", "t1"."c_current_cdemo_sk", "t1"."c_current_addr_sk", "t4"."ca_address_sk", "t4"."ca_state", "t7"."cd_demo_sk", "t7"."cd_gender", "t7"."cd_marital_status", "t7"."cd_education_status", "t7"."cd_purchase_estimate", "t7"."cd_credit_rating"
+FROM (SELECT "c_customer_sk", "c_current_cdemo_sk", "c_current_addr_sk"
+FROM (SELECT "c_customer_sk", "c_current_cdemo_sk", "c_current_addr_sk"
+FROM "CUSTOMER") AS "t"
+WHERE "c_current_addr_sk" IS NOT NULL AND "c_current_cdemo_sk" IS NOT NULL AND "c_customer_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_state"
+FROM (SELECT "ca_address_sk", "ca_state"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."c_current_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating"
+FROM (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating"
+FROM "CUSTOMER_DEMOGRAPHICS") AS "t5"
+WHERE "cd_demo_sk" IS NOT NULL) AS "t7" ON "t1"."c_current_cdemo_sk" = "t7"."cd_demo_sk"
+                    hive.sql.query.fieldNames c_customer_sk,c_current_cdemo_sk,c_current_addr_sk,ca_address_sk,ca_state,cd_demo_sk,cd_gender,cd_marital_status,cd_education_status,cd_purchase_estimate,cd_credit_rating
+                    hive.sql.query.fieldTypes int,int,int,int,char(2),int,char(1),char(1),char(20),int,char(10)
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: c_customer_sk (type: int), cd_gender (type: char(1)), cd_marital_status (type: char(1)), cd_education_status (type: char(20)), cd_purchase_estimate (type: int), cd_credit_rating (type: char(10))
-                    outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                    outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                     Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col0 (type: int)
@@ -6306,7 +6405,7 @@ WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4"
                       sort order: +
                       Map-reduce partition columns: _col0 (type: int)
                       Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                      value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 7 
@@ -6314,13 +6413,15 @@ WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4"
                 TableScan
                   alias: store_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ss_customer_sk"
+                    hive.sql.query SELECT "t1"."ss_customer_sk"
 FROM (SELECT "ss_sold_date_sk", "ss_customer_sk"
-FROM "STORE_SALES"
-WHERE "ss_customer_sk" IS NOT NULL AND "ss_sold_date_sk" IS NOT NULL) AS "t0"
+FROM (SELECT "ss_sold_date_sk", "ss_customer_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_customer_sk" IS NOT NULL AND "ss_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_sold_date_sk" = "t2"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."ss_sold_date_sk" = "t4"."d_date_sk"
                     hive.sql.query.fieldNames ss_customer_sk
                     hive.sql.query.fieldTypes int
                     hive.sql.query.split false
@@ -6348,14 +6449,16 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 TableScan
                   alias: web_sales
                   properties:
-                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."ws_bill_customer_sk"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t1"."ws_bill_customer_sk"
+FROM (SELECT "ws_sold_date_sk", "ws_bill_customer_sk"
 FROM (SELECT "ws_sold_date_sk", "ws_bill_customer_sk"
-FROM "WEB_SALES"
-WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t0"
+FROM "WEB_SALES") AS "t"
+WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."ws_sold_date_sk" = "t2"."d_date_sk"
-GROUP BY "t0"."ws_bill_customer_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."ws_sold_date_sk" = "t4"."d_date_sk"
+GROUP BY "t1"."ws_bill_customer_sk"
                     hive.sql.query.fieldNames literalTrue,ws_bill_customer_sk
                     hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
@@ -6378,14 +6481,16 @@ GROUP BY "t0"."ws_bill_customer_sk"
                 TableScan
                   alias: catalog_sales
                   properties:
-                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."cs_ship_customer_sk"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t1"."cs_ship_customer_sk"
+FROM (SELECT "cs_sold_date_sk", "cs_ship_customer_sk"
 FROM (SELECT "cs_sold_date_sk", "cs_ship_customer_sk"
-FROM "CATALOG_SALES"
-WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t0"
+FROM "CATALOG_SALES") AS "t"
+WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."cs_sold_date_sk" = "t2"."d_date_sk"
-GROUP BY "t0"."cs_ship_customer_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE "d_year" = 1999 AND "d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."cs_sold_date_sk" = "t4"."d_date_sk"
+GROUP BY "t1"."cs_ship_customer_sk"
                     hive.sql.query.fieldNames literalTrue,cs_ship_customer_sk
                     hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
@@ -6412,7 +6517,7 @@ GROUP BY "t0"."cs_ship_customer_sk"
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                 Statistics: Num rows: 1 Data size: 413 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
                   key expressions: _col0 (type: int)
@@ -6420,7 +6525,7 @@ GROUP BY "t0"."cs_ship_customer_sk"
                   sort order: +
                   Map-reduce partition columns: _col0 (type: int)
                   Statistics: Num rows: 1 Data size: 413 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                  value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
         Reducer 3 
             Execution mode: llap
             Reduce Operator Tree:
@@ -6430,14 +6535,14 @@ GROUP BY "t0"."cs_ship_customer_sk"
                 keys:
                   0 _col0 (type: int)
                   1 _col1 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36, _col40
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10, _col11
                 Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col40 is null (type: boolean)
+                  predicate: _col11 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col0 (type: int), _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
-                    outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                    expressions: _col0 (type: int), _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
+                    outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                     Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col0 (type: int)
@@ -6445,7 +6550,7 @@ GROUP BY "t0"."cs_ship_customer_sk"
                       sort order: +
                       Map-reduce partition columns: _col0 (type: int)
                       Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                      value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
         Reducer 4 
             Execution mode: llap
             Reduce Operator Tree:
@@ -6455,24 +6560,24 @@ GROUP BY "t0"."cs_ship_customer_sk"
                 keys:
                   0 _col0 (type: int)
                   1 _col1 (type: int)
-                outputColumnNames: _col32, _col33, _col34, _col35, _col36, _col42
+                outputColumnNames: _col6, _col7, _col8, _col9, _col10, _col13
                 Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col42 is null (type: boolean)
+                  predicate: _col13 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                   Top N Key Operator
                     sort order: +++++
-                    keys: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                    keys: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
                     null sort order: zzzzz
                     Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                     top n: 100
                     Select Operator
-                      expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
-                      outputColumnNames: _col32, _col33, _col34, _col35, _col36
+                      expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
+                      outputColumnNames: _col6, _col7, _col8, _col9, _col10
                       Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                       Group By Operator
                         aggregations: count()
-                        keys: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                        keys: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
                         minReductionHashAggr: 0.99
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -6770,23 +6875,26 @@ STAGE PLANS:
                 TableScan
                   alias: c
                   properties:
-                    hive.sql.query SELECT "t0"."c_customer_sk", "t0"."c_customer_id", "t0"."c_current_cdemo_sk", "t0"."c_current_hdemo_sk", "t0"."c_current_addr_sk", "t0"."c_first_shipto_date_sk", "t0"."c_first_sales_date_sk", "t0"."c_salutation", "t0"."c_first_name", "t0"."c_last_name", "t0"."c_preferred_cust_flag", "t0"."c_birth_day", "t0"."c_birth_month", "t0"."c_birth_year", "t0"."c_birth_country", "t0"."c_login", "t0"."c_email_address", "t0"."c_last_review_date", "t4"."ca_address_sk", "t4"."ca_address_id", "t4"."ca_street_number", "t4"."ca_street_name", "t4"."ca_street_type", "t4"."ca_suite_number", "t4"."ca_city", "t4"."ca_county", "t4"."ca_state", "t4"."ca_zip", "t4"."ca_country", "t4"."ca_gmt_offset", "t4"."ca_location_type", "t2"."cd_demo_sk", "t2"."cd_gender", "t2"."cd_marital_status", "t2"."cd_education_status", "t2"."cd_purchase_estimate", "t2"."cd_credit_rating", "t2"."cd_dep_count", "t2"."cd_dep_employed_count", "t2"."cd_dep_college_count"
-FROM (SELECT "c_customer_sk", "c_customer_id", "c_current_cdemo_sk", "c_current_hdemo_sk", "c_current_addr_sk", "c_first_shipto_date_sk", "c_first_sales_date_sk", "c_salutation", "c_first_name", "c_last_name", "c_preferred_cust_flag", "c_birth_day", "c_birth_month", "c_birth_year", "c_birth_country", "c_login", "c_email_address", "c_last_review_date"
-FROM "CUSTOMER"
-WHERE "c_current_addr_sk" IS NOT NULL AND ("c_current_cdemo_sk" IS NOT NULL AND "c_customer_sk" IS NOT NULL)) AS "t0"
-INNER JOIN (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating", "cd_dep_count", "cd_dep_employed_count", "cd_dep_college_count"
-FROM "CUSTOMER_DEMOGRAPHICS"
-WHERE "cd_demo_sk" IS NOT NULL) AS "t2" ON "t0"."c_current_cdemo_sk" = "t2"."cd_demo_sk"
-INNER JOIN (SELECT "ca_address_sk", "ca_address_id", "ca_street_number", "ca_street_name", "ca_street_type", "ca_suite_number", "ca_city", "ca_county", "ca_state", "ca_zip", "ca_country", "ca_gmt_offset", "ca_location_type"
-FROM "CUSTOMER_ADDRESS"
-WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t0"."c_current_addr_sk" = "t4"."ca_address_sk"
-                    hive.sql.query.fieldNames c_customer_sk,c_customer_id,c_current_cdemo_sk,c_current_hdemo_sk,c_current_addr_sk,c_first_shipto_date_sk,c_first_sales_date_sk,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address,c_last_review_date,ca_address_sk,ca_address_id,ca_street_number,ca_street_name,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset,ca_location_type,cd_demo_sk,cd_gender,cd_marital_status,cd_education_status,cd_purchase_estimate,cd_credit_rating,cd_dep_count,cd_dep_employed_count,cd_dep_college_count
-                    hive.sql.query.fieldTypes int,char(16),int,int,int,int,int,char(10),char(20),char(30),char(1),int,int,int,varchar(20),char(13),char(50),char(10),int,char(16),char(10),varchar(60),char(15),char(10),varchar(60),varchar(30),char(2),char(10),varchar(20),decimal(5,2),char(20),int,char(1),char(1),char(20),int,char(10),int,int,int
+                    hive.sql.query SELECT "t1"."c_customer_sk", "t1"."c_current_cdemo_sk", "t1"."c_current_addr_sk", "t4"."ca_address_sk", "t4"."ca_state", "t7"."cd_demo_sk", "t7"."cd_gender", "t7"."cd_marital_status", "t7"."cd_education_status", "t7"."cd_purchase_estimate", "t7"."cd_credit_rating"
+FROM (SELECT "c_customer_sk", "c_current_cdemo_sk", "c_current_addr_sk"
+FROM (SELECT "c_customer_sk", "c_current_cdemo_sk", "c_current_addr_sk"
+FROM "CUSTOMER") AS "t"
+WHERE "c_current_addr_sk" IS NOT NULL AND "c_current_cdemo_sk" IS NOT NULL AND "c_customer_sk" IS NOT NULL) AS "t1"
+INNER JOIN (SELECT "ca_address_sk", "ca_state"
+FROM (SELECT "ca_address_sk", "ca_state"
+FROM "CUSTOMER_ADDRESS") AS "t2"
+WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4" ON "t1"."c_current_addr_sk" = "t4"."ca_address_sk"
+INNER JOIN (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating"
+FROM (SELECT "cd_demo_sk", "cd_gender", "cd_marital_status", "cd_education_status", "cd_purchase_estimate", "cd_credit_rating"
+FROM "CUSTOMER_DEMOGRAPHICS") AS "t5"
+WHERE "cd_demo_sk" IS NOT NULL) AS "t7" ON "t1"."c_current_cdemo_sk" = "t7"."cd_demo_sk"
+                    hive.sql.query.fieldNames c_customer_sk,c_current_cdemo_sk,c_current_addr_sk,ca_address_sk,ca_state,cd_demo_sk,cd_gender,cd_marital_status,cd_education_status,cd_purchase_estimate,cd_credit_rating
+                    hive.sql.query.fieldTypes int,int,int,int,char(2),int,char(1),char(1),char(20),int,char(10)
                     hive.sql.query.split false
                   Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
                     expressions: c_customer_sk (type: int), cd_gender (type: char(1)), cd_marital_status (type: char(1)), cd_education_status (type: char(20)), cd_purchase_estimate (type: int), cd_credit_rating (type: char(10))
-                    outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                    outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                     Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col0 (type: int)
@@ -6794,7 +6902,7 @@ WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4"
                       sort order: +
                       Map-reduce partition columns: _col0 (type: int)
                       Statistics: Num rows: 1 Data size: 376 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                      value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
             Execution mode: vectorized, llap
             LLAP IO: no inputs
         Map 7 
@@ -6802,13 +6910,15 @@ WHERE "ca_state" IN ('CO', 'IL', 'MN') AND "ca_address_sk" IS NOT NULL) AS "t4"
                 TableScan
                   alias: store_sales
                   properties:
-                    hive.sql.query SELECT "t0"."ss_customer_sk"
+                    hive.sql.query SELECT "t1"."ss_customer_sk"
 FROM (SELECT "ss_sold_date_sk", "ss_customer_sk"
-FROM "STORE_SALES"
-WHERE "ss_customer_sk" IS NOT NULL AND "ss_sold_date_sk" IS NOT NULL) AS "t0"
+FROM (SELECT "ss_sold_date_sk", "ss_customer_sk"
+FROM "STORE_SALES") AS "t"
+WHERE "ss_customer_sk" IS NOT NULL AND "ss_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."ss_sold_date_sk" = "t2"."d_date_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE ("d_moy" < 1 OR "d_moy" > 3) AND "d_year" = 1999 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."ss_sold_date_sk" = "t4"."d_date_sk"
                     hive.sql.query.fieldNames ss_customer_sk
                     hive.sql.query.fieldTypes int
                     hive.sql.query.split false
@@ -6836,14 +6946,16 @@ WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL))
                 TableScan
                   alias: web_sales
                   properties:
-                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."ws_bill_customer_sk"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t1"."ws_bill_customer_sk"
 FROM (SELECT "ws_sold_date_sk", "ws_bill_customer_sk"
-FROM "WEB_SALES"
-WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t0"
+FROM (SELECT "ws_sold_date_sk", "ws_bill_customer_sk"
+FROM "WEB_SALES") AS "t"
+WHERE "ws_bill_customer_sk" IS NOT NULL AND "ws_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."ws_sold_date_sk" = "t2"."d_date_sk"
-GROUP BY "t0"."ws_bill_customer_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE ("d_moy" < 1 OR "d_moy" > 3) AND "d_year" = 1999 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."ws_sold_date_sk" = "t4"."d_date_sk"
+GROUP BY "t1"."ws_bill_customer_sk"
                     hive.sql.query.fieldNames literalTrue,ws_bill_customer_sk
                     hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
@@ -6866,14 +6978,16 @@ GROUP BY "t0"."ws_bill_customer_sk"
                 TableScan
                   alias: catalog_sales
                   properties:
-                    hive.sql.query SELECT TRUE AS "literalTrue", "t0"."cs_ship_customer_sk"
+                    hive.sql.query SELECT TRUE AS "literalTrue", "t1"."cs_ship_customer_sk"
+FROM (SELECT "cs_sold_date_sk", "cs_ship_customer_sk"
 FROM (SELECT "cs_sold_date_sk", "cs_ship_customer_sk"
-FROM "CATALOG_SALES"
-WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t0"
+FROM "CATALOG_SALES") AS "t"
+WHERE "cs_ship_customer_sk" IS NOT NULL AND "cs_sold_date_sk" IS NOT NULL) AS "t1"
 INNER JOIN (SELECT "d_date_sk"
-FROM "DATE_DIM"
-WHERE "d_year" = 1999 AND ("d_moy" BETWEEN 1 AND 3 AND "d_date_sk" IS NOT NULL)) AS "t2" ON "t0"."cs_sold_date_sk" = "t2"."d_date_sk"
-GROUP BY "t0"."cs_ship_customer_sk"
+FROM (SELECT "d_date_sk", "d_year", "d_moy"
+FROM "DATE_DIM") AS "t2"
+WHERE ("d_moy" < 1 OR "d_moy" > 3) AND "d_year" = 1999 AND "d_date_sk" IS NOT NULL) AS "t4" ON "t1"."cs_sold_date_sk" = "t4"."d_date_sk"
+GROUP BY "t1"."cs_ship_customer_sk"
                     hive.sql.query.fieldNames literalTrue,cs_ship_customer_sk
                     hive.sql.query.fieldTypes boolean,int
                     hive.sql.query.split false
@@ -6900,7 +7014,7 @@ GROUP BY "t0"."cs_ship_customer_sk"
                 keys:
                   0 _col0 (type: int)
                   1 _col0 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                 Statistics: Num rows: 1 Data size: 413 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
                   key expressions: _col0 (type: int)
@@ -6908,7 +7022,7 @@ GROUP BY "t0"."cs_ship_customer_sk"
                   sort order: +
                   Map-reduce partition columns: _col0 (type: int)
                   Statistics: Num rows: 1 Data size: 413 Basic stats: COMPLETE Column stats: NONE
-                  value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                  value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
         Reducer 3 
             Execution mode: llap
             Reduce Operator Tree:
@@ -6918,14 +7032,14 @@ GROUP BY "t0"."cs_ship_customer_sk"
                 keys:
                   0 _col0 (type: int)
                   1 _col1 (type: int)
-                outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36, _col40
+                outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10, _col11
                 Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col40 is null (type: boolean)
+                  predicate: _col11 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                   Select Operator
-                    expressions: _col0 (type: int), _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
-                    outputColumnNames: _col0, _col32, _col33, _col34, _col35, _col36
+                    expressions: _col0 (type: int), _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
+                    outputColumnNames: _col0, _col6, _col7, _col8, _col9, _col10
                     Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
                     Reduce Output Operator
                       key expressions: _col0 (type: int)
@@ -6933,7 +7047,7 @@ GROUP BY "t0"."cs_ship_customer_sk"
                       sort order: +
                       Map-reduce partition columns: _col0 (type: int)
                       Statistics: Num rows: 1 Data size: 454 Basic stats: COMPLETE Column stats: NONE
-                      value expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                      value expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
         Reducer 4 
             Execution mode: llap
             Reduce Operator Tree:
@@ -6943,24 +7057,24 @@ GROUP BY "t0"."cs_ship_customer_sk"
                 keys:
                   0 _col0 (type: int)
                   1 _col1 (type: int)
-                outputColumnNames: _col32, _col33, _col34, _col35, _col36, _col42
+                outputColumnNames: _col6, _col7, _col8, _col9, _col10, _col13
                 Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                 Filter Operator
-                  predicate: _col42 is null (type: boolean)
+                  predicate: _col13 is null (type: boolean)
                   Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                   Top N Key Operator
                     sort order: +++++
-                    keys: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                    keys: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
                     null sort order: zzzzz
                     Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                     top n: 100
                     Select Operator
-                      expressions: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
-                      outputColumnNames: _col32, _col33, _col34, _col35, _col36
+                      expressions: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
+                      outputColumnNames: _col6, _col7, _col8, _col9, _col10
                       Statistics: Num rows: 1 Data size: 499 Basic stats: COMPLETE Column stats: NONE
                       Group By Operator
                         aggregations: count()
-                        keys: _col32 (type: char(1)), _col33 (type: char(1)), _col34 (type: char(20)), _col35 (type: int), _col36 (type: char(10))
+                        keys: _col6 (type: char(1)), _col7 (type: char(1)), _col8 (type: char(20)), _col9 (type: int), _col10 (type: char(10))
                         minReductionHashAggr: 0.99
                         mode: hash
                         outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5
@@ -7262,138 +7376,172 @@ POSTHOOK: Input: default@store_sales
 PREHOOK: query: DROP TABLE catalog_sales
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@catalog_sales
+PREHOOK: Output: database:default
 PREHOOK: Output: default@catalog_sales
 POSTHOOK: query: DROP TABLE catalog_sales
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@catalog_sales
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@catalog_sales
 PREHOOK: query: DROP TABLE catalog_returns
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@catalog_returns
+PREHOOK: Output: database:default
 PREHOOK: Output: default@catalog_returns
 POSTHOOK: query: DROP TABLE catalog_returns
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@catalog_returns
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@catalog_returns
 PREHOOK: query: DROP TABLE store_sales
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@store_sales
+PREHOOK: Output: database:default
 PREHOOK: Output: default@store_sales
 POSTHOOK: query: DROP TABLE store_sales
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@store_sales
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@store_sales
 PREHOOK: query: DROP TABLE store_returns
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@store_returns
+PREHOOK: Output: database:default
 PREHOOK: Output: default@store_returns
 POSTHOOK: query: DROP TABLE store_returns
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@store_returns
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@store_returns
 PREHOOK: query: DROP TABLE web_sales
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@web_sales
+PREHOOK: Output: database:default
 PREHOOK: Output: default@web_sales
 POSTHOOK: query: DROP TABLE web_sales
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@web_sales
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@web_sales
 PREHOOK: query: DROP TABLE web_returns
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@web_returns
+PREHOOK: Output: database:default
 PREHOOK: Output: default@web_returns
 POSTHOOK: query: DROP TABLE web_returns
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@web_returns
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@web_returns
 PREHOOK: query: DROP TABLE customer
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@customer
+PREHOOK: Output: database:default
 PREHOOK: Output: default@customer
 POSTHOOK: query: DROP TABLE customer
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@customer
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@customer
 PREHOOK: query: DROP TABLE customer_address
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@customer_address
+PREHOOK: Output: database:default
 PREHOOK: Output: default@customer_address
 POSTHOOK: query: DROP TABLE customer_address
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@customer_address
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@customer_address
 PREHOOK: query: DROP TABLE customer_demographics
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@customer_demographics
+PREHOOK: Output: database:default
 PREHOOK: Output: default@customer_demographics
 POSTHOOK: query: DROP TABLE customer_demographics
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@customer_demographics
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@customer_demographics
 PREHOOK: query: DROP TABLE inventory
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@inventory
+PREHOOK: Output: database:default
 PREHOOK: Output: default@inventory
 POSTHOOK: query: DROP TABLE inventory
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@inventory
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@inventory
 PREHOOK: query: DROP TABLE item
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@item
+PREHOOK: Output: database:default
 PREHOOK: Output: default@item
 POSTHOOK: query: DROP TABLE item
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@item
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@item
 PREHOOK: query: DROP TABLE warehouse
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@warehouse
+PREHOOK: Output: database:default
 PREHOOK: Output: default@warehouse
 POSTHOOK: query: DROP TABLE warehouse
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@warehouse
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@warehouse
 PREHOOK: query: DROP TABLE date_dim
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@date_dim
+PREHOOK: Output: database:default
 PREHOOK: Output: default@date_dim
 POSTHOOK: query: DROP TABLE date_dim
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@date_dim
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@date_dim
 PREHOOK: query: DROP TABLE store
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@store
+PREHOOK: Output: database:default
 PREHOOK: Output: default@store
 POSTHOOK: query: DROP TABLE store
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@store
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@store
 PREHOOK: query: DROP TABLE household_demographics
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@household_demographics
+PREHOOK: Output: database:default
 PREHOOK: Output: default@household_demographics
 POSTHOOK: query: DROP TABLE household_demographics
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@household_demographics
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@household_demographics
 PREHOOK: query: DROP TABLE time_dim
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@time_dim
+PREHOOK: Output: database:default
 PREHOOK: Output: default@time_dim
 POSTHOOK: query: DROP TABLE time_dim
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@time_dim
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@time_dim
 PREHOOK: query: DROP TABLE reason
 PREHOOK: type: DROPTABLE
 PREHOOK: Input: default@reason
+PREHOOK: Output: database:default
 PREHOOK: Output: default@reason
 POSTHOOK: query: DROP TABLE reason
 POSTHOOK: type: DROPTABLE
 POSTHOOK: Input: default@reason
+POSTHOOK: Output: database:default
 POSTHOOK: Output: default@reason
 PREHOOK: query: FROM src
 SELECT
diff --git a/ql/src/test/results/clientpositive/llap/jdbc_handler.q.out b/ql/src/test/results/clientpositive/llap/jdbc_handler.q.out
index 75b884b0198c..f4f596006aaa 100644
--- a/ql/src/test/results/clientpositive/llap/jdbc_handler.q.out
+++ b/ql/src/test/results/clientpositive/llap/jdbc_handler.q.out
@@ -261,18 +261,18 @@ STAGE PLANS:
                     Statistics: Num rows: 250 Data size: 21750 Basic stats: COMPLETE Column stats: COMPLETE
                     Group By Operator
                       keys: key (type: string)
-                      minReductionHashAggr: 0.5
+                      minReductionHashAggr: 0.4
                       mode: hash
                       outputColumnNames: _col0
-                      Statistics: Num rows: 125 Data size: 10875 Basic stats: COMPLETE Column stats: COMPLETE
+                      Statistics: Num rows: 250 Data size: 21750 Basic stats: COMPLETE Column stats: COMPLETE
                       Reduce Output Operator
                         key expressions: _col0 (type: string)
                         null sort order: z
                         sort order: +
                         Map-reduce partition columns: _col0 (type: string)
-                        Statistics: Num rows: 125 Data size: 10875 Basic stats: COMPLETE Column stats: COMPLETE
+                        Statistics: Num rows: 250 Data size: 21750 Basic stats: COMPLETE Column stats: COMPLETE
             Execution mode: vectorized, llap
-            LLAP IO: no inputs
+            LLAP IO: all inputs
         Reducer 2 
             Execution mode: llap
             Reduce Operator Tree:
@@ -283,22 +283,22 @@ STAGE PLANS:
                   0 
                   1 
                 outputColumnNames: _col0, _col1
-                Statistics: Num rows: 125 Data size: 34000 Basic stats: COMPLETE Column stats: NONE
+                Statistics: Num rows: 250 Data size: 68000 Basic stats: COMPLETE Column stats: NONE
                 Reduce Output Operator
                   key expressions: _col0 (type: string), _col1 (type: string)
                   null sort order: zz
                   sort order: ++
-                  Statistics: Num rows: 125 Data size: 34000 Basic stats: COMPLETE Column stats: NONE
+                  Statistics: Num rows: 250 Data size: 68000 Basic stats: COMPLETE Column stats: NONE
         Reducer 3 
             Execution mode: vectorized, llap
             Reduce Operator Tree:
               Select Operator
                 expressions: KEY.reducesinkkey0 (type: string), KEY.reducesinkkey1 (type: string)
                 outputColumnNames: _col0, _col1
-                Statistics: Num rows: 125 Data size: 34000 Basic stats: COMPLETE Column stats: NONE
+                Statistics: Num rows: 250 Data size: 68000 Basic stats: COMPLETE Column stats: NONE
                 File Output Operator
                   compressed: false
-                  Statistics: Num rows: 125 Data size: 34000 Basic stats: COMPLETE Column stats: NONE
+                  Statistics: Num rows: 250 Data size: 68000 Basic stats: COMPLETE Column stats: NONE
                   table:
                       input format: org.apache.hadoop.mapred.SequenceFileInputFormat
                       output format: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
@@ -310,11 +310,11 @@ STAGE PLANS:
                 keys: KEY._col0 (type: string)
                 mode: mergepartial
                 outputColumnNames: _col0
-                Statistics: Num rows: 125 Data size: 10875 Basic stats: COMPLETE Column stats: COMPLETE
+                Statistics: Num rows: 250 Data size: 21750 Basic stats: COMPLETE Column stats: COMPLETE
                 Reduce Output Operator
                   null sort order: 
                   sort order: 
-                  Statistics: Num rows: 125 Data size: 10875 Basic stats: COMPLETE Column stats: COMPLETE
+                  Statistics: Num rows: 250 Data size: 21750 Basic stats: COMPLETE Column stats: COMPLETE
                   value expressions: _col0 (type: string)
 
   Stage: Stage-0
diff --git a/ql/src/test/results/clientpositive/llap/jdbc_split_filter.q.out b/ql/src/test/results/clientpositive/llap/jdbc_split_filter.q.out
index 97cf6f586a7a..ad9605391d5d 100644
--- a/ql/src/test/results/clientpositive/llap/jdbc_split_filter.q.out
+++ b/ql/src/test/results/clientpositive/llap/jdbc_split_filter.q.out
@@ -146,9 +146,10 @@ HiveJdbcConverter(convention=[JDBC.DERBY])
     JdbcAggregate(group=[{0, 4, 5}], agg#0=[sum($1)])
       JdbcFilter(condition=[IS NULL($2)])
         JdbcJoin(condition=[AND(=($1, $3), =($0, $2))], joinType=[left])
-          JdbcProject(fkey=[$2], ikey=[$0])
+          HiveProject(fkey=[$2], ikey=[$0])
             JdbcHiveTableScan(table=[[default, ext_simple_derby_table1]], table:alias=[ext_simple_derby_table1])
-          JdbcProject(fkey=[$2], ikey=[$0], datekey=[$4], dkey=[$3])
-            JdbcFilter(condition=[AND(IS NOT NULL($0), IS NOT NULL($2))])
-              JdbcHiveTableScan(table=[[default, ext_simple_derby_table2]], table:alias=[ext_simple_derby_table2])
+          JdbcProject(fkey=[$1], ikey=[$0], datekey=[$3], dkey=[$2])
+            JdbcFilter(condition=[AND(IS NOT NULL($0), IS NOT NULL($1))])
+              JdbcProject(ikey=[$0], fkey=[$2], dkey=[$3], datekey=[$4])
+                JdbcHiveTableScan(table=[[default, ext_simple_derby_table2]], table:alias=[ext_simple_derby_table2])
 
diff --git a/ql/src/test/results/clientpositive/llap/qt_database_derby.q.out b/ql/src/test/results/clientpositive/llap/qt_database_derby.q.out
new file mode 100644
index 000000000000..da56622c061d
--- /dev/null
+++ b/ql/src/test/results/clientpositive/llap/qt_database_derby.q.out
@@ -0,0 +1,47 @@
+PREHOOK: query: CREATE EXTERNAL TABLE country
+(
+    id int,
+    name varchar(20)
+)
+    STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
+    TBLPROPERTIES (
+        "hive.sql.database.type" = "DERBY",
+        "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
+#### A masked pattern was here ####
+        "hive.sql.dbcp.username" = "qtestuser",
+        "hive.sql.dbcp.password" = "qtestpassword",
+        "hive.sql.dbcp.maxActive" = "1",
+        "hive.sql.table" = "COUNTRY"
+        )
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@country
+POSTHOOK: query: CREATE EXTERNAL TABLE country
+(
+    id int,
+    name varchar(20)
+)
+    STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
+    TBLPROPERTIES (
+        "hive.sql.database.type" = "DERBY",
+        "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
+#### A masked pattern was here ####
+        "hive.sql.dbcp.username" = "qtestuser",
+        "hive.sql.dbcp.password" = "qtestpassword",
+        "hive.sql.dbcp.maxActive" = "1",
+        "hive.sql.table" = "COUNTRY"
+        )
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@country
+PREHOOK: query: SELECT * FROM country
+PREHOOK: type: QUERY
+PREHOOK: Input: default@country
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT * FROM country
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@country
+#### A masked pattern was here ####
+1	India
+2	Russia
+3	USA