mirror of
https://github.com/apache/impala.git
synced 2026-01-03 06:00:52 -05:00
SHOW CREATE TABLE now supports views. It returns a CREATE VIEW statement with column names and the original sql statement. Authorization allows SHOW CREATE TABLE to be run on view if the user has VIEW_METADATA privilege on the view and SELECT privilege on all underlying views and table. E.g. "SHOW CREATE TABLE some_view" returns output of form: CREATE VIEW a_database.some_view (id, bool_col, tinyint_col) AS SELECT id, bool_col, tinyint_col FROM functional.alltypes Change-Id: Id633af2f5c1f5b0e01c13ed85c4bf9c045dc0666 Reviewed-on: http://gerrit.cloudera.org:8080/713 Reviewed-by: Alex Behm <alex.behm@cloudera.com> Tested-by: Internal Jenkins
308 lines
7.6 KiB
Plaintext
308 lines
7.6 KiB
Plaintext
====
|
|
---- CREATE_TABLE
|
|
# Simple table
|
|
CREATE TABLE test1 (
|
|
id INT
|
|
)
|
|
STORED AS TEXTFILE
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test1 (
|
|
id INT
|
|
)
|
|
STORED AS TEXTFILE
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- CREATE_TABLE
|
|
# simple table with all types
|
|
CREATE TABLE test2 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment',
|
|
bool_col BOOLEAN,
|
|
tinyint_col TINYINT,
|
|
smallint_col SMALLINT,
|
|
int_col INT,
|
|
bigint_col BIGINT,
|
|
float_col FLOAT,
|
|
double_col DOUBLE,
|
|
date_string_col STRING,
|
|
string_col STRING,
|
|
timestamp_col TIMESTAMP
|
|
)
|
|
STORED AS TEXTFILE
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test2 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment',
|
|
bool_col BOOLEAN,
|
|
tinyint_col TINYINT,
|
|
smallint_col SMALLINT,
|
|
int_col INT,
|
|
bigint_col BIGINT,
|
|
float_col FLOAT,
|
|
double_col DOUBLE,
|
|
date_string_col STRING,
|
|
string_col STRING,
|
|
timestamp_col TIMESTAMP
|
|
)
|
|
STORED AS TEXTFILE
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- CREATE_TABLE
|
|
# all types and partitioned
|
|
CREATE TABLE test3 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment',
|
|
bool_col BOOLEAN,
|
|
tinyint_col TINYINT,
|
|
smallint_col SMALLINT,
|
|
int_col INT,
|
|
bigint_col BIGINT,
|
|
float_col FLOAT,
|
|
double_col DOUBLE,
|
|
date_string_col STRING,
|
|
string_col STRING,
|
|
timestamp_col TIMESTAMP
|
|
)
|
|
PARTITIONED BY (
|
|
x INT,
|
|
y INT,
|
|
a BOOLEAN
|
|
)
|
|
STORED AS TEXTFILE
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test3 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment',
|
|
bool_col BOOLEAN,
|
|
tinyint_col TINYINT,
|
|
smallint_col SMALLINT,
|
|
int_col INT,
|
|
bigint_col BIGINT,
|
|
float_col FLOAT,
|
|
double_col DOUBLE,
|
|
date_string_col STRING,
|
|
string_col STRING,
|
|
timestamp_col TIMESTAMP
|
|
)
|
|
PARTITIONED BY (
|
|
x INT,
|
|
y INT,
|
|
a BOOLEAN
|
|
)
|
|
STORED AS TEXTFILE
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- CREATE_TABLE
|
|
# With a table comment
|
|
CREATE TABLE test4 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
COMMENT 'This is a test'
|
|
STORED AS TEXTFILE
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test4 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
COMMENT 'This is a test'
|
|
STORED AS TEXTFILE
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- CREATE_TABLE
|
|
# With the row format specified
|
|
CREATE TABLE test5 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ESCAPED BY '\\' LINES TERMINATED BY '\n'
|
|
STORED AS TEXTFILE
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test5 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ESCAPED BY '\\' LINES TERMINATED BY '\n'
|
|
WITH SERDEPROPERTIES ('line.delim'='\n', 'field.delim'=',',
|
|
'serialization.format'=',', 'escape.delim'='\\')
|
|
STORED AS TEXTFILE
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- CREATE_TABLE
|
|
# testing with parquet specified
|
|
CREATE TABLE test6 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
STORED AS PARQUET
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test6 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
STORED AS PARQUET
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- CREATE_TABLE
|
|
# with extra table properties and sequencefile
|
|
CREATE TABLE test7 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
STORED AS SEQUENCEFILE
|
|
TBLPROPERTIES ('key3'='val3', 'key2'='val2', 'key1'='val1')
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test7 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
STORED AS SEQUENCEFILE
|
|
LOCATION '$$location_uri$$'
|
|
TBLPROPERTIES ('key3'='val3', 'key2'='val2', 'key1'='val1')
|
|
====
|
|
---- CREATE_TABLE
|
|
# testing with rcfile specified
|
|
CREATE TABLE test8 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
STORED AS RCFILE
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test8 (
|
|
year INT,
|
|
month INT,
|
|
id INT COMMENT 'Add a comment'
|
|
)
|
|
STORED AS RCFILE
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- CREATE_TABLE
|
|
# Test create table as select
|
|
CREATE TABLE test_as_select (
|
|
id INT,
|
|
bool_col BOOLEAN,
|
|
tinyint_col TINYINT,
|
|
smallint_col SMALLINT,
|
|
int_col INT,
|
|
bigint_col BIGINT,
|
|
float_col FLOAT,
|
|
double_col DOUBLE,
|
|
date_string_col STRING,
|
|
string_col STRING,
|
|
timestamp_col TIMESTAMP,
|
|
year INT,
|
|
month INT
|
|
)
|
|
STORED AS TEXTFILE
|
|
---- RESULTS
|
|
CREATE TABLE show_create_table_test_db.test_as_select (
|
|
id INT,
|
|
bool_col BOOLEAN,
|
|
tinyint_col TINYINT,
|
|
smallint_col SMALLINT,
|
|
int_col INT,
|
|
bigint_col BIGINT,
|
|
float_col FLOAT,
|
|
double_col DOUBLE,
|
|
date_string_col STRING,
|
|
string_col STRING,
|
|
timestamp_col TIMESTAMP,
|
|
year INT,
|
|
month INT
|
|
)
|
|
STORED AS TEXTFILE
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- QUERY
|
|
SHOW CREATE TABLE functional_text_lzo.tinytable
|
|
---- RESULTS
|
|
CREATE EXTERNAL TABLE functional_text_lzo.tinytable (
|
|
a STRING,
|
|
b STRING
|
|
)
|
|
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
|
|
STORED AS INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'
|
|
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
|
|
LOCATION '$$location_uri$$'
|
|
====
|
|
---- QUERY
|
|
SHOW CREATE TABLE functional.allcomplextypes
|
|
---- RESULTS
|
|
CREATE EXTERNAL TABLE functional.allcomplextypes (
|
|
id INT,
|
|
int_array_col ARRAY<INT>,
|
|
array_array_col ARRAY<ARRAY<INT>>,
|
|
map_array_col ARRAY<MAP<STRING,INT>>,
|
|
struct_array_col ARRAY<STRUCT<f1:BIGINT,f2:STRING>>,
|
|
int_map_col MAP<STRING,INT>,
|
|
array_map_col MAP<STRING,ARRAY<INT>>,
|
|
map_map_col MAP<STRING,MAP<STRING,INT>>,
|
|
struct_map_col MAP<STRING,STRUCT<f1:BIGINT,f2:STRING>>,
|
|
int_struct_col STRUCT<f1:INT,f2:INT>,
|
|
complex_struct_col STRUCT<f1:INT,f2:ARRAY<INT>,f3:MAP<STRING,INT>>,
|
|
nested_struct_col STRUCT<f1:INT,f2:STRUCT<f11:BIGINT,f12:STRUCT<f21:BIGINT>>>,
|
|
complex_nested_struct_col STRUCT<f1:INT,f2:ARRAY<STRUCT<f11:BIGINT,f12:MAP<STRING,STRUCT<f21:BIGINT>>>>>
|
|
)
|
|
PARTITIONED BY (
|
|
year INT,
|
|
month INT
|
|
)
|
|
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ESCAPED BY '\\'
|
|
WITH SERDEPROPERTIES ('field.delim'=',', 'serialization.format'=',', 'escape.delim'='\\')
|
|
STORED AS TEXTFILE
|
|
LOCATION '$$location_uri$$'
|
|
TBLPROPERTIES ('transient_lastDdlTime'='1405990341')
|
|
====
|
|
---- QUERY
|
|
SHOW CREATE TABLE functional.alltypes_view
|
|
---- RESULTS
|
|
CREATE VIEW functional.alltypes_view AS
|
|
SELECT * FROM functional.alltypes
|
|
====
|
|
---- CREATE_VIEW
|
|
# View with column aliases
|
|
CREATE VIEW column_aliases_view (foo, bar, baz) AS
|
|
SELECT tinyint_col, id, bigint_col
|
|
FROM functional.alltypes;
|
|
---- RESULTS
|
|
# A view with column aliases is expanded into a SELECT with an inline view.
|
|
CREATE VIEW show_create_table_test_db.column_aliases_view AS
|
|
SELECT column_aliases_view.tinyint_col foo, column_aliases_view.id bar, column_aliases_view.bigint_col baz FROM (SELECT tinyint_col, id, bigint_col FROM functional.alltypes) column_aliases_view
|
|
====
|
|
---- QUERY
|
|
# Test views referencing views.
|
|
SHOW CREATE TABLE functional.view_view;
|
|
---- RESULTS
|
|
CREATE VIEW functional.view_view AS
|
|
SELECT * FROM functional.alltypes_view
|
|
====
|
|
---- QUERY
|
|
# Test complex views with multiple tables and Hive-style column aliases.
|
|
SHOW CREATE TABLE functional.complex_view
|
|
---- RESULTS
|
|
CREATE VIEW functional.complex_view AS
|
|
SELECT complex_view.`_c0` abc, complex_view.string_col xyz FROM (SELECT count(a.bigint_col), b.string_col FROM functional.alltypesagg a INNER JOIN functional.alltypestiny b ON a.id = b.id WHERE a.bigint_col < 50 GROUP BY b.string_col HAVING count(a.bigint_col) > 1 ORDER BY b.string_col ASC LIMIT 100) complex_view
|
|
====
|
|
---- CREATE_VIEW
|
|
# Test that identifiers are correctly quoted.
|
|
CREATE VIEW _quote_view (_foo, bar) AS
|
|
SELECT tinyint_col, id _id
|
|
FROM functional.alltypes;
|
|
---- RESULTS
|
|
CREATE VIEW show_create_table_test_db.`_quote_view` AS
|
|
SELECT `_quote_view`.tinyint_col `_foo`, `_quote_view`.`_id` bar FROM (SELECT tinyint_col, id `_id` FROM functional.alltypes) `_quote_view`
|
|
====
|