Skip to content

Commit 2e67b0c

Browse files
skearnesclaude
andauthored
Uniformly schema-qualify ord-schema tables in queries (#190)
The reaction queries mixed `ord.`-qualified and bare table names in their FROM/JOIN clauses (e.g. `FROM reaction` vs `FROM ord.reaction`, `JOIN percentage` vs `JOIN ord.percentage`). This is cosmetic, not a correctness issue: the connection sets `search_path=public,ord` (see search.py and conftest.py), so bare ord-schema tables already resolve. Make the qualification uniform by prefixing all ord-schema tables with `ord.` in FROM/JOIN clauses, matching the convention already used by fetch_reactions and _fetch_dataset_most_used_smiles. The rdkit-cartridge tables keep their `rdkit.` prefix (rdkit is not in the search_path), and bare table-alias column references are left as-is (the dominant style). No behavior change; the 51 queries_test.py / search_test.py cases pass against the test Postgres. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 789b804 commit 2e67b0c

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

ord_interface/api/queries.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def query_and_parameters(self) -> tuple[str, list]:
8989
query = """
9090
SELECT DISTINCT reaction.reaction_id
9191
FROM ord.reaction
92-
JOIN dataset ON dataset.id = reaction.dataset_id
92+
JOIN ord.dataset ON dataset.id = reaction.dataset_id
9393
WHERE dataset.dataset_id = ANY (%s)
9494
"""
9595
return query, [self._dataset_ids]
@@ -139,7 +139,7 @@ def query_and_parameters(self) -> tuple[str, list]:
139139
"""Returns the query and any query parameters."""
140140
query = """
141141
SELECT DISTINCT reaction.reaction_id
142-
FROM reaction
142+
FROM ord.reaction
143143
JOIN rdkit.reactions ON rdkit.reactions.id = reaction.rdkit_reaction_id
144144
WHERE rdkit.reactions.reaction @> reaction_from_smarts(%s)
145145
"""
@@ -172,7 +172,7 @@ def query_and_parameters(self) -> tuple[str, list]:
172172
SELECT DISTINCT reaction.reaction_id
173173
FROM ord.reaction
174174
JOIN ord.reaction_outcome on reaction_outcome.reaction_id = reaction.id
175-
JOIN percentage on percentage.reaction_outcome_id = reaction_outcome.id
175+
JOIN ord.percentage on percentage.reaction_outcome_id = reaction_outcome.id
176176
"""
177177
if self._min_conversion is not None and self._max_conversion is not None:
178178
query += "WHERE percentage.value >= %s AND percentage.value <= %s\n"
@@ -210,7 +210,7 @@ def query_and_parameters(self) -> tuple[str, list]:
210210
JOIN ord.reaction_outcome on reaction_outcome.reaction_id = reaction.id
211211
JOIN ord.product_compound on product_compound.reaction_outcome_id = reaction_outcome.id
212212
JOIN ord.product_measurement on product_measurement.product_compound_id = product_compound.id
213-
JOIN percentage on percentage.product_measurement_id = product_measurement.id
213+
JOIN ord.percentage on percentage.product_measurement_id = product_measurement.id
214214
WHERE product_measurement.type = 'YIELD'
215215
"""
216216
params = []
@@ -250,7 +250,7 @@ def query_and_parameters(self) -> tuple[str, list]:
250250
query = """
251251
SELECT DISTINCT reaction.reaction_id
252252
FROM ord.reaction
253-
JOIN reaction_provenance ON reaction_provenance.reaction_id = reaction.id
253+
JOIN ord.reaction_provenance ON reaction_provenance.reaction_id = reaction.id
254254
WHERE reaction_provenance.doi = ANY (%s)
255255
"""
256256
return query, [self._dois]
@@ -307,14 +307,14 @@ def query_and_parameters(self) -> tuple[str, list]:
307307
"""Returns the query and any query parameters."""
308308
if self._target == ReactionComponentQuery.Target.INPUT:
309309
mols_sql = """
310-
JOIN reaction_input ON reaction_input.reaction_id = reaction.id
311-
JOIN compound ON compound.reaction_input_id = reaction_input.id
310+
JOIN ord.reaction_input ON reaction_input.reaction_id = reaction.id
311+
JOIN ord.compound ON compound.reaction_input_id = reaction_input.id
312312
JOIN rdkit.mols ON rdkit.mols.id = compound.rdkit_mol_id
313313
"""
314314
else:
315315
mols_sql = """
316-
JOIN reaction_outcome ON reaction_outcome.reaction_id = reaction.id
317-
JOIN product_compound ON product_compound.reaction_outcome_id = reaction_outcome.id
316+
JOIN ord.reaction_outcome ON reaction_outcome.reaction_id = reaction.id
317+
JOIN ord.product_compound ON product_compound.reaction_outcome_id = reaction_outcome.id
318318
JOIN rdkit.mols ON rdkit.mols.id = product_compound.rdkit_mol_id
319319
"""
320320
if self._match_mode == ReactionComponentQuery.MatchMode.EXACT:

0 commit comments

Comments
 (0)