Search in sources :

Example 6 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class TestCreateViewTask method setUp.

@Override
@BeforeMethod
public void setUp() {
    super.setUp();
    parser = new SqlParser();
    analyzerFactory = new AnalyzerFactory(createTestingStatementAnalyzerFactory(plannerContext, new AllowAllAccessControl(), new TablePropertyManager(), new AnalyzePropertyManager()), new StatementRewrite(ImmutableSet.of()));
    QualifiedObjectName tableName = qualifiedObjectName("mock_table");
    metadata.createTable(testSession, CATALOG_NAME, someTable(tableName), false);
}
Also used : AllowAllAccessControl(io.trino.security.AllowAllAccessControl) StatementRewrite(io.trino.sql.rewrite.StatementRewrite) SqlParser(io.trino.sql.parser.SqlParser) TablePropertyManager(io.trino.metadata.TablePropertyManager) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) AnalyzerFactory(io.trino.sql.analyzer.AnalyzerFactory) StatementAnalyzerFactory.createTestingStatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory.createTestingStatementAnalyzerFactory) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class BaseDataDefinitionTaskTest method setUp.

@BeforeMethod
public void setUp() {
    queryRunner = LocalQueryRunner.create(TEST_SESSION);
    transactionManager = queryRunner.getTransactionManager();
    queryRunner.createCatalog(CATALOG_NAME, MockConnectorFactory.create("initial"), ImmutableMap.of());
    testSession = testSessionBuilder().build();
    metadata = new MockMetadata(new CatalogName(CATALOG_NAME));
    plannerContext = plannerContextBuilder().withMetadata(metadata).build();
    materializedViewPropertyManager = new MaterializedViewPropertyManager();
    materializedViewPropertyManager.addProperties(new CatalogName(CATALOG_NAME), ImmutableList.of(longProperty(MATERIALIZED_VIEW_PROPERTY_1_NAME, "property 1", MATERIALIZED_VIEW_PROPERTY_1_DEFAULT_VALUE, false), stringProperty(MATERIALIZED_VIEW_PROPERTY_2_NAME, "property 2", MATERIALIZED_VIEW_PROPERTY_2_DEFAULT_VALUE, false)));
    queryStateMachine = stateMachine(transactionManager, createTestMetadataManager(), new AllowAllAccessControl(), testSession);
}
Also used : AllowAllAccessControl(io.trino.security.AllowAllAccessControl) AbstractMockMetadata(io.trino.metadata.AbstractMockMetadata) MaterializedViewPropertyManager(io.trino.metadata.MaterializedViewPropertyManager) CatalogName(io.trino.connector.CatalogName) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class ExpressionTestUtils method resolveFunctionCalls.

public static Expression resolveFunctionCalls(PlannerContext plannerContext, Session session, TypeProvider typeProvider, Expression expression, Scope scope) {
    ExpressionAnalyzer analyzer = ExpressionAnalyzer.createWithoutSubqueries(plannerContext, new AllowAllAccessControl(), session, typeProvider, ImmutableMap.of(), node -> semanticException(EXPRESSION_NOT_CONSTANT, node, "Constant expression cannot contain a subquery"), WarningCollector.NOOP, false);
    analyzer.analyze(expression, scope);
    return ExpressionTreeRewriter.rewriteWith(new ExpressionRewriter<>() {

        @Override
        public Expression rewriteFunctionCall(FunctionCall node, Void context, ExpressionTreeRewriter<Void> treeRewriter) {
            ResolvedFunction resolvedFunction = analyzer.getResolvedFunctions().get(NodeRef.of(node));
            checkArgument(resolvedFunction != null, "Function has not been analyzed: %s", node);
            FunctionCall rewritten = treeRewriter.defaultRewrite(node, context);
            FunctionCall newFunctionCall = new FunctionCall(rewritten.getLocation(), resolvedFunction.toQualifiedName(), rewritten.getWindow(), rewritten.getFilter(), rewritten.getOrderBy(), rewritten.isDistinct(), rewritten.getNullTreatment(), rewritten.getProcessingMode(), rewritten.getArguments());
            return coerceIfNecessary(node, newFunctionCall);
        }

        @Override
        protected Expression rewriteExpression(Expression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) {
            Expression rewrittenExpression = treeRewriter.defaultRewrite(node, context);
            rewrittenExpression = coerceIfNecessary(node, rewrittenExpression);
            return rewrittenExpression;
        }

        private Expression coerceIfNecessary(Expression originalExpression, Expression rewrittenExpression) {
            // cast expression if coercion is registered
            Type coercion = analyzer.getExpressionCoercions().get(NodeRef.of(originalExpression));
            if (coercion != null) {
                rewrittenExpression = new Cast(rewrittenExpression, toSqlType(coercion), false, analyzer.getTypeOnlyCoercions().contains(NodeRef.of(originalExpression)));
            }
            return rewrittenExpression;
        }
    }, expression);
}
Also used : Cast(io.trino.sql.tree.Cast) Type(io.trino.spi.type.Type) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) Expression(io.trino.sql.tree.Expression) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) ResolvedFunction(io.trino.metadata.ResolvedFunction) ExpressionAnalyzer(io.trino.sql.analyzer.ExpressionAnalyzer) FunctionCall(io.trino.sql.tree.FunctionCall)

Example 9 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class TestKuduIntegrationDynamicFilter method testIncompleteDynamicFilterTimeout.

@Test(timeOut = 30_000)
public void testIncompleteDynamicFilterTimeout() throws Exception {
    QueryRunner runner = getQueryRunner();
    TransactionManager transactionManager = runner.getTransactionManager();
    TransactionId transactionId = transactionManager.beginTransaction(false);
    Session session = Session.builder(getSession()).setCatalogSessionProperty("kudu", "dynamic_filtering_wait_timeout", "1s").build().beginTransactionId(transactionId, transactionManager, new AllowAllAccessControl());
    QualifiedObjectName tableName = new QualifiedObjectName("kudu", "tpch", "orders");
    Optional<TableHandle> tableHandle = runner.getMetadata().getTableHandle(session, tableName);
    assertTrue(tableHandle.isPresent());
    SplitSource splitSource = runner.getSplitManager().getSplits(session, tableHandle.get(), UNGROUPED_SCHEDULING, new IncompleteDynamicFilter(), alwaysTrue());
    List<Split> splits = new ArrayList<>();
    while (!splitSource.isFinished()) {
        splits.addAll(splitSource.getNextBatch(NOT_PARTITIONED, Lifespan.taskWide(), 1000).get().getSplits());
    }
    splitSource.close();
    assertFalse(splits.isEmpty());
}
Also used : ArrayList(java.util.ArrayList) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryRunner(io.trino.testing.QueryRunner) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) TransactionId(io.trino.transaction.TransactionId) TransactionManager(io.trino.transaction.TransactionManager) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) TableHandle(io.trino.metadata.TableHandle) SplitSource(io.trino.split.SplitSource) Split(io.trino.metadata.Split) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 10 with AllowAllAccessControl

use of io.trino.security.AllowAllAccessControl in project trino by trinodb.

the class TestMinimalFunctionality method testStreamExists.

@Test
public void testStreamExists() {
    QualifiedObjectName name = new QualifiedObjectName("kinesis", "default", streamName);
    transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()).singleStatement().execute(SESSION, session -> {
        Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
        assertTrue(handle.isPresent());
    });
}
Also used : AllowAllAccessControl(io.trino.security.AllowAllAccessControl) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Aggregations

AllowAllAccessControl (io.trino.security.AllowAllAccessControl)28 Test (org.testng.annotations.Test)16 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)9 TableHandle (io.trino.metadata.TableHandle)8 CatalogName (io.trino.connector.CatalogName)7 PropertyMetadata.stringProperty (io.trino.spi.session.PropertyMetadata.stringProperty)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Session (io.trino.Session)6 AbstractMockMetadata (io.trino.metadata.AbstractMockMetadata)6 TablePropertyManager (io.trino.metadata.TablePropertyManager)6 TransactionManager (io.trino.transaction.TransactionManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 PlannerContext (io.trino.sql.PlannerContext)5 ColumnDefinition (io.trino.sql.tree.ColumnDefinition)5 CreateTable (io.trino.sql.tree.CreateTable)5 Identifier (io.trino.sql.tree.Identifier)5 Property (io.trino.sql.tree.Property)5 ImmutableList (com.google.common.collect.ImmutableList)4 Sets.immutableEnumSet (com.google.common.collect.Sets.immutableEnumSet)4 MoreFutures.getFutureValue (io.airlift.concurrent.MoreFutures.getFutureValue)4