Files
impala/testdata/workloads/functional-query/queries/QueryTest/hive-jdbc-postgres-tables.test
pranav.lodha 7f77176970 IMPALA-13869: Support for 'hive.sql.query' property for Hive JDBC tables
This patch adds support for the hive.sql.query table property in Hive
JDBC tables accessed through Impala. Impala has support for Hive
JDBC tables using the hive.sql.table property, which limits users
to simple table access. However, many use cases demand the ability
to expose complex joins, filters, aggregations, or derived columns
as external views. Hive.sql.query leads to a custom SQL query that
returns a virtual table(subquery) instead of pointing to a physical
table. These use cases cannot be achieved with just the hive.sql.table
property. This change allows Impala to:
 • Interact with views or complex queries defined on external
 systems without needing schema-level access to base tables.
 • Expose materialized logic (such as filters, joins, or
 transformations) via Hive to Impala consumers in a secure,
 abstracted way.
 • Better align with data virtualization use cases where
 physical data location and structure should be hidden from
 the querying engine.
This patch also lays the groundwork for future enhancements such
as predicate pushdown and performance optimizations for Hive
JDBC tables backed by queries.

Testing: End-to-end tests are included in
test_ext_data_sources.py.

Change-Id: I039fcc1e008233a3eeed8d09554195fdb8c8706b
Reviewed-on: http://gerrit.cloudera.org:8080/22865
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
2025-10-23 21:34:29 +00:00

752 lines
18 KiB
Plaintext

====
---- QUERY
select * from country_postgres;
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select * from country_keystore_postgres;
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select id, name, date_col from country_postgres;
---- RESULTS
1,'India',2024-01-01
2,'Russia',2024-02-01
3,'USA',2024-03-01
---- TYPES
INT, STRING, DATE
====
---- QUERY
select id, name, date_col from country_keystore_postgres;
---- RESULTS
1,'India',2024-01-01
2,'Russia',2024-02-01
3,'USA',2024-03-01
---- TYPES
INT, STRING, DATE
====
---- QUERY
select count(*) from country_postgres;
---- RESULTS
3
---- TYPES
BIGINT
====
---- QUERY
select count(*) from country_keystore_postgres;
---- RESULTS
3
---- TYPES
BIGINT
====
---- QUERY
select distinct name from country_postgres;
---- RESULTS
'India'
'Russia'
'USA'
---- TYPES
STRING
====
---- QUERY
select distinct name from country_keystore_postgres;
---- RESULTS
'India'
'Russia'
'USA'
---- TYPES
STRING
====
---- QUERY
# Check for null values
select * from country_postgres where string_col IS NULL;
---- RESULTS
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select * from country_keystore_postgres where string_col IS NULL;
---- RESULTS
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
# Order by integer column
select id, name, int_col from country_postgres order by int_col DESC;
---- RESULTS
3,'USA',3000
2,'Russia',2000
1,'India',1000
---- TYPES
INT, STRING, INT
====
---- QUERY
select id, name, int_col from country_keystore_postgres order by int_col DESC;
---- RESULTS
3,'USA',3000
2,'Russia',2000
1,'India',1000
---- TYPES
INT, STRING, INT
====
---- QUERY
# Select using case statement
select id, name, case when bool_col then 'Active' else 'Inactive' end as status from country_postgres;
---- RESULTS
1,'India','Active'
2,'Russia','Inactive'
3,'USA','Active'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select id, name, case when bool_col then 'Active' else 'Inactive' end as status from country_keystore_postgres;
---- RESULTS
1,'India','Active'
2,'Russia','Inactive'
3,'USA','Active'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Check for minimum date
select min(date_col) from country_postgres;
---- RESULTS
2024-01-01
---- TYPES
DATE
====
---- QUERY
select min(date_col) from country_keystore_postgres;
---- RESULTS
2024-01-01
---- TYPES
DATE
====
---- QUERY
# Join with a self table alias
select a.id, a.name, b.name from country_postgres a join country_postgres b on a.id <> b.id;
---- RESULTS
1,'India','Russia'
1,'India','USA'
2,'Russia','India'
2,'Russia','USA'
3,'USA','India'
3,'USA','Russia'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.name from country_keystore_postgres a join country_keystore_postgres b on a.id <> b.id;
---- RESULTS
1,'India','Russia'
1,'India','USA'
2,'Russia','India'
2,'Russia','USA'
3,'USA','India'
3,'USA','Russia'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Left join with another table
select a.id, a.name, b.string_col from country_postgres a left join country_keystore_postgres b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres a left join country_postgres b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Right join with another table
select a.id, a.name, b.string_col from country_postgres a right join country_keystore_postgres b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres a right join country_postgres b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Full outer join
select a.id, a.name, b.string_col from country_postgres a full outer join country_keystore_postgres b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres a full outer join country_postgres b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Using IN clause
select * from country_postgres where name IN ('India', 'USA');
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select * from country_keystore_postgres where name IN ('India', 'USA');
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select * from country_postgres_query;
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select * from country_keystore_postgres_query;
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select id, name, date_col from country_postgres_query;
---- RESULTS
1,'India',2024-01-01
2,'Russia',2024-02-01
3,'USA',2024-03-01
---- TYPES
INT, STRING, DATE
====
---- QUERY
select id, name, date_col from country_keystore_postgres_query;
---- RESULTS
1,'India',2024-01-01
2,'Russia',2024-02-01
3,'USA',2024-03-01
---- TYPES
INT, STRING, DATE
====
---- QUERY
select count(*) from country_postgres_query;
---- RESULTS
3
---- TYPES
BIGINT
====
---- QUERY
select count(*) from country_keystore_postgres_query;
---- RESULTS
3
---- TYPES
BIGINT
====
---- QUERY
select distinct name from country_postgres_query;
---- RESULTS
'India'
'Russia'
'USA'
---- TYPES
STRING
====
---- QUERY
select distinct name from country_keystore_postgres_query;
---- RESULTS
'India'
'Russia'
'USA'
---- TYPES
STRING
====
---- QUERY
# Check for null values
select * from country_postgres_query where string_col IS NULL;
---- RESULTS
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select * from country_keystore_postgres_query where string_col IS NULL;
---- RESULTS
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
# Order by integer column
select id, name, int_col from country_postgres_query order by int_col DESC;
---- RESULTS
3,'USA',3000
2,'Russia',2000
1,'India',1000
---- TYPES
INT, STRING, INT
====
---- QUERY
select id, name, int_col from country_keystore_postgres_query order by int_col DESC;
---- RESULTS
3,'USA',3000
2,'Russia',2000
1,'India',1000
---- TYPES
INT, STRING, INT
====
---- QUERY
# Select using case statement
select id, name, case when bool_col then 'Active' else 'Inactive' end as status from country_postgres_query;
---- RESULTS
1,'India','Active'
2,'Russia','Inactive'
3,'USA','Active'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select id, name, case when bool_col then 'Active' else 'Inactive' end as status from country_keystore_postgres_query;
---- RESULTS
1,'India','Active'
2,'Russia','Inactive'
3,'USA','Active'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Check for minimum date
select min(date_col) from country_postgres_query;
---- RESULTS
2024-01-01
---- TYPES
DATE
====
---- QUERY
select min(date_col) from country_keystore_postgres_query;
---- RESULTS
2024-01-01
---- TYPES
DATE
====
---- QUERY
# Join with a self table alias
select a.id, a.name, b.name from country_postgres_query a join country_postgres_query b on a.id <> b.id;
---- RESULTS
1,'India','Russia'
1,'India','USA'
2,'Russia','India'
2,'Russia','USA'
3,'USA','India'
3,'USA','Russia'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.name from country_keystore_postgres_query a join country_keystore_postgres_query b on
a.id <> b.id;
---- RESULTS
1,'India','Russia'
1,'India','USA'
2,'Russia','India'
2,'Russia','USA'
3,'USA','India'
3,'USA','Russia'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Left join with another table
select a.id, a.name, b.string_col from country_postgres_query a left join country_keystore_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_postgres a left join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres a left join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres_query a left join country_postgres b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres_query a left join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_postgres_query a left join country_postgres b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_postgres_query a left join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Right join with another table
select a.id, a.name, b.string_col from country_postgres_query a right join country_keystore_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres_query a right join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_postgres a right join country_keystore_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_postgres a right join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres a right join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres a right join country_keystore_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Full outer join
select a.id, a.name, b.string_col from country_postgres_query a full outer join country_keystore_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres_query a full outer join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_postgres a full outer join country_keystore_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_postgres a full outer join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres a full outer join country_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.string_col from country_keystore_postgres a full outer join country_keystore_postgres_query b on
a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Using IN clause
select * from country_postgres_query where name IN ('India', 'USA');
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select * from country_keystore_postgres_query where name IN ('India', 'USA');
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select * from quoted_col;
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
select id, name, date_col from quoted_col;
---- RESULTS
1,'India',2024-01-01
2,'Russia',2024-02-01
3,'USA',2024-03-01
---- TYPES
INT, STRING, DATE
====
---- QUERY
select count(*) from quoted_col;
---- RESULTS
3
---- TYPES
BIGINT
====
---- QUERY
select distinct name from quoted_col;
---- RESULTS
'India'
'Russia'
'USA'
---- TYPES
STRING
====
---- QUERY
# Check for null values
select * from quoted_col where `freeze` IS NULL;
---- RESULTS
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====
---- QUERY
# Order by integer column
select id, name, int_col from quoted_col order by int_col DESC;
---- RESULTS
3,'USA',3000
2,'Russia',2000
1,'India',1000
---- TYPES
INT, STRING, INT
====
---- QUERY
# Select using case statement
select id, name, case when bool_col then 'Active' else 'Inactive' end as status from quoted_col;
---- RESULTS
1,'India','Active'
2,'Russia','Inactive'
3,'USA','Active'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Check for minimum date
select min(date_col) from quoted_col;
---- RESULTS
2024-01-01
---- TYPES
DATE
====
---- QUERY
# Join with a self table alias
select a.id, a.name, b.name from quoted_col a join quoted_col b on a.id <> b.id;
---- RESULTS
1,'India','Russia'
1,'India','USA'
2,'Russia','India'
2,'Russia','USA'
3,'USA','India'
3,'USA','Russia'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Left join with another table
select a.id, a.name, b.`freeze` from quoted_col a left join quoted_col b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.`freeze` from quoted_col a left join quoted_col b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Right join with another table
select a.id, a.name, b.`freeze` from quoted_col a right join quoted_col b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.`freeze` from quoted_col a right join quoted_col b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Full outer join
select a.id, a.name, b.`freeze` from quoted_col a full outer join quoted_col b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
select a.id, a.name, b.`freeze` from quoted_col a full outer join quoted_col b on a.id = b.id;
---- RESULTS
1,'India','IN'
2,'Russia','RU'
3,'USA','US'
---- TYPES
INT, STRING, STRING
====
---- QUERY
# Using IN clause
select * from quoted_col where name IN ('India', 'USA');
---- RESULTS
1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00
3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00
---- TYPES
INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP
====