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());
}
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());
}
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);
}
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");
}
}
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));
}
Aggregations