/** * Remove the dimension with name specified * * @param attrName */ public void removeAttribute(String attrName) { if (attributeMap.containsKey(attrName.toLowerCase())) { log.info("Removing attribute {}", getAttributeByName(attrName)); attributes.remove(getAttributeByName(attrName)); attributeMap.remove(attrName.toLowerCase()); MetastoreUtil.addNameStrings(getProperties(), MetastoreUtil.getDimAttributeListKey(getName()), attributes); } }
public Dimension(Table tbl) { super(tbl); this.attributes = getAttributes(getName(), getProperties()); attributeMap = new HashMap<>(); for (CubeDimAttribute attr : attributes) { addAllAttributesToMap(attr); } }
@Override public boolean equals(Object obj) { if (!super.equals(obj)) { return false; } Dimension other = (Dimension) obj; if (this.getAttributes() == null) { if (other.getAttributes() != null) { return false; } } else if (!this.getAttributes().equals(other.getAttributes())) { return false; } if (this.getJoinChains() == null) { if (other.getJoinChains() != null) { return false; } } else if (!this.getJoinChains().equals(other.getJoinChains())) { return false; } return true; }
/** * @return the timedDimension */ public String getTimedDimension() { return getProperties().get(MetastoreUtil.getDimTimedDimensionKey(getName())); }
assertTrue(client.tableExists(cityDim.getName())); assertTrue(client.tableExists(stateDim.getName())); assertTrue(client.tableExists(countryDim.getName())); Dimension city = client.getDimension(cityDim.getName()); assertEquals(dimExpressions.size(), city.getExpressions().size()); assertEquals(dimExpressions.size(), city.getExpressionNames().size()); assertNotNull(city.getExpressionByName("stateAndCountry")); assertNotNull(city.getExpressionByName("cityaddress")); assertEquals(city.getExpressionByName("cityaddress").getDescription(), "city with state and city and zip"); assertEquals(city.getExpressionByName("cityaddress").getDisplayString(), "City Address"); city.alterExpression(stateCountryExpr); city.removeExpression("cityAddress"); city = client.getDimension(cityDim.getName()); assertEquals(1, city.getExpressions().size()); ExprColumn stateAndCountryActual = city.getExpressionByName("stateAndCountry"); assertNotNull(stateAndCountryActual.getExpressions()); assertEquals(2, stateAndCountryActual.getExpressions().size()); assertNotNull(city.getExpressionByName("stateAndCountry")); assertEquals(city.getExpressionByName("stateAndCountry").getExpr(), "concat(citystate.name, \"-\", citycountry.name)"); city.alterExpression(stateAndCountryActual); client.alterDimension(city.getName(), city); Dimension cityAltered = client.getDimension(city.getName());
private void validateDim(Dimension udim, Set<CubeDimAttribute> attrs, String basedim, String referdim) throws HiveException, LensException { assertTrue(client.tableExists(udim.getName())); Table dimTbl = client.getHiveTable(udim.getName()); assertTrue(client.isDimension(dimTbl)); Dimension dim = new Dimension(dimTbl); assertTrue(udim.equals(dim), "Equals failed for " + dim.getName()); assertTrue(udim.equals(client.getDimension(udim.getName()))); assertEquals(dim.getAttributes().size(), attrs.size()); assertNotNull(dim.getAttributeByName(basedim)); assertTrue(dim.getAttributeByName(basedim) instanceof BaseDimAttribute); if (referdim != null) { assertNotNull(dim.getAttributeByName(referdim)); assertTrue(dim.getAttributeByName(referdim) instanceof ReferencedDimAttribute); } assertEquals(udim.getAttributeNames().size() + udim.getExpressionNames().size(), dim.getAllFieldNames().size()); }
public static XDimension xdimensionFromDimension(Dimension dimension) { XDimension xd = XCF.createXDimension(); xd.setName(dimension.getName()); xd.setAttributes(new XDimAttributes()); xd.setExpressions(new XExpressions()); xd.setJoinChains(new XJoinChains()); xd.setProperties(new XProperties()); xd.getProperties().getProperty().addAll(xPropertiesFromMap(((AbstractCubeTable) dimension).getProperties())); for (CubeDimAttribute cd : dimension.getAttributes()) { xd.getAttributes().getDimAttribute().add(xDimAttrFromHiveDimAttr(cd, dimension)); } for (ExprColumn ec : dimension.getExpressions()) { xd.getExpressions().getExpression().add(xExprColumnFromHiveExprColumn(ec)); } for (JoinChain jc : dimension.getJoinChains()) { xd.getJoinChains().getJoinChain().add(getXJoinChainFromJoinChain(jc)); } return xd; }
/** * Get all dimension tables of the dimension. * * @param dim Dimension object * @return List of fact tables * @throws LensException */ public List<CubeDimensionTable> getAllDimensionTables(Dimension dim) throws LensException { List<CubeDimensionTable> dimTables = new ArrayList<>(); for (CubeDimensionTable dimTbl : getAllDimensionTables()) { if (dim == null || dimTbl.getDimName().equalsIgnoreCase(dim.getName().toLowerCase())) { dimTables.add(dimTbl); } } return dimTables; }
@Override public void addProperties() { super.addProperties(); MetastoreUtil.addNameStrings(getProperties(), MetastoreUtil.getDimAttributeListKey(getName()), attributes); setAttributedProperties(getProperties(), attributes); }
private void addAllDirectAttributesToFlattenedListFromDimension(ObjectFactory objectFactory, Dimension dimension, List<XFlattenedColumn> columnList, String chainName) { for (CubeDimAttribute cd : dimension.getAttributes()) { XFlattenedColumn fcol = objectFactory.createXFlattenedColumn(); fcol.setDimAttribute(JAXBUtils.xDimAttrFromHiveDimAttr(cd, dimension)); fcol.setTableName(dimension.getName()); if (chainName != null) { fcol.setChainName(chainName); } columnList.add(fcol); } }
if (dim.getAllFieldNames().contains(col.toLowerCase())) { if (!inCube) { String prevDim = colToTableAlias.get(col.toLowerCase()); if (prevDim != null && !prevDim.equals(dim.getName())) { throw new LensException(LensCubeErrorCode.AMBIGOUS_DIM_COLUMN.getLensErrorInfo(), col, prevDim, dim.getName()); String dimAlias = cubeql.getAliasForTableName(dim.getName()); colToTableAlias.put(col.toLowerCase(), dimAlias); tqc.addColumnsQueried(dimAlias, col.toLowerCase()); cubeql.getCube().getName(), dim.getName());
if (cubeql.getColumnsQueriedForTable(dim.getName()) != null) { for (String col : cubeql.getColumnsQueriedForTable(dim.getName())) { if (!cdim.getColumns().contains(col.toLowerCase())) { if (cdim.getBaseTable().getExpressionNames().contains(col)) { cubeql.getExprCtx().updateEvaluables(col, cdim); break; } else if (!cubeql.getDeNormCtx().addRefUsage(cubeql, cdim, col, dim.getName())) { throw new LensException(LensCubeErrorCode.NO_DIM_HAS_COLUMN.getLensErrorInfo(), dim.getName(), cubeql .getColumnsQueriedForTable(dim.getName()).toString());
storageTables.add(tableName); String whereClause = StorageUtil .getWherePartClause(dim.getTimedDimension(), null, StorageConstants.getPartitionsForLatest()); whereClauses.put(tableName, whereClause); } else { addNonExistingParts(dim.getName(), StorageConstants.getPartitionsForLatest());
col = ((CubeInterface) tbl).getColumnByName(column); } else { col = ((Dimension) tbl).getColumnByName(column); Set<ExpressionContext> ecSet = ecEntry.getValue(); for (ExpressionContext ec : ecSet) { if (ec.getSrcTable().getName().equals(cdim.getBaseTable().getName())) { if (!ec.isEvaluable(cdim)) { log.info("Not considering dim table:{} as {} is not evaluable", cdim, ec.exprCol.getName());
assertNotNull(dim.getAttributeByName("col1")); assertEquals(dim.getAttributeByName("col1").getDescription(), "first column"); assertEquals(dim.getAttributeByName("col1").getDisplayString(), "Column1"); assertNotNull(dim.getAttributeByName("col2")); assertEquals(dim.getAttributeByName("col2").getDescription(), "second column"); assertEquals(dim.getAttributeByName("col2").getDisplayString(), "Column2"); assertNotNull(dim.getExpressionByName("dimexpr")); assertEquals(dim.getExpressionByName("dimexpr").getDescription(), "dimension expression"); assertEquals(dim.getExpressionByName("dimexpr").getDisplayString(), "Dim Expression"); assertNotNull(dim.getAttributeByName("col3")); BaseDimAttribute col3 = (BaseDimAttribute) dim.getAttributeByName("col3"); assertEquals(col3.getDescription(), "inline column"); assertEquals(col3.getDisplayString(), "Column3"); assertEquals(col3.getValues().get().get(2), "Val3"); assertEquals(col3.getNumOfDistinctValues().get(), (Long) 3L); assertNotNull(dim.getAttributeByName("col4")); HierarchicalDimAttribute col4 = (HierarchicalDimAttribute) dim.getAttributeByName("col4"); assertEquals(col4.getDescription(), "hierarchical column"); BaseDimAttribute col4h1 = (BaseDimAttribute) col4.getHierarchy().get(0); assertEquals(col4h3.getChainRefColumns().get(0).getRefColumn(), "col2"); assertEquals(col4h3.getNumOfDistinctValues().get(), (Long) 1000L); assertNotNull(dim.getAttributeByName("col5")); ReferencedDimAttribute col5 = (ReferencedDimAttribute) dim.getAttributeByName("col5"); assertEquals(col5.getDescription(), "ref column"); assertEquals(col5.getDisplayString(), "Column5"); assertNotNull(dim.getAttributeByName("col3Added"));
private Dimension getDimension(Table tbl) { return new Dimension(tbl); }
public Set<String> getAttributeNames() { Set<String> dimNames = new HashSet<String>(); for (CubeDimAttribute f : getAttributes()) { MetastoreUtil.addColumnNames(f, dimNames); } return dimNames; }
public CubeColumn getColumnByName(String column) { CubeColumn cubeCol = super.getExpressionByName(column); if (cubeCol == null) { cubeCol = getAttributeByName(column); } return cubeCol; }
@Override public XJoinChains getAllJoinChains(LensSessionHandle sessionHandle, String tableName) throws LensException { try (SessionContext ignored = new SessionContext(sessionHandle)){ CubeMetastoreClient client = getClient(sessionHandle); Set<JoinChain> chains; if (client.isCube(tableName)) { chains = client.getCube(tableName).getJoinChains(); } else if (client.isDimension(tableName)) { chains = client.getDimension(tableName).getJoinChains(); } else { throw new BadRequestException("Can't get join chains. '" + tableName + "' is neither a cube nor a dimension"); } XJoinChains xJoinChains = new XJoinChains(); List<XJoinChain> joinChains = xJoinChains.getJoinChain(); if (chains != null) { for (JoinChain chain : chains) { joinChains.add(JAXBUtils.getXJoinChainFromJoinChain(chain)); } } return xJoinChains; } }