use of com.facebook.presto.spi.ColumnMetadata 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.ColumnMetadata 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.ColumnMetadata 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);
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class TestExampleMetadata method getTableMetadata.
@Test
public void getTableMetadata() {
// known table
ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(SESSION, NUMBERS_TABLE_HANDLE);
assertEquals(tableMetadata.getTable(), new SchemaTableName("example", "numbers"));
assertEquals(tableMetadata.getColumns(), ImmutableList.of(new ColumnMetadata("text", createUnboundedVarcharType()), new ColumnMetadata("value", BIGINT)));
// unknown tables should produce null
assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle(CONNECTOR_ID, "unknown", "unknown")));
assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle(CONNECTOR_ID, "example", "unknown")));
assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle(CONNECTOR_ID, "unknown", "numbers")));
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class InternalTable method builder.
public static Builder builder(List<ColumnMetadata> columns) {
ImmutableList.Builder<String> names = ImmutableList.builder();
ImmutableList.Builder<Type> types = ImmutableList.builder();
for (ColumnMetadata column : columns) {
names.add(column.getName());
types.add(column.getType());
}
return new Builder(names.build(), types.build());
}
Aggregations