Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: spark DML test #169

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/parser/spark/syntax/fixtures/insertIntoTable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- Syntax
-- INSERT INTO [ TABLE ] table_identifier REPLACE WHERE boolean_expression query


-- Single Row Insert Using a VALUES Clause
INSERT INTO students VALUES ('Amy Smith', '123 Park Ave, San Jose', 111, 12.34, '-=--@#!$%%');

-- Multi-Row Insert Using a VALUES Clause
INSERT INTO students VALUES ('Bob Brown', '456 Taylor St, Cupelation', 222222), ('Cathy Johnson', '789 Race Ave, Pale Alto', 333333);

-- Insert Using a SELECT Statement
INSERT INTO students PARTITION (student_id = 444444) SELECT name, address FROM persons WHERE name = "Dora Williams";

-- Insert Using a REPLACE WHERE Statement
INSERT INTO persons REPLACE WHERE ssn = 123456789 SELECT * FROM persons2;

-- Insert Using a TABLE Statement
INSERT INTO students TABLE visiting_students;

-- Insert Using a FROM Statement
INSERT INTO students FROM applicants SELECT name, address, student_id WHERE qualified = true;

-- Insert Using a Typed Date Literal for a Partition Column Value
INSERT INTO students PARTITION (birthday = date'2019-01-02') VALUES ('Amy Smith', '123 Park Ave, San Jose');

-- Insert with a column list
INSERT INTO students (address, name, student_id) VALUES ('Hangzhou, China', 'Kent Yao', 11215016);

-- Insert with both a partition spec and a column list
INSERT INTO students PARTITION (student_id = 11215017) (address, name) VALUES ('Hangzhou, China', 'Kent Yao Jr.');
29 changes: 29 additions & 0 deletions test/parser/spark/syntax/fixtures/insertOverwriteDirectory.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Syntax
-- INSERT OVERWRITE [ LOCAL ] DIRECTORY [ directory_path ]
-- { spark_format | hive_format }
-- { VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query }
-- USING file_format [ OPTIONS ( key = val [ , ... ] ) ]
-- [ ROW FORMAT row_format ] [ STORED AS hive_serde ]


INSERT OVERWRITE DIRECTORY '/path/to/output/directory' SELECT * FROM your_table WHERE condition;

INSERT OVERWRITE DIRECTORY '/tmp/destination'
USING parquet
OPTIONS (col1 1, col2 2, col3 'test')
SELECT * FROM test_table;

INSERT OVERWRITE DIRECTORY
USING parquet
OPTIONS ('path' '/tmp/destination', col1 1, col2 2, col3 'test')
SELECT * FROM test_table;

INSERT OVERWRITE LOCAL DIRECTORY '/tmp/destination'
USING parquet
OPTIONS (col1 1, col2 2, col3 'test')
SELECT * FROM test_table;

INSERT OVERWRITE LOCAL DIRECTORY
USING parquet
OPTIONS ('path' '/tmp/destination', col1 1, col2 2, col3 'test')
SELECT * FROM test_table;
24 changes: 24 additions & 0 deletions test/parser/spark/syntax/fixtures/insertOverwriteTable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Syntax
-- INSERT [ INTO | OVERWRITE ] [ TABLE ] table_identifier [ partition_spec ] [ ( column_list ) ] { VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query }


-- Insert Using a VALUES Clause
INSERT OVERWRITE students VALUES ('Ashur Hill', '456 Erica Ct, Cupelation', 111111), ('Brian Reed', '723 Kern Ave, Pale Alto', 222222);

-- Insert Using a SELECT Statement
INSERT OVERWRITE students PARTITION (student_id = 222222) SELECT name, address FROM persons WHERE name = "Dora Williams";

-- Insert Using a TABLE Statement
INSERT OVERWRITE students TABLE visiting_students;

-- Insert Using a FROM Statement
INSERT OVERWRITE students FROM applicants SELECT name, address, student_id WHERE qualified = true;

-- Insert Using a Typed Date Literal for a Partition Column Value
INSERT OVERWRITE students PARTITION (birthday = date'2019-01-02') VALUES('Jason Wang', '908 Bird St, Saratoga');

-- Insert with a column list
INSERT OVERWRITE students (address, name, student_id) VALUES ('Hangzhou, China', 'Kent Yao', 11215016);

-- Insert with both a partition spec and a column list
INSERT OVERWRITE students PARTITION (student_id = 11215016) (address, name) VALUES ('Hangzhou, China', 'Kent Yao Jr.');
11 changes: 11 additions & 0 deletions test/parser/spark/syntax/fixtures/loadData.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Syntax
-- LOAD DATA [ LOCAL ] INPATH path [ OVERWRITE ] INTO TABLE table_identifier [ partition_spec ]


-- Assuming the students table is in '/user/hive/warehouse/'
LOAD DATA LOCAL INPATH '/user/hive/warehouse/students' OVERWRITE INTO TABLE test_load;
LOAD DATA LOCAL INPATH '/path/to/datafile.csv' INTO TABLE my_table;
LOAD DATA INPATH '/path/to/datafile.csv' INTO TABLE my_table;

-- Assuming the test_partition table is in '/user/hive/warehouse/'
LOAD DATA LOCAL INPATH '/user/hive/warehouse/test_partition/c2=2/c3=3' OVERWRITE INTO TABLE test_load_partition PARTITION (c2=2, c3=3);
22 changes: 22 additions & 0 deletions test/parser/spark/syntax/insertStatement.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SparkSQL from '../../../../src/parser/spark';
import { readSQL } from '../../../helper';


const parser = new SparkSQL();

const features = {
insertIntoTable: readSQL(__dirname, 'insertIntoTable.sql'),
insertOverwriteTable: readSQL(__dirname, 'insertOverwriteTable.sql'),
insertOverwriteDirectory: readSQL(__dirname, 'insertOverwriteDirectory.sql'),
loadData: readSQL(__dirname, 'loadData.sql'),
};

describe('SparkSQL Insert Syntax Tests', () => {
Object.keys(features).forEach((key) => {
features[key].forEach((sql) => {
it(sql, () => {
expect(parser.validate(sql).length).toBe(0);
});
});
});
});
19 changes: 19 additions & 0 deletions test/parser/spark/syntax/loadStatement.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import SparkSQL from '../../../../src/parser/spark';
import { readSQL } from '../../../helper';


const parser = new SparkSQL();

const features = {
loadData: readSQL(__dirname, 'loadData.sql'),
};

describe('SparkSQL Insert Syntax Tests', () => {
Object.keys(features).forEach((key) => {
features[key].forEach((sql) => {
it(sql, () => {
expect(parser.validate(sql).length).toBe(0);
});
});
});
});
Loading