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; }
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; }
@Override public int hashCode() { final int PRIME = 59; int result = 1; result = result * PRIME + errorInfo.hashCode(); result = result * PRIME + (this.getMessage() == null ? 0 : this.getMessage().hashCode()); result = result * PRIME + Arrays.deepHashCode(errorMsgFormattingArgs); return result; }
@Override public int hashCode() { final int PRIME = 59; int result = 1; result = result * PRIME + errorInfo.hashCode(); result = result * PRIME + (this.getMessage() == null ? 0 : this.getMessage().hashCode()); result = result * PRIME + Arrays.deepHashCode(errorMsgFormattingArgs); return result; }
/** * Copy Constructor * @param e */ public LensException(LensException e) { this(e.getMessage(), e.getErrorInfo(), e.getCause(), e.errorMsgFormattingArgs); }
/** * Copy Constructor * @param e */ public LensException(LensException e) { this(e.getMessage(), e.getErrorInfo(), e.getCause(), e.errorMsgFormattingArgs); }
/** * Close a Lens server session. * * @param sessionid Session handle object of the session to be closed * @return APIResult object indicating if the operation was successful (check result.getStatus()) */ @DELETE @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN}) public APIResult closeSession(@QueryParam("sessionid") LensSessionHandle sessionid) { try { sessionService.closeSession(sessionid); } catch (LensException e) { log.error("Got an exception while closing {} session: ", sessionid, e); return new APIResult(Status.FAILED, e.getMessage()); } return new APIResult(Status.SUCCEEDED, "Close session with id" + sessionid + "succeeded"); }
@Test(dataProvider = "exprDataProvider") public void testParseExpr(String expr, HiveConf conf, boolean success) { try { parseExpr(expr, conf); Assert.assertTrue(success); } catch (LensException e) { Assert.assertFalse(success); Assert.assertTrue(e.getMessage().contains(expr)); Assert.assertTrue(e.getMessage().contains(LensCubeErrorCode.COULD_NOT_PARSE_EXPRESSION.name())); } } @DataProvider
@Test public void testCustomNow() throws Exception { Configuration conf = getConf(); DateTime dt = new DateTime(1990, 3, 23, 12, 0, 0, 0); conf.setLong(LensConfConstants.QUERY_CURRENT_TIME_IN_MILLIS, dt.getMillis()); String query = "select msr12 from basecube where time_range_in(d_time, 'now.day-275days','now')"; LensException e = getLensExceptionInRewrite(query, conf); assertEquals(e.getMessage(), "NO_CANDIDATE_FACT_AVAILABLE[Range not answerable]"); }
private boolean shouldBeRemoved(Candidate candidate) { if (candidate.getChildren() == null) { return false; } else if (candidate instanceof SegmentationCandidate) { SegmentationCandidate segCand = ((SegmentationCandidate) candidate); try { boolean areCandidatsPicked = segCand.rewriteInternal(conf, hconf); if (!areCandidatsPicked) { Map<String, PruneCauses<Candidate>> pruneCauses = segCand.getPruneCausesOfFailedContexts(); Map<String, String> briefCauses = pruneCauses.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getBriefCause())); log.info("Segmentation Candidates {} not picked because: {}", candidate, briefCauses); cubeql.addCandidatePruningMsg(candidate, segmentationPruned(briefCauses)); } return !areCandidatsPicked; } catch (LensException e) { log.info("Segmentation Candidates {} not picked because: {}", candidate, e.getMessage()); cubeql.addCandidatePruningMsg(candidate, segmentationPruned(e)); return true; } } else { return candidate.getChildren().stream().anyMatch(this::shouldBeRemoved); } } }
log.error("Error closing session " + sessionHandle.getPublicId() + " reason " + e.getMessage(), e);
private boolean shouldBeRemoved(Candidate candidate) { if (candidate.getChildren() == null) { return false; } else if (candidate instanceof SegmentationCandidate) { SegmentationCandidate segCand = ((SegmentationCandidate) candidate); try { boolean areCandidatsPicked = segCand.rewriteInternal(conf, hconf); if (!areCandidatsPicked) { Map<String, PruneCauses<Candidate>> pruneCauses = segCand.getPruneCausesOfFailedContexts(); Map<String, String> briefCauses = pruneCauses.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getBriefCause())); log.info("Segmentation Candidates {} not picked because: {}", candidate, briefCauses); cubeql.addCandidatePruningMsg(candidate, segmentationPruned(briefCauses)); } return !areCandidatsPicked; } catch (LensException e) { log.info("Segmentation Candidates {} not picked because: {}", candidate, e.getMessage()); cubeql.addCandidatePruningMsg(candidate, segmentationPruned(e)); return true; } } else { return candidate.getChildren().stream().anyMatch(this::shouldBeRemoved); } } }
@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 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 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 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")); } }
fail(e.getMessage());
/** * Creates the query context * @param conf the conf * @param queryName the name of query * @return the query context */ protected QueryContext createContext(Configuration conf, String queryName) { final LensDriver mockDriver = new MockDriver(); try { mockDriver.configure(conf, null, null); } catch (LensException e) { Assert.fail(e.getMessage()); } QueryContext ctx = QueryContext.createContextWithSingleDriver("test writer query", "testuser", new LensConf(), conf, mockDriver, null, false); ctx.setSelectedDriver(mockDriver); ctx.setQueryName(queryName); return ctx; }
@Test(dataProvider = "update-periods") public void test(UpdatePeriod up) throws LensException { // Normal date object parsable String nowStr = up.format(NOW); // Create partition by date object or it's string representation -- both should be same. TimePartition nowPartition = TimePartition.of(up, NOW); TimePartition nowStrPartition = TimePartition.of(up, nowStr); assertEquals(nowPartition, nowStrPartition); // Test next and previous assertTrue(nowPartition.next().after(nowPartition)); assertTrue(nowPartition.previous().before(nowPartition)); // date parse failures should give lens exception assertEquals(getLensExceptionFromPartitionParsing(up, "garbage").getMessage(), TimePartition.getWrongUpdatePeriodMessage(up, "garbage")); getLensExceptionFromPartitionParsing(up, (Date) null); getLensExceptionFromPartitionParsing(up, (String) null); getLensExceptionFromPartitionParsing(up, ""); // parse with other update periods for (UpdatePeriod up2 : UpdatePeriod.values()) { // handles the equality case and the case where monthly-quarterly have same format strings. if (up.formatStr().equals(up2.formatStr())) { continue; } // Parsing a string representation with differnet update period should give lens exception. assertEquals(getLensExceptionFromPartitionParsing(up2, nowStr).getMessage(), TimePartition.getWrongUpdatePeriodMessage(up2, nowStr)); } }
/** * Test cancel async query. * * @throws Exception the exception */ @Test public void testCancelAsyncQuery() throws Exception { int handleSize = getHandleSize(); createTestTable("test_cancel_async"); queryConf.setBoolean(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, false); QueryContext context = createContext("select a.id aid, b.id bid from " + "((SELECT ID FROM test_cancel_async) a full outer join (select id from test_cancel_async) b)", queryConf); driver.executeAsync(context); driver.cancelQuery(context.getQueryHandle()); driver.updateStatus(context); assertEquals(context.getDriverStatus().getState(), DriverQueryState.CANCELED, "Expecting query to be cancelled"); driver.closeQuery(context.getQueryHandle()); assertHandleSize(handleSize); try { driver.cancelQuery(context.getQueryHandle()); fail("Cancel on closed query should throw error"); } catch (LensException exc) { assertTrue(exc.getMessage().startsWith("Query not found")); } }