Search in sources :

Example 1 with SessionPropertyManager

use of io.prestosql.metadata.SessionPropertyManager in project hetu-core by openlookeng.

the class TestQueryPlanDeterminism method createLocalQueryRunner.

private static LocalQueryRunner createLocalQueryRunner() {
    Session defaultSession = testSessionBuilder().setCatalog("local").setSchema(TINY_SCHEMA_NAME).build();
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(defaultSession);
    // add the tpch catalog
    // local queries run directly against the generator
    localQueryRunner.createCatalog(defaultSession.getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of());
    localQueryRunner.getMetadata().getFunctionAndTypeManager().registerBuiltInFunctions(CUSTOM_FUNCTIONS);
    SessionPropertyManager sessionPropertyManager = localQueryRunner.getMetadata().getSessionPropertyManager();
    sessionPropertyManager.addSystemSessionProperties(TEST_SYSTEM_PROPERTIES);
    sessionPropertyManager.addConnectorSessionProperties(new CatalogName(TESTING_CATALOG), TEST_CATALOG_PROPERTIES);
    return localQueryRunner;
}
Also used : TpchConnectorFactory(io.prestosql.plugin.tpch.TpchConnectorFactory) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) CatalogName(io.prestosql.spi.connector.CatalogName) LocalQueryRunner(io.prestosql.testing.LocalQueryRunner) Session(io.prestosql.Session)

Example 2 with SessionPropertyManager

use of io.prestosql.metadata.SessionPropertyManager in project hetu-core by openlookeng.

the class DispatchManager method createQueryInternal.

/**
 * Creates and registers a dispatch query with the query tracker.  This method will never fail to register a query with the query
 * tracker.  If an error occurs while creating a dispatch query, a failed dispatch will be created and registered.
 */
private <C> void createQueryInternal(QueryId queryId, String slug, SessionContext sessionContext, String inputQuery, ResourceGroupManager<C> resourceGroupManager) {
    String query = inputQuery;
    Session session = null;
    DispatchQuery dispatchQuery = null;
    try {
        if (query.length() > maxQueryLength) {
            int queryLength = query.length();
            query = query.substring(0, maxQueryLength);
            throw new PrestoException(QUERY_TEXT_TOO_LARGE, format("Query text length (%s) exceeds the maximum length (%s)", queryLength, maxQueryLength));
        }
        // decode session
        session = sessionSupplier.createSession(queryId, sessionContext);
        // prepare query
        PreparedQuery preparedQuery = queryPreparer.prepareQuery(session, query);
        // select resource group
        Optional<String> queryType = getQueryType(preparedQuery.getStatement().getClass()).map(Enum::name);
        SelectionContext<C> selectionContext = resourceGroupManager.selectGroup(new SelectionCriteria(sessionContext.getIdentity().getPrincipal().isPresent(), sessionContext.getIdentity().getUser(), Optional.ofNullable(sessionContext.getSource()), sessionContext.getClientTags(), sessionContext.getResourceEstimates(), queryType));
        // apply system default session properties (does not override user set properties)
        session = sessionPropertyDefaults.newSessionWithDefaultProperties(session, queryType, selectionContext.getResourceGroupId());
        // mark existing transaction as active
        transactionManager.activateTransaction(session, isTransactionControlStatement(preparedQuery.getStatement()), accessControl);
        dispatchQuery = dispatchQueryFactory.createDispatchQuery(session, query, preparedQuery, slug, selectionContext.getResourceGroupId(), resourceGroupManager);
        boolean queryAdded = queryCreated(dispatchQuery);
        if (queryAdded && !dispatchQuery.isDone()) {
            try {
                resourceGroupManager.submit(dispatchQuery, selectionContext, queryExecutor);
                if (PropertyService.getBooleanProperty(HetuConstant.MULTI_COORDINATOR_ENABLED) && stateUpdater != null) {
                    stateUpdater.registerQuery(StateStoreConstants.QUERY_STATE_COLLECTION_NAME, dispatchQuery);
                }
                if (LOG.isDebugEnabled()) {
                    long now = System.currentTimeMillis();
                    LOG.debug("query:%s submission started at %s, ended at %s, total time use: %sms", dispatchQuery.getQueryId(), new SimpleDateFormat("HH:mm:ss:SSS").format(dispatchQuery.getCreateTime().toDate()), new SimpleDateFormat("HH:mm:ss:SSS").format(new Date(now)), now - dispatchQuery.getCreateTime().getMillis());
                }
            } catch (Throwable e) {
                // dispatch query has already been registered, so just fail it directly
                dispatchQuery.fail(e);
            }
        }
    } catch (Throwable throwable) {
        // creation must never fail, so register a failed query in this case
        if (dispatchQuery == null) {
            if (session == null) {
                session = Session.builder(new SessionPropertyManager()).setQueryId(queryId).setIdentity(sessionContext.getIdentity()).setSource(sessionContext.getSource()).build();
            }
            DispatchQuery failedDispatchQuery = failedDispatchQueryFactory.createFailedDispatchQuery(session, query, Optional.empty(), throwable);
            queryCreated(failedDispatchQuery);
        } else {
            dispatchQuery.fail(throwable);
        }
    }
}
Also used : PreparedQuery(io.prestosql.execution.QueryPreparer.PreparedQuery) PrestoException(io.prestosql.spi.PrestoException) Date(java.util.Date) SelectionCriteria(io.prestosql.spi.resourcegroups.SelectionCriteria) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) SimpleDateFormat(java.text.SimpleDateFormat) Session(io.prestosql.Session)

Example 3 with SessionPropertyManager

use of io.prestosql.metadata.SessionPropertyManager in project hetu-core by openlookeng.

the class TestQuerySessionSupplier method testCreateSession.

@Test
public void testCreateSession() {
    HttpRequestSessionContext context = new HttpRequestSessionContext(TEST_REQUEST, user -> ImmutableSet.of());
    QuerySessionSupplier sessionSupplier = new QuerySessionSupplier(createTestTransactionManager(), new AllowAllAccessControl(), new SessionPropertyManager(), new SqlEnvironmentConfig());
    Session session = sessionSupplier.createSession(new QueryId("test_query_id"), context);
    assertEquals(session.getQueryId(), new QueryId("test_query_id"));
    assertEquals(session.getUser(), "testUser");
    assertEquals(session.getSource().get(), "testSource");
    assertEquals(session.getCatalog().get(), "testCatalog");
    assertEquals(session.getSchema().get(), "testSchema");
    assertEquals(session.getPath().getRawPath().get(), "testPath");
    assertEquals(session.getLocale(), Locale.TAIWAN);
    assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei"));
    assertEquals(session.getRemoteUserAddress().get(), "testRemote");
    assertEquals(session.getClientInfo().get(), "client-info");
    assertEquals(session.getClientTags(), ImmutableSet.of("tag1", "tag2", "tag3"));
    assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").build());
    assertEquals(session.getPreparedStatements(), ImmutableMap.<String, String>builder().put("query1", "select * from foo").put("query2", "select * from bar").build());
}
Also used : AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) QueryId(io.prestosql.spi.QueryId) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) SqlEnvironmentConfig(io.prestosql.sql.SqlEnvironmentConfig) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 4 with SessionPropertyManager

use of io.prestosql.metadata.SessionPropertyManager in project hetu-core by openlookeng.

the class AutoVacuumScanner method startVacuum.

private void startVacuum(Catalog catalog, String vacuumTable, boolean isFull) {
    String catalogNameVacuumTable = catalog.getCatalogName() + "." + vacuumTable;
    if (vacuumInProgressMap.containsKey(catalogNameVacuumTable)) {
        log.debug("return Present in vacuumInProgressMap %s ", catalogNameVacuumTable);
        return;
    }
    long attempts = 0;
    QueryId queryId = dispatchManager.createQueryId();
    String slug = "x" + randomUUID().toString().toLowerCase(ENGLISH).replace("-", "");
    String vacuumQuery;
    if (isFull) {
        vacuumQuery = "vacuum table " + catalogNameVacuumTable + "  full";
    } else {
        vacuumQuery = "vacuum table " + catalogNameVacuumTable;
    }
    Session.SessionBuilder sessionBuilder = Session.builder(sessionPropertyManager).setQueryId(queryId).setIdentity(new Identity("openLooKeng", Optional.empty())).setSource("auto-vacuum");
    Session session = sessionBuilder.build();
    AutoVacuumSessionContext sessionContext = new AutoVacuumSessionContext(session);
    vacuumInProgressMap.put(catalogNameVacuumTable, System.currentTimeMillis());
    log.debug("Query.create queryId %s  catalogNameVacuumTable: %s ", queryId.toString(), catalogNameVacuumTable);
    ListenableFuture<?> lf = waitForDispatched(queryId, slug, sessionContext, vacuumQuery);
    Futures.addCallback(lf, new FutureCallback<Object>() {

        @Override
        public void onSuccess(@Nullable Object result) {
            try {
                DispatchQuery dispatchQuery = dispatchManager.getQuery(queryId);
                dispatchQuery.addStateChangeListener((state) -> {
                    Query query = getQuery(queryId, slug);
                    if ((null != query) && (!dispatchManager.getQueryInfo(queryId).getState().isDone())) {
                        query.waitForResults(attempts, Duration.valueOf("1s"), DataSize.valueOf("1MB"));
                    }
                    if (state.isDone()) {
                        log.debug("STATUS  %s QueryID %s Query %s", state.name(), queryId.toString(), vacuumQuery);
                        vacuumInProgressMap.remove(catalogNameVacuumTable);
                    }
                });
            } catch (Throwable e) {
                vacuumInProgressMap.remove(catalogNameVacuumTable);
                log.error("Filed to execute vacuum for table %s QueryID %s", catalogNameVacuumTable, queryId.toString(), e.getMessage());
            }
        }

        @Override
        public void onFailure(Throwable t) {
            vacuumInProgressMap.remove(catalogNameVacuumTable);
            log.error("Query %s request to start vacuum scan failed at queryId[%s]: %s ", vacuumQuery, queryId, t.getMessage());
        }
    }, directExecutor());
}
Also used : ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) Inject(com.google.inject.Inject) DataCenterStatementResource(io.prestosql.datacenter.DataCenterStatementResource) Duration(io.airlift.units.Duration) QueryManager(io.prestosql.execution.QueryManager) PreDestroy(javax.annotation.PreDestroy) Future(java.util.concurrent.Future) BoundedExecutor(io.airlift.concurrent.BoundedExecutor) Map(java.util.Map) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) ENGLISH(java.util.Locale.ENGLISH) PrestoException(io.prestosql.spi.PrestoException) Query(io.prestosql.server.protocol.Query) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Identity(io.prestosql.spi.security.Identity) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) DataSize(io.airlift.units.DataSize) List(java.util.List) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) StandardErrorCode(io.prestosql.spi.StandardErrorCode) ConnectorVacuumTableInfo(io.prestosql.spi.connector.ConnectorVacuumTableInfo) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) Connector(io.prestosql.spi.connector.Connector) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Logger(io.airlift.log.Logger) BlockEncodingSerde(io.prestosql.spi.block.BlockEncodingSerde) AtomicReference(java.util.concurrent.atomic.AtomicReference) ExchangeClient(io.prestosql.operator.ExchangeClient) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) QueryId(io.prestosql.spi.QueryId) NoSuchElementException(java.util.NoSuchElementException) DispatchManager(io.prestosql.dispatcher.DispatchManager) Nullable(javax.annotation.Nullable) ForStatementResource(io.prestosql.server.ForStatementResource) FutureCallback(com.google.common.util.concurrent.FutureCallback) Futures(com.google.common.util.concurrent.Futures) UUID.randomUUID(java.util.UUID.randomUUID) Catalog(io.prestosql.metadata.Catalog) ExchangeClientSupplier(io.prestosql.operator.ExchangeClientSupplier) CatalogManager(io.prestosql.metadata.CatalogManager) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) Query(io.prestosql.server.protocol.Query) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) QueryId(io.prestosql.spi.QueryId) Identity(io.prestosql.spi.security.Identity) Session(io.prestosql.Session)

Example 5 with SessionPropertyManager

use of io.prestosql.metadata.SessionPropertyManager in project hetu-core by openlookeng.

the class TestAnalyzer method testTooManyGroupingElements.

@Test
public void testTooManyGroupingElements() {
    Session session = testSessionBuilder(new SessionPropertyManager(new SystemSessionProperties(new QueryManagerConfig(), new TaskManagerConfig(), new MemoryManagerConfig(), new FeaturesConfig().setMaxGroupingSets(2048), new HetuConfig(), new SnapshotConfig()))).build();
    analyze(session, "SELECT a, b, c, d, e, f, g, h, i, j, k, SUM(l)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l)\n" + "GROUP BY CUBE (a, b, c, d, e, f), CUBE (g, h, i, j, k)");
    assertFails(session, TOO_MANY_GROUPING_SETS, "line 3:10: GROUP BY has 4096 grouping sets but can contain at most 2048", "SELECT a, b, c, d, e, f, g, h, i, j, k, l, SUM(m)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l, m)\n" + "GROUP BY CUBE (a, b, c, d, e, f), CUBE (g, h, i, j, k, l)");
    assertFails(session, TOO_MANY_GROUPING_SETS, format("line 3:10: GROUP BY has more than %s grouping sets but can contain at most 2048", Integer.MAX_VALUE), "SELECT a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae, SUM(af)" + "FROM (VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, " + "17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32))\n" + "t (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae, af)\n" + "GROUP BY CUBE (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, " + "q, r, s, t, u, v, x, w, y, z, aa, ab, ac, ad, ae)");
}
Also used : SnapshotConfig(io.prestosql.snapshot.SnapshotConfig) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) QueryManagerConfig(io.prestosql.execution.QueryManagerConfig) TaskManagerConfig(io.prestosql.execution.TaskManagerConfig) MemoryManagerConfig(io.prestosql.memory.MemoryManagerConfig) HetuConfig(io.prestosql.utils.HetuConfig) Session(io.prestosql.Session) SystemSessionProperties(io.prestosql.SystemSessionProperties) Test(org.testng.annotations.Test)

Aggregations

SessionPropertyManager (io.prestosql.metadata.SessionPropertyManager)9 Session (io.prestosql.Session)7 QueryId (io.prestosql.spi.QueryId)5 Identity (io.prestosql.spi.security.Identity)3 Test (org.testng.annotations.Test)3 TpchConnectorFactory (io.prestosql.plugin.tpch.TpchConnectorFactory)2 AllowAllAccessControl (io.prestosql.security.AllowAllAccessControl)2 PrestoException (io.prestosql.spi.PrestoException)2 CatalogName (io.prestosql.spi.connector.CatalogName)2 SqlEnvironmentConfig (io.prestosql.sql.SqlEnvironmentConfig)2 LocalQueryRunner (io.prestosql.testing.LocalQueryRunner)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 Inject (com.google.inject.Inject)1 BoundedExecutor (io.airlift.concurrent.BoundedExecutor)1 Logger (io.airlift.log.Logger)1 DataSize (io.airlift.units.DataSize)1