You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by hu...@apache.org on 2022/07/23 09:32:12 UTC
[doris] branch master updated: [feature](nereids): add equals for expression (#11067)
This is an automated email from the ASF dual-hosted git repository.
huajianlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new baef77a8f0 [feature](nereids): add equals for expression (#11067)
baef77a8f0 is described below
commit baef77a8f05965dd6ab82667b9b0006cf90b6844
Author: jakevin <ja...@gmail.com>
AuthorDate: Sat Jul 23 17:32:06 2022 +0800
[feature](nereids): add equals for expression (#11067)
add equals for datatype and some expression.
Fix some small problem like arrangement.
---
.../apache/doris/nereids/analyzer/UnboundSlot.java | 2 +-
.../doris/nereids/trees/expressions/Alias.java | 18 +++---
.../doris/nereids/trees/expressions/Between.java | 11 ++--
.../nereids/trees/expressions/SlotReference.java | 1 +
.../org/apache/doris/nereids/types/DataType.java | 15 +++++
.../apache/doris/nereids/types/VarcharType.java | 16 ++++++
.../plans/{EqualsTest.java => PlanEqualsTest.java} | 2 +-
.../apache/doris/nereids/types/DataTypeTest.java | 64 ++++++++++++++++++++++
8 files changed, 112 insertions(+), 17 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundSlot.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundSlot.java
index c0d28a7337..60b662865b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundSlot.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundSlot.java
@@ -74,7 +74,7 @@ public class UnboundSlot extends Slot implements Unbound {
return false;
}
UnboundSlot other = (UnboundSlot) o;
- return nameParts.equals(other.getNameParts());
+ return nameParts.equals(other.nameParts);
}
@Override
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java
index 8b3edd6a00..4adcb94eeb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Alias.java
@@ -98,12 +98,11 @@ public class Alias extends NamedExpression implements UnaryExpression {
if (o == null || getClass() != o.getClass()) {
return false;
}
- if (!super.equals(o)) {
- return false;
- }
- Alias alias = (Alias) o;
- return exprId.equals(alias.exprId) && name.equals(alias.name)
- && qualifier.equals(alias.qualifier) && children.equals(alias.children);
+ Alias that = (Alias) o;
+ return exprId.equals(that.exprId)
+ && name.equals(that.name)
+ && qualifier.equals(that.qualifier)
+ && child().equals(that.child());
}
@Override
@@ -116,14 +115,13 @@ public class Alias extends NamedExpression implements UnaryExpression {
return child().toString() + " AS `" + name + "`#" + exprId;
}
- public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
- return visitor.visitAlias(this, context);
- }
-
@Override
public Expression withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() == 1);
return new Alias(exprId, children.get(0), name);
}
+ public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+ return visitor.visitAlias(this, context);
+ }
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Between.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Between.java
index 98dc73590d..64b44580fb 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Between.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Between.java
@@ -80,7 +80,7 @@ public class Between extends Expression implements TernaryExpression {
}
public Expression getLowerBound() {
- return lowerBound;
+ return lowerBound;
}
public Expression getUpperBound() {
@@ -101,10 +101,11 @@ public class Between extends Expression implements TernaryExpression {
if (o == null || getClass() != o.getClass()) {
return false;
}
- Between between = (Between) o;
- return Objects.equals(compareExpr, between.compareExpr)
- && Objects.equals(lowerBound, between.lowerBound)
- && Objects.equals(upperBound, between.upperBound);
+ Between that = (Between) o;
+ return Objects.equals(compareExpr, that.compareExpr)
+ && Objects.equals(lowerBound, that.lowerBound)
+ && Objects.equals(upperBound, that.upperBound)
+ && Objects.equals(children, that.children);
}
@Override
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/SlotReference.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/SlotReference.java
index 9befc8825a..c9f72c02e7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/SlotReference.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/SlotReference.java
@@ -109,6 +109,7 @@ public class SlotReference extends Slot {
SlotReference that = (SlotReference) o;
return nullable == that.nullable
&& exprId.equals(that.exprId)
+ && dataType.equals(that.dataType)
&& name.equals(that.name)
&& qualifier.equals(that.qualifier);
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
index 92bbe79651..508c85dcc9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java
@@ -72,4 +72,19 @@ public abstract class DataType {
public abstract Type toCatalogDataType();
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
+ }
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VarcharType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VarcharType.java
index ef8abf89d9..df77733203 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VarcharType.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/VarcharType.java
@@ -20,6 +20,8 @@ package org.apache.doris.nereids.types;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
+import java.util.Objects;
+
/**
* Varchar type in Nereids.
*/
@@ -38,4 +40,18 @@ public class VarcharType extends DataType {
public Type toCatalogDataType() {
return ScalarType.createVarcharType(len);
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (!super.equals(o)) {
+ return false;
+ }
+ VarcharType that = (VarcharType) o;
+ return len == that.len;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), len);
+ }
}
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/EqualsTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java
similarity index 99%
rename from fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/EqualsTest.java
rename to fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java
index 66de8b19be..86c9ebabee 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/EqualsTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java
@@ -51,7 +51,7 @@ import java.util.List;
import java.util.Optional;
// TODO: need more detailed test
-public class EqualsTest {
+public class PlanEqualsTest {
/* *************************** Logical *************************** */
@Test
public void testLogicalAggregate(@Mocked Plan child) {
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/types/DataTypeTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/types/DataTypeTest.java
new file mode 100644
index 0000000000..50e8cca200
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/types/DataTypeTest.java
@@ -0,0 +1,64 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.types;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DataTypeTest {
+ @Test
+ public void testDataTypeEquals() {
+ BigIntType bigIntType1 = new BigIntType();
+ BigIntType bigIntType2 = new BigIntType();
+ Assert.assertEquals(bigIntType1, bigIntType2);
+ Assert.assertEquals(bigIntType1.hashCode(), bigIntType2.hashCode());
+
+ BooleanType booleanType1 = new BooleanType();
+ BooleanType booleanType2 = new BooleanType();
+ Assert.assertEquals(booleanType1, booleanType2);
+ Assert.assertEquals(booleanType1.hashCode(), booleanType2.hashCode());
+
+ DoubleType doubleType1 = new DoubleType();
+ DoubleType doubleType2 = new DoubleType();
+ Assert.assertEquals(doubleType1, doubleType2);
+ Assert.assertEquals(doubleType1.hashCode(), doubleType2.hashCode());
+
+ IntegerType integerType1 = new IntegerType();
+ IntegerType integerType2 = new IntegerType();
+ Assert.assertEquals(integerType1, integerType2);
+ Assert.assertEquals(integerType1.hashCode(), integerType2.hashCode());
+
+ NullType nullType1 = new NullType();
+ NullType nullType2 = new NullType();
+ Assert.assertEquals(nullType1, nullType2);
+ Assert.assertEquals(nullType1.hashCode(), nullType2.hashCode());
+
+ StringType stringType1 = new StringType();
+ StringType stringType2 = new StringType();
+ Assert.assertEquals(stringType1, stringType2);
+ Assert.assertEquals(stringType1.hashCode(), stringType2.hashCode());
+
+ VarcharType varcharType1 = new VarcharType(32);
+ VarcharType varcharType2 = new VarcharType(32);
+ Assert.assertEquals(varcharType1, varcharType2);
+ Assert.assertEquals(varcharType1.hashCode(), varcharType2.hashCode());
+ VarcharType varcharType3 = new VarcharType(64);
+ Assert.assertNotEquals(varcharType1, varcharType3);
+ Assert.assertNotEquals(varcharType1.hashCode(), varcharType3.hashCode());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org