Search in sources :

Example 1 with SystemSessionPropertyConfiguration

use of com.facebook.presto.spi.session.SessionPropertyConfigurationManager.SystemSessionPropertyConfiguration in project presto by prestodb.

the class TestSessionPropertyDefaults method testApplyDefaultProperties.

@Test
public void testApplyDefaultProperties() {
    SessionPropertyDefaults sessionPropertyDefaults = new SessionPropertyDefaults(TEST_NODE_INFO);
    SessionPropertyConfigurationManagerFactory factory = new TestingSessionPropertyConfigurationManagerFactory(new SystemSessionPropertyConfiguration(ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "override").put("system_default", "system_default").build(), ImmutableMap.of("override", "overridden")), ImmutableMap.of("testCatalog", ImmutableMap.<String, String>builder().put("explicit_set", "override").put("catalog_default", "catalog_default").build()));
    sessionPropertyDefaults.addConfigurationManagerFactory(factory);
    sessionPropertyDefaults.setConfigurationManager(factory.getName(), ImmutableMap.of());
    Session session = Session.builder(new SessionPropertyManager()).setQueryId(new QueryId("test_query_id")).setIdentity(new Identity("testUser", Optional.empty())).setSystemProperty(QUERY_MAX_MEMORY, "1GB").setSystemProperty(JOIN_DISTRIBUTION_TYPE, "partitioned").setSystemProperty(HASH_PARTITION_COUNT, "43").setSystemProperty("override", "should be overridden").setCatalogSessionProperty("testCatalog", "explicit_set", "explicit_set").build();
    assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").put("override", "should be overridden").build());
    assertEquals(session.getUnprocessedCatalogProperties(), ImmutableMap.of("testCatalog", ImmutableMap.<String, String>builder().put("explicit_set", "explicit_set").build()));
    session = sessionPropertyDefaults.newSessionWithDefaultProperties(session, Optional.empty(), Optional.of(TEST_RESOURCE_GROUP_ID));
    assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").put("system_default", "system_default").put("override", "overridden").build());
    assertEquals(session.getUnprocessedCatalogProperties(), ImmutableMap.of("testCatalog", ImmutableMap.<String, String>builder().put("explicit_set", "explicit_set").put("catalog_default", "catalog_default").build()));
}
Also used : SystemSessionPropertyConfiguration(com.facebook.presto.spi.session.SessionPropertyConfigurationManager.SystemSessionPropertyConfiguration) QueryId(com.facebook.presto.spi.QueryId) TestingSessionPropertyConfigurationManagerFactory(com.facebook.presto.spi.session.TestingSessionPropertyConfigurationManagerFactory) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) SessionPropertyConfigurationManagerFactory(com.facebook.presto.spi.session.SessionPropertyConfigurationManagerFactory) TestingSessionPropertyConfigurationManagerFactory(com.facebook.presto.spi.session.TestingSessionPropertyConfigurationManagerFactory) Identity(com.facebook.presto.spi.security.Identity) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 2 with SystemSessionPropertyConfiguration

use of com.facebook.presto.spi.session.SessionPropertyConfigurationManager.SystemSessionPropertyConfiguration in project presto by prestodb.

the class SessionPropertyDefaults method newSessionWithDefaultProperties.

public Session newSessionWithDefaultProperties(Session session, Optional<String> queryType, Optional<ResourceGroupId> resourceGroupId) {
    SessionPropertyConfigurationManager configurationManager = delegate.get();
    if (configurationManager == null) {
        return session;
    }
    SessionConfigurationContext context = new SessionConfigurationContext(session.getIdentity().getUser(), session.getSource(), session.getClientTags(), queryType, resourceGroupId, session.getClientInfo());
    SystemSessionPropertyConfiguration systemPropertyConfiguration = configurationManager.getSystemSessionProperties(context);
    Map<String, Map<String, String>> catalogPropertyOverrides = configurationManager.getCatalogSessionProperties(context);
    return session.withDefaultProperties(systemPropertyConfiguration, catalogPropertyOverrides);
}
Also used : SystemSessionPropertyConfiguration(com.facebook.presto.spi.session.SessionPropertyConfigurationManager.SystemSessionPropertyConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) SessionPropertyConfigurationManager(com.facebook.presto.spi.session.SessionPropertyConfigurationManager) SessionConfigurationContext(com.facebook.presto.spi.session.SessionConfigurationContext)

Example 3 with SystemSessionPropertyConfiguration

use of com.facebook.presto.spi.session.SessionPropertyConfigurationManager.SystemSessionPropertyConfiguration in project presto by prestodb.

the class TestFileSessionPropertyManager method assertProperties.

private static void assertProperties(Map<String, String> defaultProperties, Map<String, String> overrideProperties, SessionMatchSpec... spec) throws IOException {
    try (TempFile tempFile = new TempFile()) {
        Path configurationFile = tempFile.path();
        Files.write(configurationFile, CODEC.toJsonBytes(Arrays.asList(spec)));
        SessionPropertyConfigurationManager manager = new FileSessionPropertyManager(new FileSessionPropertyManagerConfig().setConfigFile(configurationFile.toFile()));
        SystemSessionPropertyConfiguration propertyConfiguration = manager.getSystemSessionProperties(CONTEXT);
        assertEquals(propertyConfiguration.systemPropertyDefaults, defaultProperties);
        assertEquals(propertyConfiguration.systemPropertyOverrides, overrideProperties);
    }
}
Also used : Path(java.nio.file.Path) TempFile(com.facebook.airlift.testing.TempFile) SystemSessionPropertyConfiguration(com.facebook.presto.spi.session.SessionPropertyConfigurationManager.SystemSessionPropertyConfiguration) SessionPropertyConfigurationManager(com.facebook.presto.spi.session.SessionPropertyConfigurationManager)

Aggregations

SystemSessionPropertyConfiguration (com.facebook.presto.spi.session.SessionPropertyConfigurationManager.SystemSessionPropertyConfiguration)3 SessionPropertyConfigurationManager (com.facebook.presto.spi.session.SessionPropertyConfigurationManager)2 TempFile (com.facebook.airlift.testing.TempFile)1 Session (com.facebook.presto.Session)1 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)1 QueryId (com.facebook.presto.spi.QueryId)1 Identity (com.facebook.presto.spi.security.Identity)1 SessionConfigurationContext (com.facebook.presto.spi.session.SessionConfigurationContext)1 SessionPropertyConfigurationManagerFactory (com.facebook.presto.spi.session.SessionPropertyConfigurationManagerFactory)1 TestingSessionPropertyConfigurationManagerFactory (com.facebook.presto.spi.session.TestingSessionPropertyConfigurationManagerFactory)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.testng.annotations.Test)1