Skip to content

Commit

Permalink
darker and mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen committed Feb 2, 2024
1 parent 3effb2d commit ff70cf8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
5 changes: 1 addition & 4 deletions edb/pgsql/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ def compile_ir_to_sql_tree(
Mapping[Tuple[irast.PathId, str], pgast.PathRangeVar]
] = None,
external_rels: Optional[
Mapping[
irast.PathId,
Tuple[pgast.BaseRelation | pgast.CommonTableExpr, Tuple[str, ...]],
]
Mapping[irast.PathId, context.ExternalRelsEntry]
] = None,
backend_runtime_params: Optional[pgparams.BackendRuntimeParams]=None,
) -> CompileResult:
Expand Down
20 changes: 12 additions & 8 deletions edb/pgsql/compiler/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ class RelOverlays:
def copy(self) -> RelOverlays:
return RelOverlays(type=self.type, ptr=self.ptr)

if TYPE_CHECKING:
# external rels entries map to:
# - the rel that represents that path id,
# - aspects provided by the rel,
# - additional path ids and aspects provided
ExternalRelsEntry = Tuple[
pgast.BaseRelation | pgast.CommonTableExpr,
Tuple[str, ...],
Tuple[Tuple[irast.PathId, Tuple[str, ...]], ...],
]


class CompilerContextLevel(compiler.ContextLevel):
#: static compilation environment
Expand Down Expand Up @@ -290,14 +301,7 @@ class CompilerContextLevel(compiler.ContextLevel):
rel_overlays: RelOverlays

#: Mapping from path ids to "external" rels given by a particular relation
external_rels: Mapping[
irast.PathId,
Tuple[
pgast.BaseRelation | pgast.CommonTableExpr,
Tuple[str, ...],
Tuple[Tuple[irast.PathId, Tuple[str, ...]], ...]
]
]
external_rels: Mapping[irast.PathId, ExternalRelsEntry]

#: The CTE and some metadata of any enclosing iterator-like
#: construct (which includes iterators, insert/update, and INSERT
Expand Down
13 changes: 11 additions & 2 deletions edb/pgsql/compiler/dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3229,12 +3229,21 @@ def compile_trigger(
tctx.external_rels = dict(tctx.external_rels)
# new_path is just the contents_cte
tctx.external_rels[new_path] = (
contents_cte, ('value', 'source'), ())
contents_cte,
('value', 'source'),
(),
)
if old_path:
# old_path is *also* the contents_cte, but without a source
# aspect, so we need to include the real database back in.
tctx.external_rels[old_path] = (
contents_cte, ('value', 'identity',), ())
contents_cte,
(
'value',
'identity',
),
(),
)

# This is somewhat subtle: we merge *every* DML into
# the "None" overlay, so that all the new database state shows
Expand Down
1 change: 1 addition & 0 deletions edb/pgsql/compiler/relgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ def process_set_as_link_property_ref(
newctx.rel, link_path_id, aspect='source', ctx=newctx
)
if link_rvar is None:
assert link_prefix.rptr is not None
link_rvar = relctx.new_pointer_rvar(
link_prefix.rptr, src_rvar=src_rvar,
link_bias=True, ctx=newctx)
Expand Down
21 changes: 13 additions & 8 deletions edb/pgsql/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4882,7 +4882,7 @@ def _compile_conversion_expr(
)
src_rel.path_outputs[(src_path_id, 'iterator')] = \
pgast.ColumnRef(name=('id',))
external_rels = {
ext_rels: Dict[irast.PathId, compiler.context.ExternalRelsEntry] = {
src_path_id: (src_rel, ('source', 'identity', 'iterator'), ())
}

Expand All @@ -4898,14 +4898,19 @@ def _compile_conversion_expr(
src_rel.path_outputs[(tgt_path_id, 'iterator')] = \
pgast.ColumnRef(name=('id',))

external_rels[ptr_path_id] = \
(src_rel, ('source'), ())
ext_rels[ptr_path_id] = (src_rel, ('source',), ())
if ptr_table:
external_rels[tgt_path_id] = \
(src_rel, ('identity', 'source', 'value', 'iterator'), ((ptr_path_id, ('source', 'identity')),))
ext_rels[tgt_path_id] = (
src_rel,
('identity', 'source', 'value', 'iterator'),
((ptr_path_id, ('source', 'identity')),),
)
else:
external_rels[tgt_path_id] = \
(src_rel, ('identity', 'value', 'iterator'), ())
ext_rels[tgt_path_id] = (
src_rel,
('identity', 'value', 'iterator'),
(),
)

# Wrap the expression into a select with iterator, so DML and
# volatile expressions are executed once for each object.
Expand Down Expand Up @@ -4979,7 +4984,7 @@ def _compile_conversion_expr(
sql_res = compiler.compile_ir_to_sql_tree(
ir,
output_format=compiler.OutputFormat.NATIVE_INTERNAL,
external_rels=external_rels,
external_rels=ext_rels,
backend_runtime_params=context.backend_runtime_params,
)
sql_tree = sql_res.ast
Expand Down
8 changes: 2 additions & 6 deletions tests/test_edgeql_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3038,10 +3038,7 @@ async def test_edgeql_ddl_ptr_using_dml_03(self):

# only one Goodbye object, as only one link exists, so only one cast is
# performed
await self.assert_query_result(
'select Goodbye',
[{}]
)
await self.assert_query_result('select Goodbye', [{}])
await self.assert_query_result(
'select World { hell }',
tb.bag([{'hell': None}, {'hell': {'id': uuid.UUID}}])
Expand Down Expand Up @@ -3084,8 +3081,7 @@ async def test_edgeql_ddl_ptr_using_dml_05(self):
"""
)
await self.assert_query_result(
'SELECT World { foo }',
[{"foo": "hello"}]
'SELECT World { foo }', [{"foo": "hello"}]
)

await self.con.execute(
Expand Down

0 comments on commit ff70cf8

Please sign in to comment.