@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()); }
@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); }