protected LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection, final String errorMsg, final String stackTrace) { return LensErrorTO.composedOf(getErrorCode(), errorMsg, stackTrace); }
protected LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection, final String errorMsg, final String stackTrace) { return LensErrorTO.composedOf(getErrorCode(), errorMsg, stackTrace); }
public final LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection) { final LensError lensError = errorCollection.getLensError(getErrorCode()); return buildLensErrorTO(errorCollection, lensError); }
public final LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection) { final LensError lensError = errorCollection.getLensError(getErrorCode()); return buildLensErrorTO(errorCollection, lensError); }
public final void buildLensErrorResponse(final ErrorCollection errorCollection, final String apiVersion, final String id) { final LensError lensError = errorCollection.getLensError(getErrorCode()); final LensErrorTO lensErrorTO = buildLensErrorTO(errorCollection, lensError); lensAPIResult = LensAPIResult.composedOf(apiVersion, id, lensErrorTO, lensError.getHttpStatusCode()); }
public final void buildLensErrorResponse(final ErrorCollection errorCollection, final String apiVersion, final String id) { final LensError lensError = errorCollection.getLensError(getErrorCode()); final LensErrorTO lensErrorTO = buildLensErrorTO(errorCollection, lensError); lensAPIResult = LensAPIResult.composedOf(apiVersion, id, lensErrorTO, lensError.getHttpStatusCode()); }
@Override public void validateSession(final LensSessionHandle sessionHandle) throws LensException { try { verifySessionInMemory(sessionHandle); } catch (LensException e) { if (e.getErrorCode() == LensServerErrorCode.SESSION_CLOSED.getLensErrorInfo().getErrorCode()) { restoreFromDb(sessionHandle); } else { throw e; } } }
@Test public void testVirtualFactColEndTimeQuery() { try { rewriteCtx("select dim2,SUM(msr1) from virtualcube where " + TWO_DAYS_RANGE, getConfWithStorages("C1")); Assert.fail("Should not come here..Column End time feature is failing.."); }catch (LensException e) { if (e.getErrorCode() == 3024) { System.out.println("Expected flow :" + e.getMessage()); }else { Assert.fail("Exception not as expected"); } } }
@Test public void testVirtualFactColStartTimeQuery() { try { rewriteCtx("select dim1,SUM(msr1) from virtualcube where " + TWO_DAYS_RANGE, getConfWithStorages("C1")); Assert.fail("Should not come here..Column Start time feature is failing.."); }catch (LensException e) { if (e.getErrorCode() == 3024) { System.out.println("Expected flow :" + e.getMessage()); }else { Assert.fail("Exception not as expected"); } } }
@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()); }
protected void assertLensExceptionInRewrite(String query, Configuration conf, LensCubeErrorCode expectedError) throws LensException, ParseException { LensException e = getLensExceptionInRewrite(query, conf); assertNotNull(e); assertEquals(e.getErrorCode(), expectedError.getLensErrorInfo().getErrorCode()); } protected String getLensExceptionErrorMessageInRewrite(String query, Configuration conf) throws LensException,
@Test public void testExpressionFieldWithOtherFields() throws Exception { // select with expression which requires dimension tables. // And there is a candidate, which is removed because // required the dimension tables in the expression are not reachable and // the expression is not evaluable on the candidate. LensException th = getLensExceptionInRewrite("select cityStateName, msr2expr, msr5, msr15 from testCube where " + TWO_DAYS_RANGE, conf); Assert.assertEquals(th.getErrorCode(), LensCubeErrorCode.NO_JOIN_CANDIDATE_AVAILABLE.getLensErrorInfo().getErrorCode()); } @Test
@Test public void testEqualTimeRangeValidation() throws Exception { // zero range String equalTimeRange = getTimeRangeString(UpdatePeriod.HOURLY, 0, 0); try { // this should throw exception because from date and to date are same driver.rewrite("SELECT cityid, testCube.msr2 from" + " testCube where " + equalTimeRange); Assert.fail("Should not reach here"); } catch (LensException exc) { Assert.assertNotNull(exc); Assert.assertEquals(exc.getErrorCode(), LensCubeErrorCode.INVALID_TIME_RANGE.getLensErrorInfo().getErrorCode()); } }
@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()); }
static PruneCauses.BriefAndDetailedError extractPruneCause(LensException e) throws ClassNotFoundException { try { ErrorCollection errorCollection = new ErrorCollectionFactory().createErrorCollection(); final LensError lensError = errorCollection.getLensError(e.getErrorCode()); return new ObjectMapper().readValue( e.getFormattedErrorMsg(lensError).substring(e.getFormattedErrorMsg(lensError) .indexOf("{"), e.getFormattedErrorMsg(lensError).length()), new TypeReference<PruneCauses.BriefAndDetailedError>() {}); } catch (IOException e1) { throw new RuntimeException("!!!"); } }
@Test public void testVirtualFactValidColumns() throws Exception { try { rewriteCtx("select SUM(msr4) from virtualCube where " + TWO_DAYS_RANGE, getConfWithStorages("C1")); fail("Rewrite should not succeed here"); } catch (LensException exc) { assertEquals(exc.getErrorCode(), LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo().getErrorCode()); } } }
@Test public void testCandidateTables() throws Exception { LensException th = getLensExceptionInRewrite( "select dim12, SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, getConf()); assertEquals(th.getErrorCode(), LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo().getErrorCode()); // this query should through exception because invalidMsr is invalid th = getLensExceptionInRewrite( "SELECT cityid, invalidMsr from testCube " + " where " + TWO_DAYS_RANGE, getConf()); assertEquals(th.getErrorCode(), LensCubeErrorCode.COLUMN_NOT_FOUND.getLensErrorInfo().getErrorCode()); }
@Test public void testColumnAmbiguity() throws Exception { String query = "SELECT ambigdim1, sum(testCube.msr1) FROM testCube join" + " citydim on testcube.cityid = citydim.id where " + TWO_DAYS_RANGE; LensException th = getLensExceptionInRewrite(query, getConf()); assertEquals(th.getErrorCode(), LensCubeErrorCode.AMBIGOUS_CUBE_COLUMN.getLensErrorInfo().getErrorCode()); String q2 = "SELECT ambigdim2 from citydim join" + " statedim on citydim.stateid = statedim.id join countrydim on" + " statedim.countryid = countrydim.id"; th = getLensExceptionInRewrite(q2, getConf()); assertEquals(th.getErrorCode(), LensCubeErrorCode.AMBIGOUS_DIM_COLUMN.getLensErrorInfo().getErrorCode()); }
@Test public void testQueryWithNow() throws Exception { LensException e = getLensExceptionInRewrite( "select SUM(msr2) from testCube where " + getTimeRangeString("NOW - 2DAYS", "NOW"), getConf()); assertEquals(e.getErrorCode(), LensCubeErrorCode.NO_CANDIDATE_FACT_AVAILABLE.getLensErrorInfo().getErrorCode()); }
protected String getLensExceptionErrorMessageInRewrite(String query, Configuration conf) throws LensException, ParseException, ClassNotFoundException { try { String hql = rewrite(query, conf); Assert.fail("Should have thrown exception. But rewrote the query : " + hql); // unreachable return null; } catch (LensException e) { ErrorCollection errorCollection = new ErrorCollectionFactory().createErrorCollection(); final LensError lensError = errorCollection.getLensError(e.getErrorCode()); log.error("Lens exception in Rewrite.", e); return e.getFormattedErrorMsg(lensError); } }