Closed frostyfan109 closed 4 years ago
Read above issue and realized it was hard to follow. This is a rewording.
For the query:
set $citric_acid = "CHEBI:30769"
select chemical_substance->gene->disease
from "/graph/gamma/quick"
where chemical_substance=[$citric_acid, "CHEBI:26836", "CHEBI:26078"]
it does concept.set_nodes(["$citric_acid", "CHEBI:26836", "CHEBI:26078"])
.
Then, in expand_nodes
, it only looks at concept.nodes[0]
even though concept.nodes
has 3 elements.
Greater detail can be found in original issue.
Tentatively closing this issue. Commit 752489f fixes this, but I'm unsure why I hadn't already done this beforehand. I remember creating a fix with a similar approach to how I did it in the aforementioned commit, but I had to undo it for some reason.
Problem
expand_nodes
is called withinSelectStatement.generate_questions
to convert set statement variables into literal values. When a list containing variables is passed into a where clause,generate_questions
fails to properly expand variables.Example (important for explanation)
In this example, chemical_substance should evaluate to
["CHEBI:30769", "CHEBI:26836", "CHEBI:26078"]
. Obviously, it doesn't due to this bug.What does the example evaluate to?
For
where chemical_substance=[$citric_acid, "CHEBI:26836", "CHEBI:26078"]
, it becomes:["CHEBI:30769"]
. When the first element in the list is a variable, all the following elements are deleted.For
where chemical_substance=["CHEBI:26836", $citric_acid, "CHEBI:26078"]
, it becomes:["CHEBI:26836", "$citric_acid", "CHEBI:26078"]
. When the list contains a variable that is not the first element, the variable is not resolved.Explanation
When a list is passed into a where clause, it calls
concept.set_nodes(list_value)
. For this example, let's clarify the following:Then, in
generate_questions
, it callsself.expand_nodes(interpreter, concept)
. Inexpand_nodes
, it doesvalue = concept.nodes[0] if len(concept.nodes) > 0 else None
. Remember,expand_nodes
is going to takevalue
, check if it's a set statement variable, and, if so, replace it with its actual value.Now, the problem with this is that if
concept.set_nodes(list_value)
is called, thenconcept.nodes
is a list. So, if only the first element is checked for being a variable, then there's some obvious issues.When the first element is a variable, then
expand_nodes
doesconcept.set_nodes(value)
, which overrides the rest of the elements in the list. Now,concept.nodes == ["CHEBI:30769"]
($citric_acid). We've lost "CHEBI:26836" and "CHEBI:26078".When the first element isn't a variable, but there are variables in the list,
expand_nodes
only checks the first element in the list, so the variables never get resolved.