Skip to content

Commit 7c74085

Browse files
author
Peter Borissow
committed
Added json parsing tests.
1 parent a550481 commit 7c74085

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/java/net/sf/jsqlparser/test/select/SelectTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,24 @@ public void testNotEqualsTo() throws JSQLParserException {
18501850

18511851
public void testJsonExpression() throws JSQLParserException {
18521852
assertSqlCanBeParsedAndDeparsed("SELECT data->'images'->'thumbnail'->'url' AS thumb FROM instagram");
1853+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM sales WHERE sale->'items'->>'description' = 'milk'");
1854+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM sales WHERE sale->'items'->>'quantity' = 12::TEXT");
1855+
//assertSqlCanBeParsedAndDeparsed("SELECT * FROM sales WHERE CAST(sale->'items'->>'quantity' AS integer) = 2");
1856+
assertSqlCanBeParsedAndDeparsed("SELECT SUM(CAST(sale->'items'->>'quantity' AS integer)) AS total_quantity_sold FROM sales");
1857+
assertSqlCanBeParsedAndDeparsed("SELECT sale->>'items' FROM sales");
1858+
assertSqlCanBeParsedAndDeparsed("SELECT json_typeof(sale->'items'), json_typeof(sale->'items'->'quantity') FROM sales");
1859+
1860+
1861+
//The following staments can be parsed but not deparsed
1862+
for (String statement : new String[]{
1863+
"SELECT doc->'site_name' FROM websites WHERE doc @> '{\"tags\":[{\"term\":\"paris\"}, {\"term\":\"food\"}]}'",
1864+
"SELECT * FROM sales where sale ->'items' @> '[{\"count\":0}]'",
1865+
"SELECT * FROM sales where sale ->'items' ? 'name'",
1866+
"SELECT * FROM sales where sale ->'items' -# 'name'"
1867+
}){
1868+
Select select = (Select) parserManager.parse(new StringReader(statement));
1869+
assertStatementCanBeDeparsedAs(select, statement, true);
1870+
}
18531871
}
18541872

18551873
public void testSelectInto1() throws JSQLParserException {

0 commit comments

Comments
 (0)