Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a NULL test when compiling iterator expressions #3012

Merged
merged 1 commit into from Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions edb/pgsql/compiler/clauses.py
Expand Up @@ -26,6 +26,7 @@
from edb.pgsql import ast as pgast
from edb.pgsql import types as pg_types

from . import astutils
from . import context
from . import dispatch
from . import output
Expand Down Expand Up @@ -215,6 +216,17 @@ def compile_iterator_expr(
query, iterator_expr.path_id, aspect='value', ctx=ctx)
iterator_query = iterator_rvar.query

# If the iterator value is nullable, add a null test. This
# makes sure that we don't spuriously produce output when
# iterating over options pointers.
assert isinstance(iterator_query, pgast.SelectStmt)
iterator_var = pathctx.get_path_value_var(
iterator_query, path_id=iterator_expr.path_id, env=ctx.env)
if iterator_var.nullable:
iterator_query.where_clause = astutils.extend_binop(
iterator_query.where_clause,
pgast.NullTest(arg=iterator_var, negated=True))

# Regardless of result type, we use transient identity,
# for path identity of the iterator expression. This is
# necessary to maintain correct correlation for the state
Expand Down
17 changes: 17 additions & 0 deletions tests/test_edgeql_select.py
Expand Up @@ -5475,6 +5475,23 @@ async def test_edgeql_select_for_03(self):
sort=lambda x: x['number'],
)

async def test_edgeql_select_for_04(self):
await self.assert_query_result(
r'''
SELECT Issue {
asdf := (
FOR z IN {.due_date} UNION (1)
)
}
FILTER .name = 'Release EdgeDB';
''',
[
{
'asdf': None
}
],
)

async def test_edgeql_select_json_01(self):
await self.assert_query_result(
r'''
Expand Down