* @throws IOException
*/
protected String restSQLExecute(String source, boolean includeTypes) throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.generator().usePrettyPrint();
SQLXContentSourceContext context = new SQLXContentSourceContext();
SQLXContentSourceParser parser = new SQLXContentSourceParser(context);
parser.parseSource(new BytesArray(source));
SQLBaseResponse sqlResponse;
Object[][] bulkArgs = context.bulkArgs();
if (bulkArgs != null && bulkArgs.length > 0) {
SQLBulkRequestBuilder requestBuilder = new SQLBulkRequestBuilder(client());
requestBuilder.bulkArgs(context.bulkArgs());
requestBuilder.stmt(context.stmt());
requestBuilder.includeTypesOnResponse(includeTypes);
sqlResponse = requestBuilder.execute().actionGet();
} else {
SQLRequestBuilder requestBuilder = new SQLRequestBuilder(client());
requestBuilder.args(context.args());
requestBuilder.stmt(context.stmt());
requestBuilder.includeTypesOnResponse(includeTypes);
sqlResponse = requestBuilder.execute().actionGet();
}
sqlResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
responseDuration = sqlResponse.duration();