Search in sources :

Example 76 with Session

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());
    });
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Metadata(com.facebook.presto.metadata.Metadata) TableHandle(com.facebook.presto.metadata.TableHandle) TableLayoutResult(com.facebook.presto.metadata.TableLayoutResult) TableLayout(com.facebook.presto.metadata.TableLayout) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) HiveQueryRunner.createBucketedSession(com.facebook.presto.hive.HiveQueryRunner.createBucketedSession) Session(com.facebook.presto.Session)

Example 77 with Session

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);
}
Also used : Assert.assertEquals(org.testng.Assert.assertEquals) QueryRunner(com.facebook.presto.testing.QueryRunner) Test(org.testng.annotations.Test) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ImmutableList(com.google.common.collect.ImmutableList) TestingEventListenerPlugin(com.facebook.presto.execution.TestEventListenerPlugin.TestingEventListenerPlugin) Collectors.toSet(java.util.stream.Collectors.toSet) AfterClass(org.testng.annotations.AfterClass) ImmutableSet(com.google.common.collect.ImmutableSet) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) Optional(java.util.Optional) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) QueryCreatedEvent(com.facebook.presto.spi.eventlistener.QueryCreatedEvent) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 78 with Session

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));
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 79 with Session

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)");
}
Also used : Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 80 with Session

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");
    });
}
Also used : Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Aggregations

Session (com.facebook.presto.Session)121 Test (org.testng.annotations.Test)61 QueryId (com.facebook.presto.spi.QueryId)21 MaterializedResult (com.facebook.presto.testing.MaterializedResult)20 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)19 PrestoException (com.facebook.presto.spi.PrestoException)17 TransactionManager (com.facebook.presto.transaction.TransactionManager)16 AccessControl (com.facebook.presto.security.AccessControl)15 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)14 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)14 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)13 AccessControlManager (com.facebook.presto.security.AccessControlManager)13 ConnectorId (com.facebook.presto.connector.ConnectorId)12 LocalQueryRunner (com.facebook.presto.testing.LocalQueryRunner)12 Type (com.facebook.presto.spi.type.Type)11 List (java.util.List)11 TableHandle (com.facebook.presto.metadata.TableHandle)10 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)10 Optional (java.util.Optional)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9