Search in sources :

Example 1 with Statement

use of io.prestosql.sql.tree.Statement in project hetu-core by openlookeng.

the class QueryRewriter method rewriteCreateTableAsSelect.

private Query rewriteCreateTableAsSelect(Connection connection, Query query, CreateTableAsSelect statement) throws SQLException, QueryRewriteException {
    QualifiedName temporaryTableName = generateTemporaryTableName(statement.getName());
    Statement rewritten = new CreateTableAsSelect(temporaryTableName, statement.getQuery(), statement.isNotExists(), statement.getProperties(), statement.isWithData(), statement.getColumnAliases(), Optional.empty());
    String createTableAsSql = formatSql(rewritten, Optional.empty());
    String checksumSql = checksumSql(getColumns(connection, statement), temporaryTableName);
    String dropTableSql = dropTableSql(temporaryTableName);
    return new Query(query.getCatalog(), query.getSchema(), ImmutableList.of(createTableAsSql), checksumSql, ImmutableList.of(dropTableSql), query.getUsername(), query.getPassword(), query.getSessionProperties());
}
Also used : Statement(io.prestosql.sql.tree.Statement) QualifiedName(io.prestosql.sql.tree.QualifiedName) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect)

Example 2 with Statement

use of io.prestosql.sql.tree.Statement in project hetu-core by openlookeng.

the class QueryRewriter method rewriteInsertQuery.

private Query rewriteInsertQuery(Connection connection, Query query, Insert statement) throws SQLException, QueryRewriteException {
    QualifiedName temporaryTableName = generateTemporaryTableName(statement.getTarget());
    Statement createTemporaryTable = new CreateTable(temporaryTableName, ImmutableList.of(new LikeClause(statement.getTarget(), Optional.of(INCLUDING))), true, ImmutableList.of(), Optional.empty());
    String createTemporaryTableSql = formatSql(createTemporaryTable, Optional.empty());
    String insertSql = formatSql(new Insert(temporaryTableName, statement.getColumns(), statement.getQuery(), statement.getOverwrite()), Optional.empty());
    String checksumSql = checksumSql(getColumnsForTable(connection, query.getCatalog(), query.getSchema(), statement.getTarget().toString()), temporaryTableName);
    String dropTableSql = dropTableSql(temporaryTableName);
    return new Query(query.getCatalog(), query.getSchema(), ImmutableList.of(createTemporaryTableSql, insertSql), checksumSql, ImmutableList.of(dropTableSql), query.getUsername(), query.getPassword(), query.getSessionProperties());
}
Also used : LikeClause(io.prestosql.sql.tree.LikeClause) Statement(io.prestosql.sql.tree.Statement) QualifiedName(io.prestosql.sql.tree.QualifiedName) CreateTable(io.prestosql.sql.tree.CreateTable) Insert(io.prestosql.sql.tree.Insert)

Example 3 with Statement

use of io.prestosql.sql.tree.Statement in project hetu-core by openlookeng.

the class CoordinatorModule method setup.

@Override
protected void setup(Binder binder) {
    ServerConfig serverConfig = buildConfigObject(ServerConfig.class);
    httpServerBinder(binder).bindResource("/ui", "webapp").withWelcomeFile("queryeditor.html");
    httpServerBinder(binder).bindResource("/tableau", "webapp/tableau");
    // discovery server
    install(installModuleIf(EmbeddedDiscoveryConfig.class, EmbeddedDiscoveryConfig::isEnabled, Modules.override(new EmbeddedDiscoveryModule()).with(new HetuEmbeddedDiscoveryModule())));
    // presto coordinator announcement
    discoveryBinder(binder).bindHttpAnnouncement("presto-coordinator");
    // statement resource
    jsonCodecBinder(binder).bindJsonCodec(QueryInfo.class);
    jsonCodecBinder(binder).bindJsonCodec(TaskInfo.class);
    jsonCodecBinder(binder).bindJsonCodec(QueryResults.class);
    jsonCodecBinder(binder).bindJsonCodec(SelectedRole.class);
    jaxrsBinder(binder).bind(io.prestosql.dispatcher.QueuedStatementResource.class);
    jaxrsBinder(binder).bind(io.prestosql.datacenter.DataCenterStatementResource.class);
    jaxrsBinder(binder).bind(io.prestosql.server.protocol.ExecutingStatementResource.class);
    binder.bind(StatementHttpExecutionMBean.class).in(Scopes.SINGLETON);
    newExporter(binder).export(StatementHttpExecutionMBean.class).withGeneratedName();
    // hetu-ui module
    binder.install(new QueryEditorUIModule());
    // catalog resource
    install(installModuleIf(DynamicCatalogConfig.class, DynamicCatalogConfig::isDynamicCatalogEnabled, new CatalogModule()));
    // resource for serving static content
    jaxrsBinder(binder).bind(WebUiResource.class);
    // failure detector
    binder.install(new FailureDetectorModule());
    jaxrsBinder(binder).bind(NodeResource.class);
    jaxrsBinder(binder).bind(WorkerResource.class);
    httpClientBinder(binder).bindHttpClient("workerInfo", ForWorkerInfo.class);
    // query monitor
    jsonCodecBinder(binder).bindJsonCodec(StatsAndCosts.class);
    configBinder(binder).bindConfig(QueryMonitorConfig.class);
    binder.bind(QueryMonitor.class).in(Scopes.SINGLETON);
    // state store
    binder.bind(StateStoreLauncher.class).to(EmbeddedStateStoreLauncher.class).in(Scopes.SINGLETON);
    // query manager
    jaxrsBinder(binder).bind(QueryResource.class);
    jaxrsBinder(binder).bind(StageResource.class);
    jaxrsBinder(binder).bind(QueryStateInfoResource.class);
    jaxrsBinder(binder).bind(ResourceGroupStateInfoResource.class);
    binder.bind(QueryIdGenerator.class).in(Scopes.SINGLETON);
    binder.bind(QueryManager.class).to(SqlQueryManager.class).in(Scopes.SINGLETON);
    newExporter(binder).export(QueryManager.class).withGeneratedName();
    binder.bind(QueryPreparer.class).in(Scopes.SINGLETON);
    binder.bind(SessionSupplier.class).to(QuerySessionSupplier.class).in(Scopes.SINGLETON);
    binder.bind(InternalResourceGroupManager.class).in(Scopes.SINGLETON);
    newExporter(binder).export(InternalResourceGroupManager.class).withGeneratedName();
    binder.bind(ResourceGroupManager.class).to(InternalResourceGroupManager.class);
    binder.bind(LegacyResourceGroupConfigurationManager.class).in(Scopes.SINGLETON);
    // dispatcher
    binder.bind(DispatchManager.class).in(Scopes.SINGLETON);
    binder.bind(FailedDispatchQueryFactory.class).in(Scopes.SINGLETON);
    binder.bind(DispatchExecutor.class).in(Scopes.SINGLETON);
    // local dispatcher
    binder.bind(DispatchQueryFactory.class).to(LocalDispatchQueryFactory.class);
    // cluster memory manager
    binder.bind(ClusterMemoryManager.class).in(Scopes.SINGLETON);
    binder.bind(ClusterMemoryPoolManager.class).to(ClusterMemoryManager.class).in(Scopes.SINGLETON);
    httpClientBinder(binder).bindHttpClient("memoryManager", ForMemoryManager.class).withTracing().withConfigDefaults(config -> {
        config.setIdleTimeout(serverConfig.getHttpClientIdleTimeout());
        config.setRequestTimeout(serverConfig.getHttpClientRequestTimeout());
    });
    bindLowMemoryKiller(LowMemoryKillerPolicy.NONE, NoneLowMemoryKiller.class);
    bindLowMemoryKiller(LowMemoryKillerPolicy.TOTAL_RESERVATION, TotalReservationLowMemoryKiller.class);
    bindLowMemoryKiller(LowMemoryKillerPolicy.TOTAL_RESERVATION_ON_BLOCKED_NODES, TotalReservationOnBlockedNodesLowMemoryKiller.class);
    newExporter(binder).export(ClusterMemoryManager.class).withGeneratedName();
    // node monitor
    binder.bind(ClusterSizeMonitor.class).in(Scopes.SINGLETON);
    // statistics calculator
    binder.install(new StatsCalculatorModule());
    // cost calculator
    binder.bind(TaskCountEstimator.class).in(Scopes.SINGLETON);
    binder.bind(CostCalculator.class).to(CostCalculatorUsingExchanges.class).in(Scopes.SINGLETON);
    binder.bind(CostCalculator.class).annotatedWith(EstimatedExchanges.class).to(CostCalculatorWithEstimatedExchanges.class).in(Scopes.SINGLETON);
    binder.bind(CostComparator.class).in(Scopes.SINGLETON);
    // cluster statistics
    jaxrsBinder(binder).bind(ClusterStatsResource.class);
    // planner
    binder.bind(PlanFragmenter.class).in(Scopes.SINGLETON);
    binder.bind(PlanOptimizers.class).in(Scopes.SINGLETON);
    // dynamic filtering service
    binder.bind(DynamicFilterService.class).in(Scopes.SINGLETON);
    // query explainer
    binder.bind(QueryExplainer.class).in(Scopes.SINGLETON);
    // explain analyze
    binder.bind(ExplainAnalyzeContext.class).in(Scopes.SINGLETON);
    // split cache map
    binder.bind(SplitCacheStateManager.class).in(Scopes.SINGLETON);
    binder.bind(RemoteTaskFactory.class).to(HttpRemoteTaskFactory.class).in(Scopes.SINGLETON);
    newExporter(binder).export(RemoteTaskFactory.class).withGeneratedName();
    binder.bind(RemoteTaskStats.class).in(Scopes.SINGLETON);
    newExporter(binder).export(RemoteTaskStats.class).withGeneratedName();
    httpClientBinder(binder).bindHttpClient("scheduler", ForScheduler.class).withTracing().withFilter(GenerateTraceTokenRequestFilter.class).withConfigDefaults(config -> {
        config.setIdleTimeout(serverConfig.getHttpClientIdleTimeout());
        config.setRequestTimeout(serverConfig.getHttpClientRequestTimeout());
        config.setMaxConnectionsPerServer(250);
    });
    binder.bind(ScheduledExecutorService.class).annotatedWith(ForScheduler.class).toInstance(newSingleThreadScheduledExecutor(threadsNamed("stage-scheduler")));
    install(installModuleIf(AutoVacuumConfig.class, config -> config.isAutoVacuumEnabled(), binder1 -> binder1.bind(AutoVacuumScanner.class).in(Scopes.SINGLETON)));
    // query execution
    binder.bind(ExecutorService.class).annotatedWith(ForQueryExecution.class).toInstance(newCachedThreadPool(threadsNamed("query-execution-%s")));
    binder.bind(QueryExecutionMBean.class).in(Scopes.SINGLETON);
    newExporter(binder).export(QueryExecutionMBean.class).as(generator -> generator.generatedNameOf(QueryExecution.class));
    MapBinder<Class<? extends Statement>, QueryExecutionFactory<?>> executionBinder = newMapBinder(binder, new TypeLiteral<Class<? extends Statement>>() {
    }, new TypeLiteral<QueryExecutionFactory<?>>() {
    });
    binder.bind(SplitSchedulerStats.class).in(Scopes.SINGLETON);
    newExporter(binder).export(SplitSchedulerStats.class).withGeneratedName();
    binder.bind(SqlQueryExecutionFactory.class).in(Scopes.SINGLETON);
    getAllQueryTypes().entrySet().stream().filter(entry -> entry.getValue() != QueryType.DATA_DEFINITION).forEach(entry -> executionBinder.addBinding(entry.getKey()).to(SqlQueryExecutionFactory.class).in(Scopes.SINGLETON));
    binder.bind(DataDefinitionExecutionFactory.class).in(Scopes.SINGLETON);
    bindDataDefinitionTask(binder, executionBinder, CreateSchema.class, CreateSchemaTask.class);
    bindDataDefinitionTask(binder, executionBinder, DropSchema.class, DropSchemaTask.class);
    bindDataDefinitionTask(binder, executionBinder, RenameSchema.class, RenameSchemaTask.class);
    bindDataDefinitionTask(binder, executionBinder, AddColumn.class, AddColumnTask.class);
    bindDataDefinitionTask(binder, executionBinder, CreateTable.class, CreateTableTask.class);
    bindDataDefinitionTask(binder, executionBinder, RenameTable.class, RenameTableTask.class);
    bindDataDefinitionTask(binder, executionBinder, RenameIndex.class, RenameIndexTask.class);
    bindDataDefinitionTask(binder, executionBinder, Comment.class, CommentTask.class);
    bindDataDefinitionTask(binder, executionBinder, RenameColumn.class, RenameColumnTask.class);
    bindDataDefinitionTask(binder, executionBinder, DropColumn.class, DropColumnTask.class);
    bindDataDefinitionTask(binder, executionBinder, DropTable.class, DropTableTask.class);
    bindDataDefinitionTask(binder, executionBinder, CreateView.class, CreateViewTask.class);
    bindDataDefinitionTask(binder, executionBinder, DropView.class, DropViewTask.class);
    bindDataDefinitionTask(binder, executionBinder, Use.class, UseTask.class);
    bindDataDefinitionTask(binder, executionBinder, SetSession.class, SetSessionTask.class);
    bindDataDefinitionTask(binder, executionBinder, ResetSession.class, ResetSessionTask.class);
    bindDataDefinitionTask(binder, executionBinder, StartTransaction.class, StartTransactionTask.class);
    bindDataDefinitionTask(binder, executionBinder, Commit.class, CommitTask.class);
    bindDataDefinitionTask(binder, executionBinder, Rollback.class, RollbackTask.class);
    bindDataDefinitionTask(binder, executionBinder, Call.class, CallTask.class);
    bindDataDefinitionTask(binder, executionBinder, CreateRole.class, CreateRoleTask.class);
    bindDataDefinitionTask(binder, executionBinder, DropRole.class, DropRoleTask.class);
    bindDataDefinitionTask(binder, executionBinder, GrantRoles.class, GrantRolesTask.class);
    bindDataDefinitionTask(binder, executionBinder, RevokeRoles.class, RevokeRolesTask.class);
    bindDataDefinitionTask(binder, executionBinder, SetRole.class, SetRoleTask.class);
    bindDataDefinitionTask(binder, executionBinder, Grant.class, GrantTask.class);
    bindDataDefinitionTask(binder, executionBinder, Revoke.class, RevokeTask.class);
    bindDataDefinitionTask(binder, executionBinder, Prepare.class, PrepareTask.class);
    bindDataDefinitionTask(binder, executionBinder, Deallocate.class, DeallocateTask.class);
    bindDataDefinitionTask(binder, executionBinder, SetPath.class, SetPathTask.class);
    bindDataDefinitionTask(binder, executionBinder, DropCache.class, DropCacheTask.class);
    bindDataDefinitionTask(binder, executionBinder, DropIndex.class, DropIndexTask.class);
    bindDataDefinitionTask(binder, executionBinder, DropCube.class, DropCubeTask.class);
    bindDataDefinitionTask(binder, executionBinder, CreateCube.class, CreateCubeTask.class);
    MapBinder<String, ExecutionPolicy> executionPolicyBinder = newMapBinder(binder, String.class, ExecutionPolicy.class);
    executionPolicyBinder.addBinding("all-at-once").to(AllAtOnceExecutionPolicy.class);
    executionPolicyBinder.addBinding("phased").to(PhasedExecutionPolicy.class);
    // cleanup
    binder.bind(ExecutorCleanup.class).in(Scopes.SINGLETON);
}
Also used : DispatchQueryFactory(io.prestosql.dispatcher.DispatchQueryFactory) CreateSchema(io.prestosql.sql.tree.CreateSchema) CostCalculator(io.prestosql.cost.CostCalculator) CostCalculatorWithEstimatedExchanges(io.prestosql.cost.CostCalculatorWithEstimatedExchanges) RollbackTask(io.prestosql.execution.RollbackTask) ForTransactionManager(io.prestosql.transaction.ForTransactionManager) ClusterSizeMonitor(io.prestosql.execution.ClusterSizeMonitor) RenameIndexTask(io.prestosql.execution.RenameIndexTask) Prepare(io.prestosql.sql.tree.Prepare) QueryManager(io.prestosql.execution.QueryManager) SqlQueryManager(io.prestosql.execution.SqlQueryManager) Statement(io.prestosql.sql.tree.Statement) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) CreateTable(io.prestosql.sql.tree.CreateTable) BoundedExecutor(io.airlift.concurrent.BoundedExecutor) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) QueryMonitor(io.prestosql.event.QueryMonitor) FailureDetectorModule(io.prestosql.failuredetector.FailureDetectorModule) RenameColumn(io.prestosql.sql.tree.RenameColumn) GrantRoles(io.prestosql.sql.tree.GrantRoles) TransactionManagerConfig(io.prestosql.transaction.TransactionManagerConfig) JsonCodecBinder.jsonCodecBinder(io.airlift.json.JsonCodecBinder.jsonCodecBinder) CreateSchemaTask(io.prestosql.execution.CreateSchemaTask) SetSessionTask(io.prestosql.execution.SetSessionTask) SplitCacheStateManager(io.prestosql.execution.SplitCacheStateManager) RevokeRolesTask(io.prestosql.execution.RevokeRolesTask) ExplainAnalyzeContext(io.prestosql.execution.ExplainAnalyzeContext) CostCalculatorUsingExchanges(io.prestosql.cost.CostCalculatorUsingExchanges) LowMemoryKiller(io.prestosql.memory.LowMemoryKiller) StatementUtils.getAllQueryTypes(io.prestosql.util.StatementUtils.getAllQueryTypes) CommentTask(io.prestosql.execution.CommentTask) DropIndexTask(io.prestosql.execution.DropIndexTask) Threads.threadsNamed(io.airlift.concurrent.Threads.threadsNamed) SetSession(io.prestosql.sql.tree.SetSession) HttpClientBinder.httpClientBinder(io.airlift.http.client.HttpClientBinder.httpClientBinder) DropView(io.prestosql.sql.tree.DropView) SplitSchedulerStats(io.prestosql.execution.scheduler.SplitSchedulerStats) TotalReservationOnBlockedNodesLowMemoryKiller(io.prestosql.memory.TotalReservationOnBlockedNodesLowMemoryKiller) CreateView(io.prestosql.sql.tree.CreateView) DiscoveryBinder.discoveryBinder(io.airlift.discovery.client.DiscoveryBinder.discoveryBinder) Call(io.prestosql.sql.tree.Call) DropRoleTask(io.prestosql.execution.DropRoleTask) DropColumn(io.prestosql.sql.tree.DropColumn) ConfigBinder.configBinder(io.airlift.configuration.ConfigBinder.configBinder) TypeLiteral(com.google.inject.TypeLiteral) QueryPreparer(io.prestosql.execution.QueryPreparer) TaskManagerConfig(io.prestosql.execution.TaskManagerConfig) Grant(io.prestosql.sql.tree.Grant) LegacyResourceGroupConfigurationManager(io.prestosql.execution.resourcegroups.LegacyResourceGroupConfigurationManager) DropRole(io.prestosql.sql.tree.DropRole) QueryMonitorConfig(io.prestosql.event.QueryMonitorConfig) StartTransactionTask(io.prestosql.execution.StartTransactionTask) DispatchExecutor(io.prestosql.dispatcher.DispatchExecutor) DropTable(io.prestosql.sql.tree.DropTable) SetPath(io.prestosql.sql.tree.SetPath) TransactionManager(io.prestosql.transaction.TransactionManager) QueryExecutionFactory(io.prestosql.execution.QueryExecution.QueryExecutionFactory) DropTableTask(io.prestosql.execution.DropTableTask) DataDefinitionTask(io.prestosql.execution.DataDefinitionTask) DataDefinitionExecutionFactory(io.prestosql.execution.DataDefinitionExecution.DataDefinitionExecutionFactory) StateStoreLauncher(io.prestosql.statestore.StateStoreLauncher) CommitTask(io.prestosql.execution.CommitTask) ResetSession(io.prestosql.sql.tree.ResetSession) EmbeddedDiscoveryModule(io.airlift.discovery.server.EmbeddedDiscoveryModule) InMemoryTransactionManager(io.prestosql.transaction.InMemoryTransactionManager) Deallocate(io.prestosql.sql.tree.Deallocate) LowMemoryKillerPolicy(io.prestosql.memory.MemoryManagerConfig.LowMemoryKillerPolicy) Binder(com.google.inject.Binder) ResetSessionTask(io.prestosql.execution.ResetSessionTask) EstimatedExchanges(io.prestosql.cost.CostCalculator.EstimatedExchanges) EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DropCubeTask(io.prestosql.execution.DropCubeTask) Comment(io.prestosql.sql.tree.Comment) RenameTable(io.prestosql.sql.tree.RenameTable) TaskCountEstimator(io.prestosql.cost.TaskCountEstimator) QueryResults(io.prestosql.client.QueryResults) CreateViewTask(io.prestosql.execution.CreateViewTask) NoneLowMemoryKiller(io.prestosql.memory.NoneLowMemoryKiller) CostComparator(io.prestosql.cost.CostComparator) DeallocateTask(io.prestosql.execution.DeallocateTask) QueryPerformanceFetcher(io.prestosql.execution.QueryPerformanceFetcher) CatalogManager(io.prestosql.metadata.CatalogManager) AutoVacuumConfig(io.prestosql.vacuum.AutoVacuumConfig) DropSchemaTask(io.prestosql.execution.DropSchemaTask) AddColumn(io.prestosql.sql.tree.AddColumn) CreateCubeTask(io.prestosql.execution.CreateCubeTask) QueryExplainer(io.prestosql.sql.analyzer.QueryExplainer) ResourceGroupManager(io.prestosql.execution.resourcegroups.ResourceGroupManager) QueryType(io.prestosql.spi.resourcegroups.QueryType) QueryInfo(io.prestosql.execution.QueryInfo) HetuEmbeddedDiscoveryModule(io.prestosql.discovery.server.HetuEmbeddedDiscoveryModule) CreateCube(io.prestosql.sql.tree.CreateCube) DynamicCatalogConfig(io.prestosql.catalog.DynamicCatalogConfig) RenameSchemaTask(io.prestosql.execution.RenameSchemaTask) RenameSchema(io.prestosql.sql.tree.RenameSchema) DropSchema(io.prestosql.sql.tree.DropSchema) PreDestroy(javax.annotation.PreDestroy) SetPathTask(io.prestosql.execution.SetPathTask) SqlQueryExecutionFactory(io.prestosql.execution.SqlQueryExecution.SqlQueryExecutionFactory) DropCacheTask(io.prestosql.execution.DropCacheTask) StartTransaction(io.prestosql.sql.tree.StartTransaction) ExportBinder.newExporter(org.weakref.jmx.guice.ExportBinder.newExporter) GrantRolesTask(io.prestosql.execution.GrantRolesTask) SetRole(io.prestosql.sql.tree.SetRole) ClusterMemoryPoolManager(io.prestosql.spi.memory.ClusterMemoryPoolManager) MapBinder(com.google.inject.multibindings.MapBinder) CreateRoleTask(io.prestosql.execution.CreateRoleTask) AllAtOnceExecutionPolicy(io.prestosql.execution.scheduler.AllAtOnceExecutionPolicy) Commit(io.prestosql.sql.tree.Commit) QueryExecutionMBean(io.prestosql.execution.QueryExecutionMBean) AutoVacuumScanner(io.prestosql.vacuum.AutoVacuumScanner) QueryExecution(io.prestosql.execution.QueryExecution) ClusterMemoryManager(io.prestosql.memory.ClusterMemoryManager) ConditionalModule.installModuleIf(io.airlift.configuration.ConditionalModule.installModuleIf) CallTask(io.prestosql.execution.CallTask) TotalReservationLowMemoryKiller(io.prestosql.memory.TotalReservationLowMemoryKiller) SelectedRole(io.prestosql.spi.security.SelectedRole) RemoteTaskFactory(io.prestosql.execution.RemoteTaskFactory) TaskInfo(io.prestosql.execution.TaskInfo) DropCache(io.prestosql.sql.tree.DropCache) RevokeTask(io.prestosql.execution.RevokeTask) Rollback(io.prestosql.sql.tree.Rollback) ForMemoryManager(io.prestosql.memory.ForMemoryManager) List(java.util.List) ForQueryExecution(io.prestosql.execution.ForQueryExecution) JaxrsBinder.jaxrsBinder(io.airlift.jaxrs.JaxrsBinder.jaxrsBinder) QueryEditorUIModule(io.prestosql.queryeditorui.QueryEditorUIModule) DropCube(io.prestosql.sql.tree.DropCube) FailedDispatchQueryFactory(io.prestosql.dispatcher.FailedDispatchQueryFactory) RenameColumnTask(io.prestosql.execution.RenameColumnTask) QueryIdGenerator(io.prestosql.execution.QueryIdGenerator) UseTask(io.prestosql.execution.UseTask) HttpServerBinder.httpServerBinder(io.airlift.http.server.HttpServerBinder.httpServerBinder) StatsCalculatorModule(io.prestosql.cost.StatsCalculatorModule) MemoryManagerConfig(io.prestosql.memory.MemoryManagerConfig) CreateRole(io.prestosql.sql.tree.CreateRole) Modules(com.google.inject.util.Modules) StatsAndCosts(io.prestosql.cost.StatsAndCosts) CreateTableTask(io.prestosql.execution.CreateTableTask) SetRoleTask(io.prestosql.execution.SetRoleTask) Singleton(javax.inject.Singleton) PlanFragmenter(io.prestosql.sql.planner.PlanFragmenter) AddColumnTask(io.prestosql.execution.AddColumnTask) ExecutionPolicy(io.prestosql.execution.scheduler.ExecutionPolicy) Inject(javax.inject.Inject) DropViewTask(io.prestosql.execution.DropViewTask) PrepareTask(io.prestosql.execution.PrepareTask) ForScheduler(io.prestosql.operator.ForScheduler) PlanOptimizers(io.prestosql.sql.planner.PlanOptimizers) AbstractConfigurationAwareModule(io.airlift.configuration.AbstractConfigurationAwareModule) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) PhasedExecutionPolicy(io.prestosql.execution.scheduler.PhasedExecutionPolicy) LocalDispatchQueryFactory(io.prestosql.dispatcher.LocalDispatchQueryFactory) RevokeRoles(io.prestosql.sql.tree.RevokeRoles) InternalResourceGroupManager(io.prestosql.execution.resourcegroups.InternalResourceGroupManager) DispatchManager(io.prestosql.dispatcher.DispatchManager) ExecutorService(java.util.concurrent.ExecutorService) MapBinder.newMapBinder(com.google.inject.multibindings.MapBinder.newMapBinder) CatalogModule(io.prestosql.catalog.CatalogModule) Scopes(com.google.inject.Scopes) DynamicFilterService(io.prestosql.dynamicfilter.DynamicFilterService) RenameIndex(io.prestosql.sql.tree.RenameIndex) Provides(com.google.inject.Provides) RemoteTaskStats(io.prestosql.server.remotetask.RemoteTaskStats) DropIndex(io.prestosql.sql.tree.DropIndex) Revoke(io.prestosql.sql.tree.Revoke) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) DropColumnTask(io.prestosql.execution.DropColumnTask) Use(io.prestosql.sql.tree.Use) StateStoreProvider(io.prestosql.statestore.StateStoreProvider) RenameTableTask(io.prestosql.execution.RenameTableTask) GrantTask(io.prestosql.execution.GrantTask) QueryIdGenerator(io.prestosql.execution.QueryIdGenerator) AutoVacuumScanner(io.prestosql.vacuum.AutoVacuumScanner) DispatchManager(io.prestosql.dispatcher.DispatchManager) FailureDetectorModule(io.prestosql.failuredetector.FailureDetectorModule) QueryPreparer(io.prestosql.execution.QueryPreparer) RemoteTaskStats(io.prestosql.server.remotetask.RemoteTaskStats) QueryMonitor(io.prestosql.event.QueryMonitor) DynamicCatalogConfig(io.prestosql.catalog.DynamicCatalogConfig) DynamicFilterService(io.prestosql.dynamicfilter.DynamicFilterService) QueryExecutionMBean(io.prestosql.execution.QueryExecutionMBean) LegacyResourceGroupConfigurationManager(io.prestosql.execution.resourcegroups.LegacyResourceGroupConfigurationManager) EmbeddedStateStoreLauncher(io.prestosql.statestore.EmbeddedStateStoreLauncher) RemoteTaskFactory(io.prestosql.execution.RemoteTaskFactory) QueryExplainer(io.prestosql.sql.analyzer.QueryExplainer) CatalogModule(io.prestosql.catalog.CatalogModule) ResourceGroupManager(io.prestosql.execution.resourcegroups.ResourceGroupManager) InternalResourceGroupManager(io.prestosql.execution.resourcegroups.InternalResourceGroupManager) SplitSchedulerStats(io.prestosql.execution.scheduler.SplitSchedulerStats) QueryExecutionFactory(io.prestosql.execution.QueryExecution.QueryExecutionFactory) SqlQueryExecutionFactory(io.prestosql.execution.SqlQueryExecution.SqlQueryExecutionFactory) PlanOptimizers(io.prestosql.sql.planner.PlanOptimizers) CostCalculatorWithEstimatedExchanges(io.prestosql.cost.CostCalculatorWithEstimatedExchanges) ForQueryExecution(io.prestosql.execution.ForQueryExecution) PlanFragmenter(io.prestosql.sql.planner.PlanFragmenter) QueryExecution(io.prestosql.execution.QueryExecution) ForQueryExecution(io.prestosql.execution.ForQueryExecution) FailedDispatchQueryFactory(io.prestosql.dispatcher.FailedDispatchQueryFactory) SqlQueryExecutionFactory(io.prestosql.execution.SqlQueryExecution.SqlQueryExecutionFactory) InternalResourceGroupManager(io.prestosql.execution.resourcegroups.InternalResourceGroupManager) CostCalculatorUsingExchanges(io.prestosql.cost.CostCalculatorUsingExchanges) ForScheduler(io.prestosql.operator.ForScheduler) ExplainAnalyzeContext(io.prestosql.execution.ExplainAnalyzeContext) ClusterSizeMonitor(io.prestosql.execution.ClusterSizeMonitor) StatsCalculatorModule(io.prestosql.cost.StatsCalculatorModule) TaskCountEstimator(io.prestosql.cost.TaskCountEstimator) CostComparator(io.prestosql.cost.CostComparator) Statement(io.prestosql.sql.tree.Statement) EmbeddedDiscoveryModule(io.airlift.discovery.server.EmbeddedDiscoveryModule) HetuEmbeddedDiscoveryModule(io.prestosql.discovery.server.HetuEmbeddedDiscoveryModule) HetuEmbeddedDiscoveryModule(io.prestosql.discovery.server.HetuEmbeddedDiscoveryModule) CostCalculator(io.prestosql.cost.CostCalculator) QueryEditorUIModule(io.prestosql.queryeditorui.QueryEditorUIModule) DispatchQueryFactory(io.prestosql.dispatcher.DispatchQueryFactory) FailedDispatchQueryFactory(io.prestosql.dispatcher.FailedDispatchQueryFactory) LocalDispatchQueryFactory(io.prestosql.dispatcher.LocalDispatchQueryFactory) SplitCacheStateManager(io.prestosql.execution.SplitCacheStateManager) AllAtOnceExecutionPolicy(io.prestosql.execution.scheduler.AllAtOnceExecutionPolicy) ExecutionPolicy(io.prestosql.execution.scheduler.ExecutionPolicy) PhasedExecutionPolicy(io.prestosql.execution.scheduler.PhasedExecutionPolicy) ClusterMemoryManager(io.prestosql.memory.ClusterMemoryManager) QueryManager(io.prestosql.execution.QueryManager) SqlQueryManager(io.prestosql.execution.SqlQueryManager) DispatchExecutor(io.prestosql.dispatcher.DispatchExecutor) SqlQueryManager(io.prestosql.execution.SqlQueryManager) DataDefinitionExecutionFactory(io.prestosql.execution.DataDefinitionExecution.DataDefinitionExecutionFactory) AutoVacuumConfig(io.prestosql.vacuum.AutoVacuumConfig)

Example 4 with Statement

use of io.prestosql.sql.tree.Statement in project hetu-core by openlookeng.

the class SqlFormatterUtil method getFormattedSql.

public static String getFormattedSql(Statement statement, SqlParser sqlParser, Optional<List<Expression>> parameters) {
    String sql = SqlFormatter.formatSql(statement, parameters);
    // verify round-trip
    Statement parsed;
    try {
        ParsingOptions parsingOptions = new ParsingOptions(REJECT);
        parsed = sqlParser.createStatement(sql, parsingOptions);
    } catch (ParsingException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, "Formatted query does not parse: " + statement);
    }
    if (!statement.equals(parsed)) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, "Query does not round-trip: " + statement);
    }
    return sql;
}
Also used : ParsingOptions(io.prestosql.sql.parser.ParsingOptions) Statement(io.prestosql.sql.tree.Statement) ParsingException(io.prestosql.sql.parser.ParsingException) PrestoException(io.prestosql.spi.PrestoException)

Example 5 with Statement

use of io.prestosql.sql.tree.Statement in project hetu-core by openlookeng.

the class TestPrepareTask method testPrepareInvalidStatement.

@Test
public void testPrepareInvalidStatement() {
    Statement statement = new Execute(identifier("foo"), emptyList());
    String sqlString = "PREPARE my_query FROM EXECUTE foo";
    assertPrestoExceptionThrownBy(() -> executePrepare("my_query", statement, sqlString, TEST_SESSION)).hasErrorCode(NOT_SUPPORTED).hasMessage("Invalid statement type for prepared statement: EXECUTE");
}
Also used : Execute(io.prestosql.sql.tree.Execute) Statement(io.prestosql.sql.tree.Statement) Test(org.testng.annotations.Test)

Aggregations

Statement (io.prestosql.sql.tree.Statement)17 PrestoException (io.prestosql.spi.PrestoException)5 List (java.util.List)5 Session (io.prestosql.Session)4 CubeManager (io.prestosql.cube.CubeManager)4 WarningCollector (io.prestosql.execution.warnings.WarningCollector)4 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)4 Metadata (io.prestosql.metadata.Metadata)4 AccessControl (io.prestosql.security.AccessControl)4 SqlParser (io.prestosql.sql.parser.SqlParser)4 Expression (io.prestosql.sql.tree.Expression)4 Optional (java.util.Optional)4 ImmutableList (com.google.common.collect.ImmutableList)3 TransactionManager (io.prestosql.transaction.TransactionManager)3 Inject (javax.inject.Inject)3 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MetadataUtil.createQualifiedObjectName (io.prestosql.metadata.MetadataUtil.createQualifiedObjectName)2 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)2 TableHandle (io.prestosql.spi.metadata.TableHandle)2