Search in sources :

Example 31 with ConnectorTableLayout

use of com.facebook.presto.spi.ConnectorTableLayout in project presto by prestodb.

the class AbstractTestHiveClient method testGetPartitionSplitsTableOfflinePartition.

@Test
public void testGetPartitionSplitsTableOfflinePartition() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorSession session = newSession();
        ConnectorTableHandle tableHandle = getTableHandle(metadata, tableOfflinePartition);
        assertNotNull(tableHandle);
        ColumnHandle dsColumn = metadata.getColumnHandles(session, tableHandle).get("ds");
        assertNotNull(dsColumn);
        Domain domain = Domain.singleValue(createUnboundedVarcharType(), utf8Slice("2012-12-30"));
        TupleDomain<ColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(dsColumn, domain));
        ConnectorTableLayout tableLayout = getTableLayout(session, metadata, tableHandle, new Constraint<>(tupleDomain), transaction);
        try {
            getSplitCount(splitManager.getSplits(transaction.getTransactionHandle(), session, tableLayout.getHandle(), SPLIT_SCHEDULING_CONTEXT));
            fail("Expected PartitionOfflineException");
        } catch (PartitionOfflineException e) {
            assertEquals(e.getTableName(), tableOfflinePartition);
            assertEquals(e.getPartition(), "ds=2012-12-30");
        }
    }
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorSession session = newSession(ImmutableMap.of(OFFLINE_DATA_DEBUG_MODE_ENABLED, true));
        ConnectorTableHandle tableHandle = getTableHandle(metadata, tableOfflinePartition);
        assertNotNull(tableHandle);
        ColumnHandle dsColumn = metadata.getColumnHandles(session, tableHandle).get("ds");
        assertNotNull(dsColumn);
        Domain domain = Domain.singleValue(createUnboundedVarcharType(), utf8Slice("2012-12-30"));
        TupleDomain<ColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(dsColumn, domain));
        ConnectorTableLayout tableLayout = getTableLayout(session, metadata, tableHandle, new Constraint<>(tupleDomain), transaction);
        getSplitCount(splitManager.getSplits(transaction.getTransactionHandle(), session, tableLayout.getHandle(), SPLIT_SCHEDULING_CONTEXT));
    }
}
Also used : HiveColumnHandle.bucketColumnHandle(com.facebook.presto.hive.HiveColumnHandle.bucketColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 32 with ConnectorTableLayout

use of com.facebook.presto.spi.ConnectorTableLayout in project presto by prestodb.

the class AbstractTestHiveClient method testGetPartitionsWithBindings.

@Test
public void testGetPartitionsWithBindings() {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorTableHandle tableHandle = getTableHandle(metadata, tablePartitionFormat);
        ConnectorTableLayout actuaTableLayout = getTableLayout(newSession(), metadata, tableHandle, new Constraint<>(withColumnDomains(ImmutableMap.of(intColumn, Domain.singleValue(BIGINT, 5L)))), transaction);
        assertExpectedTableLayout(actuaTableLayout, tableLayout);
    }
}
Also used : ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 33 with ConnectorTableLayout

use of com.facebook.presto.spi.ConnectorTableLayout in project presto by prestodb.

the class AtopMetadata method getTableLayouts.

@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
    AtopTableHandle tableHandle = (AtopTableHandle) table;
    Optional<Map<ColumnHandle, Domain>> domains = constraint.getSummary().getDomains();
    Domain endTimeDomain = Domain.all(TIMESTAMP_WITH_TIME_ZONE);
    Domain startTimeDomain = Domain.all(TIMESTAMP_WITH_TIME_ZONE);
    if (domains.isPresent()) {
        if (domains.get().containsKey(START_TIME_HANDLE)) {
            startTimeDomain = domains.get().get(START_TIME_HANDLE);
        }
        if (domains.get().containsKey(END_TIME_HANDLE)) {
            endTimeDomain = domains.get().get(END_TIME_HANDLE);
        }
    }
    AtopTableLayoutHandle layoutHandle = new AtopTableLayoutHandle(tableHandle, startTimeDomain, endTimeDomain);
    ConnectorTableLayout tableLayout = getTableLayout(session, layoutHandle);
    return ImmutableList.of(new ConnectorTableLayoutResult(tableLayout, constraint.getSummary()));
}
Also used : ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Domain(com.facebook.presto.common.predicate.Domain) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 34 with ConnectorTableLayout

use of com.facebook.presto.spi.ConnectorTableLayout in project presto by prestodb.

the class TestHiveClientFileMetastore method testPartitionNotReadable.

@Test
public void testPartitionNotReadable() {
    SchemaTableName tableName = temporaryTable("tempTable");
    Map<String, String> dynamicPartitionParameters = ImmutableMap.of(OBJECT_NOT_READABLE, "Testing Unreadable Partition");
    try {
        createDummyPartitionedTable(tableName, STATISTICS_PARTITIONED_TABLE_COLUMNS, dynamicPartitionParameters);
        try (Transaction transaction = newTransaction()) {
            ConnectorMetadata metadata = transaction.getMetadata();
            ConnectorSession session = newSession();
            ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName);
            assertNotNull(tableHandle);
            ColumnHandle dsColumn = metadata.getColumnHandles(session, tableHandle).get("ds");
            assertNotNull(dsColumn);
            ConnectorTableLayout tableLayout = getTableLayout(session, metadata, tableHandle, Constraint.alwaysTrue(), transaction);
            try {
                getSplitCount(splitManager.getSplits(transaction.getTransactionHandle(), session, tableLayout.getHandle(), SPLIT_SCHEDULING_CONTEXT));
                fail("Expected HiveNotReadableException");
            } catch (HiveNotReadableException e) {
                assertEquals(e.getTableName(), tableName);
                assertNotNull(SPLIT_SCHEDULING_CONTEXT.getWarningCollector());
                assertEquals(SPLIT_SCHEDULING_CONTEXT.getWarningCollector().getWarnings().size(), 0);
            }
        }
        try (Transaction transaction = newTransaction()) {
            ConnectorMetadata metadata = transaction.getMetadata();
            ConnectorSession session = newSession(ImmutableMap.of(HiveSessionProperties.IGNORE_UNREADABLE_PARTITION, true));
            ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName);
            assertNotNull(tableHandle);
            ColumnHandle dsColumn = metadata.getColumnHandles(session, tableHandle).get("ds");
            assertNotNull(dsColumn);
            ConnectorTableLayout tableLayout = getTableLayout(session, metadata, tableHandle, Constraint.alwaysTrue(), transaction);
            splitManager.getSplits(transaction.getTransactionHandle(), session, tableLayout.getHandle(), SPLIT_SCHEDULING_CONTEXT);
            assertNotNull(SPLIT_SCHEDULING_CONTEXT.getWarningCollector());
            assertEquals(SPLIT_SCHEDULING_CONTEXT.getWarningCollector().getWarnings().size(), 1);
            assertTrue(SPLIT_SCHEDULING_CONTEXT.getWarningCollector().getWarnings().get(0).getMessage().contains("has 1 out of 3 partitions unreadable: ds=2020-01-03... are due to Testing Unreadable Partition. "));
            assertEquals(SPLIT_SCHEDULING_CONTEXT.getWarningCollector().getWarnings().get(0).getWarningCode().getName(), "PARTITION_NOT_READABLE");
        }
    } catch (Exception e) {
        fail("Exception not expected");
    } finally {
        dropTable(tableName);
    }
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) SchemaTableName(com.facebook.presto.spi.SchemaTableName) SkipException(org.testng.SkipException) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 35 with ConnectorTableLayout

use of com.facebook.presto.spi.ConnectorTableLayout in project presto by prestodb.

the class InformationSchemaMetadata method getTableLayouts.

@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
    if (constraint.getSummary().isNone()) {
        return ImmutableList.of();
    }
    InformationSchemaTableHandle handle = checkTableHandle(table);
    Set<QualifiedTablePrefix> prefixes = calculatePrefixesWithSchemaName(session, constraint.getSummary(), constraint.predicate());
    if (isTablesEnumeratingTable(handle.getSchemaTableName())) {
        Set<QualifiedTablePrefix> tablePrefixes = calculatePrefixesWithTableName(session, prefixes, constraint.getSummary(), constraint.predicate());
        // in case of high number of prefixes it is better to populate all data and then filter
        if (tablePrefixes.size() <= MAX_PREFIXES_COUNT) {
            prefixes = tablePrefixes;
        }
    }
    if (prefixes.size() > MAX_PREFIXES_COUNT) {
        // in case of high number of prefixes it is better to populate all data and then filter
        prefixes = ImmutableSet.of(new QualifiedTablePrefix(catalogName));
    }
    ConnectorTableLayout layout = new ConnectorTableLayout(new InformationSchemaTableLayoutHandle(handle, prefixes));
    return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary()));
}
Also used : QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout)

Aggregations

ConnectorTableLayout (com.facebook.presto.spi.ConnectorTableLayout)39 ConnectorTableLayoutResult (com.facebook.presto.spi.ConnectorTableLayoutResult)27 ColumnHandle (com.facebook.presto.spi.ColumnHandle)11 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)11 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)10 ConnectorSession (com.facebook.presto.spi.ConnectorSession)8 Test (org.testng.annotations.Test)8 SchemaTableName (com.facebook.presto.spi.SchemaTableName)7 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)6 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)4 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)4 Set (java.util.Set)4 Domain (com.facebook.presto.common.predicate.Domain)3 HiveColumnHandle.bucketColumnHandle (com.facebook.presto.hive.HiveColumnHandle.bucketColumnHandle)3 Constraint (com.facebook.presto.spi.Constraint)3 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)2 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)2 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)2 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)2 ConnectorTablePartitioning (com.facebook.presto.spi.ConnectorTablePartitioning)2