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