You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/06/29 05:48:56 UTC
[49/50] kylin git commit: KYLIN-2686 The same project's computed
column's definition can not be same
KYLIN-2686 The same project's computed column's definition can not be same
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/a0b7e74c
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/a0b7e74c
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/a0b7e74c
Branch: refs/heads/master
Commit: a0b7e74c16718bb7bab3eb093d6953c393f3444a
Parents: b2fc2c2
Author: Aron.tao <24...@qq.com>
Authored: Wed Jun 28 12:41:34 2017 +0800
Committer: Hongbin Ma <ma...@kyligence.io>
Committed: Wed Jun 28 14:04:24 2017 +0800
----------------------------------------------------------------------
.../kylin/metadata/model/DataModelDesc.java | 43 ++++++++++++++------
1 file changed, 31 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/a0b7e74c/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
index 7e08f1c..7de955e 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
@@ -471,33 +471,52 @@ public class DataModelDesc extends RootPersistentEntity {
}
private void initComputedColumns(Map<String, CCInfo> ccInfoMap) {
+ if (ccInfoMap == null) {
+ logger.error("cc info map is null");
+ }
+
Set<String> ccSet = Sets.newHashSet();//make sure cc name does not duplicate within this model
- for (ComputedColumnDesc computedColumnDesc : this.computedColumnDescs) {
- computedColumnDesc.init();
+ for (ComputedColumnDesc thisCCDesc : this.computedColumnDescs) {
+ thisCCDesc.init();
+ String thisCCName = thisCCDesc.getFullName();
- if (ccSet.contains(computedColumnDesc.getFullName())) {
- throw new IllegalArgumentException(
- String.format("More than one computed column named %s exist in model %s",
- computedColumnDesc.getFullName(), this.getName()));
+ if (ccSet.contains(thisCCName)) {
+ throw new IllegalArgumentException(String.format(
+ "More than one computed column named %s exist in model %s", thisCCName, this.getName()));
} else {
- ccSet.add(computedColumnDesc.getFullName());
+ ccSet.add(thisCCName);
}
- CCInfo other = ccInfoMap.get(computedColumnDesc.getFullName());
+ CCInfo other = ccInfoMap.get(thisCCName);
if (other == null || (other.getDataModelDescs().size() == 1 && other.getDataModelDescs().contains(this))) {
- ccInfoMap.put(computedColumnDesc.getFullName(),
- new CCInfo(computedColumnDesc, Sets.<DataModelDesc> newHashSet(this)));
- } else if (other.getComputedColumnDesc().equals(computedColumnDesc)) {
+ //check whether two computer columns's definition is the same.
+ for (CCInfo sysCCInfo : ccInfoMap.values()) {
+ String definition0 = thisCCDesc.getExpression();
+ String definition1 = sysCCInfo.getComputedColumnDesc().getExpression();
+ if (isTwoCCDefinitionEquals(definition0, definition1)) {
+ throw new IllegalStateException(String.format(
+ "Computed column %s'definition: %s is already defined in other models: %s. Please change another definition, or try to keep consistent definition",
+ thisCCName, definition0, sysCCInfo.getDataModelDescs()));
+ }
+ }
+ ccInfoMap.put(thisCCName, new CCInfo(thisCCDesc, Sets.<DataModelDesc> newHashSet(this)));
+ } else if (other.getComputedColumnDesc().equals(thisCCDesc)) {
other.getDataModelDescs().add(this);
} else {
throw new IllegalStateException(String.format(
"Computed column named %s is already defined in other models: %s. Please change another name, or try to keep consistent definition", //
- computedColumnDesc.getFullName(), other.getDataModelDescs()));
+ thisCCName, other.getDataModelDescs()));
}
}
}
+ private boolean isTwoCCDefinitionEquals(String definition0, String definition1) {
+ definition0 = definition0.replaceAll("\\s*", "");
+ definition1 = definition1.replaceAll("\\s*", "");
+ return definition0.equalsIgnoreCase(definition1);
+ }
+
private void initJoinColumns() {
for (JoinTableDesc joinTable : joinTables) {