Repository: kylin Updated Branches: refs/heads/master 2dfffde26 -> 182ed0094
KYLIN-2494 ensure model has no dup among dimensions and measures Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/182ed009 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/182ed009 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/182ed009 Branch: refs/heads/master Commit: 182ed009400629dee1bd7ad0121224cacfd07668 Parents: 2dfffde Author: Li Yang <liy...@apache.org> Authored: Thu Mar 9 18:03:26 2017 +0800 Committer: Li Yang <liy...@apache.org> Committed: Thu Mar 9 18:03:26 2017 +0800 ---------------------------------------------------------------------- .../apache/kylin/common/KylinConfigBase.java | 4 ---- .../kylin/metadata/model/DataModelDesc.java | 22 +++++++++----------- .../kylin/metadata/model/DataModelDescTest.java | 11 ++++++++++ .../test_kylin_inner_join_model_desc.json | 1 + 4 files changed, 22 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/182ed009/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java index 02b2d4b..ad02fe2 100644 --- a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java +++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java @@ -329,10 +329,6 @@ abstract public class KylinConfigBase implements Serializable { return Boolean.parseBoolean(getOptional("kylin.cube.allow-appear-in-multiple-projects", "false")); } - public boolean allowModelDimensionMetricsOverlap() { - return Boolean.parseBoolean(getOptional("kylin.model.allow-dimension-metrics-overlap", "false")); - } - // ============================================================================ // JOB // ============================================================================ http://git-wip-us.apache.org/repos/asf/kylin/blob/182ed009/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 1c85f09..0a303ec 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 @@ -453,23 +453,21 @@ public class DataModelDesc extends RootPersistentEntity { } private boolean validate() { + + // ensure no dup between dimensions/metrics + for (ModelDimensionDesc dim : dimensions) { + String table = dim.getTable(); + for (String c : dim.getColumns()) { + TblColRef dcol = findColumn(table, c); + metrics = ArrayUtils.removeElement(metrics, dcol.getIdentity()); + } + } + Set<TblColRef> mcols = new HashSet<>(); for (String m : metrics) { mcols.add(findColumn(m)); } - if (!KylinConfig.getInstanceFromEnv().allowModelDimensionMetricsOverlap()) { - // validate no dup between dimensions/metrics - for (ModelDimensionDesc dim : dimensions) { - String table = dim.getTable(); - for (String c : dim.getColumns()) { - TblColRef dcol = findColumn(table, c); - if (mcols.contains(dcol)) - throw new IllegalStateException(dcol + " cannot be both dimension and metrics at the same time in " + this); - } - } - } - // validate PK/FK are in dimensions boolean pkfkDimAmended = false; for (Chain chain : joinsTree.tableChains.values()) { http://git-wip-us.apache.org/repos/asf/kylin/blob/182ed009/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java ---------------------------------------------------------------------- diff --git a/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java b/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java index 0cfa1f4..b319423 100644 --- a/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java +++ b/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java @@ -19,7 +19,9 @@ package org.apache.kylin.metadata.model; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.apache.commons.lang.ArrayUtils; import org.apache.kylin.common.util.JsonUtil; import org.apache.kylin.common.util.LocalFileMetadataTestCase; import org.apache.kylin.metadata.MetadataManager; @@ -39,6 +41,15 @@ public class DataModelDescTest extends LocalFileMetadataTestCase { public void after() throws Exception { this.cleanupTestMetadata(); } + + @Test + public void testNoDupColInDimAndMeasure() { + DataModelDesc model = MetadataManager.getInstance(getTestConfig()).getDataModelDesc("test_kylin_inner_join_model_desc"); + String[] metrics = model.getMetrics(); + TblColRef col = model.findColumn("edw.test_cal_dt.cal_dt"); + assertTrue(metrics.length == 2); + assertTrue(ArrayUtils.contains(metrics, col.getIdentity()) == false); + } @Test public void testGetCopyOf() throws JsonProcessingException { http://git-wip-us.apache.org/repos/asf/kylin/blob/182ed009/examples/test_case_data/localmeta/model_desc/test_kylin_inner_join_model_desc.json ---------------------------------------------------------------------- diff --git a/examples/test_case_data/localmeta/model_desc/test_kylin_inner_join_model_desc.json b/examples/test_case_data/localmeta/model_desc/test_kylin_inner_join_model_desc.json index 49758dd..dbb6df8 100644 --- a/examples/test_case_data/localmeta/model_desc/test_kylin_inner_join_model_desc.json +++ b/examples/test_case_data/localmeta/model_desc/test_kylin_inner_join_model_desc.json @@ -105,6 +105,7 @@ } ], "metrics": [ + "edw.test_cal_dt.cal_dt", "PRICE", "ITEM_COUNT" ],