Search in sources :

Example 1 with ConnectorTableHandle

use of io.prestosql.spi.connector.ConnectorTableHandle in project hetu-core by openlookeng.

the class TestTpcdsMetadataStatistics method testTableStatsDetails.

@Test
public void testTableStatsDetails() {
    SchemaTableName schemaTableName = new SchemaTableName("sf1", Table.CALL_CENTER.getName());
    ConnectorTableHandle tableHandle = metadata.getTableHandle(session, schemaTableName);
    TableStatistics tableStatistics = metadata.getTableStatistics(session, tableHandle, alwaysTrue(), true);
    estimateAssertion.assertClose(tableStatistics.getRowCount(), Estimate.of(6), "Row count does not match");
    // all columns have stats
    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
    for (ColumnHandle column : columnHandles.values()) {
        assertTrue(tableStatistics.getColumnStatistics().containsKey(column));
        assertNotNull(tableStatistics.getColumnStatistics().get(column));
    }
    // identifier
    assertColumnStatistics(tableStatistics.getColumnStatistics().get(columnHandles.get(CallCenterColumn.CC_CALL_CENTER_SK.getName())), ColumnStatistics.builder().setNullsFraction(Estimate.of(0)).setDistinctValuesCount(Estimate.of(6)).setRange(new DoubleRange(1, 6)).build());
    // varchar
    assertColumnStatistics(tableStatistics.getColumnStatistics().get(columnHandles.get(CallCenterColumn.CC_CALL_CENTER_ID.getName())), ColumnStatistics.builder().setNullsFraction(Estimate.of(0)).setDistinctValuesCount(Estimate.of(3)).setDataSize(Estimate.of(48.0)).build());
    // char
    assertColumnStatistics(tableStatistics.getColumnStatistics().get(columnHandles.get(CallCenterColumn.CC_ZIP.getName())), ColumnStatistics.builder().setNullsFraction(Estimate.of(0)).setDistinctValuesCount(Estimate.of(1)).setDataSize(Estimate.of(5.0)).build());
    // decimal
    assertColumnStatistics(tableStatistics.getColumnStatistics().get(columnHandles.get(CallCenterColumn.CC_GMT_OFFSET.getName())), ColumnStatistics.builder().setNullsFraction(Estimate.of(0)).setDistinctValuesCount(Estimate.of(1)).setRange(new DoubleRange(-5, -5)).build());
    // date
    assertColumnStatistics(tableStatistics.getColumnStatistics().get(columnHandles.get(CallCenterColumn.CC_REC_START_DATE.getName())), ColumnStatistics.builder().setNullsFraction(Estimate.of(0)).setDistinctValuesCount(Estimate.of(4)).setRange(new DoubleRange(10227L, 11688L)).build());
    // only null values
    assertColumnStatistics(tableStatistics.getColumnStatistics().get(columnHandles.get(CallCenterColumn.CC_CLOSED_DATE_SK.getName())), ColumnStatistics.builder().setNullsFraction(Estimate.of(1)).setDistinctValuesCount(Estimate.of(0)).build());
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) DoubleRange(io.prestosql.spi.statistics.DoubleRange) TableStatistics(io.prestosql.spi.statistics.TableStatistics) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 2 with ConnectorTableHandle

use of io.prestosql.spi.connector.ConnectorTableHandle in project hetu-core by openlookeng.

the class TestTpcdsMetadataStatistics method testNullFraction.

@Test
public void testNullFraction() {
    SchemaTableName schemaTableName = new SchemaTableName("sf1", Table.WEB_SITE.getName());
    ConnectorTableHandle tableHandle = metadata.getTableHandle(session, schemaTableName);
    TableStatistics tableStatistics = metadata.getTableStatistics(session, tableHandle, alwaysTrue(), true);
    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
    // some null values
    assertColumnStatistics(tableStatistics.getColumnStatistics().get(columnHandles.get(WebSiteColumn.WEB_REC_END_DATE.getName())), ColumnStatistics.builder().setNullsFraction(Estimate.of(0.5)).setDistinctValuesCount(Estimate.of(3)).setRange(new DoubleRange(10819L, 11549L)).build());
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) DoubleRange(io.prestosql.spi.statistics.DoubleRange) TableStatistics(io.prestosql.spi.statistics.TableStatistics) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 3 with ConnectorTableHandle

use of io.prestosql.spi.connector.ConnectorTableHandle in project hetu-core by openlookeng.

the class TestTpchMetadata method testPartTypeAndPartContainerPredicatePushdown.

@Test
public void testPartTypeAndPartContainerPredicatePushdown() {
    TpchTableHandle tableHandle = tpchMetadata.getTableHandle(session, new SchemaTableName("sf1", PART.getTableName()));
    TupleDomain<ColumnHandle> domain;
    ConstraintApplicationResult<ConnectorTableHandle> result;
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.TYPE, utf8Slice("SMALL BRUSHED COPPER"));
    result = tpchMetadata.applyFilter(session, tableHandle, new Constraint(domain, convertToPredicate(domain, PartColumn.TYPE))).get();
    assertTupleDomainEquals(result.getRemainingFilter(), TupleDomain.all(), session);
    assertTupleDomainEquals(PredicateUtils.filterOutColumnFromPredicate(((TpchTableHandle) result.getHandle()).getConstraint(), tpchMetadata.toColumnHandle(PartColumn.CONTAINER)), domain, session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.TYPE, utf8Slice("UNKNOWN"));
    result = tpchMetadata.applyFilter(session, tableHandle, new Constraint(domain, convertToPredicate(domain, PartColumn.TYPE))).get();
    assertTupleDomainEquals(result.getRemainingFilter(), TupleDomain.all(), session);
    assertTupleDomainEquals(((TpchTableHandle) result.getHandle()).getConstraint(), TupleDomain.none(), session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.CONTAINER, utf8Slice("SM BAG"));
    result = tpchMetadata.applyFilter(session, tableHandle, new Constraint(domain, convertToPredicate(domain, PartColumn.CONTAINER))).get();
    assertTupleDomainEquals(result.getRemainingFilter(), TupleDomain.all(), session);
    assertTupleDomainEquals(PredicateUtils.filterOutColumnFromPredicate(((TpchTableHandle) result.getHandle()).getConstraint(), tpchMetadata.toColumnHandle(PartColumn.TYPE)), domain, session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.CONTAINER, utf8Slice("UNKNOWN"));
    result = tpchMetadata.applyFilter(session, tableHandle, new Constraint(domain, convertToPredicate(domain, PartColumn.CONTAINER))).get();
    assertTupleDomainEquals(result.getRemainingFilter(), TupleDomain.all(), session);
    assertTupleDomainEquals(((TpchTableHandle) result.getHandle()).getConstraint(), TupleDomain.none(), session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.TYPE, utf8Slice("SMALL BRUSHED COPPER"), PartColumn.CONTAINER, utf8Slice("SM BAG"));
    result = tpchMetadata.applyFilter(session, tableHandle, new Constraint(domain, convertToPredicate(domain, PartColumn.CONTAINER))).get();
    assertTupleDomainEquals(result.getRemainingFilter(), TupleDomain.all(), session);
    assertTupleDomainEquals(((TpchTableHandle) result.getHandle()).getConstraint(), domain, session);
    domain = fixedValueTupleDomain(tpchMetadata, PartColumn.TYPE, utf8Slice("UNKNOWN"), PartColumn.CONTAINER, utf8Slice("UNKNOWN"));
    result = tpchMetadata.applyFilter(session, tableHandle, new Constraint(domain, convertToPredicate(domain, PartColumn.TYPE, PartColumn.CONTAINER))).get();
    assertTupleDomainEquals(result.getRemainingFilter(), TupleDomain.all(), session);
    assertTupleDomainEquals(((TpchTableHandle) result.getHandle()).getConstraint(), TupleDomain.none(), session);
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Constraint(io.prestosql.spi.connector.Constraint) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 4 with ConnectorTableHandle

use of io.prestosql.spi.connector.ConnectorTableHandle in project hetu-core by openlookeng.

the class TestMemoryMetadata method tableAlreadyExists.

@Test
public void tableAlreadyExists() {
    assertNoTables();
    SchemaTableName test1Table = new SchemaTableName("default", "test1");
    SchemaTableName test2Table = new SchemaTableName("default", "test2");
    metadata.createTable(SESSION, new ConnectorTableMetadata(test1Table, ImmutableList.of()), false);
    try {
        metadata.createTable(SESSION, new ConnectorTableMetadata(test1Table, ImmutableList.of()), false);
        fail("Should fail because table already exists");
    } catch (PrestoException ex) {
        assertEquals(ex.getErrorCode(), ALREADY_EXISTS.toErrorCode());
        assertEquals(ex.getMessage(), "Table [default.test1] already exists");
    }
    ConnectorTableHandle test1TableHandle = metadata.getTableHandle(SESSION, test1Table);
    metadata.createTable(SESSION, new ConnectorTableMetadata(test2Table, ImmutableList.of()), false);
    try {
        metadata.renameTable(SESSION, test1TableHandle, test2Table);
        fail("Should fail because table already exists");
    } catch (PrestoException ex) {
        assertEquals(ex.getErrorCode(), ALREADY_EXISTS.toErrorCode());
        assertEquals(ex.getMessage(), "Table [default.test2] already exists");
    }
}
Also used : PrestoException(io.prestosql.spi.PrestoException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 5 with ConnectorTableHandle

use of io.prestosql.spi.connector.ConnectorTableHandle in project hetu-core by openlookeng.

the class TestMemoryMetadata method testRenameTable.

@Test
public void testRenameTable() {
    SchemaTableName tableName = new SchemaTableName("test_schema", "test_table_to_be_renamed");
    metadata.createSchema(SESSION, "test_schema", ImmutableMap.of());
    ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(tableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty());
    metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
    // rename table to schema which does not exist
    SchemaTableName invalidSchemaTableName = new SchemaTableName("test_schema_not_exist", "test_table_renamed");
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, tableName);
    Throwable throwable = expectThrows(SchemaNotFoundException.class, () -> metadata.renameTable(SESSION, tableHandle, invalidSchemaTableName));
    assertTrue(throwable.getMessage().equals("Schema test_schema_not_exist not found"));
    // rename table to same schema
    SchemaTableName sameSchemaTableName = new SchemaTableName("test_schema", "test_renamed");
    metadata.renameTable(SESSION, metadata.getTableHandle(SESSION, tableName), sameSchemaTableName);
    assertEquals(metadata.listTables(SESSION, Optional.of("test_schema")), ImmutableList.of(sameSchemaTableName));
}
Also used : ConnectorOutputTableHandle(io.prestosql.spi.connector.ConnectorOutputTableHandle) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)90 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)58 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)58 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)46 Test (org.testng.annotations.Test)43 TestingConnectorSession (io.prestosql.testing.TestingConnectorSession)39 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)36 Constraint (io.prestosql.spi.connector.Constraint)29 PrestoException (io.prestosql.spi.PrestoException)28 Slice (io.airlift.slice.Slice)27 ConnectorInsertTableHandle (io.prestosql.spi.connector.ConnectorInsertTableHandle)27 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)27 Optional (java.util.Optional)26 ImmutableList (com.google.common.collect.ImmutableList)25 List (java.util.List)25 ImmutableMap (com.google.common.collect.ImmutableMap)23 ConnectorOutputTableHandle (io.prestosql.spi.connector.ConnectorOutputTableHandle)23 Path (org.apache.hadoop.fs.Path)23 HiveColumnHandle.bucketColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle.bucketColumnHandle)22 HiveIdentity (io.prestosql.plugin.hive.authentication.HiveIdentity)22