Search in sources :

Example 6 with Property

use of io.trino.sql.tree.Property in project trino by trinodb.

the class TableProceduresPropertyManager method getProperties.

public Map<String, Object> getProperties(CatalogName catalog, String procedureName, Map<String, Expression> sqlPropertyValues, Session session, PlannerContext plannerContext, AccessControl accessControl, Map<NodeRef<Parameter>, Expression> parameters) {
    Map<String, PropertyMetadata<?>> supportedProperties = connectorProperties.get(new Key(catalog, procedureName));
    if (supportedProperties == null) {
        throw new TrinoException(NOT_FOUND, format("Catalog '%s' table procedure '%s' property not found", catalog, procedureName));
    }
    Map<String, Optional<Object>> propertyValues = evaluateProperties(sqlPropertyValues.entrySet().stream().map(entry -> new Property(new Identifier(entry.getKey()), entry.getValue())).collect(toImmutableList()), session, plannerContext, accessControl, parameters, true, supportedProperties, INVALID_PROCEDURE_ARGUMENT, format("catalog '%s' table procedure '%s' property", catalog, procedureName));
    return propertyValues.entrySet().stream().filter(entry -> entry.getValue().isPresent()).collect(toImmutableMap(Entry::getKey, entry -> entry.getValue().orElseThrow()));
}
Also used : PropertyUtil.evaluateProperties(io.trino.metadata.PropertyUtil.evaluateProperties) ConcurrentMap(java.util.concurrent.ConcurrentMap) INVALID_PROCEDURE_ARGUMENT(io.trino.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT) CatalogName(io.trino.connector.CatalogName) NodeRef(io.trino.sql.tree.NodeRef) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Property(io.trino.sql.tree.Property) Identifier(io.trino.sql.tree.Identifier) NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) PropertyMetadata(io.trino.spi.session.PropertyMetadata) Maps(com.google.common.collect.Maps) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) AccessControl(io.trino.security.AccessControl) Parameter(io.trino.sql.tree.Parameter) Entry(java.util.Map.Entry) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) Identifier(io.trino.sql.tree.Identifier) Optional(java.util.Optional) PropertyMetadata(io.trino.spi.session.PropertyMetadata) TrinoException(io.trino.spi.TrinoException) Property(io.trino.sql.tree.Property)

Example 7 with Property

use of io.trino.sql.tree.Property in project trino by trinodb.

the class AstBuilder method visitProperty.

@Override
public Node visitProperty(SqlBaseParser.PropertyContext context) {
    NodeLocation location = getLocation(context);
    Identifier name = (Identifier) visit(context.identifier());
    SqlBaseParser.PropertyValueContext valueContext = context.propertyValue();
    if (valueContext instanceof SqlBaseParser.DefaultPropertyValueContext) {
        return new Property(location, name);
    }
    Expression value = (Expression) visit(((SqlBaseParser.NonDefaultPropertyValueContext) valueContext).expression());
    return new Property(location, name, value);
}
Also used : Identifier(io.trino.sql.tree.Identifier) NodeLocation(io.trino.sql.tree.NodeLocation) DereferenceExpression(io.trino.sql.tree.DereferenceExpression) LogicalExpression(io.trino.sql.tree.LogicalExpression) SearchedCaseExpression(io.trino.sql.tree.SearchedCaseExpression) BindExpression(io.trino.sql.tree.BindExpression) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) SimpleCaseExpression(io.trino.sql.tree.SimpleCaseExpression) SubqueryExpression(io.trino.sql.tree.SubqueryExpression) LambdaExpression(io.trino.sql.tree.LambdaExpression) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) NullIfExpression(io.trino.sql.tree.NullIfExpression) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) TryExpression(io.trino.sql.tree.TryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) Property(io.trino.sql.tree.Property)

Example 8 with Property

use of io.trino.sql.tree.Property 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 9 with Property

use of io.trino.sql.tree.Property in project trino by trinodb.

the class TestCreateMaterializedViewTask method testCreateMaterializedViewWithInvalidProperty.

@Test
public void testCreateMaterializedViewWithInvalidProperty() {
    CreateMaterializedView statement = new CreateMaterializedView(Optional.empty(), QualifiedName.of("test_mv"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("catalog", "schema", "mock_table"))), false, true, ImmutableList.of(new Property(new Identifier("baz"), new StringLiteral("abc"))), Optional.empty());
    assertTrinoExceptionThrownBy(() -> getFutureValue(new CreateMaterializedViewTask(plannerContext, new AllowAllAccessControl(), parser, analyzerFactory, materializedViewPropertyManager, new FeaturesConfig()).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP))).hasErrorCode(INVALID_MATERIALIZED_VIEW_PROPERTY).hasMessage("Catalog 'catalog' materialized view property 'baz' does not exist");
    assertEquals(metadata.getCreateMaterializedViewCallCount(), 0);
}
Also used : CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) FeaturesConfig(io.trino.FeaturesConfig) AllColumns(io.trino.sql.tree.AllColumns) 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 10 with Property

use of io.trino.sql.tree.Property in project trino by trinodb.

the class TestCreateTableTask method testCreateTableWithMaterializedViewPropertyFails.

@Test
public void testCreateTableWithMaterializedViewPropertyFails() {
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), toSqlType(BIGINT), true, emptyList(), Optional.empty())), false, ImmutableList.of(new Property(new Identifier("foo"), new StringLiteral("bar"))), Optional.empty());
    CreateTableTask createTableTask = new CreateTableTask(plannerContext, new AllowAllAccessControl(), columnPropertyManager, tablePropertyManager);
    assertTrinoExceptionThrownBy(() -> getFutureValue(createTableTask.internalExecute(statement, testSession, emptyList(), output -> {
    }))).hasErrorCode(INVALID_TABLE_PROPERTY).hasMessage("Catalog 'catalog' table property 'foo' does not exist");
    assertEquals(metadata.getCreateTableCallCount(), 0);
}
Also used : Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) CreateTable(io.trino.sql.tree.CreateTable) Property(io.trino.sql.tree.Property) PropertyMetadata.stringProperty(io.trino.spi.session.PropertyMetadata.stringProperty) ColumnDefinition(io.trino.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Aggregations

Property (io.trino.sql.tree.Property)13 Identifier (io.trino.sql.tree.Identifier)12 StringLiteral (io.trino.sql.tree.StringLiteral)9 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)6 LongLiteral (io.trino.sql.tree.LongLiteral)6 Test (org.junit.jupiter.api.Test)6 AllColumns (io.trino.sql.tree.AllColumns)4 Test (org.testng.annotations.Test)4 AllowAllAccessControl (io.trino.security.AllowAllAccessControl)3 PropertyMetadata.stringProperty (io.trino.spi.session.PropertyMetadata.stringProperty)3 ArrayConstructor (io.trino.sql.tree.ArrayConstructor)3 CreateMaterializedView (io.trino.sql.tree.CreateMaterializedView)3 SetProperties (io.trino.sql.tree.SetProperties)3 FeaturesConfig (io.trino.FeaturesConfig)2 TrinoException (io.trino.spi.TrinoException)2 PropertyMetadata.integerProperty (io.trino.spi.session.PropertyMetadata.integerProperty)2 QueryUtil.simpleQuery (io.trino.sql.QueryUtil.simpleQuery)2 BooleanLiteral (io.trino.sql.tree.BooleanLiteral)2 CreateTable (io.trino.sql.tree.CreateTable)2 Expression (io.trino.sql.tree.Expression)2