-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add support for TableFunction [WITH OFFSET|ORDINALITY] #2219
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
Changes from 3 commits
348e82f
78dc700
bf1892e
6549bcb
a066a96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -545,6 +545,8 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */ | |
| <K_WHERE:"WHERE"> | ||
| <K_WINDOW:"WINDOW"> | ||
| <K_WITH:"WITH"> | ||
| <K_WITH_OFFSET:"WITH OFFSET"> | ||
| <K_WITH_ORDINALITY:"WITH ORDINALITY"> | ||
| <K_WITH_TIES:"WITH TIES"> | ||
| <K_WITHIN:"WITHIN"> | ||
| <K_WITHOUT:"WITHOUT"> | ||
|
@@ -6636,14 +6638,20 @@ TableFunction TableFunction(): | |
Token prefix = null; | ||
Function function; | ||
TableFunction functionItem; | ||
Token withClause = null; | ||
} | ||
{ | ||
[ prefix = <K_LATERAL> ] | ||
function=Function() | ||
[ withClause = <K_WITH_OFFSET> | withClause = <K_WITH_ORDINALITY> ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ <K_WITH> ( withClause = <K_OFFSET> | withClause = <K_ORDINALITY> ) ] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried changing to this, but there is a new test failing:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the issue, I needed to add ORDINALITY to the restricted SQL2016 keywords There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please see here for an explanation: https://manticore-projects.com/JSQLParser/contribution.html#manage-reserved-keywords I don't think, we need to reserve those keywords but only whitelist them properly by running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made those changes, and pushed up. Thank you |
||
{ | ||
return prefix!=null | ||
? new TableFunction(prefix.image, function) | ||
: new TableFunction(function); | ||
? withClause!=null | ||
? new TableFunction(prefix.image, function, withClause.image) | ||
: new TableFunction(prefix.image, function) | ||
: withClause!=null | ||
? new TableFunction(function, withClause.image) | ||
: new TableFunction(function); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
import net.sf.jsqlparser.JSQLParserException; | ||
import net.sf.jsqlparser.test.TestUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
@@ -47,4 +49,14 @@ void testTableFunctionWithNamedParameterWhereNameIsOuterKeyword() throws JSQLPar | |
" lateral flatten(input => i.DATA_VALUE:Friends, outer => true) AS f1;"; | ||
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); | ||
} | ||
|
||
@ParameterizedTest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
@ValueSource(strings = { | ||
"WITH OFFSET", | ||
"WITH ORDINALITY" | ||
}) | ||
void testTableFunctionWithSupportedWithClauses(String withClause) throws JSQLParserException { | ||
String sqlStr = "SELECT * FROM UNNEST(ARRAY[1, 2, 3]) " + withClause + " AS t(a, b)"; | ||
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the compound token. Just
WITH
andORDINALITY
/ The goal must be to define as few tokens as possible.