Search in sources :

Example 1 with SetProperties

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));
}
Also used : Identifier(io.trino.sql.tree.Identifier) SetProperties(io.trino.sql.tree.SetProperties) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) Property(io.trino.sql.tree.Property) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 2 with SetProperties

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>");
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) SetProperties(io.trino.sql.tree.SetProperties) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) Property(io.trino.sql.tree.Property) Test(org.junit.jupiter.api.Test)

Example 3 with SetProperties

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>");
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) SetProperties(io.trino.sql.tree.SetProperties) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) Property(io.trino.sql.tree.Property) Test(org.junit.jupiter.api.Test)

Aggregations

Identifier (io.trino.sql.tree.Identifier)3 LongLiteral (io.trino.sql.tree.LongLiteral)3 Property (io.trino.sql.tree.Property)3 SetProperties (io.trino.sql.tree.SetProperties)3 StringLiteral (io.trino.sql.tree.StringLiteral)3 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)2 BooleanLiteral (io.trino.sql.tree.BooleanLiteral)2 Test (org.junit.jupiter.api.Test)2 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)1 Test (org.testng.annotations.Test)1