Search in sources :

Example 31 with Trigger

use of org.apache.hadoop.hive.ql.wm.Trigger in project hive by apache.

the class TestTriggersTezSessionPoolManager method testTriggerCustomNonExistent.

@Test(timeout = 60000)
public void testTriggerCustomNonExistent() throws Exception {
    Expression expression = ExpressionFactory.fromString("OPEN_FILES > 50");
    Trigger trigger = new ExecutionTrigger("non_existent", expression, new Action(Action.Type.KILL_QUERY));
    setupTriggers(Lists.newArrayList(trigger));
    String query = "select l.under_col, l.value from " + tableName + " l join " + tableName + " r on l.under_col>=r.under_col";
    runQueryWithTrigger(query, null, null);
}
Also used : ExecutionTrigger(org.apache.hadoop.hive.ql.wm.ExecutionTrigger) Action(org.apache.hadoop.hive.ql.wm.Action) WMTrigger(org.apache.hadoop.hive.metastore.api.WMTrigger) ExecutionTrigger(org.apache.hadoop.hive.ql.wm.ExecutionTrigger) Trigger(org.apache.hadoop.hive.ql.wm.Trigger) Expression(org.apache.hadoop.hive.ql.wm.Expression) Test(org.junit.Test)

Example 32 with Trigger

use of org.apache.hadoop.hive.ql.wm.Trigger in project hive by apache.

the class TestTriggersTezSessionPoolManager method testTriggerHighBytesWrite.

@Test(timeout = 60000)
public void testTriggerHighBytesWrite() throws Exception {
    Expression expression = ExpressionFactory.fromString("FILE_BYTES_WRITTEN > 100");
    Trigger trigger = new ExecutionTrigger("big_write", expression, new Action(Action.Type.KILL_QUERY));
    setupTriggers(Lists.newArrayList(trigger));
    String query = "select sleep(t1.under_col, 5), t1.value from " + tableName + " t1 join " + tableName + " t2 on t1.under_col>=t2.under_col";
    runQueryWithTrigger(query, null, trigger + " violated");
}
Also used : ExecutionTrigger(org.apache.hadoop.hive.ql.wm.ExecutionTrigger) Action(org.apache.hadoop.hive.ql.wm.Action) WMTrigger(org.apache.hadoop.hive.metastore.api.WMTrigger) ExecutionTrigger(org.apache.hadoop.hive.ql.wm.ExecutionTrigger) Trigger(org.apache.hadoop.hive.ql.wm.Trigger) Expression(org.apache.hadoop.hive.ql.wm.Expression) Test(org.junit.Test)

Example 33 with Trigger

use of org.apache.hadoop.hive.ql.wm.Trigger in project hive by apache.

the class TestTriggersTezSessionPoolManager method testTriggerCustomCreatedFiles.

@Test(timeout = 120000)
public void testTriggerCustomCreatedFiles() throws Exception {
    List<String> cmds = getConfigs();
    Expression expression = ExpressionFactory.fromString("CREATED_FILES > 5");
    Trigger trigger = new ExecutionTrigger("high_read_ops", expression, new Action(Action.Type.KILL_QUERY));
    setupTriggers(Lists.newArrayList(trigger));
    String query = "create table testtab2 as select * from " + tableName;
    runQueryWithTrigger(query, cmds, trigger + " violated");
    // partitioned insert
    expression = ExpressionFactory.fromString("CREATED_FILES > 10");
    trigger = new ExecutionTrigger("high_read_ops", expression, new Action(Action.Type.KILL_QUERY));
    setupTriggers(Lists.newArrayList(trigger));
    cmds.add("drop table src3");
    cmds.add("create table src3 (key int) partitioned by (value string)");
    query = "insert overwrite table src3 partition (value) select sleep(under_col, 10), value from " + tableName + " where under_col < 100";
    runQueryWithTrigger(query, cmds, trigger + " violated");
}
Also used : ExecutionTrigger(org.apache.hadoop.hive.ql.wm.ExecutionTrigger) Action(org.apache.hadoop.hive.ql.wm.Action) WMTrigger(org.apache.hadoop.hive.metastore.api.WMTrigger) ExecutionTrigger(org.apache.hadoop.hive.ql.wm.ExecutionTrigger) Trigger(org.apache.hadoop.hive.ql.wm.Trigger) Expression(org.apache.hadoop.hive.ql.wm.Expression) Test(org.junit.Test)

Example 34 with Trigger

use of org.apache.hadoop.hive.ql.wm.Trigger in project hive by apache.

the class TestTriggersWorkloadManager method setupTriggers.

@Override
protected void setupTriggers(final List<Trigger> triggers) throws Exception {
    WorkloadManager wm = WorkloadManager.getInstance();
    WMPool pool = new WMPool("rp", "llap");
    pool.setAllocFraction(1.0f);
    pool.setQueryParallelism(1);
    WMFullResourcePlan rp = new WMFullResourcePlan(new WMResourcePlan("rp"), Lists.newArrayList(pool));
    rp.getPlan().setDefaultPoolPath("llap");
    for (Trigger trigger : triggers) {
        rp.addToTriggers(wmTriggerFromTrigger(trigger));
        rp.addToPoolTriggers(new WMPoolTrigger("llap", trigger.getName()));
    }
    wm.updateResourcePlanAsync(rp).get(10, TimeUnit.SECONDS);
}
Also used : WMFullResourcePlan(org.apache.hadoop.hive.metastore.api.WMFullResourcePlan) WMPoolTrigger(org.apache.hadoop.hive.metastore.api.WMPoolTrigger) Trigger(org.apache.hadoop.hive.ql.wm.Trigger) WMResourcePlan(org.apache.hadoop.hive.metastore.api.WMResourcePlan) WMPool(org.apache.hadoop.hive.metastore.api.WMPool) WMPoolTrigger(org.apache.hadoop.hive.metastore.api.WMPoolTrigger) WorkloadManager(org.apache.hadoop.hive.ql.exec.tez.WorkloadManager)

Example 35 with Trigger

use of org.apache.hadoop.hive.ql.wm.Trigger in project hive by apache.

the class KillTriggerActionHandler method applyAction.

@Override
public void applyAction(final Map<TezSessionState, Trigger> queriesViolated) {
    for (Map.Entry<TezSessionState, Trigger> entry : queriesViolated.entrySet()) {
        switch(entry.getValue().getAction().getType()) {
            case KILL_QUERY:
                TezSessionState sessionState = entry.getKey();
                String queryId = sessionState.getWmContext().getQueryId();
                try {
                    KillQuery killQuery = sessionState.getKillQuery();
                    // if kill query is null then session might have been released to pool or closed already
                    if (killQuery != null) {
                        sessionState.getKillQuery().killQuery(queryId, entry.getValue().getViolationMsg());
                    }
                } catch (HiveException e) {
                    LOG.warn("Unable to kill query {} for trigger violation");
                }
                break;
            default:
                throw new RuntimeException("Unsupported action: " + entry.getValue());
        }
    }
}
Also used : Trigger(org.apache.hadoop.hive.ql.wm.Trigger) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) KillQuery(org.apache.hadoop.hive.ql.session.KillQuery) Map(java.util.Map)

Aggregations

Trigger (org.apache.hadoop.hive.ql.wm.Trigger)37 ExecutionTrigger (org.apache.hadoop.hive.ql.wm.ExecutionTrigger)34 WMTrigger (org.apache.hadoop.hive.metastore.api.WMTrigger)29 Action (org.apache.hadoop.hive.ql.wm.Action)28 Expression (org.apache.hadoop.hive.ql.wm.Expression)28 Test (org.junit.Test)28 WMPoolTrigger (org.apache.hadoop.hive.metastore.api.WMPoolTrigger)8 ArrayList (java.util.ArrayList)7 WMFullResourcePlan (org.apache.hadoop.hive.metastore.api.WMFullResourcePlan)5 HashMap (java.util.HashMap)3 WMPool (org.apache.hadoop.hive.metastore.api.WMPool)3 WMResourcePlan (org.apache.hadoop.hive.metastore.api.WMResourcePlan)3 IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 WorkloadManager (org.apache.hadoop.hive.ql.exec.tez.WorkloadManager)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 KillQuery (org.apache.hadoop.hive.ql.session.KillQuery)1