Skip to content

Commit

Permalink
fix error when sql select from more than one table
Browse files Browse the repository at this point in the history
  • Loading branch information
qidi1 committed Oct 8, 2023
1 parent b0d5783 commit acfab5a
Show file tree
Hide file tree
Showing 12 changed files with 3,976 additions and 3,930 deletions.
7 changes: 6 additions & 1 deletion sqlgpt_parser/parser/mysql_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ def p_table_primary(p):
r"""table_primary : aliased_relation
| derived_table
| LPAREN relations RPAREN"""
if len(p) == 3:
if len(p) == 4:
p[0] = p[2]
else:
p[0] = p[1]
Expand Down Expand Up @@ -2950,6 +2950,7 @@ def p_non_reserved(p):
| CELIING
| CEIL
| CEILING
| CHARACTER
| CHARACTER_LENGTH
| CHAR_LENGTH
| COERCIBILITY
Expand Down Expand Up @@ -3061,12 +3062,14 @@ def p_non_reserved(p):
| LOG
| LOG10
| LOG2
| LONG
| LOWER
| LPAD
| LTRIM
| MAKEDATE
| MAKE_SET
| MASTER_POS_WAIT
| MATCH
| MD5
| MID
| MONTHNAME
Expand All @@ -3088,6 +3091,7 @@ def p_non_reserved(p):
| POWER
| QUOTE
| RANDOM_BYTES
| RANGE
| RANK
| READS
| REDOFILE
Expand Down Expand Up @@ -3380,6 +3384,7 @@ def p_not_keyword_token(p):
| SERIALIZABLE
| SESSION
| SHARE
| SHOW
| SHUTDOWN
| SIGN
| SIGNED
Expand Down
2,137 changes: 1,071 additions & 1,066 deletions sqlgpt_parser/parser/mysql_parser/parser_table.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions sqlgpt_parser/parser/mysql_parser/reserved.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,6 @@
'CAST',
'CHANGE',
'CHAR',
'CHARACTER',
'CHECK',
'COLLATE',
'CONCAT',
Expand Down Expand Up @@ -851,11 +850,9 @@
'LOCALTIME',
'LOCALTIMESTAMP',
'LOCK',
'LONG',
'LONGBLOB',
'LONGTEXT',
'LOW_PRIORITY',
'MATCH',
'MAXVALUE',
'MEDIUMBLOB',
'MEDIUMINT',
Expand Down Expand Up @@ -886,7 +883,6 @@
'PROCEDURE',
'RADIANS',
'RAND',
'RANGE',
'READ',
'REAL',
'RECURSIVE',
Expand All @@ -906,7 +902,6 @@
'SECOND_MICROSECOND',
'SELECT',
'SET',
'SHOW',
'SIGNAL',
'SIN',
'SMALLINT',
Expand Down Expand Up @@ -990,6 +985,7 @@
'CELIING',
'CEIL',
'CEILING',
'CHARACTER',
'CHARACTER_LENGTH',
'CHAR_LENGTH',
'COERCIBILITY',
Expand Down Expand Up @@ -1102,6 +1098,7 @@
'LOG',
'LOG10',
'LOG2',
'LONG',
'LOWER',
'LPAD',
'LTRIM',
Expand Down Expand Up @@ -1131,6 +1128,7 @@
'POWER',
'QUOTE',
'RANDOM_BYTES',
'RANGE',
'RANK',
'READS',
'REDOFILE',
Expand Down Expand Up @@ -1341,6 +1339,7 @@
"LOCKED",
"LOGS",
"MASTER",
'MATCH',
'MAX',
"MAX_ROWS",
"MB",
Expand Down Expand Up @@ -1420,6 +1419,7 @@
"SERIALIZABLE",
"SESSION",
"SHARE",
'SHOW',
"SHUTDOWN",
'SIGN',
"SIGNED",
Expand Down
7 changes: 6 additions & 1 deletion sqlgpt_parser/parser/oceanbase_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ def p_table_primary(p):
r"""table_primary : aliased_relation
| derived_table
| LPAREN relations RPAREN"""
if len(p) == 3:
if len(p) == 4:
p[0] = p[2]
else:
p[0] = p[1]
Expand Down Expand Up @@ -3082,6 +3082,7 @@ def p_non_reserved(p):
| CEILING
| CHAIN
| CHANGED
| CHARACTER
| CHARACTER_LENGT
| CHARACTER_LENGTH
| CHARSET
Expand Down Expand Up @@ -3393,6 +3394,7 @@ def p_non_reserved(p):
| LOGFILE
| LOGONLY_REPLICA_NUM
| LOGS
| LONG
| LONGB
| LOOP
| LOWER
Expand Down Expand Up @@ -3427,6 +3429,7 @@ def p_non_reserved(p):
| MASTER_SSL_KEY
| MASTER_SSL_VERIFY_SERVER_CERT
| MASTER_USER
| MATCH
| MATCHED
| MATERIALIZED
| MAX
Expand Down Expand Up @@ -3575,6 +3578,7 @@ def p_non_reserved(p):
| R32
| RANDOM
| RANDOM_BYTES
| RANGE
| RANK
| READS
| READ_ONLY
Expand Down Expand Up @@ -3675,6 +3679,7 @@ def p_non_reserved(p):
| SHA1
| SHA2
| SHARE
| SHOW
| SHUTDOWN
| SKIP
| SIGN
Expand Down
2,837 changes: 1,421 additions & 1,416 deletions sqlgpt_parser/parser/oceanbase_parser/parser_table.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions sqlgpt_parser/parser/oceanbase_parser/reserved.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@
'CASE',
'CHANGE',
'CHAR',
'CHARACTER',
'CHECK',
'COLLATE',
'CONCAT',
Expand Down Expand Up @@ -846,11 +845,9 @@
'LOCALTIME',
'LOCALTIMESTAMP',
'LOCK',
'LONG',
'LONGBLOB',
'LONGTEXT',
'LOW_PRIORITY',
'MATCH',
'MAXVALUE',
'MEDIUMBLOB',
'MEDIUMINT',
Expand Down Expand Up @@ -881,7 +878,6 @@
'PROCEDURE',
'RADIANS',
'RAND',
'RANGE',
'READ',
'REAL',
'RECURSIVE',
Expand All @@ -901,7 +897,6 @@
'SECOND_MICROSECOND',
'SELECT',
'SET',
'SHOW',
'SIGNAL',
'SIN',
'SMALLINT',
Expand Down Expand Up @@ -1041,6 +1036,7 @@
'CEILING',
'CHAIN',
'CHANGED',
'CHARACTER',
'CHARACTER_LENGT',
'CHARACTER_LENGTH',
'CHARSET',
Expand Down Expand Up @@ -1354,6 +1350,7 @@
'LOGFILE',
'LOGONLY_REPLICA_NUM',
'LOGS',
'LONG',
'LONGB',
'LOOP',
'LOWER',
Expand Down Expand Up @@ -1388,6 +1385,7 @@
'MASTER_SSL_KEY',
'MASTER_SSL_VERIFY_SERVER_CERT',
'MASTER_USER',
'MATCH',
'MATCHED',
'MATERIALIZED',
'MAX',
Expand Down Expand Up @@ -1538,6 +1536,7 @@
'R32',
'RANDOM',
'RANDOM_BYTES',
'RANGE',
'RANK',
'RAWTOHEX',
'READS',
Expand Down Expand Up @@ -1641,6 +1640,7 @@
'SHA1',
'SHA2',
'SHARE',
'SHOW',
'SHUTDOWN',
'SKIP',
'SIGN',
Expand Down
7 changes: 6 additions & 1 deletion sqlgpt_parser/parser/odps_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ def p_table_primary(p):
r"""table_primary : aliased_relation
| derived_table
| LPAREN relations RPAREN"""
if len(p) == 3:
if len(p) == 4:
p[0] = p[2]
else:
p[0] = p[1]
Expand Down Expand Up @@ -3088,6 +3088,7 @@ def p_non_reserved(p):
| CEILING
| CHAIN
| CHANGED
| CHARACTER
| CHARACTER_LENGT
| CHARACTER_LENGTH
| CHARSET
Expand Down Expand Up @@ -3399,6 +3400,7 @@ def p_non_reserved(p):
| LOGFILE
| LOGONLY_REPLICA_NUM
| LOGS
| LONG
| LONGB
| LOOP
| LOWER
Expand Down Expand Up @@ -3433,6 +3435,7 @@ def p_non_reserved(p):
| MASTER_SSL_KEY
| MASTER_SSL_VERIFY_SERVER_CERT
| MASTER_USER
| MATCH
| MATCHED
| MATERIALIZED
| MAX
Expand Down Expand Up @@ -3583,6 +3586,7 @@ def p_non_reserved(p):
| RANDOM
| RANDOM_BYTES
| RANK
| RANGE
| READS
| READ_ONLY
| READ_WRITE
Expand Down Expand Up @@ -3682,6 +3686,7 @@ def p_non_reserved(p):
| SHA1
| SHA2
| SHARE
| SHOW
| SHUTDOWN
| SKIP
| SIGN
Expand Down
2,839 changes: 1,422 additions & 1,417 deletions sqlgpt_parser/parser/odps_parser/parser_table.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions sqlgpt_parser/parser/odps_parser/reserved.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@
'PREPARE',
'PRIMARY',
'PROCEDURE',
'RANGE',
'READS',
'REAL',
'RECURSIVE',
Expand Down Expand Up @@ -742,7 +741,6 @@
'CASE',
'CHANGE',
'CHAR',
'CHARACTER',
'CHECK',
'COLLATE',
'CONCAT',
Expand Down Expand Up @@ -846,11 +844,9 @@
'LOCALTIME',
'LOCALTIMESTAMP',
'LOCK',
'LONG',
'LONGBLOB',
'LONGTEXT',
'LOW_PRIORITY',
'MATCH',
'MAXVALUE',
'MEDIUMBLOB',
'MEDIUMINT',
Expand Down Expand Up @@ -901,7 +897,6 @@
'SECOND_MICROSECOND',
'SELECT',
'SET',
'SHOW',
'SIGNAL',
'SIN',
'SMALLINT',
Expand Down Expand Up @@ -1041,6 +1036,7 @@
'CEILING',
'CHAIN',
'CHANGED',
'CHARACTER',
'CHARACTER_LENGT',
'CHARACTER_LENGTH',
'CHARSET',
Expand Down Expand Up @@ -1354,6 +1350,7 @@
'LOGFILE',
'LOGONLY_REPLICA_NUM',
'LOGS',
'LONG',
'LONGB',
'LOOP',
'LOWER',
Expand Down Expand Up @@ -1388,6 +1385,7 @@
'MASTER_SSL_KEY',
'MASTER_SSL_VERIFY_SERVER_CERT',
'MASTER_USER',
'MATCH',
'MATCHED',
'MATERIALIZED',
'MAX',
Expand Down Expand Up @@ -1539,6 +1537,7 @@
'R32',
'RANDOM',
'RANDOM_BYTES',
'RANGE',
'RANK',
'RAWTOHEX',
'READS',
Expand Down Expand Up @@ -1642,6 +1641,7 @@
'SHA1',
'SHA2',
'SHARE',
'SHOW',
'SHUTDOWN',
'SKIP',
'SIGN',
Expand Down
11 changes: 9 additions & 2 deletions sqlgpt_parser/parser/parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,16 @@ def visit_query_specification(self, node, context):
| ParserUtils.CollectInfo.COLLECT_MIN_MAX_EXPRESSION_COLUMN
)
self.process(node.select, context)
context = ParserUtils.CollectInfo.COLLECT_TABLE
context = (
ParserUtils.CollectInfo.COLLECT_TABLE
| ParserUtils.CollectInfo.COLLECT_FILTER_COLUMN
)
if node.from_:
self.process(node.from_, context)
if isinstance(node.from_, list):
for item in node.from_:
self.process(item, context)
else:
self.process(node.from_, context)
context = (
ParserUtils.CollectInfo.COLLECT_IN_EXPRESSION_COLUMN
| ParserUtils.CollectInfo.COLLECT_FILTER_COLUMN
Expand Down
Loading

0 comments on commit acfab5a

Please sign in to comment.