use of org.apache.hadoop.hive.metastore.model.MScheduledQuery in project hive by apache.
the class TestScheduledQueryStatements method testExecuteImmediate.
@Test
public void testExecuteImmediate() throws ParseException, Exception {
// use a different namespace because the schq executor might be able to
// catch the new schq execution immediately
env_setup.getTestCtx().hiveConf.setVar(ConfVars.HIVE_SCHEDULED_QUERIES_NAMESPACE, "immed");
IDriver driver = createDriver();
driver.run("set role admin");
driver.run("create scheduled query immed cron '0 0 7 * * ? *' as select 1");
int cnt0 = ScheduledQueryExecutionService.getForcedScheduleCheckCount();
driver.run("alter scheduled query immed execute");
try (CloseableObjectStore os = new CloseableObjectStore(env_setup.getTestCtx().hiveConf)) {
Optional<MScheduledQuery> sq = os.getMScheduledQuery(new ScheduledQueryKey("immed", "immed"));
assertTrue(sq.isPresent());
assertThat(sq.get().getNextExecution(), Matchers.lessThanOrEqualTo((int) (System.currentTimeMillis() / 1000)));
int cnt1 = ScheduledQueryExecutionService.getForcedScheduleCheckCount();
assertNotEquals(cnt1, cnt0);
}
}
use of org.apache.hadoop.hive.metastore.model.MScheduledQuery in project hive by apache.
the class TestScheduledQueryStatements method checkScheduleCreation.
private void checkScheduleCreation(String schqName, String schedule, String expectedSchedule) throws CommandProcessorException, Exception {
IDriver driver = createDriver();
driver.run("set role admin");
driver.run("create scheduled query " + schqName + " " + schedule + " as select 1 from tu");
try (CloseableObjectStore os = new CloseableObjectStore(env_setup.getTestCtx().hiveConf)) {
Optional<MScheduledQuery> sq = os.getMScheduledQuery(new ScheduledQueryKey(schqName, "hive"));
assertTrue(sq.isPresent());
assertEquals(expectedSchedule, sq.get().getSchedule());
}
}
use of org.apache.hadoop.hive.metastore.model.MScheduledQuery in project hive by apache.
the class ObjectStore method scheduledQueryInsert.
public void scheduledQueryInsert(ScheduledQuery scheduledQuery) throws NoSuchObjectException, AlreadyExistsException, InvalidInputException {
MScheduledQuery schq = MScheduledQuery.fromThrift(scheduledQuery);
boolean commited = false;
try {
Optional<MScheduledQuery> existing = getMScheduledQuery(scheduledQuery.getScheduleKey());
if (existing.isPresent()) {
throw new AlreadyExistsException("Scheduled query with name: " + scheduledQueryKeyRef(scheduledQuery.getScheduleKey()) + " already exists.");
}
openTransaction();
Integer nextExecutionTime = computeNextExecutionTime(schq.getSchedule());
schq.setNextExecution(nextExecutionTime);
pm.makePersistent(schq);
commited = commitTransaction();
} finally {
if (!commited) {
rollbackTransaction();
}
}
}
use of org.apache.hadoop.hive.metastore.model.MScheduledQuery in project hive by apache.
the class ObjectStore method getMScheduledQuery.
public Optional<MScheduledQuery> getMScheduledQuery(ScheduledQueryKey key) {
MScheduledQuery s = null;
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MScheduledQuery.class, "scheduleName == sName && clusterNamespace == ns");
query.declareParameters("java.lang.String sName, java.lang.String ns");
query.setUnique(true);
s = (MScheduledQuery) query.execute(key.getScheduleName(), key.getClusterNamespace());
pm.retrieve(s);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
return Optional.ofNullable(s);
}
use of org.apache.hadoop.hive.metastore.model.MScheduledQuery in project hive by apache.
the class ObjectStore method scheduledQueryUpdate.
public void scheduledQueryUpdate(ScheduledQuery scheduledQuery) throws NoSuchObjectException, AlreadyExistsException, InvalidInputException {
MScheduledQuery schq = MScheduledQuery.fromThrift(scheduledQuery);
boolean commited = false;
try {
Optional<MScheduledQuery> existing = getMScheduledQuery(scheduledQuery.getScheduleKey());
if (!existing.isPresent()) {
throw new NoSuchObjectException("Scheduled query with name: " + scheduledQueryKeyRef(scheduledQuery.getScheduleKey()) + " doesn't exists.");
}
openTransaction();
MScheduledQuery persisted = existing.get();
persisted.doUpdate(schq);
if (!scheduledQuery.isSetNextExecution()) {
Integer nextExecutionTime = computeNextExecutionTime(schq.getSchedule());
persisted.setNextExecution(nextExecutionTime);
} else {
persisted.setNextExecution(schq.getNextExecution());
}
pm.makePersistent(persisted);
commited = commitTransaction();
} finally {
if (!commited) {
rollbackTransaction();
}
}
}
Aggregations