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