@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());
 }
 @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_CANDIDATE_FACT_AVAILABLE.getLensErrorInfo().getErrorCode());
 }
示例#4
0
 /**
  * Close a Lens server session.
  *
  * @param publicId Session's public id of the session to be closed
  * @return APIResult object indicating if the operation was successful (check result.getStatus())
  */
 @DELETE
 @Path("{publicId}")
 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
 public APIResult closeSession(@PathParam("publicId") UUID publicId) {
   log.info("Closing session with id: {}", publicId);
   LensSessionHandle sessionHandle = getOpenSession(publicId);
   checkSessionHandle(sessionHandle);
   openSessions.remove(publicId);
   try {
     sessionService.closeSession(sessionHandle);
   } catch (LensException e) {
     return new APIResult(Status.FAILED, e.getMessage());
   }
   return new APIResult(Status.SUCCEEDED, "Close session with id" + sessionHandle + "succeeded");
 }
  @Test
  public void testCubeQueryContinuousUpdatePeriod() throws Exception {
    LensException th = null;
    try {
      rewrite("cube select" + " SUM(msr2) from testCube where " + TWO_DAYS_RANGE, conf);
    } catch (LensException e) {
      th = e;
      log.error("Semantic exception while testing cube query.", e);
    }
    if (!CubeTestSetup.isZerothHour()) {
      Assert.assertNotNull(th);
      Assert.assertEquals(
          th.getErrorCode(), LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getValue());
    }
    // hourly partitions for two days
    conf.setBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, true);

    DateFormat qFmt = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
    Calendar qCal = Calendar.getInstance();
    Date toDate = qCal.getTime();
    String qTo = qFmt.format(toDate);
    qCal.setTime(TWODAYS_BACK);
    Date from2DaysBackDate = qCal.getTime();
    String qFrom = qFmt.format(from2DaysBackDate);
    String twoDaysInRangeClause = " time_range_in(d_time, '" + qFrom + "', '" + qTo + "')";

    String hqlQuery =
        rewrite("select SUM(msr2) from testCube" + " where " + twoDaysInRangeClause, conf);
    Map<String, String> whereClauses = new HashMap<String, String>();
    whereClauses.put(
        CubeTestSetup.getDbName() + "c1_testfact",
        TestBetweenTimeRangeWriter.getBetweenClause(
            cubeName, "dt", from2DaysBackDate, toDate, UpdatePeriod.CONTINUOUS.format()));
    String expected =
        getExpectedQuery(cubeName, "select sum(testcube.msr2) FROM ", null, null, whereClauses);
    System.out.println("HQL:" + hqlQuery);
    TestCubeRewriter.compareQueries(hqlQuery, expected);

    // multiple range query
    // from date 4 days back
    qCal.setTime(BEFORE_4_DAYS_START);
    Date from4DaysBackDate = qCal.getTime();
    String qFrom4Days = qFmt.format(from4DaysBackDate);
    String fourDaysInRangeClause = " time_range_in(d_time, '" + qFrom4Days + "', '" + qTo + "')";

    hqlQuery =
        rewrite(
            "select SUM(msr2) from testCube"
                + " where "
                + twoDaysInRangeClause
                + " OR "
                + fourDaysInRangeClause,
            conf);

    whereClauses = new HashMap<String, String>();
    whereClauses.put(
        CubeTestSetup.getDbName() + "c1_testfact",
        TestBetweenTimeRangeWriter.getBetweenClause(
                cubeName, "dt", from2DaysBackDate, toDate, UpdatePeriod.CONTINUOUS.format())
            + " OR"
            + TestBetweenTimeRangeWriter.getBetweenClause(
                cubeName, "dt", from4DaysBackDate, toDate, UpdatePeriod.CONTINUOUS.format()));
    expected =
        getExpectedQuery(cubeName, "select sum(testcube.msr2) FROM ", null, null, whereClauses);
    System.out.println("HQL:" + hqlQuery);
    TestCubeRewriter.compareQueries(hqlQuery, expected);

    // format option in the query
    conf.set(CubeQueryConfUtil.PART_WHERE_CLAUSE_DATE_FORMAT, "yyyy-MM-dd HH:mm:ss");
    hqlQuery = rewrite("select SUM(msr2) from testCube" + " where " + TWO_DAYS_RANGE, conf);
    whereClauses = new HashMap<String, String>();
    whereClauses.put(
        CubeTestSetup.getDbName() + "c1_testfact",
        TestBetweenTimeRangeWriter.getBetweenClause(
            cubeName,
            "dt",
            getUptoHour(CubeTestSetup.TWODAYS_BACK),
            getUptoHour(CubeTestSetup.NOW),
            TestTimeRangeWriter.DB_FORMAT));
    expected =
        getExpectedQuery(cubeName, "select sum(testcube.msr2) FROM ", null, null, whereClauses);
    System.out.println("HQL:" + hqlQuery);
    TestCubeRewriter.compareQueries(hqlQuery, expected);
  }