use of com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecutionFactory in project presto by prestodb.
the class PrestoSparkQueryRunner method execute.
@Override
public MaterializedResult execute(Session session, String sql) {
IPrestoSparkQueryExecutionFactory executionFactory = prestoSparkService.getQueryExecutionFactory();
IPrestoSparkQueryExecution execution = executionFactory.create(sparkContext, createSessionInfo(session), Optional.of(sql), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), new TestingPrestoSparkTaskExecutorFactoryProvider(instanceId), Optional.empty(), Optional.empty());
List<List<Object>> results = execution.execute();
List<MaterializedRow> rows = results.stream().map(result -> new MaterializedRow(DEFAULT_PRECISION, result)).collect(toImmutableList());
if (execution instanceof PrestoSparkQueryExecution) {
PrestoSparkQueryExecution p = (PrestoSparkQueryExecution) execution;
if (!p.getUpdateType().isPresent()) {
return new MaterializedResult(rows, p.getOutputTypes());
} else {
return new MaterializedResult(rows, p.getOutputTypes(), ImmutableMap.of(), ImmutableSet.of(), p.getUpdateType(), OptionalLong.of((Long) getOnlyElement(getOnlyElement(rows).getFields())), ImmutableList.of());
}
} else {
return new MaterializedResult(rows, ImmutableList.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty(), OptionalLong.empty(), ImmutableList.of());
}
}
use of com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecutionFactory in project presto by prestodb.
the class PrestoSparkRunner method run.
public void run(String user, Optional<Principal> principal, Map<String, String> extraCredentials, String catalog, String schema, Optional<String> source, Optional<String> userAgent, Optional<String> clientInfo, Set<String> clientTags, Map<String, String> sessionProperties, Map<String, Map<String, String>> catalogSessionProperties, Optional<String> sqlText, Optional<String> sqlLocation, Optional<String> sqlFileHexHash, Optional<String> sqlFileSizeInBytes, Optional<String> traceToken, Optional<String> sparkQueueName, Optional<String> queryStatusInfoOutputLocation, Optional<String> queryDataOutputLocation) {
IPrestoSparkQueryExecutionFactory queryExecutionFactory = driverPrestoSparkService.getQueryExecutionFactory();
PrestoSparkSession session = new PrestoSparkSession(user, principal, extraCredentials, Optional.ofNullable(catalog), Optional.ofNullable(schema), source, userAgent, clientInfo, clientTags, Optional.empty(), Optional.empty(), sessionProperties, catalogSessionProperties, traceToken);
IPrestoSparkQueryExecution queryExecution = queryExecutionFactory.create(distribution.getSparkContext(), session, sqlText, sqlLocation, sqlFileHexHash, sqlFileSizeInBytes, sparkQueueName, new DistributionBasedPrestoSparkTaskExecutorFactoryProvider(distribution), queryStatusInfoOutputLocation, queryDataOutputLocation);
List<List<Object>> results = queryExecution.execute();
System.out.println("Rows: " + results.size());
results.forEach(System.out::println);
}
Aggregations