Search in sources :

Example 1 with SqlPathElement

use of io.trino.sql.SqlPathElement in project trino by trinodb.

the class SetPathTask method execute.

@Override
public ListenableFuture<Void> execute(SetPath statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
    Session session = stateMachine.getSession();
    if (!session.getClientCapabilities().contains(ClientCapabilities.PATH.toString())) {
        throw new TrinoException(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().isEmpty() && session.getCatalog().isEmpty()) {
            throw semanticException(MISSING_CATALOG_NAME, 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);
            getRequiredCatalogHandle(metadata, session, statement, catalogName);
        });
    }
    stateMachine.setSetPath(sqlPath.toString());
    return immediateVoidFuture();
}
Also used : SqlPath(io.trino.sql.SqlPath) TrinoException(io.trino.spi.TrinoException) SqlPathElement(io.trino.sql.SqlPathElement) Session(io.trino.Session)

Example 2 with SqlPathElement

use of io.trino.sql.SqlPathElement in project trino by trinodb.

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.trino.sql.tree.Identifier) SqlPath(io.trino.sql.SqlPath) ImmutableList(com.google.common.collect.ImmutableList) SqlPathElement(io.trino.sql.SqlPathElement) Test(org.testng.annotations.Test)

Aggregations

SqlPath (io.trino.sql.SqlPath)2 SqlPathElement (io.trino.sql.SqlPathElement)2 ImmutableList (com.google.common.collect.ImmutableList)1 Session (io.trino.Session)1 TrinoException (io.trino.spi.TrinoException)1 Identifier (io.trino.sql.tree.Identifier)1 Test (org.testng.annotations.Test)1