Search in sources :

Example 1 with AllColumns

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

the class TestPrepareTask method testPrepare.

@Test
public void testPrepare() {
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")));
    String sqlString = "PREPARE my_query FROM SELECT * FROM foo";
    Map<String, String> statements = executePrepare("my_query", query, sqlString, TEST_SESSION);
    assertEquals(statements, ImmutableMap.of("my_query", "SELECT *\nFROM\n  foo\n"));
}
Also used : Query(io.trino.sql.tree.Query) QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) AllColumns(io.trino.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 2 with AllColumns

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

the class TestQueryPreparer method testSelectStatement.

@Test
public void testSelectStatement() {
    PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(TEST_SESSION, "SELECT * FROM foo");
    assertEquals(preparedQuery.getStatement(), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}
Also used : PreparedQuery(io.trino.execution.QueryPreparer.PreparedQuery) AllColumns(io.trino.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 3 with AllColumns

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

the class TestQueryPreparer method testExecuteStatement.

@Test
public void testExecuteStatement() {
    Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT * FROM foo").build();
    PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query");
    assertEquals(preparedQuery.getStatement(), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}
Also used : PreparedQuery(io.trino.execution.QueryPreparer.PreparedQuery) AllColumns(io.trino.sql.tree.AllColumns) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 4 with AllColumns

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

the class TestPrepareTask method testPrepareNameExists.

@Test
public void testPrepareNameExists() {
    Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT bar, baz from foo").build();
    Query query = simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo")));
    String sqlString = "PREPARE my_query FROM SELECT * FROM foo";
    Map<String, String> statements = executePrepare("my_query", query, sqlString, session);
    assertEquals(statements, ImmutableMap.of("my_query", "SELECT *\nFROM\n  foo\n"));
}
Also used : Query(io.trino.sql.tree.Query) QueryUtil.simpleQuery(io.trino.sql.QueryUtil.simpleQuery) AllColumns(io.trino.sql.tree.AllColumns) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 5 with AllColumns

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

the class TestCreateMaterializedViewTask method testCreateDenyPermission.

@Test
public void testCreateDenyPermission() {
    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(), Optional.empty());
    TestingAccessControlManager accessControl = new TestingAccessControlManager(transactionManager, emptyEventListenerManager());
    accessControl.loadSystemAccessControl(AllowAllSystemAccessControl.NAME, ImmutableMap.of());
    accessControl.deny(privilege("test_mv", CREATE_MATERIALIZED_VIEW));
    StatementAnalyzerFactory statementAnalyzerFactory = createTestingStatementAnalyzerFactory(plannerContext, accessControl, new TablePropertyManager(), new AnalyzePropertyManager());
    AnalyzerFactory analyzerFactory = new AnalyzerFactory(statementAnalyzerFactory, new StatementRewrite(ImmutableSet.of()));
    assertThatThrownBy(() -> getFutureValue(new CreateMaterializedViewTask(plannerContext, accessControl, parser, analyzerFactory, materializedViewPropertyManager, new FeaturesConfig()).execute(statement, queryStateMachine, ImmutableList.of(), WarningCollector.NOOP))).isInstanceOf(AccessDeniedException.class).hasMessageContaining("Cannot create materialized view catalog.schema.test_mv");
}
Also used : AccessDeniedException(io.trino.spi.security.AccessDeniedException) CreateMaterializedView(io.trino.sql.tree.CreateMaterializedView) FeaturesConfig(io.trino.FeaturesConfig) StatementRewrite(io.trino.sql.rewrite.StatementRewrite) AllColumns(io.trino.sql.tree.AllColumns) TablePropertyManager(io.trino.metadata.TablePropertyManager) TestingAccessControlManager(io.trino.testing.TestingAccessControlManager) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) Test(org.testng.annotations.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