Search in sources :

Example 1 with MScheduledQuery

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);
    }
}
Also used : IDriver(org.apache.hadoop.hive.ql.IDriver) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) Test(org.junit.Test)

Example 2 with MScheduledQuery

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());
    }
}
Also used : IDriver(org.apache.hadoop.hive.ql.IDriver) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery)

Example 3 with MScheduledQuery

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();
        }
    }
}
Also used : AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery)

Example 4 with MScheduledQuery

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);
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery)

Example 5 with MScheduledQuery

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();
        }
    }
}
Also used : NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery)

Aggregations

MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)11 ScheduledQueryKey (org.apache.hadoop.hive.metastore.api.ScheduledQueryKey)4 IDriver (org.apache.hadoop.hive.ql.IDriver)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Query (javax.jdo.Query)3 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)3 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)3 ReplicationMetricList (org.apache.hadoop.hive.metastore.api.ReplicationMetricList)3 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)3 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)3 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)3 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)3 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)3 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)3 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)3 Test (org.junit.Test)3 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)2 MScheduledExecution (org.apache.hadoop.hive.metastore.model.MScheduledExecution)2