use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class TpchMetadata method getColumnMetadata.
@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle);
String columnName = ((TpchColumnHandle) columnHandle).getColumnName();
for (ColumnMetadata column : tableMetadata.getColumns()) {
if (column.getName().equals(columnName)) {
return column;
}
}
throw new IllegalArgumentException(String.format("Table %s does not have column %s", tableMetadata.getTable(), columnName));
}
use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class TestRaptorMetadata method testCreateBucketedTableExistingDistribution.
@Test
public void testCreateBucketedTableExistingDistribution() {
MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
// create orders table
assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
ConnectorTableMetadata table = getOrdersTable(ImmutableMap.of(BUCKET_COUNT_PROPERTY, 16, BUCKETED_ON_PROPERTY, ImmutableList.of("orderkey"), DISTRIBUTION_NAME_PROPERTY, "orders"));
metadata.createTable(SESSION, table);
ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
assertInstanceOf(tableHandle, RaptorTableHandle.class);
RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
long tableId = raptorTableHandle.getTableId();
assertEquals(raptorTableHandle.getTableId(), 1);
assertTableColumnsEqual(metadataDao.listBucketColumns(tableId), ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderkey", BIGINT, 1, OptionalInt.of(0), OptionalInt.empty(), false)));
assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(16));
assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
// create lineitems table
assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_LINEITEMS));
table = getLineItemsTable(ImmutableMap.of(BUCKET_COUNT_PROPERTY, 16, BUCKETED_ON_PROPERTY, ImmutableList.of("orderkey"), DISTRIBUTION_NAME_PROPERTY, "orders"));
metadata.createTable(SESSION, table);
tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_LINEITEMS);
assertInstanceOf(tableHandle, RaptorTableHandle.class);
raptorTableHandle = (RaptorTableHandle) tableHandle;
tableId = raptorTableHandle.getTableId();
assertEquals(tableId, 2);
assertTableColumnsEqual(metadataDao.listBucketColumns(tableId), ImmutableList.of(new TableColumn(DEFAULT_TEST_LINEITEMS, "orderkey", BIGINT, 1, OptionalInt.of(0), OptionalInt.empty(), false)));
assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(16));
assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
}
use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class TestRaptorMetadata method testInvalidOrderingColumns.
@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Ordering column does not exist: orderdatefoo")
public void testInvalidOrderingColumns() throws Exception {
assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdatefoo")));
metadata.createTable(SESSION, ordersTable);
fail("Expected createTable to fail");
}
use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class TestRaptorMetadata method assertTableEqual.
private static void assertTableEqual(ConnectorTableMetadata actual, ConnectorTableMetadata expected) {
assertEquals(actual.getTable(), expected.getTable());
List<ColumnMetadata> actualColumns = actual.getColumns().stream().filter(columnMetadata -> !columnMetadata.isHidden()).collect(Collectors.toList());
List<ColumnMetadata> expectedColumns = expected.getColumns();
assertEquals(actualColumns.size(), expectedColumns.size());
for (int i = 0; i < actualColumns.size(); i++) {
ColumnMetadata actualColumn = actualColumns.get(i);
ColumnMetadata expectedColumn = expectedColumns.get(i);
assertEquals(actualColumn.getName(), expectedColumn.getName());
assertEquals(actualColumn.getType(), expectedColumn.getType());
}
assertEquals(actual.getProperties(), expected.getProperties());
}
use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.
the class TestRaptorMetadata method testCreateTable.
@Test
public void testCreateTable() {
assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
metadata.createTable(SESSION, getOrdersTable());
ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
assertInstanceOf(tableHandle, RaptorTableHandle.class);
assertEquals(((RaptorTableHandle) tableHandle).getTableId(), 1);
ConnectorTableMetadata table = metadata.getTableMetadata(SESSION, tableHandle);
assertTableEqual(table, getOrdersTable());
ColumnHandle columnHandle = metadata.getColumnHandles(SESSION, tableHandle).get("orderkey");
assertInstanceOf(columnHandle, RaptorColumnHandle.class);
assertEquals(((RaptorColumnHandle) columnHandle).getColumnId(), 1);
ColumnMetadata columnMetadata = metadata.getColumnMetadata(SESSION, tableHandle, columnHandle);
assertNotNull(columnMetadata);
assertEquals(columnMetadata.getName(), "orderkey");
assertEquals(columnMetadata.getType(), BIGINT);
}
Aggregations