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();
}
}
}
use of org.apache.hadoop.hive.metastore.model.MScheduledQuery in project hive by apache.
the class TestScheduledQueryStatements method testCreateFromNonDefaultDatabase.
@Test
public void testCreateFromNonDefaultDatabase() throws ParseException, Exception {
IDriver driver = createDriver();
driver.run("set role admin");
driver.run("use asd");
driver.run("create table tt (a integer)");
// the scheduled query may reference a table inside the current database
driver.run("create scheduled query nonDef cron '* * * * * ? *' as select 1 from tt");
try (CloseableObjectStore os = new CloseableObjectStore(env_setup.getTestCtx().hiveConf)) {
Optional<MScheduledQuery> sq = os.getMScheduledQuery(new ScheduledQueryKey("nonDef", "hive"));
assertTrue(sq.isPresent());
assertEquals("select 1 from `asd`.`tt`", sq.get().toThrift().getQuery());
}
}
use of org.apache.hadoop.hive.metastore.model.MScheduledQuery in project hive by apache.
the class TestScheduledQueryStatements method testAlter.
@Test
public void testAlter() throws ParseException, Exception {
IDriver driver = createDriver();
driver.run("set role admin");
driver.run("create scheduled query alter1 cron '0 0 7 * * ? *' as select 1 from tu");
driver.run("alter scheduled query alter1 executed as 'user3'");
driver.run("alter scheduled query alter1 defined as select 22 from tu");
try (CloseableObjectStore os = new CloseableObjectStore(env_setup.getTestCtx().hiveConf)) {
Optional<MScheduledQuery> sq = os.getMScheduledQuery(new ScheduledQueryKey("alter1", "hive"));
assertTrue(sq.isPresent());
assertEquals("user3", sq.get().toThrift().getUser());
assertThat(sq.get().getNextExecution(), Matchers.greaterThan((int) (System.currentTimeMillis() / 1000)));
}
}
Aggregations