public static LensException wrap(Exception e) { if (e instanceof LensException) { return (LensException) e; } return new LensException(e); }
private boolean isErrorMsgEqual(final LensException e) { if (this.getMessage() == null && e.getMessage() == null) { return true; } if (this.getMessage() != null && e.getMessage() != null) { return this.getMessage().equals(e.getMessage()); } return false; }
protected LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection, final String errorMsg, final String stackTrace) { return LensErrorTO.composedOf(getErrorCode(), errorMsg, stackTrace); }
/** * Copy Constructor * @param e */ public LensException(LensException e) { this(e.getMessage(), e.getErrorInfo(), e.getCause(), e.errorMsgFormattingArgs); }
public final LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection) { final LensError lensError = errorCollection.getLensError(getErrorCode()); return buildLensErrorTO(errorCollection, lensError); }
@Test public void testColumnErrors() throws Exception { LensException e; e = getLensExceptionInRewrite("select msr11 + msr2 from basecube" + " where " + TWO_DAYS_RANGE, conf); e.buildLensErrorResponse(new ErrorCollectionFactory().createErrorCollection(), null, "testid"); assertEquals(e.getErrorCode(), LensCubeErrorCode.NO_FACT_HAS_COLUMN.getLensErrorInfo().getErrorCode()); assertTrue(e.getMessage().contains("msr11"), e.getMessage()); assertTrue(e.getMessage().contains("msr2"), e.getMessage()); // no fact has the all the dimensions queried e = getLensExceptionInRewrite("select dim1, test_time_dim, msr3, msr13 from basecube where " + TWO_DAYS_RANGE, conf); assertEquals(e.getErrorCode(), LensCubeErrorCode.NO_JOIN_CANDIDATE_AVAILABLE.getLensErrorInfo().getErrorCode()); assertTrue(e.getMessage().contains("[msr3, msr13]")); }
@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 testJdbcSqlException() throws Exception { final String query = "SELECT invalid_column FROM execute_test"; try { PreparedQueryContext pContext = new PreparedQueryContext(query, "SA", baseConf, drivers); driver.validate(pContext); driver.prepare(pContext); } catch (LensException e) { assertEquals(e.getErrorInfo().getErrorCode(), 4001); assertEquals(e.getErrorInfo().getErrorName(), "SEMANTIC_ERROR"); assertTrue(e.getMessage().contains("user lacks privilege or object not found: EXECUTE_TEST")); } }
@Test(priority = 2) public void testAdminControl() throws Exception { long currentTime = System.currentTimeMillis(); XJob job = getTestJob("0/5 * * * * ?", queryString, currentTime, currentTime + 180000); LensSessionHandle sessionHandle = scheduler.openSessionAsUser(user); SchedulerJobHandle jobHandle1 = scheduler.submitJob(sessionHandle, job); SchedulerJobHandle jobHandle2 = scheduler.submitJob(sessionHandle, job); SchedulerJobHandle jobHandle3 = scheduler.submitJob(sessionHandle, job); // Fourth should throw an error. try { SchedulerJobHandle jobHandle = scheduler.submitJob(sessionHandle, job); } catch (LensException e) { Assert.assertEquals(e.getErrorCode(), 5009); Assert.assertEquals(e.getErrorInfo().getErrorName(), LensSchedulerErrorCode.MAX_SCHEDULED_JOB_EXCEEDED.name()); } scheduler.expireJob(sessionHandle, jobHandle1); scheduler.expireJob(sessionHandle, jobHandle2); scheduler.expireJob(sessionHandle, jobHandle3); }
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 testFactValidity() throws ParseException, LensException, HiveException, ClassNotFoundException { String query = "select msr2 from " + CubeTestSetup.TEST_CUBE_NAME + " where " + LAST_YEAR_RANGE; LensException e = getLensExceptionInRewrite(query, getConf()); assertEquals(e.getErrorInfo().getErrorName(), "NO_UNION_CANDIDATE_AVAILABLE"); }
@Override public void run() { SessionState.setCurrentSessionState(state); for (int i = 0; i < 1000; i++) { try { thrDriver.updateStatus(qctx); if (qctx.getDriverStatus().isFinished()) { log.info("@@ " + handle.getHandleId() + " >> " + qctx.getDriverStatus().getState()); break; } Thread.sleep(POLL_DELAY); } catch (LensException e) { log.error("Got Exception " + e.getCause(), e); errCount.incrementAndGet(); break; } catch (InterruptedException e) { log.error("Encountred Interrupted exception", e); break; } } } });
le.buildLensErrorResponse(errorCollection, null, requestId); status = le.getLensAPIResult().getHttpStatusCode(); } else if (exception instanceof WebApplicationException) { status = Response.Status.fromStatusCode(((WebApplicationException) exception).getResponse().getStatus()); return Response.status(status).entity(le.getLensAPIResult()).build();
/** * Copy Constructor * @param e */ public LensException(LensException e) { this(e.getMessage(), e.getErrorInfo(), e.getCause(), e.errorMsgFormattingArgs); }
@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"); } } }
public final LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection) { final LensError lensError = errorCollection.getLensError(getErrorCode()); return buildLensErrorTO(errorCollection, lensError); }
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); } }
@Test public void testQueryTimeRange() throws LensException { String query = "select msr2 from " + CubeTestSetup.TEST_CUBE_NAME + " where " + PREV_FIVE_TO_NEXT_FIVE_YEAR_RANGE; LensException e = getLensExceptionInRewrite(query, getConf()); assertEquals(e.getErrorInfo().getErrorName(), "QUERY_OUT_OF_ALLOWED_RANGE"); }
} catch (LensException e) { errCount.incrementAndGet(); log.info(q + " executeAsync error: " + e.getCause()); continue;
/** * Check started. * * @throws LensException the lens exception */ public void checkStarted() throws LensException { if (!isStarted) { throw new LensException("Spark driver is not started yet"); } }