@Test public void testColumnErrors() throws Exception { LensException th; th = getLensExceptionInRewrite( "select nocolexpr, SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf); Assert.assertEquals( th.getErrorCode(), LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo().getErrorCode()); Assert.assertTrue( getLensExceptionErrorMessageInRewrite( "select nocolexpr, SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf) .contains("nonexist")); Assert.assertTrue( getLensExceptionErrorMessageInRewrite( "select invalidexpr, SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf) .contains("invalidexpr")); th = getLensExceptionInRewrite( "select invalidexpr, " + "SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf); Assert.assertEquals( th.getErrorCode(), LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo().getErrorCode()); }
@Test public void testDerivedCube() throws ParseException, LensException, HiveException { LensException th = getLensExceptionInRewrite( "select avgmsr from derivedCube" + " where " + TWO_DAYS_RANGE, conf); Assert.assertEquals( th.getErrorCode(), LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo().getErrorCode()); }
static void extractTabAliasForCol(CubeQueryContext cubeql, TrackQueriedColumns tqc) throws LensException { Map<String, String> colToTableAlias = cubeql.getColToTableAlias(); Set<String> columns = tqc.getTblAliasToColumns().get(CubeQueryContext.DEFAULT_TABLE); if (columns == null) { return; } for (String col : columns) { boolean inCube = false; if (cubeql.getCube() != null) { Set<String> cols = cubeql.getCube().getAllFieldNames(); if (cols.contains(col.toLowerCase())) { String cubeAlias = cubeql.getAliasForTableName(cubeql.getCube().getName()); colToTableAlias.put(col.toLowerCase(), cubeAlias); tqc.addColumnsQueried(cubeAlias, col.toLowerCase()); inCube = true; } } for (Dimension dim : cubeql.getDimensions()) { 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()); } else { // throw error because column is in both cube and dimension table throw new LensException( LensCubeErrorCode.AMBIGOUS_CUBE_COLUMN.getLensErrorInfo(), col, cubeql.getCube().getName(), dim.getName()); } } } if (colToTableAlias.get(col.toLowerCase()) == null) { throw new LensException(LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo(), col); } } }