Search in sources :

Example 1 with SqlPath

use of io.prestosql.sql.SqlPath in project hetu-core by openlookeng.

the class TestQuerySessionSupplier method testSqlPathCreation.

@Test
public void testSqlPathCreation() {
    ImmutableList.Builder<SqlPathElement> correctValues = ImmutableList.builder();
    correctValues.add(new SqlPathElement(Optional.of(new Identifier("normal")), new Identifier("schema")));
    correctValues.add(new SqlPathElement(Optional.of(new Identifier("who.uses.periods")), new Identifier("in.schema.names")));
    correctValues.add(new SqlPathElement(Optional.of(new Identifier("same,deal")), new Identifier("with,commas")));
    correctValues.add(new SqlPathElement(Optional.of(new Identifier("aterrible")), new Identifier("thing!@#$%^&*()")));
    List<SqlPathElement> expected = correctValues.build();
    SqlPath path = new SqlPath(Optional.of("normal.schema," + "\"who.uses.periods\".\"in.schema.names\"," + "\"same,deal\".\"with,commas\"," + "aterrible.\"thing!@#$%^&*()\""));
    assertEquals(path.getParsedPath(), expected);
    assertEquals(path.toString(), Joiner.on(", ").join(expected));
}
Also used : Identifier(io.prestosql.sql.tree.Identifier) SqlPath(io.prestosql.sql.SqlPath) ImmutableList(com.google.common.collect.ImmutableList) SqlPathElement(io.prestosql.sql.SqlPathElement) Test(org.testng.annotations.Test)

Example 2 with SqlPath

use of io.prestosql.sql.SqlPath in project hetu-core by openlookeng.

the class SetPathTask method execute.

@Override
public ListenableFuture<?> execute(SetPath statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    if (!session.getClientCapabilities().contains(ClientCapabilities.PATH.toString())) {
        throw new PrestoException(NOT_SUPPORTED, "SET PATH not supported by client");
    }
    // convert to IR before setting HTTP headers - ensures that the representations of all path objects outside the parser remain consistent
    SqlPath sqlPath = new SqlPath(Optional.of(statement.getPathSpecification().toString()));
    for (SqlPathElement element : sqlPath.getParsedPath()) {
        if (!element.getCatalog().isPresent() && !session.getCatalog().isPresent()) {
            throw new SemanticException(CATALOG_NOT_SPECIFIED, statement, "Catalog must be specified for each path element when session catalog is not set");
        }
        element.getCatalog().ifPresent(catalog -> {
            String catalogName = catalog.getValue().toLowerCase(ENGLISH);
            if (!metadata.getCatalogHandle(session, catalogName).isPresent()) {
                throw new PrestoException(NOT_FOUND, "Catalog does not exist: " + catalogName);
            }
        });
    }
    stateMachine.setSetPath(sqlPath.toString());
    return immediateFuture(null);
}
Also used : SqlPath(io.prestosql.sql.SqlPath) PrestoException(io.prestosql.spi.PrestoException) SqlPathElement(io.prestosql.sql.SqlPathElement) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 3 with SqlPath

use of io.prestosql.sql.SqlPath in project hetu-core by openlookeng.

the class TestSessionFunctions method testCurrentPath.

@Test
public void testCurrentPath() {
    Session session = testSessionBuilder().setPath(new SqlPath(Optional.of("testPath"))).build();
    try (QueryAssertions queryAssertions = new QueryAssertions(session)) {
        queryAssertions.assertQuery("SELECT CURRENT_PATH", "SELECT CAST('" + session.getPath().toString() + "' AS VARCHAR)");
    }
    Session emptyPathSession = testSessionBuilder().setPath(new SqlPath(Optional.empty())).build();
    try (QueryAssertions queryAssertions = new QueryAssertions(emptyPathSession)) {
        queryAssertions.assertQuery("SELECT CURRENT_PATH", "VALUES VARCHAR ''");
    }
}
Also used : SqlPath(io.prestosql.sql.SqlPath) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 4 with SqlPath

use of io.prestosql.sql.SqlPath in project hetu-core by openlookeng.

the class SystemConnectorSessionUtil method toSession.

// this does not preserve any connector properties (for the system connector)
public static Session toSession(ConnectorTransactionHandle transactionHandle, ConnectorSession session) {
    TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId();
    ConnectorIdentity connectorIdentity = session.getIdentity();
    Identity identity = new Identity(connectorIdentity.getUser(), connectorIdentity.getPrincipal());
    return Session.builder(new SessionPropertyManager(SYSTEM_SESSION_PROPERTIES)).setQueryId(new QueryId(session.getQueryId())).setTransactionId(transactionId).setCatalog("catalog").setSchema("schema").setPath(new SqlPath(Optional.of("path"))).setIdentity(identity).setTimeZoneKey(session.getTimeZoneKey()).setLocale(session.getLocale()).setStartTime(session.getStartTime()).build();
}
Also used : SqlPath(io.prestosql.sql.SqlPath) QueryId(io.prestosql.spi.QueryId) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) ConnectorIdentity(io.prestosql.spi.security.ConnectorIdentity) ConnectorIdentity(io.prestosql.spi.security.ConnectorIdentity) Identity(io.prestosql.spi.security.Identity) TransactionId(io.prestosql.transaction.TransactionId)

Example 5 with SqlPath

use of io.prestosql.sql.SqlPath in project hetu-core by openlookeng.

the class QuerySessionSupplier method createSession.

@Override
public Session createSession(QueryId queryId, SessionContext context) {
    Identity identity = context.getIdentity();
    accessControl.checkCanSetUser(identity.getPrincipal(), identity.getUser());
    AccessControlUtil.checkCanImpersonateUser(accessControl, context);
    SessionBuilder sessionBuilder = Session.builder(sessionPropertyManager).setQueryId(queryId).setIdentity(identity).setSource(context.getSource()).setCatalog(context.getCatalog()).setSchema(context.getSchema()).setPath(new SqlPath(path)).setRemoteUserAddress(context.getRemoteUserAddress()).setUserAgent(context.getUserAgent()).setClientInfo(context.getClientInfo()).setClientTags(context.getClientTags()).setClientCapabilities(context.getClientCapabilities()).setTraceToken(context.getTraceToken()).setResourceEstimates(context.getResourceEstimates());
    if (context.getPath() != null) {
        sessionBuilder.setPath(new SqlPath(Optional.of(context.getPath())));
    }
    if (context.getTimeZoneId() != null) {
        sessionBuilder.setTimeZoneKey(getTimeZoneKey(context.getTimeZoneId()));
    }
    if (context.getLanguage() != null) {
        sessionBuilder.setLocale(Locale.forLanguageTag(context.getLanguage()));
    }
    for (Entry<String, String> entry : context.getSystemProperties().entrySet()) {
        sessionBuilder.setSystemProperty(entry.getKey(), entry.getValue());
    }
    for (Entry<String, Map<String, String>> catalogProperties : context.getCatalogSessionProperties().entrySet()) {
        String catalog = catalogProperties.getKey();
        for (Entry<String, String> entry : catalogProperties.getValue().entrySet()) {
            sessionBuilder.setCatalogSessionProperty(catalog, entry.getKey(), entry.getValue());
        }
    }
    for (Entry<String, String> preparedStatement : context.getPreparedStatements().entrySet()) {
        sessionBuilder.addPreparedStatement(preparedStatement.getKey(), preparedStatement.getValue());
    }
    if (context.supportClientTransaction()) {
        sessionBuilder.setClientTransactionSupport();
    }
    Session session = sessionBuilder.build();
    if (context.getTransactionId().isPresent()) {
        session = session.beginTransactionId(context.getTransactionId().get(), transactionManager, accessControl);
    }
    return session;
}
Also used : SqlPath(io.prestosql.sql.SqlPath) SessionBuilder(io.prestosql.Session.SessionBuilder) Identity(io.prestosql.spi.security.Identity) Map(java.util.Map) Session(io.prestosql.Session)

Aggregations

SqlPath (io.prestosql.sql.SqlPath)5 Session (io.prestosql.Session)3 Identity (io.prestosql.spi.security.Identity)2 SqlPathElement (io.prestosql.sql.SqlPathElement)2 Test (org.testng.annotations.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 SessionBuilder (io.prestosql.Session.SessionBuilder)1 SessionPropertyManager (io.prestosql.metadata.SessionPropertyManager)1 PrestoException (io.prestosql.spi.PrestoException)1 QueryId (io.prestosql.spi.QueryId)1 ConnectorIdentity (io.prestosql.spi.security.ConnectorIdentity)1 SemanticException (io.prestosql.sql.analyzer.SemanticException)1 Identifier (io.prestosql.sql.tree.Identifier)1 TransactionId (io.prestosql.transaction.TransactionId)1 Map (java.util.Map)1