nick-boss-tech opened a new pull request, #5148: URL: https://github.com/apache/solr/pull/5148
🤖 *AI text below* 🤖 *(posted on behalf of Nick Shanin)* https://issues.apache.org/jira/browse/SOLR-9396 ## What happens today **A `[subquery]` fails when it reads a `$row.` field that the outer `fl` does not list.** A subquery can read a value from the parent document with a reference such as `depts.q={!term f=dept_id_s v=$row.dept_id}`. The transformer does not ask the index for `dept_id`. If the outer `fl` does not list it, the field is missing from the document, and the transformer fails with `while invoking depts:[subquery] on doc=...` ([SubQueryAugmenterFactory.java L344-L365 before this change](https://github.com/nick-boss-tech/solr/blob/c3cdf7b46e8cfff3673f76d881f32cf8e7b00622/solr/core/src/java/org/apache/solr/response/transform/SubQueryAugmenterFactory.java#L344-L365)). The ticket's example fails with the same message. Its workaround is to list every referenced field in `fl`, or to use `fl=*`. ## What this change does **The transformer asks the index for the fields its subquery references.** When the transformer is created, it scans the subquery's own parameter values for `$row.field` and `${row.field}` references and adds those field names to the fields the request reads ([SubQueryAugmenterFactory.java L307-L362](https://github.com/nick-boss-tech/solr/blob/a5ab2eda4e6a9bcad5668653e80c0d0b510e6388/solr/core/src/java/org/apache/solr/response/transform/SubQueryAugmenterFactory.java#L307-L362)). The response shape does not change. A field that `fl` does not list is read for the subquery but is still not written to the response ([TestSubQueryTransformer.java L257-L283](https://github.com/nick-boss-tech/solr/blob/a5ab2eda4e6a9bcad5668653e80c0d0b510e6388/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformer.java#L257-L283)). A request that already lists the field sees no change. The cost is one extra field read for each referenced field that `fl` did not name. ## Proof **The new test fails on the base code and passes with this change.** - [TestSubQueryTransformer.testRowFieldNotInFl](https://github.com/nick-boss-tech/solr/blob/a5ab2eda4e6a9bcad5668653e80c0d0b510e6388/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformer.java#L257-L283) is new. The base run used the base `SubQueryAugmenterFactory.java` with this test file. In that run the new test was the only failure in TestSubQueryTransformer: 1 of 11 failed, and the other 10 passed. - At head a5ab2eda4e6a9bcad5668653e80c0d0b510e6388, verified 2026-10-05: TestSubQueryTransformer 11 of 11, TestSubQueryTransformerCrossCore 3 of 3, TestSubQueryTransformerDistrib 1 of 1, and TestChildDocTransformer 2 of 2 pass. ## A choice to check **The transformer reads `$row.field` and `${row.field}` names from the subquery's own parameters, not from every field of the request.** Options considered: scan the subquery's parameter values for `$row.field` and `${row.field}` references (implemented), or read every field whenever a `[subquery]` is present. The scan reads only the fields a subquery names. It cannot see a reference that reaches the subquery through another request parameter (see Limits). Reading every field needs no scan, but then every subquery reads every field. Was the scan the right call? ## Limits **The scan has two limits, and `/get` has no test.** - Only a `$row.field` or `${row.field}` reference written in the subquery's own parameters is scanned. A reference that reaches the subquery through another request parameter is not scanned, so that field must still be listed in `fl`. - The scan also matches the `${row.` spelling. The query parser never treats that spelling as a row reference, so the scan can add a field read that nothing uses. Narrowing the pattern to the `$row.` spelling only is a named follow-up: a small change in `SubQueryAugmenterFactory` with a focused run of the subquery transformer tests. - The real-time get path (`/get`) uses the same field parsing, but no test covers it. Changelog: [changelog/unreleased/SOLR-9396-subquery-row-fields.yml](https://github.com/nick-boss-tech/solr/blob/a5ab2eda4e6a9bcad5668653e80c0d0b510e6388/changelog/unreleased/SOLR-9396-subquery-row-fields.yml) ### AI assistance AI agents assisted with research, implementation, review, and drafting. Nick Shanin directed the work and takes responsibility for this contribution. -- 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]
