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

Make aql query more robust #280

Merged
merged 4 commits into from
Jun 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/components/ConnectivityQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@
</v-col>
<v-col class="pa-2">
<v-autocomplete
v-model="edgeVariable[i/2]"
v-model="edgeVariable[(i-2)/2]"
:items="edgeVariableItems"
dense
/>
</v-col>
<v-col class="pa-2">
<v-autocomplete
v-model="edgeVariableValue[i/2]"
:items="edgeVariableOptions[i/2]"
v-model="edgeVariableValue[(i-2)/2]"
:items="edgeVariableOptions[(i-2)/2]"
dense
/>
</v-col>
Expand Down Expand Up @@ -147,20 +147,23 @@ export default {
for (let i = 0; i < selectedHops.value + 1; i += 1) {
const queryOperator = nodeQuerySelection.value[i] === 'is (exact)' ? '==' : '=~';
if (i === 0) {
pathQueryText += `FILTER p.vertices[${i}].${nodeVariable.value[i]} ${queryOperator} '${nodeVariableValue.value[i]}'`;
} else {
pathQueryText += ` AND p.vertices[${i}].${nodeVariable.value[i]} ${queryOperator} '${nodeVariableValue.value[i]}'`;
pathQueryText += `FILTER UPPER(p.vertices[${i}].${nodeVariable.value[i]}) ${queryOperator} UPPER('${nodeVariableValue.value[i]}')`;
} else if (nodeVariableValue.value[i] !== '') {
pathQueryText += ` AND UPPER(p.vertices[${i}].${nodeVariable.value[i]}) ${queryOperator} UPPER('${nodeVariableValue.value[i]}')`;
}
}
for (let i = 0; i < selectedHops.value; i += 1) {
if (i === 0 && edgeVariableValue.value[i] !== '') {
pathQueryText += ` FILTER p.edges[${i}].${edgeVariable.value[i]} == '${edgeVariableValue.value[i]}'`;
} else if (edgeVariableValue.value[i] !== '') {
pathQueryText += ` AND p.edges[${i}].${edgeVariable.value[i]} == '${edgeVariableValue.value[i]}'`;
}
}
Comment on lines +155 to 161
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't these have query operators?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because edge selection will always be precise for the marclab... But now I'm not sure if it makes sense in other use cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see one small change you can make to simplify things even more with the query

In general, I think we should offer more query operators for both nodes and edges. I can see use cases for >, <, !=, etc. Is that something you're considering?

I verified:

  • * for nodes + edges
  • edge filtering
  • remove unnecessary arguments
  • make query not case sensitive

I can't run a query that queries the network for edge.value == 15 with no nodes. I'm not sure if that's a query we should allow, or not, though. (looks like this is covered by #283)

Yes so currently the first node needs to be selected in order to run a query successfully.
I've also created an issue to address numerical queries #284 , which I think we agreed on slack will be a later functionality

const queryOperator = nodeQuerySelection.value[0] === 'is (exact)' ? '==' : '=~';
const aqlQuery = `
let startNodes = (FOR n in [${store.state.nodeTableNames}][**] FILTER n.${nodeVariable.value[0]} ${queryOperator} '${nodeVariableValue.value[0]}' RETURN n)
let paths = (FOR n IN startNodes FOR v, e, p IN 1..${selectedHops.value} ANY n GRAPH '${store.state.networkName}' ${pathQueryText} RETURN {nodes: p.vertices[*], paths: p})
let all_nodes = (for p in paths RETURN p.nodes)
let nodes_first = (for p in paths RETURN p.nodes[0])
let nodes_last = (for p in paths RETURN p.nodes[${selectedHops.value}])
let path = (for p in paths RETURN p.paths)
RETURN {all_nodes: UNIQUE(all_nodes[**]), nodes_first: UNIQUE(nodes_first), nodes_last: UNIQUE(nodes_last), paths: path}
let startNodes = (FOR n in [${store.state.nodeTableNames}][**] FILTER UPPER(n.${nodeVariable.value[0]}) ${queryOperator} UPPER('${nodeVariableValue.value[0]}') RETURN n)
let paths = (FOR n IN startNodes FOR v, e, p IN 1..${selectedHops.value} ANY n GRAPH '${store.state.networkName}' ${pathQueryText} RETURN {paths: p})
RETURN {paths: paths[**].paths}
`;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down