Search in sources :

Example 1 with ScheduledQueryKey

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.

the class QTestScheduledQueryCleaner method clearScheduledQueries.

private void clearScheduledQueries(HiveConf conf) {
    if (System.getenv(QTestUtil.QTEST_LEAVE_FILES) != null) {
        return;
    }
    Set<String> scheduledQueries = ScheduledQueryCreationRegistryHook.getSchedules();
    for (String name : scheduledQueries) {
        ScheduledQueryMaintenanceRequest request = new ScheduledQueryMaintenanceRequest();
        request.setType(ScheduledQueryMaintenanceRequestType.DROP);
        ScheduledQuery schq = new ScheduledQuery();
        schq.setScheduleKey(new ScheduledQueryKey(name, conf.getVar(ConfVars.HIVE_SCHEDULED_QUERIES_NAMESPACE)));
        request.setScheduledQuery(schq);
        try {
            // propagate new conf to meta store
            Hive db = Hive.get(conf);
            db.getMSC().scheduledQueryMaintenance(request);
            db.close(false);
        } catch (Exception e) {
            LOG.error("Can't remove scheduled query: " + name + " " + e.getMessage());
        }
    }
    scheduledQueries.clear();
}
Also used : Hive(org.apache.hadoop.hive.ql.metadata.Hive) ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery)

Example 2 with ScheduledQueryKey

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.

the class ScheduledQueryAnalyzer method interpretAstNode.

private ScheduledQuery interpretAstNode(ASTNode ast) throws SemanticException {
    // child0 is the schedule name
    String scheduleName = ast.getChild(0).getText();
    String clusterNamespace = conf.getVar(ConfVars.HIVE_SCHEDULED_QUERIES_NAMESPACE);
    LOG.info("scheduled query namespace:" + clusterNamespace);
    ScheduledQueryKey key = new ScheduledQueryKey(scheduleName, clusterNamespace);
    ScheduledQuery ret = new ScheduledQuery(key);
    // child 1..n are arguments/options/etc
    for (int i = 1; i < ast.getChildCount(); i++) {
        processScheduledQueryAstNode(ret, (ASTNode) ast.getChild(i));
    }
    return ret;
}
Also used : ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery)

Example 3 with ScheduledQueryKey

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey 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 4 with ScheduledQueryKey

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey 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 5 with ScheduledQueryKey

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.

the class TestMetastoreScheduledQueries method testCleanup.

@Test
public void testCleanup() throws Exception {
    String namespace = "cleanup";
    ObjectStore objStore = new ObjectStore();
    objStore.setConf(metaStore.getConf());
    objStore.deleteScheduledExecutions(0);
    ScheduledQuery schq = createScheduledQuery(new ScheduledQueryKey("q1", namespace));
    ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
    r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
    r.setScheduledQuery(schq);
    objStore.scheduledQueryMaintenance(r);
    Thread.sleep(1000);
    ScheduledQueryPollRequest request = new ScheduledQueryPollRequest(namespace);
    ScheduledQueryPollResponse pollResult = objStore.scheduledQueryPoll(request);
    try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
        MScheduledExecution q = pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
        assertEquals(QueryState.INITED, q.getState());
    }
    Thread.sleep(1000);
    objStore.deleteScheduledExecutions(0);
    try (PersistenceManager pm = PersistenceManagerProvider.getPersistenceManager()) {
        try {
            pm.getObjectById(MScheduledExecution.class, pollResult.getExecutionId());
            fail("The execution is expected to be deleted at this point...");
        } catch (JDOObjectNotFoundException e) {
        // expected
        }
    }
}
Also used : ObjectStore(org.apache.hadoop.hive.metastore.ObjectStore) ScheduledQueryPollRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest) MScheduledExecution(org.apache.hadoop.hive.metastore.model.MScheduledExecution) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) PersistenceManager(javax.jdo.PersistenceManager) ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Aggregations

ScheduledQueryKey (org.apache.hadoop.hive.metastore.api.ScheduledQueryKey)17 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)11 Test (org.junit.Test)10 MetastoreUnitTest (org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)7 ScheduledQueryMaintenanceRequest (org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest)7 ScheduledQueryPollResponse (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse)5 PersistenceManager (javax.jdo.PersistenceManager)4 ScheduledQueryPollRequest (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest)4 MScheduledExecution (org.apache.hadoop.hive.metastore.model.MScheduledExecution)4 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)4 IDriver (org.apache.hadoop.hive.ql.IDriver)4 ArrayList (java.util.ArrayList)2 ObjectStore (org.apache.hadoop.hive.metastore.ObjectStore)2 ScheduledQueryProgressInfo (org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo)2 CronBuilder (com.cronutils.builder.CronBuilder)1 CronDefinitionBuilder (com.cronutils.model.definition.CronDefinitionBuilder)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 Query (javax.jdo.Query)1