-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[BUG] JSQLParser 5.1: PostgreSQL: fail to parse dollar-quoted string constants with tags #2233
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
Comments
@E1izabeth: thank you for reporting, I will look into this asap. |
Greetings. "Dollar quoting" is actually supported and the following works: select
$$
[
{"some":"json","with":"properties"},
{"other":"json","with":"properties"}
]
$$::jsonb What is missing is the support for the "optional tag" and I do wonder if this ever has worked (not arguing though). So I will have to look for a solution to extend this token. |
Thanks |
@E1izabeth: I dived deep into this issue and unfortunately I can not offer much hope here:
-- this works
select $tag$this is a test $tag$ -- this works but alters the content
select $tag$this
is
a
test
$tag$ So the statement will be parsed and return the correct AST. But content of the String Value can't be guaranteed. This gets us back to item 1) It never worked but failed faster. Best and cheers! |
@manticore-projects thank you so much for your effort and responsiveness |
I am still fighting to get this white space right ... |
How cool is this one: @Test
void testDollarQuotedText() throws JSQLParserException {
String sqlStr = "SELECT $tag$This\nis\na\ntest\n$tag$ from dual where a=b";
PlainSelect st = (PlainSelect) CCJSqlParserUtil.parse(sqlStr);
StringValue stringValue = st.getSelectItem(0).getExpression(StringValue.class);
Assertions.assertEquals("This\nis\na\ntest\n", stringValue.getValue());
} Now, unfortunately I am battling with some collisions with other valid syntax, mainly |
Unfortunately I have only bad news:
We are using too many tokens and are pretty much at the end of JavaCC 7 here and I will have to test/decide if switching to JavaCC 8 or CongoCC can solve this challenge. That would be a "next version" though, after releasing the current JSQLParser 5.2. So what are our possible instant options here: a) this has never worked before, but just failed instantly while now it hangs (based on support of --> I can help you by showing how to run JSQLParser supervised so it will fail within definable timeout. This should be done anyway since also other complex statements can freeze. b) or I can provide a If you have any better idea, please do let me know. |
I see. Thank you.
For option |
On 1) ExecutorService executorService = Executors.newSingleThreadExecutor();
final CCJSqlParser parser = new CCJSqlParser(sqlStr)
.withSquareBracketQuotation(false)
.withAllowComplexParsing(true)
.withBackslashEscapeCharacter(false);
Future<Statements> future = executorService.submit(new Callable<Statements>() {
@Override
public Statements call() throws ParseException {
return parser.Statements();
}
});
try {
future.get(6000, TimeUnit.MILLISECONDS);
long endMillis = System.currentTimeMillis();
System.out.println("Time to parse [ms]: " + (endMillis - startMillis) / i);
} catch (TimeoutException | InterruptedException ex2) {
parser.interrupted = true;
future.cancel(true);
throw new JSQLParserException("Failed to within reasonable time ", ex2);
} Or simply: CCJSqlParserUtil.parse(String sql, ExecutorService executorService, Consumer<CCJSqlParser> consumer); |
Thank you! We'll modify according to your suggestions. |
Greetings @E1izabeth I have started a JavaCC 8 based development branch and I can confirm that JavaCC 8 lift the restrictions on defining tokens and allows us to expand the grammar. This will allow us to incorporate the Dollar-quoted tags above, tests have been positive. Unfortunately, some of the Token internals have changed and right now rewriting of Tokens (used for T-SQL bracket-quoting and advanced escaping) does not work. So all of this will need extra work and will take some time, but I won't give up on it. |
Hi, @manticore-projects!
It would be great if you could provide us with any branch or snapshot when it becomes possible. |
Sure, I am down to 54 failing tests out of 2,900 tests in total. JavaCC 8 based branch: https://github.com/JSQLParser/JSqlParser/tree/javacc8 |
Thanks |
DBeaver licenses are welcome :-) |
@E1izabeth Compliments! I have fixed a massive performance regression in released JSQLParser-5.2 and have added proper JHM benchmarks for avoiding just mischief in the future. Please see https://github.com/JSQLParser/JSqlParser#performance You can use JSQLParser-5.3 Snapshot as a drop-in hotfix. It does not change anything except performance and is fully compatible. I will work in parallel on releasing a hotfix asap but its NOT in my control. Any questions or concerns, please just ask. |
Thank you! |
The parser fails to parse dollar-quoted string constants with tags (see https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING)
SQL example:
The error I get:
However, replacing dollar-quotes
$json$
with single quotes'
or removing the tag (to leave only double dollar$$
) works.Software Information:
Additional information
It used to be supported in JSQLParser 4.5
Connected issue in DBeaver dbeaver/dbeaver#37028
The text was updated successfully, but these errors were encountered: