[enhancement](chore)add single space separator rule to fe check style (#12354)

Some times, our code use more than one space as separator by mistake. This PR add a CheckStyle rule SingleSpaceSeparator to check that for Nereids.
This commit is contained in:
morrySnow
2022-09-05 21:59:58 +08:00
committed by GitHub
parent b8e38b9167
commit 190717dbcc
13 changed files with 24 additions and 22 deletions

View File

@ -391,6 +391,7 @@ under the License.
<property name="tokens" value="METHOD_REF"/>
<property name="option" value="nl"/>
</module>
<module name="SingleSpaceSeparator"/>
<module name="WhitespaceAfter">
<property name="tokens"
value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE,

View File

@ -47,6 +47,7 @@ under the License.
<!-- other -->
<suppress files="org[\\/]apache[\\/]doris[\\/](?!nereids)[^\\/]+[\\/]|PaloFe\.java" checks="DeclarationOrder" />
<suppress files="org[\\/]apache[\\/]doris[\\/](?!nereids)[^\\/]+[\\/]|PaloFe\.java" checks="OverloadMethodsDeclarationOrder" />
<suppress files="org[\\/]apache[\\/]doris[\\/](?!nereids)[^\\/]+[\\/]|PaloFe\.java" checks="SingleSpaceSeparator" />
<suppress files="org[\\/]apache[\\/]doris[\\/](?!nereids)[^\\/]+[\\/]|PaloFe\.java" checks="VariableDeclarationUsageDistance" />
<!-- exclude rules for special files -->

View File

@ -64,13 +64,13 @@ public class UnboundFunction extends Expression implements Unbound {
String params = children.stream()
.map(Expression::toSql)
.collect(Collectors.joining(", "));
return name + "(" + (isDistinct ? "DISTINCT " : "") + params + ")";
return name + "(" + (isDistinct ? "DISTINCT " : "") + params + ")";
}
@Override
public String toString() {
String params = Joiner.on(", ").join(children);
return "'" + name + "(" + (isDistinct ? "DISTINCT " : "") + params + ")";
return "'" + name + "(" + (isDistinct ? "DISTINCT " : "") + params + ")";
}
@Override

View File

@ -265,7 +265,7 @@ public class ExpressionTranslator extends DefaultExpressionVisitor<Expr, PlanTra
@Override
public Expr visitBinaryArithmetic(BinaryArithmetic binaryArithmetic, PlanTranslatorContext context) {
ArithmeticExpr arithmeticExpr = new ArithmeticExpr(binaryArithmetic.getLegacyOperator(),
ArithmeticExpr arithmeticExpr = new ArithmeticExpr(binaryArithmetic.getLegacyOperator(),
binaryArithmetic.child(0).accept(this, context),
binaryArithmetic.child(1).accept(this, context));
return arithmeticExpr;

View File

@ -356,7 +356,7 @@ public class PhysicalPlanTranslator extends DefaultPlanVisitor<PlanFragment, Pla
TupleDescriptor leftChildOutputTupleDesc = leftPlanRoot.getOutputTupleDesc();
TupleDescriptor leftTuple =
leftChildOutputTupleDesc != null ? leftChildOutputTupleDesc : context.getTupleDesc(leftPlanRoot);
leftChildOutputTupleDesc != null ? leftChildOutputTupleDesc : context.getTupleDesc(leftPlanRoot);
TupleDescriptor rightChildOutputTupleDesc = rightPlanRoot.getOutputTupleDesc();
TupleDescriptor rightTuple =
rightChildOutputTupleDesc != null ? rightChildOutputTupleDesc : context.getTupleDesc(rightPlanRoot);

View File

@ -32,7 +32,7 @@ public class LogicalLeafPatternGenerator extends PatternGenerator {
@Override
public String genericType() {
return "<" + opType.name + ">";
return "<" + opType.name + ">";
}
@Override

View File

@ -275,7 +275,7 @@ public abstract class PatternGenerator {
childrenPattern = ", " + childrenPattern;
}
String pattern = "default " + methodGeneric + "\n"
String pattern = "default " + methodGeneric + "\n"
+ "PatternDescriptor" + genericParam + "\n"
+ " " + patterName + "(" + methodParam + ") {\n"
+ " return new PatternDescriptor" + genericParam + "(\n"

View File

@ -51,7 +51,7 @@ public class SimplifyNotExprRule extends AbstractExpressionRewriteRule {
Expression child = not.child();
if (child instanceof ComparisonPredicate) {
ComparisonPredicate cp = (ComparisonPredicate) not.child();
Expression left = rewrite(cp.left(), context);
Expression left = rewrite(cp.left(), context);
Expression right = rewrite(cp.right(), context);
// TODO: visit concrete class instead of `instanceof`.
@ -59,7 +59,7 @@ public class SimplifyNotExprRule extends AbstractExpressionRewriteRule {
return new LessThanEqual(left, right);
} else if (child instanceof GreaterThanEqual) {
return new LessThan(left, right);
} else if (child instanceof LessThan) {
} else if (child instanceof LessThan) {
return new GreaterThanEqual(left, right);
} else if (child instanceof LessThanEqual) {
return new GreaterThan(left, right);
@ -68,7 +68,7 @@ public class SimplifyNotExprRule extends AbstractExpressionRewriteRule {
}
} else if (child instanceof CompoundPredicate) {
CompoundPredicate cp = (CompoundPredicate) not.child();
Expression left = rewrite(new Not(cp.left()), context);
Expression left = rewrite(new Not(cp.left()), context);
Expression right = rewrite(new Not(cp.right()), context);
return cp.flip(left, right);
}

View File

@ -42,7 +42,7 @@ import org.apache.doris.nereids.util.ExpressionUtils;
* |
* scan
*/
public class MergeConsecutiveFilters extends OneRewriteRuleFactory {
public class MergeConsecutiveFilters extends OneRewriteRuleFactory {
@Override
public Rule build() {
return logicalFilter(logicalFilter()).then(filter -> {

View File

@ -34,7 +34,7 @@ import java.util.List;
/**
* weekOfYear function
*/
public class WeekOfYear extends BoundFunction implements UnaryExpression, ImplicitCastInputTypes {
public class WeekOfYear extends BoundFunction implements UnaryExpression, ImplicitCastInputTypes {
private static final List<AbstractDataType> EXPECTED_INPUT_TYPES = ImmutableList.of(
new TypeCollection(DateTimeType.INSTANCE)

View File

@ -102,7 +102,7 @@ public class JoinUtils {
* @return true if the equal can be used as hash join condition
*/
boolean isHashJoinCondition(EqualTo equalTo) {
List<SlotReference> equalLeft = equalTo.left().collect(SlotReference.class::isInstance);
List<SlotReference> equalLeft = equalTo.left().collect(SlotReference.class::isInstance);
if (equalLeft.isEmpty()) {
return false;
}

View File

@ -121,17 +121,17 @@ public class ExpressionRewriteTest {
assertRewrite("(a and b) or ((d and c) and (d and e))", "(a and b) or (d and c and e)");
assertRewrite("(a or b) and ((d or c) or (d or e))", "(a or b) and (d or c or e)");
assertRewrite("(a and b) or (a and b and c)", "a and b");
assertRewrite("(a or b) and (a or b or c)", "a or b");
assertRewrite("(a and b) or (a and b and c)", "a and b");
assertRewrite("(a or b) and (a or b or c)", "a or b");
assertRewrite("a and true", "a");
assertRewrite("a or false", "a");
assertRewrite("a and true", "a");
assertRewrite("a or false", "a");
assertRewrite("a and false", "false");
assertRewrite("a or true", "true");
assertRewrite("a and false", "false");
assertRewrite("a or true", "true");
assertRewrite("a or false or false or false", "a");
assertRewrite("a and true and true and true", "a");
assertRewrite("a or false or false or false", "a");
assertRewrite("a and true and true and true", "a");
assertRewrite("(a and b) or a ", "a");
assertRewrite("(a or b) and a ", "a");

View File

@ -362,7 +362,7 @@ public class AnalyzeWhereSubqueryTest extends TestWithFeService implements Patte
ImmutableList.of("default_cluster:test", "t7")), "aa")
)))
).when(FieldChecker.check("outputExpressions", ImmutableList.of(
new Alias(new ExprId(8), new Max(new SlotReference(new ExprId(0), "aa", BigIntType.INSTANCE, true,
new Alias(new ExprId(8), new Max(new SlotReference(new ExprId(0), "aa", BigIntType.INSTANCE, true,
ImmutableList.of("t2"))), "max(aa)")
)))
.when(FieldChecker.check("groupByExpressions", ImmutableList.of()))
@ -414,7 +414,7 @@ public class AnalyzeWhereSubqueryTest extends TestWithFeService implements Patte
logicalAggregate(
logicalProject()
).when(FieldChecker.check("outputExpressions", ImmutableList.of(
new Alias(new ExprId(8), new Max(new SlotReference(new ExprId(0), "aa", BigIntType.INSTANCE, true,
new Alias(new ExprId(8), new Max(new SlotReference(new ExprId(0), "aa", BigIntType.INSTANCE, true,
ImmutableList.of("t2"))), "max(aa)"),
new SlotReference(new ExprId(7), "v2", BigIntType.INSTANCE, true,
ImmutableList.of("default_cluster:test", "t7")))))