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()));
}
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);
}
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);
}
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);
}
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);
}
Aggregations