alibaba / alibaba/cobar

SQLParserDelegate不能解析DDL语句中的FOREIGN KEY

Open
#83 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.2k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

```
CREATE TABLE IF NOT EXISTS `test_table_normal`(
scoreID INTEGER NOT NULL PRIMARY KEY,
stuID INTEGER NOT NULL,
KEMUID INTEGER NOT NULL,
score FLOAT,
FOREIGN KEY SCORE_ID_FK (stuID) REFERENCES students (stuid),
CONSTRAINT CHK_SCORE_ZIP CHECK (SCORE > 0)
);
```
```
ALTER TABLE test_table_normal
ADD FOREIGN KEY (stuID)
REFERENCES Persons(stuID);
```
报错:
```
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; Error occurs around this fragment: {FLOAT,
FOREIGN KEY SCORE}. Error cause: unsupportted column definition
at com.alibaba.cobar.parser.recognizer.SQLParserDelegate.parse(SQLParserDelegate.java:155)
at com.alibaba.cobar.parser.recognizer.SQLParserDelegate.parse(SQLParserDelegate.java:160)
at com.alibaba.cobar.parser.recognizer.SQLParserDelegate.parse(SQLParserDelegate.java:164)
at com.alibaba.cobar.parser.recognizer.SQLParserDelegateTest.testCreateAndDropTable(SQLParserDelegateTest.java:157)
```

Contributor guide

Open the contributing guide

Research direction

Start with SQLParserDelegate.java around the reported parse failure at line 155, then inspect SQLParserDelegateTest.java and testCreateAndDropTable around line 157. Run the supplied CREATE TABLE and ALTER TABLE statements as regression cases; done means both FOREIGN KEY forms parse without the unsupported column definition error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.