Streams: Support subqueries with multiple parameters #416
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Evaluating streams using subqueries with multiple parameters is currently broken in two ways. To illustrate this, consider this example taken from a report on Discord:
This subquery has two parameter match clauses: the
INoperator and the direct equals.The first issue is that we used to compute the
WHEREclause of the subquery withSqlTools.compileClause. That method will merge theANDinto a singleParameterMatchClause, which is valid for bucket definitions but not for streams! Since each parameter is an explicit object with streams, this would cause two parameters to be derived from the sameParameterMatchClause, which then causes values for the two parameters to get duplicated:evaluateParameterRow(projectInvitation, {project: 'p', appliedTo: '[1,2]'})yields lookup with keys[1,p], [1,p], [2, p], [2, p].[1, p], [2, p].The reason we used
compileClauseis that we only support a subset of filter operators forWHEREclauses in subqueries, and those happened to align with whatSqlTools.compileClausewould support. So the first part of the fix is to compile subquery predicates with the same logic as we compile the outer query, and then applying a validator to ensure there are no nested subqueries or other unsupported filters.A second issue is that
StreamVariant.findStaticInstantiations(used inSubquery.compileEvaluator) was missing a transform from "list of values per parameter" to "list of lookups" via the cartesian product. That's only relevant for subqueries with more than one parameter:[1], [p].[1, p].