From 5f0a0851a690b6fbf28b0576d651447b48a93345 Mon Sep 17 00:00:00 2001 From: hayden Date: Mon, 10 Jul 2023 10:09:28 +0800 Subject: [PATCH] test: hivesql show syntax unit tests --- test/parser/hive/syntax/fixtures/show.sql | 107 ++++++++++++++++++ test/parser/hive/syntax/showStatement.test.ts | 16 +++ 2 files changed, 123 insertions(+) create mode 100644 test/parser/hive/syntax/fixtures/show.sql create mode 100644 test/parser/hive/syntax/showStatement.test.ts diff --git a/test/parser/hive/syntax/fixtures/show.sql b/test/parser/hive/syntax/fixtures/show.sql new file mode 100644 index 0000000..5c163cb --- /dev/null +++ b/test/parser/hive/syntax/fixtures/show.sql @@ -0,0 +1,107 @@ +-- Show Databases +SHOW SCHEMAS; + +SHOW DATABASES LIKE 'identifier_with_wildcards'; + +-- Show Connectors +SHOW CONNECTORS; + +-- Show Tables +SHOW TABLES; + +SHOW TABLES IN db1 'identifier_with_wildcards'; + +-- Show Views +SHOW VIEWS; + +SHOW VIEWS FROM schema1 LIKE 'pattern_with_wildcards'; + +SHOW MATERIALIZED VIEWS IN database2 LIKE 'pattern_with_wildcards'; + +-- Show Partitions +SHOW PARTITIONS tbl1; + +SHOW PARTITIONS table_name PARTITION(ds='2010-03-03', hr='12'); + +SHOW PARTITIONS databaseFoo.tableBar WHERE hr >= 10 AND ds='2010-03-03' ORDER BY hr DESC LIMIT 10; + +-- Show Table/Partition Extended +SHOW TABLE EXTENDED LIKE part_table; + +SHOW TABLE EXTENDED IN database3 LIKE 'identifier_with_wildcards' PARTITION(ds='2010-03-03', hr='12'); + +-- Show Table Properties +SHOW TBLPROPERTIES tblname; + +SHOW TBLPROPERTIES tblname("foo"); + +-- Show Create Table +SHOW CREATE TABLE db.tbl1; + +-- Show Indexes +-- SHOW INDEX ON idx_tbl; + +-- SHOW FORMATTED INDEXES ON idx_tbl2 FROM db_1; + +-- Show Columns +SHOW COLUMNS FROM tble; + +SHOW COLUMNS IN table_name FROM db_1 LIKE 'pattern_with_wildcards'; + +-- Show Functions +SHOW FUNCTIONS; + +SHOW FUNCTIONS LIKE ""; + +-- Show Locks +SHOW LOCKS tbl1; + +SHOW LOCKS tbl2 EXTENDED; + +SHOW LOCKS tbl3 PARTITION (ds='2010-03-03', hr='12'); + +SHOW LOCKS tbl4 PARTITION (ds='2010-03-03', hr='12') EXTENDED; + +SHOW LOCKS DATABASE db1; + +-- Show Conf +SHOW CONF 'conf1'; + +-- Show Transactions +SHOW TRANSACTIONS; + +-- Show Compactions +SHOW COMPACTIONS; + +SHOW COMPACTIONS DATABASE db1; + +SHOW COMPACTIONS tbl0; + +SHOW COMPACTIONS db1.tbl0 +PARTITION (p=101,day='Monday') +POOL 'pool0' +TYPE 'minor' +STATUS 'ready for clean' +ORDER BY cq_table DESC, cq_state +LIMIT 42; + +-- Show Roles +SHOW ROLES; + +SHOW CURRENT ROLES; + +-- Show Role Grant +SHOW ROLE GRANT USER user1; + +-- Show Principals +SHOW PRINCIPALS role1; + +-- Show Grant +SHOW GRANT USER ashutosh ON TABLE hivejiratable; + +SHOW GRANT ROLE role1 ON ALL; + +SHOW GRANT ON TABLE hivejiratable; + + + diff --git a/test/parser/hive/syntax/showStatement.test.ts b/test/parser/hive/syntax/showStatement.test.ts new file mode 100644 index 0000000..5a7bb2e --- /dev/null +++ b/test/parser/hive/syntax/showStatement.test.ts @@ -0,0 +1,16 @@ +import HiveSQL from '../../../../src/parser/hive'; +import { readSQL } from '../../../helper'; + +const parser = new HiveSQL(); + +const features = { + shows: readSQL(__dirname, 'show.sql'), +}; + +describe('Hive Show Syntax Tests', () => { + features.shows.forEach((show) => { + it(show, () => { + expect(parser.validate(show).length).toBe(0); + }); + }); +});