Skip to content

Json functions #1263

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

Merged
merged 10 commits into from
Jul 16, 2021
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
3 changes: 3 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ under the License.
<rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary" />
<rule ref="category/java/errorprone.xml/UnusedNullCheckInEquals" />
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" />

<!-- for Codazy -->
<rule ref="category/java/errorprone.xml/MissingBreakInSwitch" />

<rule ref="category/java/multithreading.xml/AvoidThreadGroup" />
<rule ref="category/java/multithreading.xml/DontCallThreadRun" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void setIgnoreNulls(boolean ignoreNulls) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity", "PMD.MissingBreakInSwitch"})
public String toString() {
StringBuilder b = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,8 @@ public interface ExpressionVisitor {
void visit(XMLSerializeExpr aThis);

void visit(TimezoneExpression aThis);

void visit(JsonAggregateFunction aThis);

void visit(JsonFunction aThis);
}
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,24 @@ public void visit(XMLSerializeExpr expr) {
public void visit(TimezoneExpression expr) {
expr.getLeftExpression().accept(this);
}

@Override
public void visit(JsonAggregateFunction expression) {
Expression expr = expression.getExpression();
if (expr!=null) {
expr.accept(this);
}

expr = expression.getFilterExpression();
if (expr!=null) {
expr.accept(this);
}
}

@Override
public void visit(JsonFunction expression) {
for (JsonFunctionExpression expr: expression.getExpressions()) {
expr.getExpression().accept(this);
}
}
}
140 changes: 140 additions & 0 deletions src/main/java/net/sf/jsqlparser/expression/FilterOverImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression;

import java.util.List;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.select.OrderByElement;

/**
*
* @author tw
*/
public class FilterOverImpl extends ASTNodeAccessImpl {
private final OrderByClause orderBy = new OrderByClause();
private final PartitionByClause partitionBy = new PartitionByClause();
private AnalyticType analyticType = AnalyticType.FILTER_ONLY;
private Expression filterExpression = null;
private WindowElement windowElement = null;

public AnalyticType getAnalyticType() {
return analyticType;
}

public void setAnalyticType(AnalyticType analyticType) {
this.analyticType = analyticType;
}

public FilterOverImpl withAnalyticType(AnalyticType analyticType) {
this.setAnalyticType(analyticType);
return this;
}

public List<OrderByElement> getOrderByElements() {
return orderBy.getOrderByElements();
}

public void setOrderByElements(List<OrderByElement> orderByElements) {
orderBy.setOrderByElements(orderByElements);
}

public FilterOverImpl withOrderByElements(List<OrderByElement> orderByElements) {
this.setOrderByElements(orderByElements);
return this;
}

public ExpressionList getPartitionExpressionList() {
return partitionBy.getPartitionExpressionList();
}

public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
setPartitionExpressionList(partitionExpressionList, false);
}

public void setPartitionExpressionList(ExpressionList partitionExpressionList, boolean brackets) {
partitionBy.setPartitionExpressionList(partitionExpressionList, brackets);
}

public boolean isPartitionByBrackets() {
return partitionBy.isBrackets();
}

public Expression getFilterExpression() {
return filterExpression;
}

public void setFilterExpression(Expression filterExpression) {
this.filterExpression = filterExpression;
}


public FilterOverImpl withFilterExpression(Expression filterExpression) {
this.setFilterExpression(filterExpression);
return this;
}

public WindowElement getWindowElement() {
return windowElement;
}

public void setWindowElement(WindowElement windowElement) {
this.windowElement = windowElement;
}

public FilterOverImpl withWindowElement(WindowElement windowElement) {
this.setWindowElement(windowElement);
return this;
}

@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity", "PMD.MissingBreakInSwitch"})
public StringBuilder append(StringBuilder builder) {
if (filterExpression != null) {
builder.append("FILTER (WHERE ");
builder.append(filterExpression.toString());
builder.append(")");
if (analyticType != AnalyticType.FILTER_ONLY) {
builder.append(" ");
}
}

switch (analyticType) {
case FILTER_ONLY:
return builder;
case WITHIN_GROUP:
builder.append("WITHIN GROUP");
break;
default:
builder.append("OVER");
}
builder.append(" (");

partitionBy.toStringPartitionBy(builder);
orderBy.toStringOrderByElements(builder);

if (windowElement != null) {
if (orderBy.getOrderByElements() != null) {
builder.append(' ');
}
builder.append(windowElement);
}

builder.append(")");

return builder;
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
StringBuilder builder = new StringBuilder();
return append(builder).toString();
}
}
Loading