use of com.facebook.presto.Session in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method getHiveTableProperty.
private Object getHiveTableProperty(String tableName, Function<HiveTableLayoutHandle, Object> propertyGetter) {
Session session = getSession();
Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata();
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(catalog, TPCH_SCHEMA, tableName));
assertTrue(tableHandle.isPresent());
List<TableLayoutResult> layouts = metadata.getLayouts(transactionSession, tableHandle.get(), Constraint.alwaysTrue(), Optional.empty());
TableLayout layout = getOnlyElement(layouts).getLayout();
return propertyGetter.apply((HiveTableLayoutHandle) layout.getHandle().getConnectorHandle());
});
}
use of com.facebook.presto.Session in project presto by prestodb.
the class TestEventListener method testNormalQuery.
@Test
public void testNormalQuery() throws Exception {
// We expect the following events
// QueryCreated: 1, QueryCompleted: 1, Splits: SPLITS_PER_NODE (leaf splits) + LocalExchange[SINGLE] split + Aggregation/Output split
int expectedEvents = 1 + 1 + SPLITS_PER_NODE + 1 + 1;
EventsBuilder events = generateEvents("SELECT sum(linenumber) FROM lineitem", expectedEvents);
QueryCreatedEvent queryCreatedEvent = getOnlyElement(events.getQueryCreatedEvents());
assertEquals(queryCreatedEvent.getContext().getServerVersion(), "testversion");
assertEquals(queryCreatedEvent.getContext().getServerAddress(), "127.0.0.1");
assertEquals(queryCreatedEvent.getContext().getEnvironment(), "testing");
assertEquals(queryCreatedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
assertEquals(queryCreatedEvent.getMetadata().getQuery(), "SELECT sum(linenumber) FROM lineitem");
QueryCompletedEvent queryCompletedEvent = getOnlyElement(events.getQueryCompletedEvents());
assertEquals(queryCompletedEvent.getIoMetadata().getOutput(), Optional.empty());
assertEquals(queryCompletedEvent.getIoMetadata().getInputs().size(), 1);
assertEquals(queryCompletedEvent.getContext().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
assertEquals(getOnlyElement(queryCompletedEvent.getIoMetadata().getInputs()).getConnectorId(), "tpch");
assertEquals(queryCreatedEvent.getMetadata().getQueryId(), queryCompletedEvent.getMetadata().getQueryId());
assertEquals(queryCompletedEvent.getStatistics().getCompletedSplits(), SPLITS_PER_NODE + 2);
List<SplitCompletedEvent> splitCompletedEvents = events.getSplitCompletedEvents();
// leaf splits + aggregation split
assertEquals(splitCompletedEvents.size(), SPLITS_PER_NODE + 2);
// All splits must have the same query ID
Set<String> actual = splitCompletedEvents.stream().map(SplitCompletedEvent::getQueryId).collect(toSet());
assertEquals(actual, ImmutableSet.of(queryCompletedEvent.getMetadata().getQueryId()));
// Sum of row count processed by all leaf stages is equal to the number of rows in the table
long actualCompletedPositions = splitCompletedEvents.stream().filter(// filter out the root stage
e -> !e.getStageId().endsWith(".0")).mapToLong(e -> e.getStatistics().getCompletedPositions()).sum();
MaterializedResult result = queryRunner.execute(session, "SELECT count(*) FROM lineitem");
long expectedCompletedPositions = (long) result.getMaterializedRows().get(0).getField(0);
assertEquals(actualCompletedPositions, expectedCompletedPositions);
assertEquals(queryCompletedEvent.getStatistics().getTotalRows(), expectedCompletedPositions);
}
use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestQueries method testExplainExecuteWithUsing.
@Test
public void testExplainExecuteWithUsing() {
Session session = Session.builder(getSession()).addPreparedStatement("my_query", "SELECT * FROM orders where orderkey < ?").build();
MaterializedResult result = computeActual(session, "EXPLAIN (TYPE LOGICAL) EXECUTE my_query USING 7");
assertEquals(getOnlyElement(result.getOnlyColumnAsSet()), getExplainPlan("SELECT * FROM orders where orderkey < 7", LOGICAL));
}
use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestQueries method testExecuteUsingComplexJoinCriteria.
@Test
public void testExecuteUsingComplexJoinCriteria() {
String query = "SELECT * FROM (VALUES 1) t(a) JOIN (VALUES 2) u(a) ON t.a + u.a < ?";
Session session = Session.builder(getSession()).addPreparedStatement("my_query", query).build();
assertQuery(session, "EXECUTE my_query USING 5", "VALUES (1, 2)");
}
use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestQueries method testPreparedStatementWithSubqueries.
@Test
public void testPreparedStatementWithSubqueries() {
List<QueryTemplate.Parameter> leftValues = parameter("left").of("", "1 = ", "EXISTS", "1 IN", "1 = ANY", "1 = ALL", "2 <> ANY", "2 <> ALL", "0 < ALL", "0 < ANY", "1 <= ALL", "1 <= ANY");
queryTemplate("SELECT %left% (SELECT 1 WHERE 2 = ?)").replaceAll(leftValues).forEach(query -> {
Session session = Session.builder(getSession()).addPreparedStatement("my_query", query).build();
assertQuery(session, "EXECUTE my_query USING 2", "SELECT true");
});
}
Aggregations