Search in sources :

Example 11 with Property

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

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

Example 13 with Property

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

the class TestSqlParser method testCreateSchema.

@Test
public void testCreateSchema() {
    assertStatement("CREATE SCHEMA test", new CreateSchema(QualifiedName.of("test"), false, ImmutableList.of()));
    assertStatement("CREATE SCHEMA IF NOT EXISTS test", new CreateSchema(QualifiedName.of("test"), true, ImmutableList.of()));
    assertStatement("CREATE SCHEMA test WITH (a = 'apple', b = 123)", new CreateSchema(QualifiedName.of("test"), false, ImmutableList.of(new Property(new Identifier("a"), new StringLiteral("apple")), new Property(new Identifier("b"), new LongLiteral("123")))));
    assertStatement("CREATE SCHEMA \"some name that contains space\"", new CreateSchema(QualifiedName.of("some name that contains space"), false, ImmutableList.of()));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) StringLiteral(io.trino.sql.tree.StringLiteral) LongLiteral(io.trino.sql.tree.LongLiteral) CreateSchema(io.trino.sql.tree.CreateSchema) Property(io.trino.sql.tree.Property) Test(org.junit.jupiter.api.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