Search in sources :

Example 36 with QualifiedName

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);
}
Also used : FeaturesConfig(io.trino.FeaturesConfig) QualifiedName(io.trino.sql.tree.QualifiedName) AllColumns(io.trino.sql.tree.AllColumns) CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) Identifier(io.trino.sql.tree.Identifier) MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) Property(io.trino.sql.tree.Property) PropertyMetadata.integerProperty(io.trino.spi.session.PropertyMetadata.integerProperty) PropertyMetadata.stringProperty(io.trino.spi.session.PropertyMetadata.stringProperty) Test(org.testng.annotations.Test)

Example 37 with QualifiedName

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);
}
Also used : QualifiedName(io.trino.sql.tree.QualifiedName) Test(org.testng.annotations.Test)

Example 38 with QualifiedName

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
}
Also used : QualifiedName(io.trino.sql.tree.QualifiedName) Test(org.testng.annotations.Test)

Example 39 with QualifiedName

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);
}
Also used : QualifiedName(io.trino.sql.tree.QualifiedName) Test(org.testng.annotations.Test)

Example 40 with QualifiedName

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();
}
Also used : Type(io.trino.spi.type.Type) QualifiedName(io.trino.sql.tree.QualifiedName) TrinoException(io.trino.spi.TrinoException) CatalogName(io.trino.connector.CatalogName) SetSession(io.trino.sql.tree.SetSession) Session(io.trino.Session)

Aggregations

QualifiedName (io.trino.sql.tree.QualifiedName)42 Test (org.testng.annotations.Test)29 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)7 FunctionCall (io.trino.sql.tree.FunctionCall)7 Identifier (io.trino.sql.tree.Identifier)7 ImmutableList (com.google.common.collect.ImmutableList)4 AllColumns (io.trino.sql.tree.AllColumns)4 Test (org.junit.jupiter.api.Test)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 MetadataManager.createTestMetadataManager (io.trino.metadata.MetadataManager.createTestMetadataManager)3 ResolvedFunction (io.trino.metadata.ResolvedFunction)3 ASC_NULLS_LAST (io.trino.spi.connector.SortOrder.ASC_NULLS_LAST)3 BIGINT (io.trino.spi.type.BigintType.BIGINT)3 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)3 TypeSignatureProvider.fromTypes (io.trino.sql.analyzer.TypeSignatureProvider.fromTypes)3 OrderingScheme (io.trino.sql.planner.OrderingScheme)3 PlanMatchPattern.functionCall (io.trino.sql.planner.assertions.PlanMatchPattern.functionCall)3 PlanMatchPattern.patternRecognition (io.trino.sql.planner.assertions.PlanMatchPattern.patternRecognition)3 PlanMatchPattern.specification (io.trino.sql.planner.assertions.PlanMatchPattern.specification)3