Search in sources :

Example 51 with ColumnHandle

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

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

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

the class TestMongoSession method testBuildQueryStringType.

@Test
public void testBuildQueryStringType() {
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(COL1, Domain.create(ValueSet.ofRanges(range(createUnboundedVarcharType(), utf8Slice("hello"), false, utf8Slice("world"), true)), false), COL2, Domain.create(ValueSet.ofRanges(greaterThanOrEqual(createUnboundedVarcharType(), utf8Slice("a value"))), false)));
    Document query = MongoSession.buildQuery(tupleDomain);
    Document expected = new Document().append(COL1.getName(), new Document().append("$gt", "hello").append("$lte", "world")).append(COL2.getName(), new Document("$gte", "a value"));
    assertEquals(query, expected);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Document(org.bson.Document) Test(org.testng.annotations.Test)

Example 54 with ColumnHandle

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

the class TestMongoSession method testBuildQueryNull.

@Test
public void testBuildQueryNull() {
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(COL1, Domain.create(ValueSet.ofRanges(greaterThan(BIGINT, 200L)), true)));
    Document query = MongoSession.buildQuery(tupleDomain);
    Document expected = new Document("$or", asList(new Document(COL1.getName(), new Document("$gt", 200L)), new Document(COL1.getName(), new Document("$exists", true).append("$eq", null))));
    assertEquals(query, expected);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Document(org.bson.Document) Test(org.testng.annotations.Test)

Example 55 with ColumnHandle

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

the class TestMongoSession method testBuildQuery.

@Test
public void testBuildQuery() {
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(COL1, Domain.create(ValueSet.ofRanges(range(BIGINT, 100L, false, 200L, true)), false), COL2, Domain.singleValue(createUnboundedVarcharType(), utf8Slice("a value"))));
    Document query = MongoSession.buildQuery(tupleDomain);
    Document expected = new Document().append(COL1.getName(), new Document().append("$gt", 100L).append("$lte", 200L)).append(COL2.getName(), new Document("$eq", "a value"));
    assertEquals(query, expected);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Document(org.bson.Document) Test(org.testng.annotations.Test)

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