public Map<String, String> matches(JoinsTree another) { return matches(another, Collections.<String, String> emptyMap()); }
private void initJoinsTree() { List<JoinDesc> joins = new ArrayList<>(); for (JoinTableDesc joinTable : joinTables) { joins.add(joinTable.getJoin()); } joinsTree = new JoinsTree(rootFactTableRef, joins); }
public JoinDesc getJoinByPKSide(TableRef table) { return joinsTree.getJoinByPKSide(table); }
private static Map<String, String> matches(DataModelDesc model, OLAPContext ctx) { Map<String, String> result = Maps.newHashMap(); TableRef firstTable = ctx.firstTableScan.getTableRef(); Map<String, String> matchUp = null; if (ctx.joins.isEmpty() && model.isLookupTable(firstTable.getTableIdentity())) { // one lookup table String modelAlias = model.findFirstTable(firstTable.getTableIdentity()).getAlias(); matchUp = ImmutableMap.of(firstTable.getAlias(), modelAlias); } else if (ctx.joins.size() != ctx.allTableScans.size() - 1) { // has hanging tables ctx.realizationCheck.addModelIncapableReason(model, RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.MODEL_BAD_JOIN_SEQUENCE)); throw new IllegalStateException("Please adjust the sequence of join tables. " + toErrorMsg(ctx)); } else { // normal big joins if (ctx.joinsTree == null) { ctx.joinsTree = new JoinsTree(firstTable, ctx.joins); } matchUp = ctx.joinsTree.matches(model.getJoinsTree(), result); } if (matchUp == null) { ctx.realizationCheck.addModelIncapableReason(model, RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.MODEL_UNMATCHED_JOIN)); return null; } result.putAll(matchUp); ctx.realizationCheck.addCapableModel(model, result); return result; }
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)); } // validate PK/FK are in dimensions boolean pkfkDimAmended = false; for (Chain chain : joinsTree.getTableChains().values()) { pkfkDimAmended = validatePkFkDim(chain.join, mcols) || pkfkDimAmended; } return pkfkDimAmended; }
public Map<String, String> matches(JoinsTree another, Map<String, String> constraints) { Map<String, String> matchUp = new HashMap<>(); for (Chain chain : tableChains.values()) { if (matchInTree(chain, another, constraints, matchUp) == false) return null; } return matchUp; }
private boolean matchInTree(Chain chain, JoinsTree another, Map<String, String> constraints, Map<String, String> matchUp) { String thisAlias = chain.table.getAlias(); if (matchUp.containsKey(thisAlias)) return true; String constraint = constraints.get(thisAlias); if (constraint != null) { return matchChain(chain, another.tableChains.get(constraint), matchUp); } for (Chain anotherChain : another.tableChains.values()) { if (matchChain(chain, anotherChain, matchUp)) { return true; } } return false; }
if (joinsTree.matchNum(originJoinsTree) != originDataModelDesc.getJoinTables().length + 1) checkRet.append("The join shouldn't be modified in this model.");
private static Map<String, String> matches(DataModelDesc model, OLAPContext ctx) { Map<String, String> result = Maps.newHashMap(); TableRef firstTable = ctx.firstTableScan.getTableRef(); Map<String, String> matchUp = null; if (ctx.joins.isEmpty() && model.isLookupTable(firstTable.getTableIdentity())) { // one lookup table String modelAlias = model.findFirstTable(firstTable.getTableIdentity()).getAlias(); matchUp = ImmutableMap.of(firstTable.getAlias(), modelAlias); } else if (ctx.joins.size() != ctx.allTableScans.size() - 1) { // has hanging tables ctx.realizationCheck.addModelIncapableReason(model, RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.MODEL_BAD_JOIN_SEQUENCE)); throw new IllegalStateException("Please adjust the sequence of join tables. " + toErrorMsg(ctx)); } else { // normal big joins if (ctx.joinsTree == null) { ctx.joinsTree = new JoinsTree(firstTable, ctx.joins); } matchUp = ctx.joinsTree.matches(model.getJoinsTree(), result); } if (matchUp == null) { ctx.realizationCheck.addModelIncapableReason(model, RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.MODEL_UNMATCHED_JOIN)); return null; } result.putAll(matchUp); ctx.realizationCheck.addCapableModel(model, result); return result; }
@Test public void testBasics() { DataModelManager mgr = DataModelManager.getInstance(KylinConfig.getInstanceFromEnv()); DataModelDesc model = mgr.getDataModelDesc("ci_left_join_model"); JoinsTree joinsTree = model.getJoinsTree(); Chain chain = joinsTree.getTableChains().get("BUYER_COUNTRY"); assertTrue(chain.table == model.findTable("BUYER_COUNTRY")); assertTrue(chain.fkSide.table == model.findTable("BUYER_ACCOUNT")); assertTrue(chain.fkSide.fkSide.table == model.findTable("TEST_ORDER")); assertTrue(chain.fkSide.fkSide.fkSide.table == model.findTable("TEST_KYLIN_FACT")); assertTrue(chain.fkSide.fkSide.fkSide.join == null); assertTrue(chain.fkSide.fkSide.fkSide.fkSide == null); }
public int matchNum(JoinsTree another) { Map<String, String> matchUp = new HashMap<>(); for (Chain chain : tableChains.values()) { matchInTree(chain, another, Collections.<String, String> emptyMap(), matchUp); } return matchUp.size(); }
private boolean matchChain(Chain chain, Chain anotherChain, Map<String, String> matchUp) { String thisAlias = chain.table.getAlias(); String anotherAlias = anotherChain.table.getAlias(); String curMatch = matchUp.get(thisAlias); if (curMatch != null) return curMatch.equals(anotherAlias); if (curMatch == null && matchUp.values().contains(anotherAlias)) return false; boolean matches = false; if (chain.join == null) { matches = anotherChain.join == null && chain.table.getTableDesc().getIdentity().equals(anotherChain.table.getTableDesc().getIdentity()); } else { matches = joinDescMatcher.matches(chain.join, anotherChain.join) && matchChain(chain.fkSide, anotherChain.fkSide, matchUp); } if (matches) { matchUp.put(thisAlias, anotherAlias); } return matches; }
@Test public void testMatch() { DataModelManager mgr = DataModelManager.getInstance(KylinConfig.getInstanceFromEnv()); DataModelDesc model = mgr.getDataModelDesc("ci_inner_join_model"); JoinsTree joinsTree = model.getJoinsTree(); Map<String, String> matchUp = joinsTree.matches(joinsTree); for (Entry<String, String> e : matchUp.entrySet()) { assertTrue(e.getKey().equals(e.getValue())); } assertTrue(model.getAllTables().size() == matchUp.size()); } }
public JoinsTree getSubgraphByAlias(Set<String> aliases) { Map<String, Chain> subgraph = Maps.newHashMap(); for (String alias : aliases) { Chain chain = tableChains.get(alias); if (chain == null) throw new IllegalArgumentException("Table with alias " + alias + " is not found"); while (chain.getFkSide() != null) { subgraph.put(chain.table.getAlias(), chain); chain = chain.getFkSide(); } subgraph.put(chain.table.getAlias(), chain); } return new JoinsTree(subgraph); }
logger.info("Checking snapshot of {}", lookup); try { JoinDesc join = cubeSeg.getModel().getJoinsTree().getJoinByPKSide(lookup); ILookupTable table = cubeMgr.getLookupTable(cubeSeg, join); if (table != null) {
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)); } // validate PK/FK are in dimensions boolean pkfkDimAmended = false; for (Chain chain : joinsTree.getTableChains().values()) { pkfkDimAmended = validatePkFkDim(chain.join, mcols) || pkfkDimAmended; } return pkfkDimAmended; }
public List<Chain> unmatchedChain(JoinsTree another, Map<String, String> constraints) { Map<String, String> matchUp = new HashMap<>(); List<Chain> unmatchedChainList = Lists.newArrayList(); for (Chain chain : tableChains.values()) { if (matchInTree(chain, another, constraints, matchUp) == false) unmatchedChainList.add(chain); } return unmatchedChainList; }
private boolean matchInTree(Chain chain, JoinsTree another, Map<String, String> constraints, Map<String, String> matchUp) { String thisAlias = chain.table.getAlias(); if (matchUp.containsKey(thisAlias)) return true; String constraint = constraints.get(thisAlias); if (constraint != null) { return matchChain(chain, another.tableChains.get(constraint), matchUp); } for (Chain anotherChain : another.tableChains.values()) { if (matchChain(chain, anotherChain, matchUp)) { return true; } } return false; }
public Map<String, String> matches(JoinsTree another) { return matches(another, Collections.<String, String> emptyMap()); }
private void initJoinsTree() { List<JoinDesc> joins = new ArrayList<>(); for (JoinTableDesc joinTable : joinTables) { joins.add(joinTable.getJoin()); } joinsTree = new JoinsTree(rootFactTableRef, joins); }