use of io.crate.action.sql.SQLOperations in project crate by crate.
the class SQLIntegrationTestCase method systemExecute.
/**
* Execute a SQL statement as system query on a specific node in the cluster
*
* @param stmt the SQL statement
* @param schema the schema that should be used for this statement
* schema is nullable, which means the default schema ("doc") is used
* @param node the name of the node on which the stmt is executed
* @return the SQL Response
*/
public SQLResponse systemExecute(String stmt, @Nullable String schema, String node) {
SQLOperations sqlOperations = internalCluster().getInstance(SQLOperations.class, node);
UserLookup userLookup;
try {
userLookup = internalCluster().getInstance(UserLookup.class, node);
} catch (ConfigurationException ignored) {
// If enterprise is not enabled there is no UserLookup instance bound in guice
userLookup = userName -> User.CRATE_USER;
}
try (Session session = sqlOperations.createSession(schema, userLookup.findUser("crate"))) {
response = sqlExecutor.exec(stmt, session);
}
return response;
}
Aggregations