KYLIN-2462 fix PK/FK backward-compatibility issue (By LiYang)
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/675c0d82 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/675c0d82 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/675c0d82 Branch: refs/heads/master-hadoop3.0 Commit: 675c0d82a0e568cf6b7a4d36ae12fc8966d5d705 Parents: 8733dda Author: lidongsjtu <lid...@apache.org> Authored: Thu Apr 13 20:00:26 2017 +0800 Committer: lidongsjtu <lid...@apache.org> Committed: Thu Apr 13 20:04:42 2017 +0800 ---------------------------------------------------------------------- .../org/apache/kylin/common/KylinVersion.java | 47 +++++++++++++++----- .../org/apache/kylin/cube/model/CubeDesc.java | 13 ++++++ 2 files changed, 50 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/675c0d82/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java ---------------------------------------------------------------------- diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java b/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java index 465ca5a..14fcfd0 100644 --- a/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java +++ b/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java @@ -33,7 +33,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; -public class KylinVersion { +public class KylinVersion implements Comparable { private static final String COMMIT_SHA1_v15 = "commit_SHA1"; private static final String COMMIT_SHA1_v13 = "commit.sha1"; @@ -66,22 +66,44 @@ public class KylinVersion { return "" + major + "." + minor + "." + revision; } + @Override + public int compareTo(Object o) { + KylinVersion v = (KylinVersion) o; + int comp; + + comp = this.major - v.major; + if (comp != 0) + return comp; + + comp = this.minor - v.minor; + if (comp != 0) + return comp; + + comp = this.revision - v.revision; + if (comp != 0) + return comp; + + return (this.isSnapshot ? 0 : 1) - (v.isSnapshot ? 0 : 1); + } + /** * Require MANUAL updating kylin version per ANY upgrading. */ private static final KylinVersion CURRENT_KYLIN_VERSION = new KylinVersion("2.0.0"); + private static final KylinVersion VERSION_200 = new KylinVersion("2.0.0"); + private static final Set<KylinVersion> SIGNATURE_INCOMPATIBLE_REVISIONS = new HashSet<KylinVersion>(); /** - * 1.5.1 is actually compatible with 1.5.0's cube. However the "calculate signature" method in 1.5.1 code base somehow - * gives different signature values for 1.5.0 cubes. To prevent from users having to take care of this mess, as people - * usually won't expect to take lots of efforts for small upgrade (from 1.5.0 to 1.5.1), a special list of + * 1.5.1 is actually compatible with 1.5.0's cube. However the "calculate signature" method in 1.5.1 code base somehow + * gives different signature values for 1.5.0 cubes. To prevent from users having to take care of this mess, as people + * usually won't expect to take lots of efforts for small upgrade (from 1.5.0 to 1.5.1), a special list of * SIGNATURE_INCOMPATIBLE_REVISIONS is introduced to silently take care of such legacy cubes. - * + * * We should NEVER add new stuff to SIGNATURE_INCOMPATIBLE_REVISIONS. "calculate signature" should always return consistent values * to compatible versions. If it's impossible to maintain consistent signatures between upgrade, we should increase the minor version, - * e.g. it's better to skip 1.5.1 and use 1.6.0 as the next release version to 1.5.0, or even to use 2.0.0, as people tends to accept + * e.g. it's better to skip 1.5.1 and use 1.6.0 as the next release version to 1.5.0, or even to use 2.0.0, as people tends to accept * doing more (e.g. Having to use sth like a metastore upgrade tool when upgrading Kylin) */ static { @@ -100,6 +122,14 @@ public class KylinVersion { return CURRENT_KYLIN_VERSION; } + public static boolean isBefore200(String ver) { + return new KylinVersion(ver).compareTo(VERSION_200) < 0; + } + + public static void main(String[] args) { + System.out.println(getKylinClientInformation()); + } + public boolean isCompatibleWith(KylinVersion v) { KylinVersion current = CURRENT_KYLIN_VERSION; if (current.major != v.major || current.minor != v.minor) { @@ -135,10 +165,6 @@ public class KylinVersion { return !signatureIncompatible; } - public static void main(String[] args) { - System.out.println(getKylinClientInformation()); - } - public static String getKylinClientInformation() { StringBuilder buf = new StringBuilder(); @@ -172,4 +198,5 @@ public class KylinVersion { return StringUtils.EMPTY; } } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/675c0d82/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java ---------------------------------------------------------------------- diff --git a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java index 820a172..0cbe9b7 100644 --- a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java +++ b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java @@ -875,6 +875,19 @@ public class CubeDesc extends RootPersistentEntity implements IEngineAware { private TblColRef initDimensionColRef(DimensionDesc dim, String colName) { TblColRef col = model.findColumn(dim.getTable(), colName); + + // for backward compatibility + if (KylinVersion.isBefore200(getVersion())) { + // always use FK instead PK, FK could be shared by more than one lookup tables + JoinDesc join = dim.getJoin(); + if (join != null) { + int idx = ArrayUtils.indexOf(join.getPrimaryKeyColumns(), col); + if (idx >= 0) { + col = join.getForeignKeyColumns()[idx]; + } + } + } + return initDimensionColRef(col); }