public StandaloneQueryRunner(Session defaultSession) throws Exception { requireNonNull(defaultSession, "defaultSession is null"); try { server = createTestingPrestoServer(); } catch (Exception e) { close(); throw e; } this.prestoClient = new TestingPrestoClient(server, defaultSession); refreshNodes(); server.getMetadata().addFunctions(AbstractTestQueries.CUSTOM_FUNCTIONS); SessionPropertyManager sessionPropertyManager = server.getMetadata().getSessionPropertyManager(); sessionPropertyManager.addSystemSessionProperties(AbstractTestQueries.TEST_SYSTEM_PROPERTIES); sessionPropertyManager.addConnectorSessionProperties("catalog", AbstractTestQueries.TEST_CATALOG_PROPERTIES); }
private static LocalQueryRunner createLocalQueryRunner() { Session defaultSession = testSessionBuilder() .setCatalog("local") .setSchema(TINY_SCHEMA_NAME) .build(); LocalQueryRunner localQueryRunner = new LocalQueryRunner(defaultSession); // add the tpch catalog // local queries run directly against the generator localQueryRunner.createCatalog( defaultSession.getCatalog().get(), new TpchConnectorFactory(localQueryRunner.getNodeManager(), 1), ImmutableMap.<String, String>of()); localQueryRunner.createCatalog(TPCH_SAMPLED_SCHEMA, new SampledTpchConnectorFactory(localQueryRunner.getNodeManager(), 1, 2), ImmutableMap.<String, String>of()); localQueryRunner.getMetadata().addFunctions(CUSTOM_FUNCTIONS); SessionPropertyManager sessionPropertyManager = localQueryRunner.getMetadata().getSessionPropertyManager(); sessionPropertyManager.addSystemSessionProperties(AbstractTestQueries.TEST_SYSTEM_PROPERTIES); sessionPropertyManager.addConnectorSessionProperties("connector", AbstractTestQueries.TEST_CATALOG_PROPERTIES); return localQueryRunner; }
public Session toSession(SessionPropertyManager sessionPropertyManager) { return new Session( new QueryId(queryId), transactionId, clientTransactionSupport, new Identity(user, Optional.empty()), source, catalog, schema, timeZoneKey, locale, remoteUserAddress, userAgent, startTime, systemProperties, catalogProperties, sessionPropertyManager); }
public FullConnectorSession( String queryId, Identity identity, TimeZoneKey timeZoneKey, Locale locale, long startTime, Map<String, String> properties, String catalog, SessionPropertyManager sessionPropertyManager) { this.queryId = requireNonNull(queryId, "queryId is null"); this.identity = requireNonNull(identity, "identity is null"); this.timeZoneKey = requireNonNull(timeZoneKey, "timeZoneKey is null"); this.locale = requireNonNull(locale, "locale is null"); this.startTime = startTime; this.properties = ImmutableMap.copyOf(requireNonNull(properties, "properties is null")); this.catalog = requireNonNull(catalog, "catalog is null"); this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); }
@Inject public ExecuteResource( HttpServerInfo serverInfo, AccessControl accessControl, SessionPropertyManager sessionPropertyManager, @ForExecute HttpClient httpClient, QueryIdGenerator queryIdGenerator, JsonCodec<QueryResults> queryResultsCodec) { this.serverInfo = requireNonNull(serverInfo, "serverInfo is null"); this.accessControl = requireNonNull(accessControl, "accessControl is null"); this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); this.httpClient = requireNonNull(httpClient, "httpClient is null"); this.queryIdGenerator = requireNonNull(queryIdGenerator, "queryIdGenerator is null"); this.queryResultsCodec = requireNonNull(queryResultsCodec, "queryResultsCodec is null"); }
@Inject public StatementResource( QueryManager queryManager, AccessControl accessControl, SessionPropertyManager sessionPropertyManager, ExchangeClientSupplier exchangeClientSupplier, QueryIdGenerator queryIdGenerator) { this.queryManager = requireNonNull(queryManager, "queryManager is null"); this.accessControl = requireNonNull(accessControl, "accessControl is null"); this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); this.exchangeClientSupplier = requireNonNull(exchangeClientSupplier, "exchangeClientSupplier is null"); this.queryIdGenerator = requireNonNull(queryIdGenerator, "queryIdGenerator is null"); queryPurger.scheduleWithFixedDelay(new PurgeQueriesRunnable(queries, queryManager), 200, 200, MILLISECONDS); }
@Test(enabled = false) public void testName() throws Exception { String s = "select count(*) from test where ali = 5"; Statement statement = new SqlParser().createStatement(s); Analysis analysis = new Analysis(statement, ImmutableList.of(), false); Session build = Session.builder(new SessionPropertyManager()) .setQueryId(QueryId.valueOf("test")) .setCatalog("test") .setCatalog("test") .setCatalog("test") .build(); QueryPlanner queryPlanner = new QueryPlanner(analysis, new SymbolAllocator(), new PlanNodeIdAllocator(), null, null, build); RelationPlan plan = queryPlanner.plan((Query) statement); // EffectivePredicateExtractor.extract(plan.getRoot(), ImmutableMap.of(new Symbol("ali"), BIGINT)); EffectivePredicateExtractor.extract(plan.getRoot()); }
@Inject public ExpressionCompiler() { TransactionManager transactionManager = TransactionManager.createTestTransactionManager(); Metadata metadata = MetadataManager.createTestMetadataManager(); this.serde = metadata.getBlockEncodingSerde(); this.metadata = metadata; this.featuresConfig = new FeaturesConfig(); this.typeManager = metadata.getTypeManager(); this.session = Session.builder(new SessionPropertyManager()) .setIdentity(new Identity("user", Optional.empty())) .setTimeZoneKey(TimeZoneKey.UTC_KEY) .setLocale(Locale.ENGLISH) .setQueryId(QueryId.valueOf("row_expression_compiler")) .setTransactionId(transactionManager.beginTransaction(IsolationLevel.REPEATABLE_READ, true, true)) .build(); this.expressionOptimizer = new ExpressionOptimizer(metadata.getFunctionRegistry(), metadata.getTypeManager(), session); }
public static Session toSession(TransactionId transactionId, ConnectorSession session) { return Session.builder(new SessionPropertyManager(SYSTEM_SESSION_PROPERTIES)) .setQueryId(new QueryId(session.getQueryId())) .setTransactionId(transactionId) .setCatalog("catalog") .setSchema("schema") .setIdentity(session.getIdentity()) .setTimeZoneKey(session.getTimeZoneKey()) .setLocale(session.getLocale()) .setStartTime(session.getStartTime()) .build(); }
public Session( QueryId queryId, Optional<TransactionId> transactionId, boolean clientTransactionSupport, Identity identity, Optional<String> source, Optional<String> catalog, Optional<String> schema, TimeZoneKey timeZoneKey, Locale locale, Optional<String> remoteUserAddress, Optional<String> userAgent, long startTime, Map<String, String> systemProperties, Map<String, Map<String, String>> catalogProperties, SessionPropertyManager sessionPropertyManager) { this.queryId = requireNonNull(queryId, "queryId is null"); this.transactionId = requireNonNull(transactionId, "transactionId is null"); this.clientTransactionSupport = clientTransactionSupport; this.identity = identity; this.source = requireNonNull(source, "source is null"); this.catalog = requireNonNull(catalog, "catalog is null"); this.schema = requireNonNull(schema, "schema is null"); this.timeZoneKey = requireNonNull(timeZoneKey, "timeZoneKey is null"); this.locale = requireNonNull(locale, "locale is null"); this.remoteUserAddress = requireNonNull(remoteUserAddress, "remoteUserAddress is null"); this.userAgent = requireNonNull(userAgent, "userAgent is null"); this.startTime = startTime; this.systemProperties = ImmutableMap.copyOf(requireNonNull(systemProperties, "systemProperties is null")); this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); ImmutableMap.Builder<String, Map<String, String>> catalogPropertiesBuilder = ImmutableMap.<String, Map<String, String>>builder(); catalogProperties.entrySet().stream() .map(entry -> Maps.immutableEntry(entry.getKey(), ImmutableMap.copyOf(entry.getValue()))) .forEach(catalogPropertiesBuilder::put); this.catalogProperties = catalogPropertiesBuilder.build(); checkArgument(catalog.isPresent() || !schema.isPresent(), "schema is set but catalog is not"); }
private static void parseSessionHeader(String header, Multimap<String, Entry<String, String>> sessionPropertiesByCatalog, SessionPropertyManager sessionPropertyManager) { List<String> nameValue = Splitter.on('=').limit(2).trimResults().splitToList(header); assertRequest(nameValue.size() == 2, "Invalid %s header", PRESTO_SESSION); String fullPropertyName = nameValue.get(0); String catalog; String name; List<String> nameParts = Splitter.on('.').splitToList(fullPropertyName); if (nameParts.size() == 1) { catalog = null; name = nameParts.get(0); } else if (nameParts.size() == 2) { catalog = nameParts.get(0); name = nameParts.get(1); } else { throw badRequest(format("Invalid %s header", PRESTO_SESSION)); } assertRequest(catalog == null || !catalog.isEmpty(), "Invalid %s header", PRESTO_SESSION); assertRequest(!name.isEmpty(), "Invalid %s header", PRESTO_SESSION); String value = nameValue.get(1); // validate session property value PropertyMetadata<?> metadata = sessionPropertyManager.getSessionPropertyMetadata(fullPropertyName); try { sessionPropertyManager.decodeProperty(fullPropertyName, value, metadata.getJavaType()); } catch (RuntimeException e) { throw badRequest(format("Invalid %s header", PRESTO_SESSION)); } sessionPropertiesByCatalog.put(catalog, Maps.immutableEntry(name, value)); }
@Inject public TaskResource(TaskManager taskManager, SessionPropertyManager sessionPropertyManager, @ForAsyncHttp BoundedExecutor responseExecutor, @ForAsyncHttp ScheduledExecutorService timeoutExecutor) { this.taskManager = requireNonNull(taskManager, "taskManager is null"); this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); this.responseExecutor = requireNonNull(responseExecutor, "responseExecutor is null"); this.timeoutExecutor = requireNonNull(timeoutExecutor, "timeoutExecutor is null"); }
@Inject public QueryResource(QueryManager queryManager, AccessControl accessControl, SessionPropertyManager sessionPropertyManager, QueryIdGenerator queryIdGenerator) { this.queryManager = requireNonNull(queryManager, "queryManager is null"); this.accessControl = requireNonNull(accessControl, "accessControl is null"); this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); this.queryIdGenerator = requireNonNull(queryIdGenerator, "queryIdGenerator is null"); }
public static SessionBuilder testSessionBuilder() { return Session.builder(new SessionPropertyManager()) .setQueryId(queryIdGenerator.createNextQueryId()) .setIdentity(new Identity("user", Optional.empty())) .setSource("test") .setCatalog("catalog") .setSchema("schema") .setTimeZoneKey(UTC_KEY) .setLocale(ENGLISH) .setRemoteUserAddress("address") .setUserAgent("agent"); }
@Test public void testCreateSession() throws Exception { HttpServletRequest request = new MockHttpServletRequest( ImmutableListMultimap.<String, String>builder() .put(PRESTO_USER, "testUser") .put(PRESTO_SOURCE, "testSource") .put(PRESTO_CATALOG, "testCatalog") .put(PRESTO_SCHEMA, "testSchema") .put(PRESTO_LANGUAGE, "zh-TW") .put(PRESTO_TIME_ZONE, "Asia/Taipei") .put(PRESTO_SESSION, QUERY_MAX_MEMORY + "=1GB") .put(PRESTO_SESSION, DISTRIBUTED_JOIN + "=true," + HASH_PARTITION_COUNT + " = 43") .build(), "testRemote"); Session session = createSessionForRequest(request, new AllowAllAccessControl(), new SessionPropertyManager(), new QueryId("test_query_id")); assertEquals(session.getQueryId(), new QueryId("test_query_id")); assertEquals(session.getUser(), "testUser"); assertEquals(session.getSource().get(), "testSource"); assertEquals(session.getCatalog().get(), "testCatalog"); assertEquals(session.getSchema().get(), "testSchema"); assertEquals(session.getLocale(), Locale.TAIWAN); assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei")); assertEquals(session.getRemoteUserAddress().get(), "testRemote"); assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder() .put(QUERY_MAX_MEMORY, "1GB") .put(DISTRIBUTED_JOIN, "true") .put(HASH_PARTITION_COUNT, "43") .build()); }
public static SessionBuilder builder(SessionPropertyManager sessionPropertyManager) { return new SessionBuilder(sessionPropertyManager); }
private SessionBuilder(SessionPropertyManager sessionPropertyManager) { this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); }