|
@@ -144,12 +144,15 @@ sql_parser_tests = [
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "col1"},
|
|
|
"right": {"type": "int", "value": 2},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
"right": {
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "col2"},
|
|
|
"right": {"type": "int", "value": 4},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
}
|
|
|
],
|
|
@@ -186,6 +189,7 @@ sql_parser_tests = [
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "col1"},
|
|
|
"right": {"type": "int", "value": 2},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -194,13 +198,17 @@ sql_parser_tests = [
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "col2"},
|
|
|
"right": {"type": "int", "value": 4},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
"right": {
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "col3"},
|
|
|
"right": {"type": "identifier", "value": "col2"},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
}
|
|
|
],
|
|
@@ -214,23 +222,28 @@ sql_parser_tests = [
|
|
|
"where": {
|
|
|
"type": "或",
|
|
|
"left": {
|
|
|
+ "type": "且",
|
|
|
"left": {
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "c1"},
|
|
|
"right": {"type": "int", "value": 1},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
- "type": "且",
|
|
|
"right": {
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "c2"},
|
|
|
"right": {"type": "int", "value": 3},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
"right": {
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "c3"},
|
|
|
"right": {"type": "int", "value": 3},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
}
|
|
|
],
|
|
@@ -249,6 +262,7 @@ sql_parser_tests = [
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "c1"},
|
|
|
"right": {"type": "int", "value": 1},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
"right": {
|
|
|
"type": "或",
|
|
@@ -256,26 +270,47 @@ sql_parser_tests = [
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "c2"},
|
|
|
"right": {"type": "int", "value": 3},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
"right": {
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "c3"},
|
|
|
"right": {"type": "int", "value": 3},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
"right": {
|
|
|
"type": "相等",
|
|
|
"left": {"type": "identifier", "value": "c4"},
|
|
|
"right": {"type": "string", "value": "'asd'"},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
}
|
|
|
],
|
|
|
),
|
|
|
(
|
|
|
"select * from t2;",
|
|
|
- [{'type': 'select_stmt', 'select_cols': [{'type': 'select_all_column', 'target': {'type': 'select_all_column', 'value': 'select_all_column'}}], 'table_names': ['t2'], 'where': {}}]
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "type": "select_stmt",
|
|
|
+ "select_cols": [
|
|
|
+ {
|
|
|
+ "type": "select_all_column",
|
|
|
+ "target": {
|
|
|
+ "type": "select_all_column",
|
|
|
+ "value": "select_all_column",
|
|
|
+ },
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "table_names": ["t2"],
|
|
|
+ "where": {},
|
|
|
+ }
|
|
|
+ ],
|
|
|
),
|
|
|
(
|
|
|
"select c2 as t from t2 where col1>2;",
|
|
@@ -294,6 +329,7 @@ sql_parser_tests = [
|
|
|
"type": "大于",
|
|
|
"left": {"type": "identifier", "value": "col1"},
|
|
|
"right": {"type": "int", "value": 2},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
}
|
|
|
],
|
|
@@ -319,6 +355,7 @@ sql_parser_tests = [
|
|
|
{"type": "int", "value": 1},
|
|
|
{"type": "int", "value": 2},
|
|
|
],
|
|
|
+ "op_type": "bin_contains_op",
|
|
|
},
|
|
|
"right": {
|
|
|
"type": "包含于",
|
|
@@ -328,7 +365,9 @@ sql_parser_tests = [
|
|
|
{"type": "int", "value": 4},
|
|
|
{"type": "int", "value": 5},
|
|
|
],
|
|
|
+ "op_type": "bin_contains_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
}
|
|
|
],
|
|
@@ -376,8 +415,10 @@ sql_parser_tests = [
|
|
|
"field": "Cno",
|
|
|
},
|
|
|
"right": {"type": "string", "value": "'81003'"},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
},
|
|
|
+ "op_type": "bin_contains_op",
|
|
|
},
|
|
|
}
|
|
|
],
|
|
@@ -414,12 +455,14 @@ sql_parser_tests = [
|
|
|
"field": "Sno",
|
|
|
},
|
|
|
"right": {"type": "table_field", "table": "SC", "field": "Sno"},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
},
|
|
|
"where": {
|
|
|
"type": "相等",
|
|
|
"left": {"type": "table_field", "table": "SC", "field": "Cno"},
|
|
|
"right": {"type": "string", "value": "'81003'"},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
}
|
|
|
],
|
|
@@ -462,6 +505,7 @@ sql_parser_tests = [
|
|
|
"table": "SC",
|
|
|
"field": "Sno",
|
|
|
},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
"right": {
|
|
|
"type": "相等",
|
|
@@ -471,7 +515,9 @@ sql_parser_tests = [
|
|
|
"field": "Cno",
|
|
|
},
|
|
|
"right": {"type": "string", "value": "'81003'"},
|
|
|
+ "op_type": "bin_cmp_op",
|
|
|
},
|
|
|
+ "op_type": "bin_logical_op",
|
|
|
},
|
|
|
},
|
|
|
"where": {},
|
|
@@ -484,7 +530,15 @@ sql_parser_tests = [
|
|
|
[
|
|
|
{
|
|
|
"type": "select_stmt",
|
|
|
- "select_cols": [{'type': 'select_all_column', 'target': {'type': 'select_all_column', 'value': 'select_all_column'}}],
|
|
|
+ "select_cols": [
|
|
|
+ {
|
|
|
+ "type": "select_all_column",
|
|
|
+ "target": {
|
|
|
+ "type": "select_all_column",
|
|
|
+ "value": "select_all_column",
|
|
|
+ },
|
|
|
+ }
|
|
|
+ ],
|
|
|
"table_names": ["tb1", "tb2"],
|
|
|
"where": {},
|
|
|
}
|
|
@@ -497,14 +551,59 @@ sql_checker_tests = [
|
|
|
("create table person(name string, age int, classId int);", True),
|
|
|
("select age from person;", True),
|
|
|
("select * from person;", True),
|
|
|
- ("select gender from person;", 'column `gender` not exists in `person`'),
|
|
|
+ ("select gender from person;", "column `gender` not exists in `person`"),
|
|
|
("select 123 from person;", True),
|
|
|
("drop table class;", True),
|
|
|
("create table class (id int, grade int, faculty string);", True),
|
|
|
("select * from class where grade = 2 and faculty = 'Computer Science';", True),
|
|
|
(
|
|
|
"select * from class where grade = 2 and count=33;",
|
|
|
- 'column `count` not exists in `class`',
|
|
|
+ "column `count` not exists in `class`",
|
|
|
),
|
|
|
("select age, class.grade from class, person;", True),
|
|
|
+ (
|
|
|
+ "select age, person.grade from class, person;",
|
|
|
+ "column `person.grade` not exists in `class, person`",
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ """SELECT person.name, grade, faculty
|
|
|
+ FROM person
|
|
|
+ WHERE name = '张三' and classId IN (
|
|
|
+ SELECT *
|
|
|
+ FROM class
|
|
|
+ WHERE class.id = classId
|
|
|
+ );
|
|
|
+ """,
|
|
|
+ "column `grade` not exists in `person`",
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ """select person.name
|
|
|
+ from person join class
|
|
|
+ on class.id=person.classId and person.grade=2
|
|
|
+ where age=22;
|
|
|
+ """,
|
|
|
+ "column `person.grade` not exists in `person, class`",
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ """select person.name
|
|
|
+ from person join class
|
|
|
+ on class.id=person.classId and class.grade=2
|
|
|
+ where age=22;
|
|
|
+ """,
|
|
|
+ True,
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ """select person.name
|
|
|
+ from person join class
|
|
|
+ on class.id=person.classId and class.grade = 'zxc'
|
|
|
+ where age=22;
|
|
|
+ """,
|
|
|
+ "column `class.grade` type is `int`, but `string:'zxc'` type is `string`, cannot `相等`",
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ """select person.name
|
|
|
+ from person where age>name;
|
|
|
+ """,
|
|
|
+ "column `age` type is `int`, but `name` type is `string`, cannot `大于`",
|
|
|
+ ),
|
|
|
]
|