public boolean isCubeMeasure(String col) { if (col == null) { return false; } col = col.trim(); // Take care of brackets added around col names in HQLParsrer.getString if (col.startsWith("(") && col.endsWith(")") && col.length() > 2) { col = col.substring(1, col.length() - 1); } String[] split = StringUtils.split(col, "."); if (split.length <= 1) { col = col.trim().toLowerCase(); if (queriedExprs.contains(col)) { return exprCtx .getExpressionContext(col, getAliasForTableName(cube.getName())) .hasMeasures(); } else { return cube.getMeasureNames().contains(col); } } else { String cubeName = split[0].trim().toLowerCase(); String colName = split[1].trim().toLowerCase(); if (cubeName.equalsIgnoreCase(cube.getName()) || cubeName.equals(getAliasForTableName(cube.getName()))) { if (queriedExprs.contains(colName)) { return exprCtx.getExpressionContext(colName, cubeName).hasMeasures(); } else { return cube.getMeasureNames().contains(colName.toLowerCase()); } } else { return false; } } }
/** * Figure out queried dim attributes and measures from the cube query context * * @param cubeql * @throws LensException */ private void findDimAttributesAndMeasures(CubeQueryContext cubeql) throws LensException { CubeInterface cube = cubeql.getCube(); if (cube != null) { Set<String> cubeColsQueried = cubeql.getColumnsQueried(cube.getName()); Set<String> queriedDimAttrs = new HashSet<String>(); Set<String> queriedMsrs = new HashSet<String>(); Set<String> queriedExprs = new HashSet<String>(); if (cubeColsQueried != null && !cubeColsQueried.isEmpty()) { for (String col : cubeColsQueried) { if (cube.getMeasureNames().contains(col)) { queriedMsrs.add(col); } else if (cube.getDimAttributeNames().contains(col)) { queriedDimAttrs.add(col); } else if (cube.getExpressionNames().contains(col)) { queriedExprs.add(col); } } } cubeql.addQueriedDimAttrs(queriedDimAttrs); cubeql.addQueriedMsrs(queriedMsrs); cubeql.addQueriedExprs(queriedExprs); } }