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;
}
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);
}
}
}
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());
}
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());
}
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)");
}
Aggregations