Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Implemented
-
qpid-java-broker-8.0.6
-
None
Description
Current version of broker query engine doesn't support subqueries referencing fields from the parent query. To support this possibility it's needed to pass the context from parent query to the subquery.
To pass context from parent query to the subquery it's needed to add current stream item and it's alias to the Evaluation context. It can be done using Stream#peek() inside of SelectEvaluator#evaluate().
As the aliases from parent query will affect subquery sorting, it also will be required to consider added aliases in QueryEvaluator#createComparator().
This should allow to use values from parent queries in subqueries, e.g.:
SELECT id, name, (SELECT name FROM connection WHERE SUBSTRING(name, 1, POSITION(']' IN name)) = '[' + SUBSTRING(c.name, 1, POSITION('|' IN c.name) - 1) + ']') as connection, (SELECT id FROM connection WHERE SUBSTRING(name, 1, POSITION(']' IN name)) = '[' + SUBSTRING(c.name, 1, POSITION('|' IN c.name) - 1) + ']') as connectionId, (SELECT name FROM session WHERE id = c.session.id) as session FROM consumer c
or
SELECT
name,
destination,
(SELECT id FROM queue WHERE name = b.destination) AS destinationId,
exchange,
(SELECT id FROM exchange WHERE name = b.exchange) AS exchangeId
FROM binding b
WHERE name = 'broadcast.amqp_user1.xxx.#'
or
SELECT alias, (SELECT COUNT(id) FROM queue WHERE POSITION(UPPER(c.alias) IN name) > 0) AS queueCount FROM certificate c
This would allow to retrieve values from associated entities without firing additional queries.