public static LocalQueryRunner createLocalQueryRunner(Map<String, String> extraSessionProperties) { SessionBuilder sessionBuilder = testSessionBuilder() .setCatalog("tpch") .setSchema(TINY_SCHEMA_NAME); extraSessionProperties.forEach(sessionBuilder::setSystemProperty); Session session = sessionBuilder.build(); LocalQueryRunner localQueryRunner = new LocalQueryRunner(session); // add tpch localQueryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of()); return localQueryRunner; } }
.setIdentity(identity) .setSource(session.getSource().orElse(null)) .setCatalog(catalog.orElse(null)) .setSchema(schema.orElse(null)) .setPath(session.getPath()) .setTimeZoneKey(session.getTimeZoneKey()) .setClientInfo(session.getClientInfo().orElse(null)) .setStartTime(session.getStartTime()) .build();
.setIdentity(identity) .setSource(context.getSource()) .setCatalog(context.getCatalog()) .setSchema(context.getSchema()) .setPath(new SqlPath(path)) .setRemoteUserAddress(context.getRemoteUserAddress()) Session session = sessionBuilder.build(); if (context.getTransactionId().isPresent()) { session = session.beginTransactionId(context.getTransactionId().get(), transactionManager, accessControl);
public static SessionBuilder testSessionBuilder(SessionPropertyManager sessionPropertyManager) { return Session.builder(sessionPropertyManager) .setQueryId(queryIdGenerator.createNextQueryId()) .setIdentity(new Identity("user", Optional.empty())) .setSource("test") .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) .setTimeZoneKey(DEFAULT_TIME_ZONE_KEY) .setLocale(ENGLISH) .setRemoteUserAddress("address") .setUserAgent("agent"); }
public static Session toSession(ConnectorTransactionHandle transactionHandle, ConnectorSession session) { TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId(); return Session.builder(new SessionPropertyManager(SYSTEM_SESSION_PROPERTIES)) .setQueryId(new QueryId(session.getQueryId())) .setTransactionId(transactionId) .setCatalog("catalog") .setSchema("schema") .setPath(new SqlPath(Optional.of("path"))) .setIdentity(session.getIdentity()) .setTimeZoneKey(session.getTimeZoneKey()) .setLocale(session.getLocale()) .setStartTime(session.getStartTime()) .build(); } }
@Setup public void setUp() throws IOException { queryRunner = new LocalQueryRunner(testSessionBuilder() .setCatalog("memory") .setSchema("default") .build()); queryRunner.installPlugin(new GeoPlugin()); queryRunner.createCatalog("memory", new MemoryConnectorFactory(), ImmutableMap.of()); Path path = Paths.get(BenchmarkSpatialJoin.class.getClassLoader().getResource("us-states.tsv").getPath()); String polygonValues = Files.lines(path) .map(line -> line.split("\t")) .map(parts -> format("('%s', '%s')", parts[0], parts[1])) .collect(Collectors.joining(",")); queryRunner.execute(format("CREATE TABLE memory.default.polygons AS SELECT * FROM (VALUES %s) as t (name, wkt)", polygonValues)); }
@Setup public void setUp() throws IOException { queryRunner = new LocalQueryRunner(testSessionBuilder() .setCatalog("memory") .setSchema("default") .build()); queryRunner.installPlugin(new GeoPlugin()); queryRunner.createCatalog("memory", new MemoryConnectorFactory(), ImmutableMap.of()); Path path = Paths.get(BenchmarkGeometryAggregations.class.getClassLoader().getResource("us-states.tsv").getPath()); String polygonValues = Files.lines(path) .map(line -> line.split("\t")) .map(parts -> format("('%s', '%s')", parts[0], parts[1])) .collect(Collectors.joining(",")); queryRunner.execute( format("CREATE TABLE memory.default.us_states AS SELECT ST_GeometryFromText(t.wkt) AS geom FROM (VALUES %s) as t (name, wkt)", polygonValues)); }
@Test public void notAllPropertiesSetForDataGeneration() { Session session = testSessionBuilder() .setCatalog("blackhole") .setSchema("default") .build(); try { assertThatQueryReturnsValue( format("CREATE TABLE nation WITH ( %s = 3, %s = 1 ) as SELECT * FROM tpch.tiny.nation", ROWS_PER_PAGE_PROPERTY, SPLIT_COUNT_PROPERTY), 25L, session); fail("Expected exception to be thrown here!"); } catch (RuntimeException ex) { // expected exception } }
private static LocalQueryRunner createQueryRunner(Map<String, String> sessionProperties) { Session.SessionBuilder sessionBuilder = testSessionBuilder() .setCatalog("local") .setSchema("tiny") .setSystemProperty("task_concurrency", "1"); // these tests don't handle exchanges from local parallel sessionProperties.entrySet().forEach(entry -> sessionBuilder.setSystemProperty(entry.getKey(), entry.getValue())); LocalQueryRunner queryRunner = new LocalQueryRunner(sessionBuilder.build()); queryRunner.createCatalog(queryRunner.getDefaultSession().getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of()); return queryRunner; }
@Test(timeOut = 240_000) public void testResourceOverCommit() throws Exception { Map<String, String> properties = ImmutableMap.<String, String>builder() .put("query.max-memory-per-node", "1kB") .put("query.max-total-memory-per-node", "1kB") .put("query.max-memory", "1kB") .build(); try (DistributedQueryRunner queryRunner = createQueryRunner(TINY_SESSION, properties)) { try { queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk"); fail(); } catch (RuntimeException e) { // expected } Session session = testSessionBuilder() .setCatalog("tpch") .setSchema("tiny") .setSystemProperty(RESOURCE_OVERCOMMIT, "true") .build(); queryRunner.execute(session, "SELECT COUNT(*), clerk FROM orders GROUP BY clerk"); } }
@Test public void testQueryTypeBasedSelection() throws InterruptedException { Session session = testSessionBuilder() .setCatalog("tpch") .setSchema("sf100000") .build(); QueryId queryId = createQuery(queryRunner, session, "EXPLAIN " + LONG_LASTING_QUERY); waitForQueryState(queryRunner, queryId, ImmutableSet.of(RUNNING, FINISHED)); Optional<ResourceGroupId> resourceGroupId = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(queryId).getResourceGroupId(); assertTrue(resourceGroupId.isPresent(), "Query should have a resource group"); assertEquals(resourceGroupId.get(), createResourceGroupId("explain")); }
@Setup public void setup() { checkState(numberOfTables >= 2, "numberOfTables must be >= 2"); Session session = testSessionBuilder() .setSystemProperty("join_reordering_strategy", joinReorderingStrategy) .setSystemProperty("join_distribution_type", "AUTOMATIC") .setCatalog("tpch") .setSchema("tiny") .build(); queryRunner = new LocalQueryRunner(session); queryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of()); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("EXPLAIN SELECT * FROM nation n1"); for (int i = 2; i <= numberOfTables; i++) { stringBuilder.append(format(" JOIN nation n%s ON n%s.nationkey = n%s.nationkey", i, i - 1, i)); } query = stringBuilder.toString(); }
private void assertResourceGroupWithClientTags(Set<String> clientTags, ResourceGroupId expectedResourceGroup) throws InterruptedException { Session session = testSessionBuilder() .setCatalog("tpch") .setSchema("sf100000") .setSource("client_tags") .setClientTags(clientTags) .build(); QueryId queryId = createQuery(queryRunner, session, LONG_LASTING_QUERY); waitForQueryState(queryRunner, queryId, ImmutableSet.of(RUNNING, FINISHED)); Optional<ResourceGroupId> resourceGroupId = queryRunner.getCoordinator().getQueryManager().getFullQueryInfo(queryId).getResourceGroupId(); assertTrue(resourceGroupId.isPresent(), "Query should have a resource group"); assertEquals(resourceGroupId.get(), expectedResourceGroup, format("Expected: '%s' resource group, found: %s", expectedResourceGroup, resourceGroupId.get())); } }
public static LocalQueryRunner createQueryRunner(Map<String, String> catalogProperties, Class<? extends AtopFactory> factoryClass) { Session session = testSessionBuilder() .setCatalog("atop") .setSchema("default") .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(TimeZone.getDefault().getID())) .build(); LocalQueryRunner queryRunner = new LocalQueryRunner(session); try { AtopConnectorFactory connectorFactory = new AtopConnectorFactory(factoryClass, LocalAtopQueryRunner.class.getClassLoader()); ImmutableMap.Builder<String, String> properties = ImmutableMap.<String, String>builder() .putAll(catalogProperties) .put("atop.max-history-days", "1"); queryRunner.createCatalog("atop", connectorFactory, properties.build()); return queryRunner; } catch (Exception e) { closeAllSuppress(e, queryRunner); throw e; } } }
private static DistributedQueryRunner createThriftQueryRunnerInternal(List<DriftServer> servers, int nodeCount, Map<String, String> properties) throws Exception { String addresses = servers.stream() .map(server -> "localhost:" + driftServerPort(server)) .collect(joining(",")); Session defaultSession = testSessionBuilder() .setCatalog("thrift") .setSchema("tiny") .build(); DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(defaultSession) .setNodeCount(nodeCount) .setExtraProperties(properties) .build(); queryRunner.installPlugin(new ThriftPlugin()); Map<String, String> connectorProperties = ImmutableMap.<String, String>builder() .put("presto.thrift.client.addresses", addresses) .put("presto.thrift.client.connect-timeout", "30s") .put("presto-thrift.lookup-requests-concurrency", "2") .build(); queryRunner.createCatalog("thrift", "presto-thrift", connectorProperties); return queryRunner; }
@Setup public void setup() { String tpch = "tpch"; session = testSessionBuilder() .setCatalog(tpch) .setSchema("sf1") .setSystemProperty("iterative_optimizer_enabled", iterativeOptimizerEnabled) .build(); queryRunner = new LocalQueryRunner(session); queryRunner.createCatalog(tpch, new TpchConnectorFactory(4), ImmutableMap.of(TPCH_COLUMN_NAMING_PROPERTY, ColumnNaming.STANDARD.name())); queries = IntStream.rangeClosed(1, 22) .boxed() .filter(i -> i != 15) // q15 has two queries in it .map(i -> readResource(String.format("/io/airlift/tpch/queries/q%d.sql", i))) .collect(toImmutableList()); }
public static DistributedQueryRunner createQueryRunner() throws Exception { Session defaultSession = testSessionBuilder() .setCatalog("tpch") .setSchema(TINY_SCHEMA_NAME) .setSystemProperty(SystemSessionProperties.TASK_CONCURRENCY, "2") .setSystemProperty(SystemSessionProperties.SPILL_ENABLED, "true") .setSystemProperty(SystemSessionProperties.AGGREGATION_OPERATOR_UNSPILL_MEMORY_LIMIT, "128kB") .build(); ImmutableMap<String, String> extraProperties = ImmutableMap.<String, String>builder() .put("experimental.spiller-spill-path", Paths.get(System.getProperty("java.io.tmpdir"), "presto", "spills").toString()) .put("experimental.spiller-max-used-space-threshold", "1.0") .put("experimental.memory-revoking-threshold", "0.0") // revoke always .put("experimental.memory-revoking-target", "0.0") .build(); DistributedQueryRunner queryRunner = new DistributedQueryRunner(defaultSession, 2, extraProperties); try { queryRunner.installPlugin(new TpchPlugin()); queryRunner.createCatalog("tpch", "tpch"); return queryRunner; } catch (Exception e) { queryRunner.close(); throw e; } }
public MemoryLocalQueryRunner(Map<String, String> properties) { Session.SessionBuilder sessionBuilder = testSessionBuilder() .setCatalog("memory") .setSchema("default"); properties.forEach(sessionBuilder::setSystemProperty); localQueryRunner = createMemoryLocalQueryRunner(sessionBuilder.build()); }
@BeforeClass public void setUp() { queryRunner = new LocalQueryRunner(testSessionBuilder() .setCatalog("local") .setSchema("tiny") .build()); queryRunner.createCatalog( queryRunner.getDefaultSession().getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of()); }
@Test public void fieldLength() { Session session = testSessionBuilder() .setCatalog("blackhole") .setSchema("default") .build(); assertThatQueryReturnsValue( format("CREATE TABLE nation WITH ( %s = 8, %s = 1, %s = 1, %s = 1 ) AS " + "SELECT nationkey, name, regionkey, comment, 'abc' short_varchar FROM tpch.tiny.nation", FIELD_LENGTH_PROPERTY, ROWS_PER_PAGE_PROPERTY, PAGES_PER_SPLIT_PROPERTY, SPLIT_COUNT_PROPERTY), 25L, session); MaterializedResult rows = queryRunner.execute(session, "SELECT * FROM nation"); assertEquals(rows.getRowCount(), 1); MaterializedRow row = Iterables.getOnlyElement(rows); assertEquals(row.getFieldCount(), 5); assertEquals(row.getField(0), 0L); assertEquals(row.getField(1), "********"); assertEquals(row.getField(2), 0L); assertEquals(row.getField(3), "********"); assertEquals(row.getField(4), "***"); // this one is shorter due to column type being VARCHAR(3) assertThatQueryReturnsValue("DROP TABLE nation", true); }