/** * Get join chains from properties * * @return set of join chains */ private static Set<JoinChain> getJoinChains(AbstractBaseTable tbl, String propName, Map<String, String> props) { Set<JoinChain> joinChains = new HashSet<>(); String joinChainsStr = MetastoreUtil.getNamedStringValue(props, propName); if (!StringUtils.isBlank(joinChainsStr)) { String[] cnames = joinChainsStr.split(","); for (String chainName : cnames) { JoinChain chain = new JoinChain(tbl, chainName); joinChains.add(chain); } } return joinChains; }
private void addAllChainedColsToFlattenedList(CubeMetastoreClient client, ObjectFactory objectFactory, AbstractBaseTable baseTbl, List<XFlattenedColumn> columnList) throws HiveException, LensException { for (JoinChain chain : baseTbl.getJoinChains()) { Dimension dim = client.getDimension(chain.getDestTable()); addAllDirectAttributesToFlattenedListFromDimension(objectFactory, dim, columnList, chain.getName()); addAllDirectExpressionsToFlattenedList(objectFactory, dim, columnList, chain.getName()); } }
/** * Alters the joinchain if already existing or just adds if it is new chain * * @param joinchain join chain */ public void alterJoinChain(JoinChain joinchain) { if (joinchain == null) { throw new NullPointerException("Cannot add null joinchain"); } // Replace dimension if already existing if (chainMap.containsKey(joinchain.getName().toLowerCase())) { joinChains.remove(getChainByName(joinchain.getName())); log.info("Replacing joinchain {} with {}", getChainByName(joinchain.getName()), joinchain); } joinChains.add(joinchain); chainMap.put(joinchain.getName().toLowerCase(), joinchain); MetastoreUtil.addNameStrings(getProperties(), getJoinChainListPropKey(getName()), joinChains); joinchain.addProperties(this); }
private void processJoinChains(CubeQueryContext cubeql) throws HiveException, LensException { for (JoinChain chain : cubeql.getJoinchains().values()) { Set<String> dims = chain.getIntermediateDimensions(); dims.add(chain.getDestTable()); for (String dim : dims) { Dimension dimension = cubeql.getMetastoreClient().getDimension(dim); dimensionToJoinChainsMap.computeIfAbsent(dimension, k -> new ArrayList<>()).add(chain); } } }
/** * Create XJoinChain from cube join chain */ public static XJoinChain getXJoinChainFromJoinChain(JoinChain jc) { XJoinChain xjc = XCF.createXJoinChain(); xjc.setName(jc.getName()); xjc.setDescription(jc.getDescription()); xjc.setDisplayString(jc.getDisplayString()); xjc.setDestTable(jc.getDestTable()); xjc.setPaths(new XJoinPaths()); for (JoinChain.Path path : jc.getPaths()) { xjc.getPaths().getPath().add(xJoinPathFromJoinPath(path)); } return xjc; }
chain.add(new TableReference("citydim", "stateid")); chain.add(new TableReference("statedim", "id")); JoinChain zipState = new JoinChain("stateFromZip", "Zip State", "zip State desc"); zipState.addPath(chain); joinChains.add(zipState); assertEquals(zipchain.getDisplayString(), "Zip State"); assertEquals(zipchain.getDescription(), "zip State desc"); assertEquals(zipchain.getPaths().size(), 1); assertEquals(zipchain.getPaths().get(0).getReferences().size(), 4); assertEquals(zipchain.getPaths().get(0).getReferences().get(0).toString(), "zipdim.cityid"); assertEquals(zipchain.getPaths().get(0).getReferences().get(1).toString(), "citydim.id"); assertEquals(zipchain.getPaths().get(0).getReferences().get(2).toString(), "citydim.stateid"); assertEquals(zipchain.getPaths().get(0).getReferences().get(3).toString(), "statedim.id");
assertEquals(cube2.getJoinChains().size(), 7); JoinChain zipchain = cube2.getChainByName("cityfromzip"); assertEquals(zipchain.getDisplayString(), "Zip City"); assertEquals(zipchain.getDescription(), "zip city desc"); assertEquals(zipchain.getPaths().size(), 2); assertEquals(zipchain.getPaths().get(0).getReferences().size(), 4); assertEquals(zipchain.getPaths().get(0).getReferences().get(0).toString(), "testmetastorecube.zipcode"); assertEquals(zipchain.getPaths().get(0).getReferences().get(1).toString(), "zipdim.zipcode"); assertEquals(zipchain.getPaths().get(0).getReferences().get(2).toString(), "zipdim.cityid"); assertEquals(zipchain.getPaths().get(0).getReferences().get(3).toString(), "citydim.id"); assertEquals(zipchain.getPaths().get(1).getReferences().size(), 4); assertEquals(zipchain.getPaths().get(1).getReferences().get(0).toString(), "testmetastorecube.zipcode2"); assertEquals(zipchain.getPaths().get(1).getReferences().get(1).toString(), "zipdim.zipcode"); assertEquals(zipchain.getPaths().get(1).getReferences().get(2).toString(), "zipdim.cityid"); assertEquals(zipchain.getPaths().get(1).getReferences().get(3).toString(), "citydim.id"); JoinChain citychain = cube2.getChainByName("city"); assertEquals(citychain.getDisplayString(), "Cube City"); assertEquals(citychain.getDescription(), "cube city desc"); assertEquals(citychain.getPaths().size(), 1); assertEquals(citychain.getPaths().get(0).getReferences().size(), 2); assertEquals(citychain.getPaths().get(0).getReferences().get(0).toString(), "testmetastorecube.cityid"); assertEquals(citychain.getPaths().get(0).getReferences().get(1).toString(), "citydim.id"); assertNotNull(cube2.getDimAttributeByName("zipcityname")); ChainRefCol zipCityChain = ((ReferencedDimAttribute) cube2.getDimAttributeByName("zipcityname"))
for (String dimName : chain.getIntermediateDimensions()) { cubeql.addOptionalJoinDimTable(dimName, true); Dimension dimension = cubeql.getMetastoreClient().getDimension(chain.getDestTable()); Aliased<Dimension> aliasedDimension = Aliased.create(dimension, chain.getName()); multipleJoinPaths.computeIfAbsent(aliasedDimension, k -> new ArrayList<>()) .addAll(chain.getRelationEdges(cubeql.getMetastoreClient()));
toAlter.removeTimedDimension("dt"); JoinChain cityChain = new JoinChain("city", "Cube City", "cube city desc modified"); List<TableReference> chain = new ArrayList<>(); chain.add(new TableReference(cubeName, "cityid")); chain.add(new TableReference("citydim", "id")); cityChain.addPath(chain); toAlter.alterJoinChain(cityChain); toAlter.removeJoinChain("cityFromZip"); assertNull(altered.getDimAttributeByName("location2")); assertNull(altered.getChainByName("cityFromZip")); assertEquals(altered.getChainByName("city").getDescription(), "cube city desc modified");
public Set<String> getJoinChainNames() { Set<String> chainNames = new HashSet<>(); for (JoinChain f : getJoinChains()) { chainNames.add(f.getName().toLowerCase()); } return chainNames; }
/** * Create cube's JoinChain from JAXB counterpart * * @param xj * @return {@link JoinChain} */ public static JoinChain joinChainFromXJoinChain(XJoinChain xj) { JoinChain jc = new JoinChain(xj.getName(), xj.getDisplayString(), xj.getDescription()); for (int i = 0; i < xj.getPaths().getPath().size(); i++) { XJoinPath xchain = xj.getPaths().getPath().get(i); List<TableReference> chain = new ArrayList<TableReference>(xchain.getEdges().getEdge().size() * 2); for (XJoinEdge xRef : xchain.getEdges().getEdge()) { chain.add(new TableReference(xRef.getFrom().getTable(), xRef.getFrom().getColumn(), xRef.getFrom().isMapsToMany())); chain.add(new TableReference(xRef.getTo().getTable(), xRef.getTo().getColumn(), xRef.getTo().isMapsToMany())); } jc.addPath(chain); } return jc; }
joinchains.put(aliasLowerCaseStr, new JoinChain(joinchain)); String destTable = joinchain.getDestTable(); boolean added = addQueriedTable(alias, destTable, isOptional, true); if (!added) {
for (JoinChain chain : cubeql.getJoinchains().values()) { OptionalDimCtx optdim = cubeql.getOptionalDimensionMap().get(Aliased.create((Dimension) cubeql.getCubeTbls() .get(chain.getName()), chain.getName())); if (!checkForFactColumnExistsAndValidForRange(sc, chain.getSourceColumns(), cubeql)) { chain.getSourceColumns()); cubeql.addStoragePruningMsg(sc, CandidateTablePruneCause.columnNotFound( chain.getSourceColumns())); toRemove = true; break;
log.error("Missing chain definition for " + crCol.getChainName()); } else { xcc.setDestTable(baseTable.getChainByName(crCol.getChainName()).getDestTable());
public void addProperties(AbstractCubeTable tbl) { if (tbl instanceof Cube) { addProperties((Cube) tbl); } else { addProperties((Dimension) tbl); } }
/** * Create XJoinChain from cube join chain */ public static XJoinChain getXJoinChainFromJoinChain(JoinChain jc) { XJoinChain xjc = XCF.createXJoinChain(); xjc.setName(jc.getName()); xjc.setDescription(jc.getDescription()); xjc.setDisplayString(jc.getDisplayString()); xjc.setDestTable(jc.getDestTable()); xjc.setPaths(new XJoinPaths()); for (JoinChain.Path path : jc.getPaths()) { xjc.getPaths().getPath().add(xJoinPathFromJoinPath(path)); } return xjc; }
Assert.assertTrue(hcube.getJoinChainNames().contains("chain1")); JoinChain chain1 = hcube.getChainByName("chain1"); Assert.assertEquals(chain1.getDisplayString(), "Chain-1"); Assert.assertEquals(chain1.getDescription(), "first chain"); Assert.assertEquals(chain1.getPaths().size(), 1); List<TableReference> links = chain1.getPaths().get(0).getReferences(); Assert.assertEquals(links.size(), 2); Assert.assertEquals(links.get(0).toString(), "testgetcube.col1");
for (String dimName : chain.getIntermediateDimensions()) { cubeql.addOptionalJoinDimTable(dimName, true); Dimension dimension = cubeql.getMetastoreClient().getDimension(chain.getDestTable()); Aliased<Dimension> aliasedDimension = Aliased.create(dimension, chain.getName()); multipleJoinPaths.computeIfAbsent(aliasedDimension, k -> new ArrayList<>()) .addAll(chain.getRelationEdges(cubeql.getMetastoreClient()));
public Set<String> getJoinChainNames() { Set<String> chainNames = new HashSet<>(); for (JoinChain f : getJoinChains()) { chainNames.add(f.getName().toLowerCase()); } return chainNames; }
/** * Create cube's JoinChain from JAXB counterpart * * @param xj * @return {@link JoinChain} */ public static JoinChain joinChainFromXJoinChain(XJoinChain xj) { JoinChain jc = new JoinChain(xj.getName(), xj.getDisplayString(), xj.getDescription()); for (int i = 0; i < xj.getPaths().getPath().size(); i++) { XJoinPath xchain = xj.getPaths().getPath().get(i); List<TableReference> chain = new ArrayList<TableReference>(xchain.getEdges().getEdge().size() * 2); for (XJoinEdge xRef : xchain.getEdges().getEdge()) { chain.add(new TableReference(xRef.getFrom().getTable(), xRef.getFrom().getColumn(), xRef.getFrom().isMapsToMany())); chain.add(new TableReference(xRef.getTo().getTable(), xRef.getTo().getColumn(), xRef.getTo().isMapsToMany())); } jc.addPath(chain); } return jc; }