Search in sources :

Example 66 with SchemaTableName

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

the class TestTpchMetadata method testColumnStats.

private void testColumnStats(String schema, TpchTable<?> table, TpchColumn<?> column, Constraint<ColumnHandle> constraint, ColumnStatistics expected) {
    TpchTableHandle tableHandle = tpchMetadata.getTableHandle(session, new SchemaTableName(schema, table.getTableName()));
    List<ColumnHandle> columnHandles = ImmutableList.copyOf(tpchMetadata.getColumnHandles(session, tableHandle).values());
    TableStatistics tableStatistics = tpchMetadata.getTableStatistics(session, tableHandle, Optional.empty(), columnHandles, constraint);
    ColumnHandle columnHandle = tpchMetadata.getColumnHandles(session, tableHandle).get(column.getSimplifiedColumnName());
    ColumnStatistics actual = tableStatistics.getColumnStatistics().get(columnHandle);
    EstimateAssertion estimateAssertion = new EstimateAssertion(TOLERANCE);
    estimateAssertion.assertClose(actual.getDistinctValuesCount(), expected.getDistinctValuesCount(), "distinctValuesCount");
    estimateAssertion.assertClose(actual.getDataSize(), expected.getDataSize(), "dataSize");
    estimateAssertion.assertClose(actual.getNullsFraction(), expected.getNullsFraction(), "nullsFraction");
    estimateAssertion.assertClose(actual.getRange(), expected.getRange(), "range");
}
Also used : ColumnStatistics(com.facebook.presto.spi.statistics.ColumnStatistics) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TableStatistics(com.facebook.presto.spi.statistics.TableStatistics) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 67 with SchemaTableName

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

the class TestTpchMetadata method testTableStats.

private void testTableStats(String schema, TpchTable<?> table, Constraint<ColumnHandle> constraint, double expectedRowCount) {
    TpchTableHandle tableHandle = tpchMetadata.getTableHandle(session, new SchemaTableName(schema, table.getTableName()));
    List<ColumnHandle> columnHandles = ImmutableList.copyOf(tpchMetadata.getColumnHandles(session, tableHandle).values());
    TableStatistics tableStatistics = tpchMetadata.getTableStatistics(session, tableHandle, Optional.empty(), columnHandles, constraint);
    double actualRowCountValue = tableStatistics.getRowCount().getValue();
    assertEquals(tableStatistics.getRowCount(), Estimate.of(actualRowCountValue));
    assertEquals(actualRowCountValue, expectedRowCount, expectedRowCount * TOLERANCE);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TableStatistics(com.facebook.presto.spi.statistics.TableStatistics) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 68 with SchemaTableName

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

the class TestTpchMetadata method testPartTypeAndPartContainerPredicatePushdown.

@Test
public void testPartTypeAndPartContainerPredicatePushdown() {
    TpchTableHandle tableHandle = tpchMetadata.getTableHandle(session, new SchemaTableName("sf1", PART.getTableName()));
    TupleDomain<ColumnHandle> domain;
    ConnectorTableLayoutResult tableLayout;
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.TYPE, utf8Slice("SMALL BRUSHED COPPER"));
    tableLayout = getTableOnlyLayout(tpchMetadata, session, tableHandle, new Constraint<>(domain, convertToPredicate(domain, PartColumn.TYPE)));
    assertTupleDomainEquals(tableLayout.getUnenforcedConstraint(), TupleDomain.all(), session);
    assertTupleDomainEquals(filterOutColumnFromPredicate(tableLayout.getTableLayout().getPredicate(), tpchMetadata.toColumnHandle(PartColumn.CONTAINER)), domain, session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.TYPE, utf8Slice("UNKNOWN"));
    tableLayout = getTableOnlyLayout(tpchMetadata, session, tableHandle, new Constraint<>(domain, convertToPredicate(domain, PartColumn.TYPE)));
    assertTupleDomainEquals(tableLayout.getUnenforcedConstraint(), TupleDomain.all(), session);
    assertTupleDomainEquals(tableLayout.getTableLayout().getPredicate(), TupleDomain.none(), session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.CONTAINER, utf8Slice("SM BAG"));
    tableLayout = getTableOnlyLayout(tpchMetadata, session, tableHandle, new Constraint<>(domain, convertToPredicate(domain, PartColumn.CONTAINER)));
    assertTupleDomainEquals(tableLayout.getUnenforcedConstraint(), TupleDomain.all(), session);
    assertTupleDomainEquals(filterOutColumnFromPredicate(tableLayout.getTableLayout().getPredicate(), tpchMetadata.toColumnHandle(PartColumn.TYPE)), domain, session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.CONTAINER, utf8Slice("UNKNOWN"));
    tableLayout = getTableOnlyLayout(tpchMetadata, session, tableHandle, new Constraint<>(domain, convertToPredicate(domain, PartColumn.CONTAINER)));
    assertTupleDomainEquals(tableLayout.getUnenforcedConstraint(), TupleDomain.all(), session);
    assertTupleDomainEquals(tableLayout.getTableLayout().getPredicate(), TupleDomain.none(), session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.TYPE, utf8Slice("SMALL BRUSHED COPPER"), PartColumn.CONTAINER, utf8Slice("SM BAG"));
    tableLayout = getTableOnlyLayout(tpchMetadata, session, tableHandle, new Constraint<>(domain, convertToPredicate(domain, PartColumn.CONTAINER)));
    assertTupleDomainEquals(tableLayout.getUnenforcedConstraint(), TupleDomain.all(), session);
    assertTupleDomainEquals(tableLayout.getTableLayout().getPredicate(), domain, session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.TYPE, utf8Slice("UNKNOWN"), PartColumn.CONTAINER, utf8Slice("UNKNOWN"));
    tableLayout = getTableOnlyLayout(tpchMetadata, session, tableHandle, new Constraint<>(domain, convertToPredicate(domain, PartColumn.TYPE, PartColumn.CONTAINER)));
    assertTupleDomainEquals(tableLayout.getUnenforcedConstraint(), TupleDomain.all(), session);
    assertTupleDomainEquals(tableLayout.getTableLayout().getPredicate(), TupleDomain.none(), session);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) Constraint(com.facebook.presto.spi.Constraint) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Test(org.testng.annotations.Test)

Example 69 with SchemaTableName

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

the class RedisConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(config, "config is null");
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new RedisConnectorModule(), binder -> {
            binder.bind(RedisConnectorId.class).toInstance(new RedisConnectorId(catalogName));
            binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            if (tableDescriptionSupplier.isPresent()) {
                binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, RedisTableDescription>>>() {
                }).toInstance(tableDescriptionSupplier.get());
            } else {
                binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, RedisTableDescription>>>() {
                }).to(RedisTableDescriptionSupplier.class).in(Scopes.SINGLETON);
            }
        });
        Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(RedisConnector.class);
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}
Also used : JsonModule(com.facebook.airlift.json.JsonModule) SchemaTableName(com.facebook.presto.spi.SchemaTableName) NodeManager(com.facebook.presto.spi.NodeManager) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) Bootstrap(com.facebook.airlift.bootstrap.Bootstrap) TypeManager(com.facebook.presto.common.type.TypeManager) Supplier(java.util.function.Supplier) Map(java.util.Map)

Example 70 with SchemaTableName

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

the class TpchMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder();
    for (String schemaName : getSchemaNames(session, Optional.ofNullable(prefix.getSchemaName()))) {
        for (TpchTable<?> tpchTable : TpchTable.getTables()) {
            if (prefix.getTableName() == null || tpchTable.getTableName().equals(prefix.getTableName())) {
                ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpchTable, columnNaming);
                tableColumns.put(new SchemaTableName(schemaName, tpchTable.getTableName()), tableMetadata.getColumns());
            }
        }
    }
    return tableColumns.build();
}
Also used : Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Aggregations

SchemaTableName (com.facebook.presto.spi.SchemaTableName)370 ImmutableList (com.google.common.collect.ImmutableList)122 Test (org.testng.annotations.Test)107 List (java.util.List)100 PrestoException (com.facebook.presto.spi.PrestoException)99 ImmutableMap (com.google.common.collect.ImmutableMap)95 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)91 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)79 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)73 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)68 ConnectorSession (com.facebook.presto.spi.ConnectorSession)62 ArrayList (java.util.ArrayList)60 ColumnHandle (com.facebook.presto.spi.ColumnHandle)58 Table (com.facebook.presto.hive.metastore.Table)57 Map (java.util.Map)57 Optional (java.util.Optional)55 Column (com.facebook.presto.hive.metastore.Column)52 Collectors.toList (java.util.stream.Collectors.toList)48 Path (org.apache.hadoop.fs.Path)47 Objects.requireNonNull (java.util.Objects.requireNonNull)46