Search in sources :

Example 1 with SessionBuilder

use of com.facebook.presto.Session.SessionBuilder in project presto by prestodb.

the class HttpRequestSessionFactory method createSession.

@Override
public Session createSession(QueryId queryId, TransactionManager transactionManager, AccessControl accessControl, SessionPropertyManager sessionPropertyManager) {
    accessControl.checkCanSetUser(identity.getPrincipal().orElse(null), identity.getUser());
    SessionBuilder sessionBuilder = Session.builder(sessionPropertyManager).setQueryId(queryId).setIdentity(identity).setSource(source).setCatalog(catalog).setSchema(schema).setRemoteUserAddress(remoteUserAddress).setUserAgent(userAgent).setClientInfo(clientInfo);
    if (timeZoneId != null) {
        sessionBuilder.setTimeZoneKey(getTimeZoneKey(timeZoneId));
    }
    if (language != null) {
        sessionBuilder.setLocale(Locale.forLanguageTag(language));
    }
    for (Entry<String, String> entry : systemProperties.entrySet()) {
        sessionBuilder.setSystemProperty(entry.getKey(), entry.getValue());
    }
    for (Entry<String, Map<String, String>> catalogProperties : catalogSessionProperties.entrySet()) {
        String catalog = catalogProperties.getKey();
        for (Entry<String, String> entry : catalogProperties.getValue().entrySet()) {
            sessionBuilder.setCatalogSessionProperty(catalog, entry.getKey(), entry.getValue());
        }
    }
    for (Entry<String, String> preparedStatement : preparedStatements.entrySet()) {
        sessionBuilder.addPreparedStatement(preparedStatement.getKey(), preparedStatement.getValue());
    }
    if (clientTransactionSupport) {
        sessionBuilder.setClientTransactionSupport();
    }
    Session session = sessionBuilder.build();
    if (transactionId.isPresent()) {
        session = session.beginTransactionId(transactionId.get(), transactionManager, accessControl);
    }
    return session;
}
Also used : SessionBuilder(com.facebook.presto.Session.SessionBuilder) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableCollectors.toImmutableMap(com.facebook.presto.util.ImmutableCollectors.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session)

Example 2 with SessionBuilder

use of com.facebook.presto.Session.SessionBuilder in project presto by prestodb.

the class TestCompletedEventWarnings method setUp.

@BeforeClass
public void setUp() throws Exception {
    SessionBuilder sessionBuilder = testSessionBuilder();
    generatedEvents = new EventsBuilder();
    queryRunner = DistributedQueryRunner.builder(sessionBuilder.build()).setExtraProperties(ImmutableMap.of("testing-warning-collector.preloaded-warnings", String.valueOf(TEST_WARNINGS))).setNodeCount(1).build();
    queryRunner.installPlugin(new TestingEventListenerPlugin(generatedEvents));
    generatedEvents.initialize(EXPECTED_EVENTS);
}
Also used : EventsBuilder(com.facebook.presto.execution.TestEventListener.EventsBuilder) TestingEventListenerPlugin(com.facebook.presto.execution.TestEventListenerPlugin.TestingEventListenerPlugin) SessionBuilder(com.facebook.presto.Session.SessionBuilder) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with SessionBuilder

use of com.facebook.presto.Session.SessionBuilder in project presto by prestodb.

the class TestCompletedEventWarnings method assertWarnings.

private void assertWarnings(@Language("SQL") String sql, Map<String, String> sessionProperties, List<WarningCode> expectedWarnings) throws InterruptedException {
    // Task concurrency must be 1 otherwise these tests fail due to change in the number of EXPECTED_EVENTS
    SessionBuilder sessionBuilder = testSessionBuilder().setSystemProperty("task_concurrency", "1");
    sessionProperties.forEach(sessionBuilder::setSystemProperty);
    queryRunner.execute(sessionBuilder.build(), sql);
    generatedEvents.waitForEvents(10);
    Set<WarningCode> warnings = getOnlyElement(generatedEvents.getQueryCompletedEvents()).getWarnings().stream().map(PrestoWarning::getWarningCode).collect(toImmutableSet());
    for (WarningCode warningCode : expectedWarnings) {
        if (!warnings.contains(warningCode)) {
            fail("Expected warning: " + warningCode);
        }
    }
}
Also used : SessionBuilder(com.facebook.presto.Session.SessionBuilder) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) WarningCode(com.facebook.presto.spi.WarningCode)

Example 4 with SessionBuilder

use of com.facebook.presto.Session.SessionBuilder in project presto by prestodb.

the class QuerySessionSupplier method createSession.

@Override
public Session createSession(QueryId queryId, SessionContext context) {
    Identity identity = context.getIdentity();
    accessControl.checkCanSetUser(identity, new AccessControlContext(queryId, Optional.ofNullable(context.getClientInfo()), Optional.ofNullable(context.getSource())), identity.getPrincipal(), identity.getUser());
    SessionBuilder sessionBuilder = Session.builder(sessionPropertyManager).setQueryId(queryId).setIdentity(identity).setSource(context.getSource()).setCatalog(context.getCatalog()).setSchema(context.getSchema()).setRemoteUserAddress(context.getRemoteUserAddress()).setUserAgent(context.getUserAgent()).setClientInfo(context.getClientInfo()).setClientTags(context.getClientTags()).setTraceToken(context.getTraceToken()).setResourceEstimates(context.getResourceEstimates()).setTracer(context.getTracer());
    if (forcedSessionTimeZone.isPresent()) {
        sessionBuilder.setTimeZoneKey(forcedSessionTimeZone.get());
    } else if (context.getTimeZoneId() != null) {
        sessionBuilder.setTimeZoneKey(getTimeZoneKey(context.getTimeZoneId()));
    }
    if (context.getLanguage() != null) {
        sessionBuilder.setLocale(Locale.forLanguageTag(context.getLanguage()));
    }
    for (Entry<String, String> entry : context.getSystemProperties().entrySet()) {
        sessionBuilder.setSystemProperty(entry.getKey(), entry.getValue());
    }
    for (Entry<String, Map<String, String>> catalogProperties : context.getCatalogSessionProperties().entrySet()) {
        String catalog = catalogProperties.getKey();
        for (Entry<String, String> entry : catalogProperties.getValue().entrySet()) {
            sessionBuilder.setCatalogSessionProperty(catalog, entry.getKey(), entry.getValue());
        }
    }
    for (Entry<String, String> preparedStatement : context.getPreparedStatements().entrySet()) {
        sessionBuilder.addPreparedStatement(preparedStatement.getKey(), preparedStatement.getValue());
    }
    if (context.supportClientTransaction()) {
        sessionBuilder.setClientTransactionSupport();
    }
    for (Entry<SqlFunctionId, SqlInvokedFunction> entry : context.getSessionFunctions().entrySet()) {
        sessionBuilder.addSessionFunction(entry.getKey(), entry.getValue());
    }
    Session session = sessionBuilder.build();
    if (context.getTransactionId().isPresent()) {
        session = session.beginTransactionId(context.getTransactionId().get(), transactionManager, accessControl);
    }
    return session;
}
Also used : AccessControlContext(com.facebook.presto.spi.security.AccessControlContext) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) SessionBuilder(com.facebook.presto.Session.SessionBuilder) Identity(com.facebook.presto.spi.security.Identity) Map(java.util.Map) Session(com.facebook.presto.Session)

Example 5 with SessionBuilder

use of com.facebook.presto.Session.SessionBuilder in project presto by prestodb.

the class BenchmarkQueryRunner method createLocalQueryRunner.

public static LocalQueryRunner createLocalQueryRunner(boolean hashingEnabled) {
    SessionBuilder sessionBuilder = testSessionBuilder().setCatalog("tpch").setSchema(TINY_SCHEMA_NAME);
    if (hashingEnabled) {
        sessionBuilder.setSystemProperty("optimizer.optimize_hash_generation", "true");
    }
    Session session = sessionBuilder.build();
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(session);
    // add tpch
    localQueryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of());
    return localQueryRunner;
}
Also used : TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) SessionBuilder(com.facebook.presto.Session.SessionBuilder) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Session(com.facebook.presto.Session)

Aggregations

SessionBuilder (com.facebook.presto.Session.SessionBuilder)6 Session (com.facebook.presto.Session)4 TestingSession.testSessionBuilder (com.facebook.presto.testing.TestingSession.testSessionBuilder)4 LocalQueryRunner (com.facebook.presto.testing.LocalQueryRunner)2 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)2 Map (java.util.Map)2 EventsBuilder (com.facebook.presto.execution.TestEventListener.EventsBuilder)1 TestingEventListenerPlugin (com.facebook.presto.execution.TestEventListenerPlugin.TestingEventListenerPlugin)1 WarningCode (com.facebook.presto.spi.WarningCode)1 SqlFunctionId (com.facebook.presto.spi.function.SqlFunctionId)1 SqlInvokedFunction (com.facebook.presto.spi.function.SqlInvokedFunction)1 AccessControlContext (com.facebook.presto.spi.security.AccessControlContext)1 Identity (com.facebook.presto.spi.security.Identity)1 ImmutableCollectors.toImmutableMap (com.facebook.presto.util.ImmutableCollectors.toImmutableMap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 BeforeClass (org.testng.annotations.BeforeClass)1