KYLIN-1875 fix ParameterDesc equals() & hashcode()
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/5460dea3 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/5460dea3 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/5460dea3 Branch: refs/heads/KYILN-1875-B Commit: 5460dea314f0ed89bcc096b645af4ed41d267374 Parents: e0713d3 Author: Yang Li <liy...@apache.org> Authored: Thu Dec 1 06:58:08 2016 +0800 Committer: Yang Li <liy...@apache.org> Committed: Mon Dec 5 21:38:48 2016 +0800 ---------------------------------------------------------------------- .../kylin/metadata/model/FunctionDesc.java | 1 + .../kylin/metadata/model/ParameterDesc.java | 36 +++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/5460dea3/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java ---------------------------------------------------------------------- diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java index dfa6f3b..b9e5543 100644 --- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java +++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/FunctionDesc.java @@ -248,6 +248,7 @@ public class FunctionDesc { final int prime = 31; int result = 1; result = prime * result + ((expression == null) ? 0 : expression.hashCode()); + result = prime * result + ((returnType == null) ? 0 : returnType.hashCode()); result = prime * result + ((isCount() || parameter == null) ? 0 : parameter.hashCode()); return result; } http://git-wip-us.apache.org/repos/asf/kylin/blob/5460dea3/core-metadata/src/main/java/org/apache/kylin/metadata/model/ParameterDesc.java ---------------------------------------------------------------------- diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/ParameterDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/ParameterDesc.java index 329799f..4a95fea 100644 --- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/ParameterDesc.java +++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/ParameterDesc.java @@ -22,8 +22,10 @@ import java.io.UnsupportedEncodingException; import java.util.List; import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.collect.ImmutableList; /** */ @@ -36,9 +38,10 @@ public class ParameterDesc { private String value; @JsonProperty("next_parameter") + @JsonInclude(JsonInclude.Include.NON_NULL) private ParameterDesc nextParameter; - private List<TblColRef> colRefs; + private List<TblColRef> colRefs = ImmutableList.of(); public String getType() { return type; @@ -89,21 +92,36 @@ public class ParameterDesc { ParameterDesc that = (ParameterDesc) o; - if (nextParameter != null ? !nextParameter.equals(that.nextParameter) : that.nextParameter != null) - return false; if (type != null ? !type.equals(that.type) : that.type != null) return false; - if (value != null ? !value.equals(that.value) : that.value != null) - return false; - - return true; + + ParameterDesc p = this, q = that; + int refi = 0, refj = 0; + for (; p != null && q != null; p = p.nextParameter, q = q.nextParameter) { + if (p.isColumnType()) { + if (q.isColumnType() == false) + return false; + if (refi >= this.colRefs.size() || refj >= that.colRefs.size()) + return false; + if (this.colRefs.get(refi).equals(that.colRefs.get(refj)) == false) + return false; + refi++; + refj++; + } else { + if (q.isColumnType() == true) + return false; + if (p.value.equals(q.value) == false) + return false; + } + } + + return p == null && q == null; } @Override public int hashCode() { int result = type != null ? type.hashCode() : 0; - result = 31 * result + (value != null ? value.hashCode() : 0); - result = 31 * result + (nextParameter != null ? nextParameter.hashCode() : 0); + result = 31 * result + (colRefs != null ? colRefs.hashCode() : 0); return result; }