blob: 3765f5f7b0252dc2e9ae4123b1e0ebf88a24bda0 [file] [log] [blame]
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','','',
'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','','',
'CREATE TABLE SIMPLE_DERBY_TABLE2 ("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','','',
'CREATE TABLE SIMPLE_DERBY_TABLE3 ("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','','',
'CREATE TABLE SIMPLE_DERBY_TABLE4 ("ikey2" INTEGER, "bkey2" BIGINT, "fkey2" REAL, "dkey2" DOUBLE, "datekey2" DATE)' );
CREATE EXTERNAL TABLE ext_simple_derby_table1
(
ikey int,
bkey bigint,
fkey float,
dkey double
)
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.dbcp.username" = "APP",
"hive.sql.dbcp.password" = "mine",
"hive.sql.table" = "SIMPLE_DERBY_TABLE1",
"hive.sql.dbcp.maxActive" = "1"
);
CREATE EXTERNAL TABLE ext_simple_derby_table2
(
ikey int,
bkey bigint,
fkey float,
dkey double,
datekey string
)
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.dbcp.username" = "APP",
"hive.sql.dbcp.password" = "mine",
"hive.sql.table" = "SIMPLE_DERBY_TABLE2",
"hive.sql.dbcp.maxActive" = "1"
);
CREATE EXTERNAL TABLE ext_simple_derby_table3
(
ikey2 int,
bkey2 bigint,
fkey2 float,
dkey2 double
)
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.dbcp.username" = "APP",
"hive.sql.dbcp.password" = "mine",
"hive.sql.table" = "SIMPLE_DERBY_TABLE3",
"hive.sql.dbcp.maxActive" = "1"
);
CREATE EXTERNAL TABLE ext_simple_derby_table4
(
ikey2 int,
bkey2 bigint,
fkey2 float,
dkey2 double,
datekey2 string
)
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.dbcp.username" = "APP",
"hive.sql.dbcp.password" = "mine",
"hive.sql.table" = "SIMPLE_DERBY_TABLE4",
"hive.sql.dbcp.maxActive" = "1"
);
explain cbo
with t1 as (select fkey, ikey, sum(dkey) as dk_sum, sum(dkey2) as dk2_sum
from ext_simple_derby_table1 left join ext_simple_derby_table3
on ikey = ikey2
where fkey2 is null
group by fkey, ikey),
t2 as (select datekey, fkey, ikey, sum(dkey) as dk_sum2, sum(dkey2) as dk2_sum2
from ext_simple_derby_table2 left join ext_simple_derby_table4
on ikey = ikey2
where fkey2 is null
group by datekey, fkey, ikey)
select t1.fkey, t2.ikey, sum(t1.ikey)
from t1 left join t2
on t1.ikey = t2.ikey AND t1.fkey = t2.fkey
where t2.fkey is null
group by t2.datekey, t1.fkey, t2.ikey;