github-advanced-security[bot] commented on code in PR #18923:
URL: https://github.com/apache/druid/pull/18923#discussion_r2700195445
##########
multi-stage-query/src/main/java/org/apache/druid/msq/dart/controller/ControllerHolder.java:
##########
@@ -166,10 +191,25 @@
public boolean run(final QueryListener listener) throws Exception
{
if (state.compareAndSet(State.ACCEPTED, State.RUNNING)) {
- controller.run(listener);
+ final CaptureReportQueryListener reportListener = new
CaptureReportQueryListener(listener);
+ controller.run(reportListener);
+ updateStateOnQueryComplete(reportListener.getReport());
return true;
} else {
return false;
}
}
+
+ private void updateStateOnQueryComplete(final MSQTaskReportPayload report)
+ {
+ switch (report.getStatus().getStatus()) {
Review Comment:
## Missing enum case in switch
Switch statement does not have a case for [RUNNING](1).
[Show more
details](https://github.com/apache/druid/security/code-scanning/10773)
##########
sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java:
##########
@@ -1184,4 +1217,136 @@
}
return projectedRow;
}
+
+ /**
+ * This table contains currently running and recently completed queries from
all SQL engines.
+ * Enabled based on {@link PlannerConfig#isEnableSysQueriesTable()}.
+ */
+ static class QueriesTable extends AbstractTable implements
ProjectableFilterableTable
+ {
+ private final Provider<SqlEngineRegistry> sqlEngineRegistryProvider;
+ private final ObjectMapper jsonMapper;
+ private final AuthorizerMapper authorizerMapper;
+
+ public QueriesTable(
+ final Provider<SqlEngineRegistry> sqlEngineRegistryProvider,
+ final ObjectMapper jsonMapper,
+ final AuthorizerMapper authorizerMapper
+ )
+ {
+ this.sqlEngineRegistryProvider = sqlEngineRegistryProvider;
+ this.jsonMapper = jsonMapper;
+ this.authorizerMapper = authorizerMapper;
+ }
+
+ @Override
+ public RelDataType getRowType(final RelDataTypeFactory typeFactory)
+ {
+ return RowSignatures.toRelDataType(QUERIES_SIGNATURE, typeFactory);
+ }
+
+ @Override
+ public TableType getJdbcTableType()
+ {
+ return TableType.SYSTEM_TABLE;
+ }
+
+ @Override
+ public Enumerable<Object[]> scan(
+ final DataContext root,
+ final List<RexNode> filters,
+ @Nullable final int[] projects
+ )
+ {
+ final AuthenticationResult authenticationResult = (AuthenticationResult)
Preconditions.checkNotNull(
+ root.get(PlannerContext.DATA_CTX_AUTHENTICATION_RESULT),
+ "authenticationResult in dataContext"
+ );
+
+ // Check STATE READ authorization
+ final AuthorizationResult stateReadAuthorization =
AuthorizationUtils.authorizeAllResourceActions(
+ authenticationResult,
+ Collections.singletonList(new
ResourceAction(Resource.STATE_RESOURCE, Action.READ)),
+ authorizerMapper
+ );
+
+ // Get queries from all engines
+ final List<QueryInfo> allQueries = new ArrayList<>();
+ for (final SqlEngine sqlEngine :
sqlEngineRegistryProvider.get().getAllEngines()) {
+ final GetQueriesResponse response = sqlEngine.getRunningQueries(
+ false, // selfOnly false to get queries from all servers
+ true, // includeComplete true to include all queries
+ authenticationResult,
+ stateReadAuthorization
+ );
+ allQueries.addAll(response.getQueries());
+ }
+
+ // Determine if we need to serialize the info field (based on projection
pushdown)
+ final int[] nonNullProjects = projects == null ? QUERIES_PROJECT_ALL :
projects;
+ final boolean includeInfo = containsIndex(nonNullProjects,
QUERIES_INFO_INDEX);
+
+ // Build rows
+ final FluentIterable<Object[]> results = FluentIterable
+ .from(allQueries)
+ .transform(queryInfo -> buildQueryRow(queryInfo, includeInfo,
jsonMapper))
+ .transform(row -> projectQueriesRow(row, nonNullProjects));
+
+ return Linq4j.asEnumerable(results);
+ }
+
+ /**
+ * Build a full row for a query.
+ */
+ private static Object[] buildQueryRow(
+ final QueryInfo queryInfo,
+ final boolean includeInfo,
+ final ObjectMapper jsonMapper
+ )
+ {
+ final Object[] row = new Object[QUERIES_SIGNATURE.size()];
+ row[0] = queryInfo.executionId();
+ row[1] = queryInfo.engine();
+ row[2] = queryInfo.state().toString();
Review Comment:
## Useless toString on String
Redundant call to 'toString' on a String object.
[Show more
details](https://github.com/apache/druid/security/code-scanning/10774)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]