Skip to content

GH-3707: Preserve subquery when adding optional QueryBuilder - #4218

Open
arimu1 wants to merge 1 commit into
apache:mainfrom
arimu1:fix/3707-querybuilder-optional-where
Open

arimu1 wants to merge 1 commit into
apache:mainfrom
arimu1:fix/3707-querybuilder-optional-where

Conversation

@arimu1

@arimu1 arimu1 commented Sep 12, 2026

Copy link
Copy Markdown

Fixes #3707

Summary

  • addOptional(AbstractQueryBuilder) now wraps the nested builder as an OPTIONAL { SELECT ... WHERE ... } subquery via ElementSubQuery, instead of copying only its WHERE ElementGroup.
  • Applies to SELECT/ASK/CONSTRUCT/DESCRIBE/WHERE builders and UPDATE WhereQuadHolder.

Problem

Adding a nested SelectBuilder with select.addOptional(selectOptional) dropped the inner SELECT variables and produced a flat optional BGP (reporter’s ORDER BY / subquery use case).

Test plan

Wrap nested query builders in an optional subquery element instead of
merging only their WHERE patterns, so SELECT variables are retained.

Fixes apache#3707
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Select clause disappear from where clause

1 participant