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();
}
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));
}
Aggregations