Skip to content

Commit

Permalink
fix sonar issue
Browse files Browse the repository at this point in the history
Signed-off-by: maggie-zhu <[email protected]>
  • Loading branch information
maggie-zhu committed Jan 22, 2025
1 parent 7bdb70f commit 082ebbd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,22 @@
// limitations under the License.
package com.starrocks.connector.parser.pinot;

import com.starrocks.analysis.AnalyticExpr;
import com.starrocks.analysis.AnalyticWindow;
import com.starrocks.analysis.ArithmeticExpr;
import com.starrocks.analysis.Expr;
import com.starrocks.analysis.FunctionCallExpr;
import com.starrocks.analysis.FunctionName;
import com.starrocks.analysis.FunctionParams;
import com.starrocks.analysis.HintNode;
import com.starrocks.analysis.IntLiteral;
import com.starrocks.analysis.OrderByElement;
import com.starrocks.analysis.ParseNode;
import com.starrocks.sql.ast.Identifier;
import com.starrocks.sql.ast.QualifiedName;
import com.starrocks.sql.parser.NodePosition;
import com.starrocks.sql.parser.StarRocksParser;
import com.starrocks.sql.parser.SyntaxSugars;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;

import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;

import static java.util.stream.Collectors.toList;

public class AstBuilder extends com.starrocks.sql.parser.AstBuilder {

protected AstBuilder(long sqlMode) {
Expand Down Expand Up @@ -82,45 +71,4 @@ public ParseNode visitSimpleFunctionCall(StarRocksParser.SimpleFunctionCallConte
return SyntaxSugars.parse(functionCallExpr);
}
}

private AnalyticExpr buildOverClause(FunctionCallExpr functionCallExpr, StarRocksParser.OverContext context,
NodePosition pos) {
functionCallExpr.setIsAnalyticFnCall(true);
List<OrderByElement> orderByElements = new ArrayList<>();
if (context.ORDER() != null) {
orderByElements = visit(context.sortItem(), OrderByElement.class);
}
List<Expr> partitionExprs = visit(context.partition, Expr.class);
return new AnalyticExpr(functionCallExpr, partitionExprs, orderByElements,
(AnalyticWindow) visitIfPresent(context.windowFrame()),
context.bracketHint() == null ? null : context.bracketHint().identifier().stream()
.map(RuleContext::getText).collect(toList()), pos);
}

private ParseNode visitIfPresent(ParserRuleContext context) {
if (context != null) {
return visit(context);
} else {
return null;
}
}

private QualifiedName getQualifiedName(StarRocksParser.QualifiedNameContext context) {
List<String> parts = new ArrayList<>();
NodePosition pos = createPos(context);
for (ParseTree c : context.children) {
if (c instanceof TerminalNode) {
TerminalNode t = (TerminalNode) c;
if (t.getSymbol().getType() == StarRocksParser.DOT_IDENTIFIER) {
parts.add(t.getText().substring(1));
}
} else if (c instanceof StarRocksParser.IdentifierContext) {
StarRocksParser.IdentifierContext identifierContext = (StarRocksParser.IdentifierContext) c;
Identifier identifier = (Identifier) visit(identifierContext);
parts.add(identifier.getValue());
}
}

return QualifiedName.of(parts, pos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static double getMultiplier(String outputTimeUnitStr) {
}

public static String[] parseDateFormat(String pattern) {
String regex = "^(.*?)( tz\\((.*?)\\))?$";
String regex = "^([\\d\\- :yMdHm]{10,16})( tz\\((.*?)\\))?$";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(pattern);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7205,7 +7205,7 @@ public ParseNode visitWindowFunction(StarRocksParser.WindowFunctionContext conte
return functionCallExpr;
}

private AnalyticExpr buildOverClause(FunctionCallExpr functionCallExpr, StarRocksParser.OverContext context,
protected AnalyticExpr buildOverClause(FunctionCallExpr functionCallExpr, StarRocksParser.OverContext context,
NodePosition pos) {
functionCallExpr.setIsAnalyticFnCall(true);
List<OrderByElement> orderByElements = new ArrayList<>();
Expand Down Expand Up @@ -8279,7 +8279,7 @@ private TableName getTableName(StarRocksParser.QualifiedNameContext context) {
return qualifiedNameToTableName(getQualifiedName(context));
}

private QualifiedName getQualifiedName(StarRocksParser.QualifiedNameContext context) {
protected QualifiedName getQualifiedName(StarRocksParser.QualifiedNameContext context) {
List<String> parts = new ArrayList<>();
NodePosition pos = createPos(context);
for (ParseTree c : context.children) {
Expand Down

0 comments on commit 082ebbd

Please sign in to comment.