use of com.facebook.presto.spi.session.PropertyMetadata in project presto by prestodb.
the class AbstractPropertyManager method getProperties.
public final Map<String, Object> getProperties(ConnectorId connectorId, // only use this for error messages
String catalog, Map<String, Expression> sqlPropertyValues, Session session, Metadata metadata, List<Expression> parameters) {
Map<String, PropertyMetadata<?>> supportedProperties = connectorProperties.get(connectorId);
if (supportedProperties == null) {
throw new PrestoException(NOT_FOUND, "Catalog not found: " + catalog);
}
ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
// Fill in user-specified properties
for (Map.Entry<String, Expression> sqlProperty : sqlPropertyValues.entrySet()) {
String propertyName = sqlProperty.getKey().toLowerCase(ENGLISH);
PropertyMetadata<?> property = supportedProperties.get(propertyName);
if (property == null) {
throw new PrestoException(propertyError, format("Catalog '%s' does not support %s property '%s'", catalog, propertyType, propertyName));
}
Object sqlObjectValue;
try {
sqlObjectValue = evaluatePropertyValue(sqlProperty.getValue(), property.getSqlType(), session, metadata, parameters);
} catch (SemanticException e) {
throw new PrestoException(propertyError, format("Invalid value for %s property '%s': Cannot convert '%s' to %s", propertyType, property.getName(), sqlProperty.getValue(), property.getSqlType()), e);
}
Object value;
try {
value = property.decode(sqlObjectValue);
} catch (Exception e) {
throw new PrestoException(propertyError, format("Unable to set %s property '%s' to '%s': %s", propertyType, property.getName(), sqlProperty.getValue(), e.getMessage()), e);
}
properties.put(property.getName(), value);
}
Map<String, Object> userSpecifiedProperties = properties.build();
// Fill in the remaining properties with non-null defaults
for (PropertyMetadata<?> propertyMetadata : supportedProperties.values()) {
if (!userSpecifiedProperties.containsKey(propertyMetadata.getName())) {
Object value = propertyMetadata.getDefaultValue();
if (value != null) {
properties.put(propertyMetadata.getName(), value);
}
}
}
return properties.build();
}
use of com.facebook.presto.spi.session.PropertyMetadata in project presto by prestodb.
the class AbstractPropertiesSystemTable method cursor.
@Override
public final RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId();
InMemoryRecordSet.Builder table = InMemoryRecordSet.builder(tableMetadata);
Map<ConnectorId, Map<String, PropertyMetadata<?>>> connectorProperties = propertySupplier.get();
for (Entry<String, ConnectorId> entry : new TreeMap<>(transactionManager.getCatalogNames(transactionId)).entrySet()) {
String catalog = entry.getKey();
Map<String, PropertyMetadata<?>> properties = new TreeMap<>(connectorProperties.getOrDefault(entry.getValue(), ImmutableMap.of()));
for (PropertyMetadata<?> propertyMetadata : properties.values()) {
table.addRow(catalog, propertyMetadata.getName(), firstNonNull(propertyMetadata.getDefaultValue(), "").toString(), propertyMetadata.getSqlType().toString(), propertyMetadata.getDescription());
}
}
return table.build().cursor();
}
Aggregations