File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -141,7 +141,26 @@ void WhereClause::prependAndTerm(std::shared_ptr<BoolTerm> t) {
141141 throw std::logic_error (" Term of first OR term is not an AND term; there is no global AND term" );
142142 }
143143 } else {
144- throw std::logic_error (" There is more than term in the root OR term; can't pick a global AND term" );
144+ // We've hit the following case:
145+ //
146+ // WHERE ... OR .. OR ...
147+ //
148+ // A solution is to construct the new root and the global AndTerm.
149+ // Push down the current root as the only child of the AndTerm.
150+ // In essence, we're replacing the following constraints:
151+ //
152+ // WHERE ... OR .. OR ...
153+ //
154+ // With:
155+ //
156+ // WHERE <BoolTerm> AND (... OR .. OR ...)
157+ //
158+ auto newRootOrTerm = std::make_shared<OrTerm>();
159+ andTerm = std::make_shared<AndTerm>();
160+ andTerm->addBoolTerm (_rootOrTerm);
161+ newRootOrTerm->addBoolTerm (andTerm);
162+ _rootOrTerm = newRootOrTerm;
163+ andTerm = std::dynamic_pointer_cast<AndTerm>(_rootOrTerm->_terms [0 ]);
145164 }
146165
147166 if (!andTerm->merge (*t, AndTerm::PREPEND)) {
You can’t perform that action at this time.
0 commit comments