SQL: Break long lines in parse tree walker (elastic/x-pack-elasticsearch#3451)
SQL's parse tree visitors had some lines longer than 140 characters. This break them into multiple lines. Original commit: elastic/x-pack-elasticsearch@58310b02f8
This commit is contained in:
parent
f5ff5a94a0
commit
f7159ce56f
|
@ -20,10 +20,6 @@
|
|||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]expression[/\\]TypedAttribute.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]expression[/\\]UnresolvedAttribute.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]optimizer[/\\]Optimizer.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]parser[/\\]CommandBuilder.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]parser[/\\]ExpressionBuilder.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]parser[/\\]LogicalPlanBuilder.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]parser[/\\]SqlParser.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]plan[/\\]logical[/\\]command[/\\]Explain.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]planner[/\\]PlanningException.java" checks="LineLength" />
|
||||
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]planner[/\\]QueryFolder.java" checks="LineLength" />
|
||||
|
|
|
@ -50,7 +50,8 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
|
|||
type = Debug.Type.OPTIMIZED;
|
||||
}
|
||||
}
|
||||
Debug.Format format = (ctx.format != null && ctx.format.getType() == SqlBaseLexer.GRAPHVIZ ? Debug.Format.GRAPHVIZ : Debug.Format.TEXT);
|
||||
boolean graphViz = ctx.format != null && ctx.format.getType() == SqlBaseLexer.GRAPHVIZ;
|
||||
Debug.Format format = graphViz ? Debug.Format.GRAPHVIZ : Debug.Format.TEXT;
|
||||
|
||||
return new Debug(loc, plan(ctx.statement()), type, format);
|
||||
}
|
||||
|
@ -92,13 +93,13 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
|
|||
type = Explain.Type.ALL;
|
||||
}
|
||||
}
|
||||
Explain.Format format = (ctx.format != null && ctx.format.getType() == SqlBaseLexer.GRAPHVIZ ? Explain.Format.GRAPHVIZ : Explain.Format.TEXT);
|
||||
boolean graphViz = ctx.format != null && ctx.format.getType() == SqlBaseLexer.GRAPHVIZ;
|
||||
Explain.Format format = graphViz ? Explain.Format.GRAPHVIZ : Explain.Format.TEXT;
|
||||
boolean verify = (ctx.verify != null ? Booleans.parseBoolean(ctx.verify.getText().toLowerCase(Locale.ROOT), true) : true);
|
||||
|
||||
return new Explain(loc, plan(ctx.statement()), type, format, verify);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object visitShowFunctions(ShowFunctionsContext ctx) {
|
||||
return new ShowFunctions(source(ctx), string(ctx.pattern));
|
||||
|
@ -114,7 +115,6 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
|
|||
return new ShowSchemas(source(ctx));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object visitShowColumns(ShowColumnsContext ctx) {
|
||||
TableIdentifier identifier = visitTableIdentifier(ctx.tableIdentifier());
|
||||
|
|
|
@ -254,7 +254,8 @@ abstract class ExpressionBuilder extends IdentifierBuilder {
|
|||
|
||||
@Override
|
||||
public Object visitMatchQuery(MatchQueryContext ctx) {
|
||||
return new MatchQueryPredicate(source(ctx), new UnresolvedAttribute(source(ctx.singleField), visitQualifiedName(ctx.singleField)), string(ctx.queryString), string(ctx.options));
|
||||
return new MatchQueryPredicate(source(ctx), new UnresolvedAttribute(source(ctx.singleField),
|
||||
visitQualifiedName(ctx.singleField)), string(ctx.queryString), string(ctx.options));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -264,7 +265,8 @@ abstract class ExpressionBuilder extends IdentifierBuilder {
|
|||
|
||||
@Override
|
||||
public Order visitOrderBy(OrderByContext ctx) {
|
||||
return new Order(source(ctx), expression(ctx.expression()), (ctx.DESC() != null ? Order.OrderDirection.DESC : Order.OrderDirection.ASC));
|
||||
return new Order(source(ctx), expression(ctx.expression()),
|
||||
ctx.DESC() != null ? Order.OrderDirection.DESC : Order.OrderDirection.ASC);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -87,7 +87,8 @@ abstract class LogicalPlanBuilder extends ExpressionBuilder {
|
|||
}
|
||||
|
||||
if (ctx.limit != null && ctx.INTEGER_VALUE() != null) {
|
||||
plan = new Limit(source(ctx.limit), new Literal(source(ctx), Integer.parseInt(ctx.limit.getText()), DataTypes.INTEGER), plan);
|
||||
plan = new Limit(source(ctx.limit), new Literal(source(ctx),
|
||||
Integer.parseInt(ctx.limit.getText()), DataTypes.INTEGER), plan);
|
||||
}
|
||||
|
||||
return plan;
|
||||
|
@ -95,7 +96,12 @@ abstract class LogicalPlanBuilder extends ExpressionBuilder {
|
|||
|
||||
@Override
|
||||
public LogicalPlan visitQuerySpecification(QuerySpecificationContext ctx) {
|
||||
LogicalPlan query = (ctx.fromClause() != null)? plan(ctx.fromClause()) : new LocalRelation(source(ctx), new EmptyExecutable(emptyList()));
|
||||
LogicalPlan query;
|
||||
if (ctx.fromClause() == null) {
|
||||
query = new LocalRelation(source(ctx), new EmptyExecutable(emptyList()));
|
||||
} else {
|
||||
query = plan(ctx.fromClause());
|
||||
}
|
||||
|
||||
// add WHERE
|
||||
if (ctx.where != null) {
|
||||
|
|
|
@ -54,7 +54,8 @@ public class SqlParser {
|
|||
return invokeParser("expression", expression, SqlBaseParser::singleExpression, AstBuilder::expression);
|
||||
}
|
||||
|
||||
private <T> T invokeParser(String name, String sql, Function<SqlBaseParser, ParserRuleContext> parseFunction, BiFunction<AstBuilder, ParserRuleContext, T> visitor) {
|
||||
private <T> T invokeParser(String name, String sql, Function<SqlBaseParser, ParserRuleContext> parseFunction,
|
||||
BiFunction<AstBuilder, ParserRuleContext, T> visitor) {
|
||||
SqlBaseLexer lexer = new SqlBaseLexer(new CaseInsensitiveStream(sql));
|
||||
|
||||
lexer.removeErrorListeners();
|
||||
|
@ -154,7 +155,8 @@ public class SqlParser {
|
|||
|
||||
private static final BaseErrorListener ERROR_LISTENER = new BaseErrorListener() {
|
||||
@Override
|
||||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String message, RecognitionException e) {
|
||||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
|
||||
int charPositionInLine, String message, RecognitionException e) {
|
||||
throw new ParsingException(message, e, line, charPositionInLine);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue