use of com.facebook.presto.sql.analyzer.SemanticException in project presto by prestodb.
the class DropSchemaTask method execute.
@Override
public ListenableFuture<?> execute(DropSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
if (statement.isCascade()) {
throw new PrestoException(NOT_SUPPORTED, "CASCADE is not yet supported for DROP SCHEMA");
}
Session session = stateMachine.getSession();
CatalogSchemaName schema = createCatalogSchemaName(session, statement, Optional.of(statement.getSchemaName()));
if (!metadata.schemaExists(session, schema)) {
if (!statement.isExists()) {
throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", schema);
}
return immediateFuture(null);
}
accessControl.checkCanDropSchema(session.getRequiredTransactionId(), session.getIdentity(), schema);
metadata.dropSchema(session, schema);
return immediateFuture(null);
}
use of com.facebook.presto.sql.analyzer.SemanticException in project presto by prestodb.
the class RenameSchemaTask method execute.
@Override
public ListenableFuture<?> execute(RenameSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource()));
CatalogSchemaName target = new CatalogSchemaName(source.getCatalogName(), statement.getTarget());
if (!metadata.schemaExists(session, source)) {
throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", source);
}
if (metadata.schemaExists(session, target)) {
throw new SemanticException(SCHEMA_ALREADY_EXISTS, statement, "Target schema '%s' already exists", target);
}
accessControl.checkCanRenameSchema(session.getRequiredTransactionId(), session.getIdentity(), source, statement.getTarget());
metadata.renameSchema(session, source, statement.getTarget());
return immediateFuture(null);
}
use of com.facebook.presto.sql.analyzer.SemanticException 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.sql.analyzer.SemanticException in project presto by prestodb.
the class AbstractTestQueries method testExecuteWithParametersInGroupBy.
@Test
public void testExecuteWithParametersInGroupBy() {
try {
String query = "SELECT a + ?, count(1) FROM (VALUES 1, 2, 3, 2) t(a) GROUP BY a + ?";
Session session = Session.builder(getSession()).addPreparedStatement("my_query", query).build();
computeActual(session, "EXECUTE my_query USING 1, 1");
fail("parameters in GROUP BY and SELECT should fail");
} catch (SemanticException e) {
assertEquals(e.getCode(), MUST_BE_AGGREGATE_OR_GROUP_BY);
} catch (RuntimeException e) {
assertEquals(e.getMessage(), "line 1:10: '(a + ?)' must be an aggregate expression or appear in GROUP BY clause");
}
}
use of com.facebook.presto.sql.analyzer.SemanticException in project presto by prestodb.
the class AbstractTestQueries method testExecuteUsingColumnReferenceFails.
@Test
public void testExecuteUsingColumnReferenceFails() {
try {
String query = "SELECT ? from nation";
Session session = Session.builder(getSession()).addPreparedStatement("my_query", query).build();
computeActual(session, "EXECUTE my_query USING \"nationkey\"");
fail("nonLiteral parameters should fail");
} catch (SemanticException e) {
assertEquals(e.getCode(), EXPRESSION_NOT_CONSTANT);
} catch (RuntimeException e) {
assertEquals(e.getMessage(), "line 1:24: Constant expression cannot contain column references");
}
}
Aggregations