Search in sources :

Example 6 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 7 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 8 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)

Example 9 with MScheduledQuery

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());
    }
}
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 10 with MScheduledQuery

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

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