KYLIN-2440 Make PK/FK always exposed
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/7fa25e0f Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/7fa25e0f Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/7fa25e0f Branch: refs/heads/KYLIN-2428 Commit: 7fa25e0fafe25686450587407f2ed6f1e71cf4d3 Parents: f456961 Author: Li Yang <liy...@apache.org> Authored: Thu Feb 9 18:28:38 2017 +0800 Committer: Li Yang <liy...@apache.org> Committed: Thu Feb 9 18:28:53 2017 +0800 ---------------------------------------------------------------------- .../org/apache/kylin/cube/model/CubeDesc.java | 35 +++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/7fa25e0f/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 5e970bf..9acb90c 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 @@ -64,6 +64,7 @@ import org.apache.kylin.metadata.model.IStorageAware; import org.apache.kylin.metadata.model.JoinDesc; import org.apache.kylin.metadata.model.JoinTableDesc; import org.apache.kylin.metadata.model.MeasureDesc; +import org.apache.kylin.metadata.model.TableRef; import org.apache.kylin.metadata.model.TblColRef; import org.apache.kylin.metadata.project.ProjectInstance; import org.apache.kylin.metadata.project.ProjectManager; @@ -570,10 +571,7 @@ public class CubeDesc extends RootPersistentEntity implements IEngineAware { checkState(rowkey.getRowKeyColumns().length == dimCols.size(), "RowKey columns count (%d) doesn't match dimensions columns count (%d)", rowkey.getRowKeyColumns().length, dimCols.size()); initDictionaryDesc(); - - for (TblColRef col : allColumns) { - allColumnDescs.add(col.getColumnDesc()); - } + amendAllColumns(); } public void validateAggregationGroups() { @@ -958,6 +956,35 @@ public class CubeDesc extends RootPersistentEntity implements IEngineAware { return false; } + private void amendAllColumns() { + // make sure all PF/FK are included, thus become exposed to calcite later + Set<TableRef> tables = collectTablesOnJoinChain(allColumns); + for (TableRef t : tables) { + JoinDesc join = model.getJoinByPKSide(t); + if (join != null) { + allColumns.addAll(Arrays.asList(join.getForeignKeyColumns())); + allColumns.addAll(Arrays.asList(join.getPrimaryKeyColumns())); + } + } + + for (TblColRef col : allColumns) { + allColumnDescs.add(col.getColumnDesc()); + } + } + + private Set<TableRef> collectTablesOnJoinChain(Set<TblColRef> columns) { + Set<TableRef> result = new HashSet<>(); + for (TblColRef col : columns) { + TableRef t = col.getTableRef(); + while (t != null) { + result.add(t); + JoinDesc join = model.getJoinByPKSide(t); + t = join == null ? null : join.getFKSide(); + } + } + return result; + } + public long getRetentionRange() { return retentionRange; }