Test/hive dml (#155)
* feat: add showIndex parser rule * test: uncomment show index test cases * test: add unit tests about DML syntax to HiveSQL * test: add unit tests about export and import syntax to HiveSQL * refactor: recompile hive grammar * test: correct description of HiveSQL unit tests
This commit is contained in:
3
test/parser/hive/syntax/fixtures/delete.sql
Normal file
3
test/parser/hive/syntax/fixtures/delete.sql
Normal file
@ -0,0 +1,3 @@
|
||||
DELETE FROM tbl;
|
||||
|
||||
DELETE FROM tbl1 WHERE id = 1;
|
6
test/parser/hive/syntax/fixtures/export.sql
Normal file
6
test/parser/hive/syntax/fixtures/export.sql
Normal file
@ -0,0 +1,6 @@
|
||||
EXPORT TABLE tbl TO 'hdfs_exports_location/department';
|
||||
|
||||
EXPORT TABLE employee
|
||||
PARTITION(emp_country="in", emp_state="ka")
|
||||
TO 'hdfs_exports_location/employee'
|
||||
FOR REPLICATION('eventid');
|
8
test/parser/hive/syntax/fixtures/import.sql
Normal file
8
test/parser/hive/syntax/fixtures/import.sql
Normal file
@ -0,0 +1,8 @@
|
||||
IMPORT FROM 'hdfs_exports_location/department';
|
||||
|
||||
IMPORT TABLE employee PARTITION (emp_country="us", emp_state="tn") FROM 'hdfs_exports_location/employee';
|
||||
|
||||
IMPORT EXTERNAL TABLE employee
|
||||
PARTITION (emp_country="us", emp_state="tn")
|
||||
FROM 'hdfs_exports_location/employee'
|
||||
LOCATION 'import_target_path';
|
11
test/parser/hive/syntax/fixtures/insertFormValues.sql
Normal file
11
test/parser/hive/syntax/fixtures/insertFormValues.sql
Normal file
@ -0,0 +1,11 @@
|
||||
INSERT INTO TABLE students
|
||||
VALUES ('fred flintstone', 35, 1.28), ('barney rubble', 32, 2.32);
|
||||
|
||||
INSERT INTO TABLE pageviews PARTITION (datestamp = '2014-09-23')
|
||||
VALUES ('jsmith', 'mail.com', 'sports.com'), ('jdoe', 'mail.com', null);
|
||||
|
||||
INSERT INTO TABLE pageviews PARTITION (datestamp)
|
||||
VALUES ('tjohnson', 'sports.com', 'finance.com', '2014-09-23'), ('tlee', 'finance.com', null, '2014-09-21');
|
||||
|
||||
INSERT INTO TABLE pageviews
|
||||
VALUES ('tjohnson', 'sports.com', 'finance.com', '2014-09-23'), ('tlee', 'finance.com', null, '2014-09-21');
|
79
test/parser/hive/syntax/fixtures/insertFromQuery.sql
Normal file
79
test/parser/hive/syntax/fixtures/insertFromQuery.sql
Normal file
@ -0,0 +1,79 @@
|
||||
-- Inserting data into Hive Tables from queries
|
||||
INSERT INTO table_name PARTITION (partition_col)
|
||||
SELECT col1, col2, partition_col
|
||||
FROM source_table;
|
||||
|
||||
FROM source_table
|
||||
INSERT OVERWRITE TABLE table_name PARTITION (partition_col='value1')
|
||||
SELECT col1, col2
|
||||
WHERE partition_col = 'value1'
|
||||
INSERT INTO TABLE table_name PARTITION (partition_col='value2')
|
||||
SELECT col1, col2
|
||||
WHERE partition_col = 'value2';
|
||||
|
||||
FROM page_view_stg pvs
|
||||
INSERT OVERWRITE TABLE page_view PARTITION(dt='2008-06-08', country)
|
||||
SELECT pvs.viewTime, pvs.userid, pvs.page_url, pvs.referrer_url, null, null, pvs.ip, pvs.cnt;
|
||||
|
||||
|
||||
-- Writing data into the filesystem from queries
|
||||
INSERT OVERWRITE LOCAL DIRECTORY '/path/to/output'
|
||||
SELECT col1, col2
|
||||
FROM table_name;
|
||||
|
||||
INSERT OVERWRITE DIRECTORY '/path/to/output'
|
||||
STORED AS PARQUET
|
||||
SELECT col1, col2
|
||||
FROM table_name;
|
||||
|
||||
INSERT INTO table_name PARTITION (year, month, day)
|
||||
SELECT col1, col2,
|
||||
CASE
|
||||
WHEN month = 'January' THEN 2023
|
||||
WHEN month = 'February' THEN 2023
|
||||
ELSE 2024
|
||||
END AS year,
|
||||
CASE
|
||||
WHEN month = 'January' THEN 1
|
||||
WHEN month = 'February' THEN 2
|
||||
ELSE 3
|
||||
END AS month,
|
||||
CAST(day AS int) AS day
|
||||
FROM source_table;
|
||||
|
||||
INSERT INTO table_name PARTITION (country, state)
|
||||
SELECT col1, col2,
|
||||
CONCAT(country, '_', state) AS country_state
|
||||
FROM source_table;
|
||||
|
||||
INSERT INTO table_name PARTITION (country, state)
|
||||
SELECT col1, col2, country, state
|
||||
FROM (
|
||||
SELECT col1, col2,
|
||||
CASE
|
||||
WHEN country = 'USA' THEN 'United States'
|
||||
ELSE country
|
||||
END AS country,
|
||||
CASE
|
||||
WHEN country = 'USA' THEN 'NA'
|
||||
ELSE state
|
||||
END AS state
|
||||
FROM source_table
|
||||
) subquery;
|
||||
|
||||
INSERT OVERWRITE LOCAL DIRECTORY '/path/to/output'
|
||||
ROW FORMAT DELIMITED
|
||||
FIELDS TERMINATED BY ','
|
||||
ESCAPED BY '^'
|
||||
COLLECTION ITEMS TERMINATED BY '.'
|
||||
MAP KEYS TERMINATED BY ':'
|
||||
LINES TERMINATED BY 'n'
|
||||
NULL DEFINED AS 'x'
|
||||
SELECT col1, col2
|
||||
FROM table_name;
|
||||
|
||||
INSERT OVERWRITE LOCAL DIRECTORY '/path/to/output'
|
||||
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
|
||||
STORED AS AVRO
|
||||
SELECT col1, col2
|
||||
FROM table_name;
|
7
test/parser/hive/syntax/fixtures/load.sql
Normal file
7
test/parser/hive/syntax/fixtures/load.sql
Normal file
@ -0,0 +1,7 @@
|
||||
LOAD DATA INPATH 'hdfs://namenode:9000/user/hive/project/data1' INTO TABLE tbl1;
|
||||
|
||||
LOAD DATA LOCAL INPATH '/user/hive/project/data1'
|
||||
OVERWRITE INTO TABLE tablename
|
||||
PARTITION (pt1=1, pt2=2)
|
||||
INPUTFORMAT 'com.apache.hadoop.textInputFormat'
|
||||
SERDE 'JsonSerDe';
|
10
test/parser/hive/syntax/fixtures/merge.sql
Normal file
10
test/parser/hive/syntax/fixtures/merge.sql
Normal file
@ -0,0 +1,10 @@
|
||||
MERGE INTO demo.a AS T1 USING demo.b AS T2
|
||||
ON T1.id = T2.id
|
||||
WHEN MATCHED THEN UPDATE SET name = 'wf1'
|
||||
WHEN NOT MATCHED THEN INSERT VALUES(T2.id,T2.name);
|
||||
|
||||
MERGE INTO demo.a AS T1 USING demo.b AS T2
|
||||
ON T1.id = T2.id
|
||||
WHEN MATCHED AND sex='male' THEN UPDATE SET name = 'wf1'
|
||||
WHEN MATCHED AND sex='female' THEN UPDATE SET age = 10
|
||||
WHEN NOT MATCHED AND age>10 THEN INSERT VALUES(T2.id,T2.name);
|
@ -39,9 +39,9 @@ SHOW TBLPROPERTIES tblname("foo");
|
||||
SHOW CREATE TABLE db.tbl1;
|
||||
|
||||
-- Show Indexes
|
||||
-- SHOW INDEX ON idx_tbl;
|
||||
SHOW INDEX ON idx_tbl;
|
||||
|
||||
-- SHOW FORMATTED INDEXES ON idx_tbl2 FROM db_1;
|
||||
SHOW FORMATTED INDEXES ON idx_tbl2 FROM db_1;
|
||||
|
||||
-- Show Columns
|
||||
SHOW COLUMNS FROM tble;
|
||||
|
7
test/parser/hive/syntax/fixtures/update.sql
Normal file
7
test/parser/hive/syntax/fixtures/update.sql
Normal file
@ -0,0 +1,7 @@
|
||||
UPDATE table_name
|
||||
SET col1 = new_value;
|
||||
|
||||
UPDATE table_name
|
||||
SET col1 = new_value,
|
||||
col2 = new_value2
|
||||
WHERE id=1;
|
Reference in New Issue
Block a user