Search in sources :

Example 21 with AllColumns

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

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

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

the class TestCreateViewTask method executeCreateView.

private ListenableFuture<Void> executeCreateView(QualifiedName viewName, boolean replace) {
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("mock_table")));
    CreateView statement = new CreateView(viewName, query, replace, Optional.empty(), Optional.empty());
    return new CreateViewTask(metadata, new AllowAllAccessControl(), parser, analyzerFactory).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP);
}
Also used : Query(io.trino.sql.tree.Query) QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) AllColumns(io.trino.sql.tree.AllColumns) CreateView(io.trino.sql.tree.CreateView)

Example 24 with AllColumns

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

the class TestSqlParser method testWith.

@Test
public void testWith() {
    assertStatement("WITH a (t, u) AS (SELECT * FROM x), b AS (SELECT * FROM y) TABLE z", new Query(Optional.of(new With(false, ImmutableList.of(new WithQuery(identifier("a"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("x"))), Optional.of(ImmutableList.of(identifier("t"), identifier("u")))), new WithQuery(identifier("b"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("y"))), Optional.empty())))), new Table(QualifiedName.of("z")), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("WITH RECURSIVE a AS (SELECT * FROM x) TABLE y", new Query(Optional.of(new With(true, ImmutableList.of(new WithQuery(identifier("a"), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("x"))), Optional.empty())))), new Table(QualifiedName.of("y")), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : CreateTable(io.trino.sql.tree.CreateTable) DropTable(io.trino.sql.tree.DropTable) Table(io.trino.sql.tree.Table) TruncateTable(io.trino.sql.tree.TruncateTable) RenameTable(io.trino.sql.tree.RenameTable) QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) Query(io.trino.sql.tree.Query) WithQuery(io.trino.sql.tree.WithQuery) WithQuery(io.trino.sql.tree.WithQuery) AllColumns(io.trino.sql.tree.AllColumns) With(io.trino.sql.tree.With) Test(org.junit.jupiter.api.Test)

Example 25 with AllColumns

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

the class TestSqlParser method testSelectWithGroupBy.

@Test
public void testSelectWithGroupBy() {
    assertStatement("SELECT * FROM table1 GROUP BY a", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new SimpleGroupBy(ImmutableList.of(new Identifier("a")))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY a, b", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new SimpleGroupBy(ImmutableList.of(new Identifier("a"))), new SimpleGroupBy(ImmutableList.of(new Identifier("b")))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY ()", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new SimpleGroupBy(ImmutableList.of())))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY GROUPING SETS (a)", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new GroupingSets(ImmutableList.of(ImmutableList.of(new Identifier("a"))))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT a, b, GROUPING(a, b) FROM table1 GROUP BY GROUPING SETS ((a), (b))", simpleQuery(selectList(DereferenceExpression.from(QualifiedName.of("a")), DereferenceExpression.from(QualifiedName.of("b")), new GroupingOperation(Optional.empty(), ImmutableList.of(QualifiedName.of("a"), QualifiedName.of("b")))), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new GroupingSets(ImmutableList.of(ImmutableList.of(new Identifier("a")), ImmutableList.of(new Identifier("b"))))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY ALL GROUPING SETS ((a, b), (a), ()), CUBE (c), ROLLUP (d)", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(false, ImmutableList.of(new GroupingSets(ImmutableList.of(ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableList.of(new Identifier("a")), ImmutableList.of())), new Cube(ImmutableList.of(new Identifier("c"))), new Rollup(ImmutableList.of(new Identifier("d")))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
    assertStatement("SELECT * FROM table1 GROUP BY DISTINCT GROUPING SETS ((a, b), (a), ()), CUBE (c), ROLLUP (d)", simpleQuery(selectList(new AllColumns()), new Table(QualifiedName.of("table1")), Optional.empty(), Optional.of(new GroupBy(true, ImmutableList.of(new GroupingSets(ImmutableList.of(ImmutableList.of(new Identifier("a"), new Identifier("b")), ImmutableList.of(new Identifier("a")), ImmutableList.of())), new Cube(ImmutableList.of(new Identifier("c"))), new Rollup(ImmutableList.of(new Identifier("d")))))), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : GroupingSets(io.trino.sql.tree.GroupingSets) SimpleGroupBy(io.trino.sql.tree.SimpleGroupBy) CreateTable(io.trino.sql.tree.CreateTable) DropTable(io.trino.sql.tree.DropTable) Table(io.trino.sql.tree.Table) TruncateTable(io.trino.sql.tree.TruncateTable) RenameTable(io.trino.sql.tree.RenameTable) GroupBy(io.trino.sql.tree.GroupBy) SimpleGroupBy(io.trino.sql.tree.SimpleGroupBy) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) Rollup(io.trino.sql.tree.Rollup) Cube(io.trino.sql.tree.Cube) AllColumns(io.trino.sql.tree.AllColumns) GroupingOperation(io.trino.sql.tree.GroupingOperation) Test(org.junit.jupiter.api.Test)

Aggregations

AllColumns (io.trino.sql.tree.AllColumns)30 Test (org.junit.jupiter.api.Test)19 Query (io.trino.sql.tree.Query)15 QueryUtil.simpleQuery (io.trino.sql.QueryUtil.simpleQuery)14 Table (io.trino.sql.tree.Table)13 CreateTable (io.trino.sql.tree.CreateTable)12 DropTable (io.trino.sql.tree.DropTable)12 RenameTable (io.trino.sql.tree.RenameTable)12 TruncateTable (io.trino.sql.tree.TruncateTable)12 WithQuery (io.trino.sql.tree.WithQuery)11 Identifier (io.trino.sql.tree.Identifier)9 StringLiteral (io.trino.sql.tree.StringLiteral)9 Test (org.testng.annotations.Test)9 LongLiteral (io.trino.sql.tree.LongLiteral)8 QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)6 CreateMaterializedView (io.trino.sql.tree.CreateMaterializedView)6 FeaturesConfig (io.trino.FeaturesConfig)5 AllowAllAccessControl (io.trino.security.AllowAllAccessControl)5 CreateTableAsSelect (io.trino.sql.tree.CreateTableAsSelect)4 Property (io.trino.sql.tree.Property)4