Search in sources :

Example 46 with ColumnHandle

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

the class MongoSession method buildQuery.

@VisibleForTesting
static Document buildQuery(TupleDomain<ColumnHandle> tupleDomain) {
    Document query = new Document();
    if (tupleDomain.getDomains().isPresent()) {
        for (Map.Entry<ColumnHandle, Domain> entry : tupleDomain.getDomains().get().entrySet()) {
            MongoColumnHandle column = (MongoColumnHandle) entry.getKey();
            query.putAll(buildPredicate(column, entry.getValue()));
        }
    }
    return query;
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Document(org.bson.Document) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 47 with ColumnHandle

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

the class PinotPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, ConnectorTableLayoutHandle tableLayoutHandle, List<ColumnHandle> columns, SplitContext splitContext) {
    requireNonNull(split, "split is null");
    PinotSplit pinotSplit = (PinotSplit) split;
    checkArgument(pinotSplit.getConnectorId().equals(connectorId), "split is not for this connector");
    List<PinotColumnHandle> handles = new ArrayList<>();
    for (ColumnHandle handle : columns) {
        handles.add((PinotColumnHandle) handle);
    }
    switch(pinotSplit.getSplitType()) {
        case SEGMENT:
            if (pinotConfig.isUseStreamingForSegmentQueries() && pinotSplit.getGrpcPort().orElse(-1) > 0) {
                return new PinotSegmentStreamingPageSource(session, pinotConfig, pinotStreamingQueryClient, pinotSplit, handles);
            }
            return new PinotSegmentPageSource(session, pinotConfig, pinotQueryClient, pinotSplit, handles);
        case BROKER:
            switch(pinotSplit.getBrokerPinotQuery().get().getFormat()) {
                case SQL:
                    return new PinotBrokerPageSourceSql(pinotConfig, session, pinotSplit.getBrokerPinotQuery().get(), handles, pinotSplit.getExpectedColumnHandles(), clusterInfoFetcher, objectMapper);
                case PQL:
                    return new PinotBrokerPageSourcePql(pinotConfig, session, pinotSplit.getBrokerPinotQuery().get(), handles, pinotSplit.getExpectedColumnHandles(), clusterInfoFetcher, objectMapper);
            }
        default:
            throw new UnsupportedOperationException("Unknown Pinot split type: " + pinotSplit.getSplitType());
    }
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ArrayList(java.util.ArrayList)

Example 48 with ColumnHandle

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

the class PinotMetadata method getColumnHandles.

@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    PinotTableHandle pinotTableHandle = (PinotTableHandle) tableHandle;
    checkArgument(pinotTableHandle.getConnectorId().equals(connectorId), "tableHandle is not for this connector");
    String pinotTableName = getPinotTableNameFromPrestoTableName(pinotTableHandle.getTableName());
    PinotTable table = pinotPrestoConnection.getTable(pinotTableName);
    if (table == null) {
        throw new TableNotFoundException(pinotTableHandle.toSchemaTableName());
    }
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (ColumnMetadata column : table.getColumnsMetadata()) {
        columnHandles.put(column.getName().toLowerCase(ENGLISH), new PinotColumnHandle(((PinotColumnMetadata) column).getPinotName(), column.getType(), REGULAR));
    }
    return columnHandles.build();
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 49 with ColumnHandle

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

the class TestTpchMetadata method testOrdersOrderStatusPredicatePushdown.

@Test
public void testOrdersOrderStatusPredicatePushdown() {
    TpchTableHandle tableHandle = tpchMetadata.getTableHandle(session, new SchemaTableName("sf1", ORDERS.getTableName()));
    TupleDomain<ColumnHandle> domain;
    ConnectorTableLayoutResult tableLayout;
    domain = fixedValueTupleDomain(tpchMetadata, ORDER_STATUS, utf8Slice("P"));
    tableLayout = getTableOnlyLayout(tpchMetadata, session, tableHandle, new Constraint<>(domain, convertToPredicate(domain, ORDER_STATUS)));
    assertTupleDomainEquals(tableLayout.getUnenforcedConstraint(), TupleDomain.all(), session);
    assertTupleDomainEquals(tableLayout.getTableLayout().getPredicate(), domain, session);
    domain = fixedValueTupleDomain(tpchMetadata, ORDER_KEY, 42L);
    tableLayout = getTableOnlyLayout(tpchMetadata, session, tableHandle, new Constraint<>(domain, convertToPredicate(domain, ORDER_STATUS)));
    assertTupleDomainEquals(tableLayout.getUnenforcedConstraint(), domain, session);
    assertTupleDomainEquals(tableLayout.getTableLayout().getPredicate(), // Using concrete expected value instead of checking TupleDomain::isNone to make sure the test doesn't pass on some other wrong value.
    TupleDomain.columnWiseUnion(fixedValueTupleDomain(tpchMetadata, ORDER_STATUS, utf8Slice("F")), fixedValueTupleDomain(tpchMetadata, ORDER_STATUS, utf8Slice("O")), fixedValueTupleDomain(tpchMetadata, ORDER_STATUS, utf8Slice("P"))), 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 50 with ColumnHandle

use of com.facebook.presto.spi.ColumnHandle 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)

Aggregations

ColumnHandle (com.facebook.presto.spi.ColumnHandle)243 ImmutableList (com.google.common.collect.ImmutableList)90 ImmutableMap (com.google.common.collect.ImmutableMap)81 Test (org.testng.annotations.Test)81 ConnectorSession (com.facebook.presto.spi.ConnectorSession)80 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)70 Constraint (com.facebook.presto.spi.Constraint)66 Map (java.util.Map)65 SchemaTableName (com.facebook.presto.spi.SchemaTableName)60 Optional (java.util.Optional)57 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)54 List (java.util.List)54 Objects.requireNonNull (java.util.Objects.requireNonNull)53 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)47 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)47 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)46 ImmutableSet (com.google.common.collect.ImmutableSet)46 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)43 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)42 PrestoException (com.facebook.presto.spi.PrestoException)42