use of io.trino.sql.tree.SetProperties in project trino by trinodb.
the class TestSetPropertiesTask method testSetMaterializedViewProperties.
@Test
public void testSetMaterializedViewProperties() {
QualifiedObjectName materializedViewName = qualifiedObjectName("test_materialized_view");
metadata.createMaterializedView(testSession, materializedViewName, someMaterializedView(), false, false);
// set all properties to non-DEFAULT values and check the results
executeSetProperties(new SetProperties(MATERIALIZED_VIEW, asQualifiedName(materializedViewName), ImmutableList.of(new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_1_NAME), new LongLiteral("111")), new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_2_NAME), new StringLiteral("abc")))));
assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getProperties()).isEqualTo(ImmutableMap.of(MATERIALIZED_VIEW_PROPERTY_1_NAME, 111L, MATERIALIZED_VIEW_PROPERTY_2_NAME, "abc"));
// set all properties to DEFAULT and check the results
executeSetProperties(new SetProperties(MATERIALIZED_VIEW, asQualifiedName(materializedViewName), ImmutableList.of(new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_1_NAME)), new Property(new Identifier(MATERIALIZED_VIEW_PROPERTY_2_NAME)))));
// since the default value of property 1 is null, property 1 should not appear in the result, whereas property 2 should appear in
// the result with its (non-null) default value
assertThat(metadata.getMaterializedView(testSession, materializedViewName).get().getProperties()).isEqualTo(ImmutableMap.of(MATERIALIZED_VIEW_PROPERTY_2_NAME, MATERIALIZED_VIEW_PROPERTY_2_DEFAULT_VALUE));
}
use of io.trino.sql.tree.SetProperties in project trino by trinodb.
the class TestSqlParser method testSetMaterializedViewProperties.
@Test
public void testSetMaterializedViewProperties() {
assertStatement("ALTER MATERIALIZED VIEW a SET PROPERTIES foo='bar'", new SetProperties(MATERIALIZED_VIEW, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new StringLiteral("bar")))));
assertStatement("ALTER MATERIALIZED VIEW a SET PROPERTIES foo=true", new SetProperties(MATERIALIZED_VIEW, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new BooleanLiteral("true")))));
assertStatement("ALTER MATERIALIZED VIEW a SET PROPERTIES foo=123", new SetProperties(MATERIALIZED_VIEW, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")))));
assertStatement("ALTER MATERIALIZED VIEW a SET PROPERTIES foo=123, bar=456", new SetProperties(MATERIALIZED_VIEW, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")), new Property(new Identifier("bar"), new LongLiteral("456")))));
assertStatement("ALTER MATERIALIZED VIEW a SET PROPERTIES \" s p a c e \"='bar'", new SetProperties(MATERIALIZED_VIEW, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier(" s p a c e "), new StringLiteral("bar")))));
assertStatement("ALTER MATERIALIZED VIEW a SET PROPERTIES foo=123, bar=DEFAULT", new SetProperties(MATERIALIZED_VIEW, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")), new Property(new Identifier("bar")))));
assertStatementIsInvalid("ALTER MATERIALIZED VIEW a SET PROPERTIES").withMessage("line 1:41: mismatched input '<EOF>'. Expecting: <identifier>");
assertStatementIsInvalid("ALTER MATERIALIZED VIEW a SET PROPERTIES ()").withMessage("line 1:42: mismatched input '('. Expecting: <identifier>");
assertStatementIsInvalid("ALTER MATERIALIZED VIEW a SET PROPERTIES (foo='bar')").withMessage("line 1:42: mismatched input '('. Expecting: <identifier>");
}
use of io.trino.sql.tree.SetProperties in project trino by trinodb.
the class TestSqlParser method testSetTableProperties.
@Test
public void testSetTableProperties() {
assertStatement("ALTER TABLE a SET PROPERTIES foo='bar'", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new StringLiteral("bar")))));
assertStatement("ALTER TABLE a SET PROPERTIES foo=true", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new BooleanLiteral("true")))));
assertStatement("ALTER TABLE a SET PROPERTIES foo=123", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")))));
assertStatement("ALTER TABLE a SET PROPERTIES foo=123, bar=456", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")), new Property(new Identifier("bar"), new LongLiteral("456")))));
assertStatement("ALTER TABLE a SET PROPERTIES \" s p a c e \"='bar'", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier(" s p a c e "), new StringLiteral("bar")))));
assertStatement("ALTER TABLE a SET PROPERTIES foo=123, bar=DEFAULT", new SetProperties(SetProperties.Type.TABLE, QualifiedName.of("a"), ImmutableList.of(new Property(new Identifier("foo"), new LongLiteral("123")), new Property(new Identifier("bar")))));
assertStatementIsInvalid("ALTER TABLE a SET PROPERTIES").withMessage("line 1:29: mismatched input '<EOF>'. Expecting: <identifier>");
assertStatementIsInvalid("ALTER TABLE a SET PROPERTIES ()").withMessage("line 1:30: mismatched input '('. Expecting: <identifier>");
assertStatementIsInvalid("ALTER TABLE a SET PROPERTIES (foo='bar')").withMessage("line 1:30: mismatched input '('. Expecting: <identifier>");
}
Aggregations