Skip to content

Instantly share code, notes, and snippets.

@vejvarm
Created May 9, 2024 02:59
Show Gist options
  • Save vejvarm/43dda9ee14e90f4d2d9ece41fbad9346 to your computer and use it in GitHub Desktop.
Save vejvarm/43dda9ee14e90f4d2d9ece41fbad9346 to your computer and use it in GitHub Desktop.
Complex Parser example with FILTER, HAVING, GROUP BY and conditional operators (&&/||)
{
"sPREFIX": {},
"RETURN": [
"T1_school_name"
],
"TRIPLES": {
"T1": {
"label": "ROOT__school",
"school__school_name": "T1_school_name"
},
"T2": {
"label": "ROOT__budget",
"budget__SCHOOL_ID": "T1",
"budget__budgeted": "T2_budgeted"
},
"T3": {
"endowment__amount": "T3_amount",
"label": "ROOT__endowment",
"endowment__SCHOOL_ID": "T1"
},
"T4": {
"label": "ROOT__school",
"school__school_name": "T4_school_name"
}
},
"WHERE": [
"__agg__0, >, 100"
],
"vars": [
"T3",
"T2_budgeted",
"T2",
"T1_school_name",
"T4_school_name",
"T4",
"T1",
"T3_amount"
],
"aggregates": {
"__agg__0": "sum(T2_budgeted)",
"__agg__1": "CONCAT(T2_budgeted)",
"__agg__2": "sum(T2_budgeted)",
"__agg__3": "sum(T3_amount)",
"__agg__4": "sum(T3_amount)"
},
"AS": {},
"prefixed": [
"budget__SCHOOL_ID",
"endowment__amount",
"ROOT__school",
"ROOT__budget",
"budget__budgeted",
"school__school_name",
"endowment__SCHOOL_ID",
"ROOT__endowment"
],
"GROUP BY": [
"T1_school_name"
],
"ORDER BY": {},
"LIMIT": null,
"OFFSET": null,
"HAVING": [
"(, (, __agg__1, >, 100, &&, __agg__2, <, 200, ), ||, __agg__3, >, 100, )",
"__agg__4, >, 10",
[
"T1_school_name",
"not in",
"T4_school_name"
]
]
}
MATCH (T2:ROOT__budget)-[:budget__SCHOOL_ID]->(T1:ROOT__school)
MATCH (T3:ROOT__endowment)-[:endowment__SCHOOL_ID]->(T1:ROOT__school)
MATCH (T4:ROOT__school)
WHERE (sum(T2_budgeted) > 100)
WITH CONCAT(T2_budgeted) AS __agg__1,
sum(T2_budgeted) AS __agg__2,
sum(T3_amount) AS __agg__3,
sum(T3_amount) AS __agg__4
WHERE (__agg__1 > 100 AND __agg__2 < 200)
OR (__agg__3 > 100)
AND (__agg__4 > 10)
AND NOT T1_school_name IN T4_school_name
SELECT ?T1_school_name
WHERE {
?T1 a :school .
?T2 a :budget .
?T2 budget:SCHOOL_ID ?T1 .
?T1 school:school_name ?T1_school_name .
?T2 budget:budgeted ?T2_budgeted .
?T3 endowment:amount ?T3_amount .
?T3 a :endowment .
?T3 endowment:SCHOOL_ID ?T1 .
?T1 school:school_name ?T1_school_name .
?T2 budget:budgeted ?T2_budgeted .
?T3 endowment:amount ?T3_amount .
?T4 a :school .
?T4 school:school_name ?T4_school_name .
FILTER (sum(?T2_budgeted) > 100) .
}
GROUP BY ?T1_school_name
HAVING (((CONCAT( ?T2_budgeted ) > 100 && sum(?T2_budgeted) < 200) || sum(?T3_amount) > 100)) (sum( ?T3_amount) > 10) (?T1_school_name not in (?T4_school_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment