use of io.trino.sql.tree.QualifiedName in project trino by trinodb.
the class TestCreateMaterializedViewTask method testCreateMaterializedViewWithDefaultProperties.
@Test
public void testCreateMaterializedViewWithDefaultProperties() {
QualifiedName materializedViewName = QualifiedName.of("catalog", "schema", "mv");
CreateMaterializedView statement = new CreateMaterializedView(Optional.empty(), materializedViewName, simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("catalog", "schema", "mock_table"))), false, true, ImmutableList.of(// set foo to DEFAULT
new Property(new Identifier("foo")), // set bar to DEFAULT
new Property(new Identifier("bar"))), Optional.empty());
getFutureValue(new CreateMaterializedViewTask(plannerContext, new AllowAllAccessControl(), parser, analyzerFactory, materializedViewPropertyManager, new FeaturesConfig()).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP));
Optional<MaterializedViewDefinition> definitionOptional = metadata.getMaterializedView(testSession, QualifiedObjectName.valueOf(materializedViewName.toString()));
assertThat(definitionOptional).isPresent();
Map<String, Object> properties = definitionOptional.get().getProperties();
assertThat(properties.get("foo")).isEqualTo(DEFAULT_MATERIALIZED_VIEW_FOO_PROPERTY_VALUE);
assertThat(properties.get("bar")).isEqualTo(DEFAULT_MATERIALIZED_VIEW_BAR_PROPERTY_VALUE);
}
use of io.trino.sql.tree.QualifiedName in project trino by trinodb.
the class TestDropMaterializedViewTask method testDropNotExistingMaterializedView.
@Test
public void testDropNotExistingMaterializedView() {
QualifiedName viewName = qualifiedName("not_existing_materialized_view");
assertTrinoExceptionThrownBy(() -> getFutureValue(executeDropMaterializedView(viewName, false))).hasErrorCode(TABLE_NOT_FOUND).hasMessage("Materialized view '%s' does not exist", viewName);
}
use of io.trino.sql.tree.QualifiedName in project trino by trinodb.
the class TestDropTableTask method testDropTableOnViewIfExists.
@Test
public void testDropTableOnViewIfExists() {
QualifiedName viewName = qualifiedName("existing_view");
metadata.createView(testSession, asQualifiedObjectName(viewName), someView(), false);
getFutureValue(executeDropTable(viewName, true));
// no exception
}
use of io.trino.sql.tree.QualifiedName in project trino by trinodb.
the class TestDropTableTask method testDropTableOnMaterializedView.
@Test
public void testDropTableOnMaterializedView() {
QualifiedName viewName = qualifiedName("existing_materialized_view");
metadata.createMaterializedView(testSession, asQualifiedObjectName(viewName), someMaterializedView(), false, false);
assertTrinoExceptionThrownBy(() -> getFutureValue(executeDropTable(viewName, false))).hasErrorCode(TABLE_NOT_FOUND).hasMessage("Table '%s' does not exist, but a materialized view with that name exists. Did you mean DROP MATERIALIZED VIEW %s?", viewName, viewName);
}
use of io.trino.sql.tree.QualifiedName in project trino by trinodb.
the class SetSessionTask method execute.
@Override
public ListenableFuture<Void> execute(SetSession statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
QualifiedName propertyName = statement.getName();
List<String> parts = propertyName.getParts();
if (parts.size() > 2) {
throw 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 = sessionPropertyManager.getSystemSessionPropertyMetadata(parts.get(0)).orElseThrow(() -> semanticException(INVALID_SESSION_PROPERTY, statement, "Session property '%s' does not exist", statement.getName()));
} else {
CatalogName catalogName = plannerContext.getMetadata().getCatalogHandle(stateMachine.getSession(), parts.get(0)).orElseThrow(() -> semanticException(CATALOG_NOT_FOUND, statement, "Catalog '%s' does not exist", parts.get(0)));
accessControl.checkCanSetCatalogSessionProperty(SecurityContext.of(session), parts.get(0), parts.get(1));
propertyMetadata = sessionPropertyManager.getConnectorSessionPropertyMetadata(catalogName, parts.get(1)).orElseThrow(() -> 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, plannerContext, accessControl, parameterExtractor(statement, parameters));
} catch (TrinoException e) {
throw new TrinoException(INVALID_SESSION_PROPERTY, format("Unable to set session property '%s' to '%s': %s", propertyName, statement.getValue(), e.getRawMessage()));
}
String value = serializeSessionProperty(type, objectValue);
// verify the SQL value can be decoded by the property
try {
propertyMetadata.decode(objectValue);
} catch (RuntimeException e) {
throw semanticException(INVALID_SESSION_PROPERTY, statement, e.getMessage());
}
stateMachine.addSetSessionProperties(propertyName.toString(), value);
return immediateVoidFuture();
}
Aggregations