Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public String toString() {
StringBuilder b = new StringBuilder();
b.append(expr.toString());
for (Map.Entry<Expression, String> ident : idents) {
b.append(ident.getValue()).append(ident.getKey());
// Separate the operator with spaces: without them `#>`/`#>>` glue onto
// the operand (e.g. `a#>'{b}'`), and since `#` is a legal identifier
// character the result re-parses as `a#` `>` `...` -- a different tree.
b.append(' ').append(ident.getValue()).append(' ').append(ident.getKey());
}
return b.toString();
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/net/sf/jsqlparser/expression/JsonExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package net.sf.jsqlparser.expression;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.select.PlainSelect;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -39,6 +40,21 @@ void testIssue1792() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@Test
void testHashArrowOperatorsRoundTrip() throws JSQLParserException {
// #> and #>> must survive deparse+reparse: without spaces the operator glues
// onto the object (a#>'{b}') and re-parses as the comparison a# > '{b}'.
for (String sqlStr : new String[] {"SELECT a #> '{b}' FROM t",
"SELECT a #>> '{b}' FROM t"}) {
PlainSelect st = (PlainSelect) CCJSqlParserUtil.parse(sqlStr);
Assertions.assertInstanceOf(JsonExpression.class, st.getSelectItem(0).getExpression());
PlainSelect reparsed = (PlainSelect) CCJSqlParserUtil.parse(st.toString());
Assertions.assertInstanceOf(JsonExpression.class,
reparsed.getSelectItem(0).getExpression(),
sqlStr + " deparsed to " + st);
}
}

@Test
void testSnowflakeGetOperator() throws JSQLParserException {
// https://docs.snowflake.com/en/user-guide/querying-semistructured
Expand Down
Loading