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
66 changes: 29 additions & 37 deletions src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@

public PlainSelect addGroupByColumnReference(Expression expr) {
this.groupBy = Optional.ofNullable(groupBy).orElseGet(GroupByElement::new);
this.groupBy.addGroupByExpression(expr);

Check warning on line 459 in src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java

View workflow job for this annotation

GitHub Actions / Maven Verify (macos-latest)

[deprecation] addGroupByExpression(Expression) in GroupByElement has been deprecated

Check warning on line 459 in src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java

View workflow job for this annotation

GitHub Actions / Maven Verify (ubuntu-latest)

[deprecation] addGroupByExpression(Expression) in GroupByElement has been deprecated
return this;
}

Expand Down Expand Up @@ -607,43 +607,35 @@
if (ksqlWindow != null) {
builder.append(" WINDOW ").append(ksqlWindow);
}
if (preWhere != null) {
builder.append(" PREWHERE ").append(preWhere);
}
if (where != null) {
builder.append(" WHERE ").append(where);
}
if (oracleHierarchical != null) {
builder.append(oracleHierarchical);
}
if (preferringClause != null) {
builder.append(" ").append(preferringClause);
}
if (groupBy != null) {
builder.append(" ").append(groupBy);
}
if (having != null) {
builder.append(" HAVING ").append(having);
}
if (qualify != null) {
builder.append(" QUALIFY ").append(qualify);
}
if (windowDefinitions != null) {
builder.append(" WINDOW ");
builder.append(windowDefinitions.stream().map(WindowDefinition::toString)
.collect(joining(", ")));
}
if (emitChanges) {
builder.append(" EMIT CHANGES");
}
} else {
// without from
if (preWhere != null) {
builder.append(" PREWHERE ").append(preWhere);
}
if (where != null) {
builder.append(" WHERE ").append(where);
}
}
if (preWhere != null) {
builder.append(" PREWHERE ").append(preWhere);
}
if (where != null) {
builder.append(" WHERE ").append(where);
}
if (oracleHierarchical != null) {
builder.append(oracleHierarchical);
}
if (preferringClause != null) {
builder.append(" ").append(preferringClause);
}
if (groupBy != null) {
builder.append(" ").append(groupBy);
}
if (having != null) {
builder.append(" HAVING ").append(having);
}
if (qualify != null) {
builder.append(" QUALIFY ").append(qualify);
}
if (windowDefinitions != null) {
builder.append(" WINDOW ");
builder.append(windowDefinitions.stream().map(WindowDefinition::toString)
.collect(joining(", ")));
}
if (emitChanges) {
builder.append(" EMIT CHANGES");
}
if (intoTempTable != null) {
builder.append(" INTO TEMP ").append(intoTempTable);
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,29 @@ public void testSelectFunction() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(statement);
}

@Test
public void testSelectWithoutFromRetainsWhereGroupByHaving() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT 1 WHERE 1 = 1");
PlainSelect plainSelect =
(PlainSelect) assertSqlCanBeParsedAndDeparsed("SELECT 1 GROUP BY 1 HAVING 1 = 1");
assertNotNull(plainSelect.getGroupBy());
assertNotNull(plainSelect.getHaving());
}

@Test
public void testSelectWithoutFromRetainsWindowAndQualify() throws JSQLParserException {
PlainSelect plainSelect =
(PlainSelect) assertSqlCanBeParsedAndDeparsed("SELECT 1 WINDOW w AS (ORDER BY 1)");
assertEquals(1, plainSelect.getWindowDefinitions().size());
assertSqlCanBeParsedAndDeparsed("SELECT 1 QUALIFY 1 = 1");
}

@Test
public void testSelectWithoutFromRetainsHierarchicalAndPreferring() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT 1 START WITH 1 = 1 CONNECT BY LEVEL <= 1");
assertSqlCanBeParsedAndDeparsed("SELECT 1 PREFERRING HIGH 1");
}

@Test
public void testWeirdSelect() throws JSQLParserException {
String sql =
Expand Down
Loading