Search in sources :

Example 1 with IPrestoSparkQueryExecutionFactory

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());
    }
}
Also used : WARN(com.facebook.airlift.log.Level.WARN) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) Throwables.throwIfUnchecked(com.google.common.base.Throwables.throwIfUnchecked) QueryRunner(com.facebook.presto.testing.QueryRunner) ConnectorPlanOptimizerManager(com.facebook.presto.sql.planner.ConnectorPlanOptimizerManager) QueryAssertions.copyTpchTables(com.facebook.presto.tests.QueryAssertions.copyTpchTables) DEFAULT_PRECISION(com.facebook.presto.testing.MaterializedResult.DEFAULT_PRECISION) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) Duration.nanosSince(io.airlift.units.Duration.nanosSince) Files.createTempDirectory(java.nio.file.Files.createTempDirectory) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) TEST_CATALOG_PROPERTIES(com.facebook.presto.tests.AbstractTestQueries.TEST_CATALOG_PROPERTIES) AbstractTestQueries(com.facebook.presto.tests.AbstractTestQueries) ENGLISH(java.util.Locale.ENGLISH) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) HiveHdfsConfiguration(com.facebook.presto.hive.HiveHdfsConfiguration) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) FunctionImplementationType(com.facebook.presto.spi.function.FunctionImplementationType) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SparkContext(org.apache.spark.SparkContext) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) Set(java.util.Set) Plugin(com.facebook.presto.spi.Plugin) UncheckedIOException(java.io.UncheckedIOException) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) FileHiveMetastore(com.facebook.presto.hive.metastore.file.FileHiveMetastore) TESTING_CATALOG(com.facebook.presto.testing.TestingSession.TESTING_CATALOG) Database(com.facebook.presto.hive.metastore.Database) LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) OptionalLong(java.util.OptionalLong) PrestoSparkQueryExecution(com.facebook.presto.spark.PrestoSparkQueryExecutionFactory.PrestoSparkQueryExecution) TransactionManager(com.facebook.presto.transaction.TransactionManager) Session(com.facebook.presto.Session) SparkConf(org.apache.spark.SparkConf) PrincipalType(com.facebook.presto.spi.security.PrincipalType) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) File(java.io.File) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) Lock(java.util.concurrent.locks.Lock) TestingSession.createBogusTestingCatalog(com.facebook.presto.testing.TestingSession.createBogusTestingCatalog) Paths(java.nio.file.Paths) Logging(com.facebook.airlift.log.Logging) DRIVER(com.facebook.presto.spark.classloader_interface.SparkProcessType.DRIVER) TEST_SYSTEM_PROPERTIES(com.facebook.presto.tests.AbstractTestQueries.TEST_SYSTEM_PROPERTIES) Metadata(com.facebook.presto.metadata.Metadata) HdfsEnvironment(com.facebook.presto.hive.HdfsEnvironment) HivePlugin(com.facebook.presto.hive.HivePlugin) SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) SQL(com.facebook.presto.spi.function.RoutineCharacteristics.Language.SQL) Key(com.google.inject.Key) PrestoSparkConfInitializer(com.facebook.presto.spark.classloader_interface.PrestoSparkConfInitializer) PrestoSparkSession(com.facebook.presto.spark.classloader_interface.PrestoSparkSession) StatsCalculator(com.facebook.presto.cost.StatsCalculator) ConnectorManager(com.facebook.presto.connector.ConnectorManager) HiveClientConfig(com.facebook.presto.hive.HiveClientConfig) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) SPARK_EXECUTOR_CORES_PROPERTY(com.facebook.presto.spark.PrestoSparkSettingsRequirements.SPARK_EXECUTOR_CORES_PROPERTY) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SplitManager(com.facebook.presto.split.SplitManager) TINY_SCHEMA_NAME(com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) HdfsConfigurationInitializer(com.facebook.presto.hive.HdfsConfigurationInitializer) TpchTable(io.airlift.tpch.TpchTable) TpchTable.getTables(io.airlift.tpch.TpchTable.getTables) List(java.util.List) IPrestoSparkQueryExecutionFactory(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecutionFactory) Catalog(com.facebook.presto.metadata.Catalog) PrestoSparkTaskExecutorFactoryProvider(com.facebook.presto.spark.classloader_interface.PrestoSparkTaskExecutorFactoryProvider) Optional(java.util.Optional) IPrestoSparkTaskExecutorFactory(com.facebook.presto.spark.classloader_interface.IPrestoSparkTaskExecutorFactory) PluginManager(com.facebook.presto.server.PluginManager) NoHdfsAuthentication(com.facebook.presto.hive.authentication.NoHdfsAuthentication) Logger(com.facebook.airlift.log.Logger) SPARK_TASK_CPUS_PROPERTY(com.facebook.presto.spark.PrestoSparkSettingsRequirements.SPARK_TASK_CPUS_PROPERTY) HashMap(java.util.HashMap) IPrestoSparkQueryExecution(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution) HdfsConfiguration(com.facebook.presto.hive.HdfsConfiguration) ImmutableList(com.google.common.collect.ImmutableList) PageSourceManager(com.facebook.presto.split.PageSourceManager) Objects.requireNonNull(java.util.Objects.requireNonNull) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) EventListener(com.facebook.presto.spi.eventlistener.EventListener) MetastoreClientConfig(com.facebook.presto.hive.MetastoreClientConfig) HiveColumnConverterProvider(com.facebook.presto.hive.HiveColumnConverterProvider) NodePartitioningManager(com.facebook.presto.sql.planner.NodePartitioningManager) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) CatalogManager(com.facebook.presto.metadata.CatalogManager) Injector(com.google.inject.Injector) MaterializedResult(com.facebook.presto.testing.MaterializedResult) UUID.randomUUID(java.util.UUID.randomUUID) TestingAccessControlManager(com.facebook.presto.testing.TestingAccessControlManager) MaterializedRow(com.facebook.presto.testing.MaterializedRow) ERROR(com.facebook.airlift.log.Level.ERROR) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) SECONDS(java.util.concurrent.TimeUnit.SECONDS) IPrestoSparkQueryExecution(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution) OptionalLong(java.util.OptionalLong) IPrestoSparkQueryExecutionFactory(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecutionFactory) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MaterializedResult(com.facebook.presto.testing.MaterializedResult) PrestoSparkQueryExecution(com.facebook.presto.spark.PrestoSparkQueryExecutionFactory.PrestoSparkQueryExecution) IPrestoSparkQueryExecution(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Example 2 with IPrestoSparkQueryExecutionFactory

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);
}
Also used : IPrestoSparkQueryExecution(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution) PrestoSparkSession(com.facebook.presto.spark.classloader_interface.PrestoSparkSession) IPrestoSparkQueryExecutionFactory(com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecutionFactory) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List)

Aggregations

IPrestoSparkQueryExecution (com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution)2 IPrestoSparkQueryExecutionFactory (com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecutionFactory)2 PrestoSparkSession (com.facebook.presto.spark.classloader_interface.PrestoSparkSession)2 LifeCycleManager (com.facebook.airlift.bootstrap.LifeCycleManager)1 ERROR (com.facebook.airlift.log.Level.ERROR)1 WARN (com.facebook.airlift.log.Level.WARN)1 Logger (com.facebook.airlift.log.Logger)1 Logging (com.facebook.airlift.log.Logging)1 Session (com.facebook.presto.Session)1 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)1 ConnectorManager (com.facebook.presto.connector.ConnectorManager)1 StatsCalculator (com.facebook.presto.cost.StatsCalculator)1 SqlInvokedFunctionNamespaceManagerConfig (com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig)1 NoopSqlFunctionExecutor (com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor)1 SqlFunctionExecutors (com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors)1 InMemoryFunctionNamespaceManager (com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager)1 HdfsConfiguration (com.facebook.presto.hive.HdfsConfiguration)1 HdfsConfigurationInitializer (com.facebook.presto.hive.HdfsConfigurationInitializer)1 HdfsEnvironment (com.facebook.presto.hive.HdfsEnvironment)1 HiveClientConfig (com.facebook.presto.hive.HiveClientConfig)1