Search in sources :

Example 6 with SelectionCriteria

use of com.facebook.presto.spi.resourceGroups.SelectionCriteria in project presto by prestodb.

the class TestResourceGroupIdTemplate method testExtraction.

@Test
public void testExtraction() {
    ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.job_${pipeline}_user:${USER}.${USER}");
    ResourceGroupId expected = new ResourceGroupId(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("test"), "pipeline"), "job_testpipeline_user:user"), "user");
    Pattern sourcePattern = Pattern.compile("scheduler.important.(?<pipeline>[^\\[]*).*");
    StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(sourcePattern), Optional.empty(), Optional.empty(), Optional.empty(), template);
    SelectionCriteria context = new SelectionCriteria(true, "user", Optional.of("scheduler.important.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
    assertEquals(selector.match(context).map(SelectionContext::getResourceGroupId), Optional.of(expected));
}
Also used : Pattern(java.util.regex.Pattern) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) SelectionCriteria(com.facebook.presto.spi.resourceGroups.SelectionCriteria) Test(org.testng.annotations.Test)

Example 7 with SelectionCriteria

use of com.facebook.presto.spi.resourceGroups.SelectionCriteria in project presto by prestodb.

the class TestResourceGroupIdTemplate method testNoMatch.

@Test
public void testNoMatch() {
    ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.${pipeline}.${USER}");
    Pattern sourcePattern = Pattern.compile("scheduler.important.(?<pipeline>[^\\[]*).*");
    StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(sourcePattern), Optional.empty(), Optional.empty(), Optional.empty(), template);
    SelectionCriteria context = new SelectionCriteria(true, "user", Optional.of("scheduler.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
    assertFalse(selector.match(context).isPresent());
}
Also used : Pattern(java.util.regex.Pattern) SelectionCriteria(com.facebook.presto.spi.resourceGroups.SelectionCriteria) Test(org.testng.annotations.Test)

Example 8 with SelectionCriteria

use of com.facebook.presto.spi.resourceGroups.SelectionCriteria in project presto by prestodb.

the class TestDbSourceExactMatchSelector method testMatch.

@Test
public void testMatch() {
    ResourceGroupId resourceGroupId1 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "insert"));
    ResourceGroupId resourceGroupId2 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "select"));
    dao.insertExactMatchSelector("test", "@test@test_pipeline", INSERT.name(), CODEC.toJson(resourceGroupId1));
    dao.insertExactMatchSelector("test", "@test@test_pipeline", SELECT.name(), CODEC.toJson(resourceGroupId2));
    DbSourceExactMatchSelector selector = new DbSourceExactMatchSelector("test", dao);
    assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.empty())), Optional.empty());
    assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(INSERT.name()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId1));
    assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(SELECT.name()))).map(SelectionContext::getResourceGroupId), Optional.of(resourceGroupId2));
    assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_pipeline"), ImmutableSet.of("tag"), EMPTY_RESOURCE_ESTIMATES, Optional.of(DELETE.name()))), Optional.empty());
    assertEquals(selector.match(new SelectionCriteria(true, "testuser", Optional.of("@test@test_new"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.of(INSERT.name()))), Optional.empty());
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) SelectionCriteria(com.facebook.presto.spi.resourceGroups.SelectionCriteria) Test(org.testng.annotations.Test)

Aggregations

SelectionCriteria (com.facebook.presto.spi.resourceGroups.SelectionCriteria)8 Test (org.testng.annotations.Test)7 Pattern (java.util.regex.Pattern)5 ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)3 Session (com.facebook.presto.Session)1 PreparedQuery (com.facebook.presto.execution.QueryPreparer.PreparedQuery)1 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)1 PrestoException (com.facebook.presto.spi.PrestoException)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 QueryType (com.facebook.presto.spi.resourceGroups.QueryType)1 StatementUtils.getQueryType (com.facebook.presto.util.StatementUtils.getQueryType)1