use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class AtopMetadata method getTableMetadata.
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (AtopColumn column : atopTableHandle.getTable().getColumns()) {
columns.add(new ColumnMetadata(column.getName(), typeManager.getType(column.getType())));
}
SchemaTableName schemaTableName = new SchemaTableName(atopTableHandle.getSchema(), atopTableHandle.getTable().getName());
return new ConnectorTableMetadata(schemaTableName, columns.build());
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class AtopMetadata method getColumnMetadata.
@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
String columnName = ((AtopColumnHandle) columnHandle).getName();
for (ColumnMetadata column : getTableMetadata(session, tableHandle).getColumns()) {
if (column.getName().equals(columnName)) {
return column;
}
}
AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
SchemaTableName tableName = new SchemaTableName(atopTableHandle.getSchema(), atopTableHandle.getTable().getName());
throw new ColumnNotFoundException(tableName, columnName);
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class AccumuloClient method autoGenerateMapping.
/**
* Auto-generates the mapping of Presto column name to Accumulo family/qualifier, respecting the locality groups (if any).
*
* @param columns Presto columns for the table
* @param groups Mapping of locality groups to a set of Presto columns, or null if none
* @return Column mappings
*/
private static Map<String, Pair<String, String>> autoGenerateMapping(List<ColumnMetadata> columns, Optional<Map<String, Set<String>>> groups) {
Map<String, Pair<String, String>> mapping = new HashMap<>();
for (ColumnMetadata column : columns) {
Optional<String> family = getColumnLocalityGroup(column.getName(), groups);
mapping.put(column.getName(), Pair.of(family.orElse(column.getName()), column.getName()));
}
return mapping;
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class AccumuloClient method getColumnHandles.
private static List<AccumuloColumnHandle> getColumnHandles(ConnectorTableMetadata meta, String rowIdColumn) {
// Get the column mappings from the table property or auto-generate columns if not defined
Map<String, Pair<String, String>> mapping = AccumuloTableProperties.getColumnMapping(meta.getProperties()).orElse(autoGenerateMapping(meta.getColumns(), AccumuloTableProperties.getLocalityGroups(meta.getProperties())));
// The list of indexed columns
Optional<List<String>> indexedColumns = AccumuloTableProperties.getIndexColumns(meta.getProperties());
// And now we parse the configured columns and create handles for the metadata manager
ImmutableList.Builder<AccumuloColumnHandle> cBuilder = ImmutableList.builder();
for (int ordinal = 0; ordinal < meta.getColumns().size(); ++ordinal) {
ColumnMetadata cm = meta.getColumns().get(ordinal);
// Special case if this column is the row ID
if (cm.getName().equalsIgnoreCase(rowIdColumn)) {
cBuilder.add(new AccumuloColumnHandle(rowIdColumn, Optional.empty(), Optional.empty(), cm.getType(), ordinal, "Accumulo row ID", false));
} else {
if (!mapping.containsKey(cm.getName())) {
throw new InvalidParameterException(format("Misconfigured mapping for presto column %s", cm.getName()));
}
// Get the mapping for this column
Pair<String, String> famqual = mapping.get(cm.getName());
boolean indexed = indexedColumns.isPresent() && indexedColumns.get().contains(cm.getName().toLowerCase(Locale.ENGLISH));
String comment = format("Accumulo column %s:%s. Indexed: %b", famqual.getLeft(), famqual.getRight(), indexed);
// Create a new AccumuloColumnHandle object
cBuilder.add(new AccumuloColumnHandle(cm.getName(), Optional.of(famqual.getLeft()), Optional.of(famqual.getRight()), cm.getType(), ordinal, comment, indexed));
}
}
return cBuilder.build();
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class AccumuloClient method validateColumns.
private static void validateColumns(ConnectorTableMetadata meta) {
// Check all the column types, and throw an exception if the types of a map are complex
// While it is a rare case, this is not supported by the Accumulo connector
ImmutableSet.Builder<String> columnNameBuilder = ImmutableSet.builder();
for (ColumnMetadata column : meta.getColumns()) {
if (Types.isMapType(column.getType())) {
if (Types.isMapType(Types.getKeyType(column.getType())) || Types.isMapType(Types.getValueType(column.getType())) || Types.isArrayType(Types.getKeyType(column.getType())) || Types.isArrayType(Types.getValueType(column.getType()))) {
throw new PrestoException(INVALID_TABLE_PROPERTY, "Key/value types of a MAP column must be plain types");
}
}
columnNameBuilder.add(column.getName().toLowerCase(Locale.ENGLISH));
}
// Validate the columns are distinct
if (columnNameBuilder.build().size() != meta.getColumns().size()) {
throw new PrestoException(INVALID_TABLE_PROPERTY, "Duplicate column names are not supported");
}
Optional<Map<String, Pair<String, String>>> columnMapping = AccumuloTableProperties.getColumnMapping(meta.getProperties());
if (columnMapping.isPresent()) {
// Validate there are no duplicates in the column mapping
long distinctMappings = columnMapping.get().values().stream().distinct().count();
if (distinctMappings != columnMapping.get().size()) {
throw new PrestoException(INVALID_TABLE_PROPERTY, "Duplicate column family/qualifier pair detected in column mapping, check the value of " + AccumuloTableProperties.COLUMN_MAPPING);
}
// Validate no column is mapped to the reserved entry
String reservedRowIdColumn = AccumuloPageSink.ROW_ID_COLUMN.toString();
if (columnMapping.get().values().stream().filter(pair -> pair.getKey().equals(reservedRowIdColumn) && pair.getValue().equals(reservedRowIdColumn)).count() > 0) {
throw new PrestoException(INVALID_TABLE_PROPERTY, format("Column familiy/qualifier mapping of %s:%s is reserved", reservedRowIdColumn, reservedRowIdColumn));
}
} else if (AccumuloTableProperties.isExternal(meta.getProperties())) {
// But column generation is for internal tables only
throw new PrestoException(INVALID_TABLE_PROPERTY, "Column generation for external tables is not supported, must specify " + AccumuloTableProperties.COLUMN_MAPPING);
}
}
Aggregations