use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.
the class ResetSessionTask method execute.
@Override
public ListenableFuture<?> execute(ResetSession statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
List<String> parts = statement.getName().getParts();
if (parts.size() > 2) {
throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", statement.getName());
}
// validate the property name
if (parts.size() == 1) {
metadata.getSessionPropertyManager().getSystemSessionPropertyMetadata(parts.get(0)).orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName()));
} else {
ConnectorId connectorId = metadata.getCatalogHandle(stateMachine.getSession(), parts.get(0)).orElseThrow(() -> new SemanticException(MISSING_CATALOG, statement, "Catalog %s does not exist", parts.get(0)));
metadata.getSessionPropertyManager().getConnectorSessionPropertyMetadata(connectorId, parts.get(1)).orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName()));
}
stateMachine.addResetSessionProperties(statement.getName().toString());
return immediateFuture(null);
}
use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.
the class SetSessionTask method execute.
@Override
public ListenableFuture<?> execute(SetSession statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
QualifiedName propertyName = statement.getName();
List<String> parts = propertyName.getParts();
if (parts.size() > 2) {
throw new SemanticException(INVALID_SESSION_PROPERTY, statement, "Invalid session property '%s'", propertyName);
}
// validate the property name
PropertyMetadata<?> propertyMetadata;
if (parts.size() == 1) {
accessControl.checkCanSetSystemSessionProperty(session.getIdentity(), parts.get(0));
propertyMetadata = metadata.getSessionPropertyManager().getSystemSessionPropertyMetadata(parts.get(0)).orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName()));
} else {
ConnectorId connectorId = metadata.getCatalogHandle(stateMachine.getSession(), parts.get(0)).orElseThrow(() -> new SemanticException(MISSING_CATALOG, statement, "Catalog %s does not exist", parts.get(0)));
accessControl.checkCanSetCatalogSessionProperty(session.getRequiredTransactionId(), session.getIdentity(), parts.get(0), parts.get(1));
propertyMetadata = metadata.getSessionPropertyManager().getConnectorSessionPropertyMetadata(connectorId, parts.get(1)).orElseThrow(() -> new SemanticException(INVALID_SESSION_PROPERTY, statement, "Session property %s does not exist", statement.getName()));
}
Type type = propertyMetadata.getSqlType();
Object objectValue;
try {
objectValue = evaluatePropertyValue(statement.getValue(), type, session, metadata, parameters);
} catch (SemanticException e) {
throw new PrestoException(StandardErrorCode.INVALID_SESSION_PROPERTY, format("Unable to set session property '%s' to '%s': %s", propertyName, statement.getValue(), e.getMessage()));
}
String value = serializeSessionProperty(type, objectValue);
// verify the SQL value can be decoded by the property
stateMachine.addSetSessionProperties(propertyName.toString(), value);
return immediateFuture(null);
}
use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.
the class TestingPrestoServer method createCatalog.
public ConnectorId createCatalog(String catalogName, String connectorName, Map<String, String> properties) {
ConnectorId connectorId = connectorManager.createConnection(catalogName, connectorName, properties);
updateConnectorIdAnnouncement(announcer, connectorId);
return connectorId;
}
use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.
the class TestTransactionManager method registerConnector.
private static void registerConnector(CatalogManager catalogManager, TransactionManager transactionManager, String catalogName, ConnectorId connectorId, Connector connector) {
ConnectorId systemId = createSystemTablesConnectorId(connectorId);
InternalNodeManager nodeManager = new InMemoryNodeManager();
MetadataManager metadata = MetadataManager.createTestMetadataManager(catalogManager);
catalogManager.registerCatalog(new Catalog(catalogName, connectorId, connector, createInformationSchemaConnectorId(connectorId), new InformationSchemaConnector(catalogName, nodeManager, metadata, new AllowAllAccessControl()), systemId, new SystemConnector(systemId, nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, connectorId))));
}
use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.
the class Session method beginTransactionId.
public Session beginTransactionId(TransactionId transactionId, TransactionManager transactionManager, AccessControl accessControl) {
requireNonNull(transactionId, "transactionId is null");
checkArgument(!this.transactionId.isPresent(), "Session already has an active transaction");
requireNonNull(transactionManager, "transactionManager is null");
requireNonNull(accessControl, "accessControl is null");
for (Entry<String, String> property : systemProperties.entrySet()) {
// verify permissions
accessControl.checkCanSetSystemSessionProperty(identity, property.getKey());
// validate session property value
sessionPropertyManager.validateSystemSessionProperty(property.getKey(), property.getValue());
}
// Now that there is a transaction, the catalog name can be resolved to a connector, and the catalog properties can be validated
ImmutableMap.Builder<ConnectorId, Map<String, String>> connectorProperties = ImmutableMap.builder();
for (Entry<String, Map<String, String>> catalogEntry : unprocessedCatalogProperties.entrySet()) {
String catalogName = catalogEntry.getKey();
Map<String, String> catalogProperties = catalogEntry.getValue();
if (catalogProperties.isEmpty()) {
continue;
}
ConnectorId connectorId = transactionManager.getOptionalCatalogMetadata(transactionId, catalogName).orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + catalogName)).getConnectorId();
for (Entry<String, String> property : catalogProperties.entrySet()) {
// verify permissions
accessControl.checkCanSetCatalogSessionProperty(transactionId, identity, catalogName, property.getKey());
// validate session property value
sessionPropertyManager.validateCatalogSessionProperty(connectorId, catalogName, property.getKey(), property.getValue());
}
connectorProperties.put(connectorId, catalogProperties);
}
return new Session(queryId, Optional.of(transactionId), clientTransactionSupport, identity, source, catalog, schema, timeZoneKey, locale, remoteUserAddress, userAgent, clientInfo, startTime, systemProperties, connectorProperties.build(), ImmutableMap.of(), sessionPropertyManager, preparedStatements);
}
Aggregations