Skip to content

Commit 5679006

Browse files
committed
Initial draft: webinterface
1 parent c4be7fc commit 5679006

File tree

5 files changed

+271
-86
lines changed

5 files changed

+271
-86
lines changed

backend/backend.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
DATA_ROOT = os.environ['DATA_ROOT'] # "/home/michael/projects/code/resources/data/"
1818
BINARY_DIR = os.environ['LINGODB_BINARY_DIR'] # "/home/michael/projects/code/build/lingodb-release/"
19+
SCRIPT_DIR = os.environ['LINGODB_SCRIPT_DIR'] # "/home/michael/projects/code/build/lingodb-release/"
1920
app = FastAPI()
2021
api_app = FastAPI(title="api app")
2122
if "WEBINTERFACE_LOCAL" in os.environ:
@@ -95,10 +96,13 @@ def analyze(query_str, db):
9596
print(BINARY_DIR+"run-sql "+query_file+" "+ DATA_ROOT + db)
9697
output = subprocess.check_output([BINARY_DIR+"run-sql",query_file, DATA_ROOT + db], universal_newlines=True, stderr=subprocess.STDOUT, timeout=20,
9798
env={"LINGODB_SNAPSHOT_DIR": snapshotdir, "LINGODB_SNAPSHOT_PASSES": "true", "LINGODB_SNAPSHOT_LEVEL":"important", "LINGODB_EXECUTION_MODE":"NONE"})
98-
result = subprocess.run(f"{BINARY_DIR}mlir-db-opt --strip-debuginfo {snapshotdir}/important-snapshot-qopt.mlir > {snapshotdir}/important-snapshot-qopt.mlir.alt",
99+
result = subprocess.run(f"bash {SCRIPT_DIR}/clean-snapshot.sh {BINARY_DIR} {snapshotdir}/important-snapshot-qopt.mlir {snapshotdir}/important-snapshot-qopt.mlir.alt",
99100
universal_newlines=True, stderr=subprocess.STDOUT, shell=True)
100-
result = subprocess.run(f"{BINARY_DIR}mlir-db-opt --strip-debuginfo {snapshotdir}/important-snapshot-subop-opt.mlir > {snapshotdir}/important-snapshot-subop-opt.mlir.alt",
101+
print(result)
102+
result = subprocess.run(f"bash {SCRIPT_DIR}/clean-snapshot.sh {BINARY_DIR} {snapshotdir}/important-snapshot-subop-opt.mlir {snapshotdir}/important-snapshot-subop-opt.mlir.alt",
101103
universal_newlines=True, stderr=subprocess.STDOUT, shell=True)
104+
print(os.listdir(snapshotdir))
105+
102106
relalg_plan = subprocess.check_output([BINARY_DIR + "mlir-to-json", snapshotdir+"/important-snapshot-qopt.mlir.alt"],
103107
universal_newlines=True, stderr=subprocess.STDOUT)
104108
subop_plan = subprocess.check_output([BINARY_DIR + "mlir-subop-to-json", snapshotdir+"/important-snapshot-subop-opt.mlir.alt"],
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
const enumEdges = (data, edgesDown, edgesUp) => {
2+
console.log("enumEdges",data)
3+
if (Array.isArray(data)) {
4+
data.forEach((child) => {
5+
enumEdges(child, edgesDown, edgesUp)
6+
})
7+
} else if (data.type === "op") {
8+
if (data.mappedId) {
9+
console.log("setting", data.id, data.mappedId)
10+
edgesUp[data.id] = data.mappedId
11+
if (!edgesDown[data.mappedId]){
12+
edgesDown[data.mappedId] = []
13+
}
14+
edgesDown[data.mappedId].push(data.id)
15+
}
16+
data.children.forEach((child) => {
17+
enumEdges(child, edgesDown, edgesUp)
18+
})
19+
} else if (data.type === "block") {
20+
data.children.forEach((child) => {
21+
enumEdges(child, edgesDown, edgesUp)
22+
})
23+
}
24+
}
25+
26+
const indexOps = (data, indexed) => {
27+
if (Array.isArray(data)) {
28+
data.forEach((child) => {
29+
indexOps(child, indexed)
30+
})
31+
} else if (data.type === "op") {
32+
indexed[data.id] = data
33+
data.children.forEach((child) => {
34+
indexOps(child, indexed)
35+
})
36+
} else if (data.type === "block") {
37+
data.children.forEach((child) => {
38+
indexOps(child, indexed)
39+
})
40+
}
41+
}
42+
const collectChildren = (data, res) => {
43+
if (Array.isArray(data)) {
44+
data.forEach((child) => {
45+
res.push(child.id)
46+
collectChildren(child, res)
47+
})
48+
} else if (data.type === "op") {
49+
res.push(data.id)
50+
data.children.forEach((child) => {
51+
collectChildren(child, res)
52+
});
53+
} else if (data.type === "block") {
54+
data.children.forEach((child) => {
55+
collectChildren(child, res)
56+
});
57+
}
58+
}
59+
60+
61+
export const goUp = (opId, relalgBaseRef, info) => {
62+
let collectedChildren = []
63+
collectChildren(info.indexedOps[opId], collectedChildren)
64+
let res = []
65+
collectedChildren.forEach((childId) => {
66+
67+
let curr = childId
68+
while (curr) {
69+
let op = info.indexedOps[curr]
70+
if (op.id.startsWith(relalgBaseRef + ":")) {
71+
res.push(op.id)
72+
break
73+
}
74+
curr = info.edgesUp[curr]
75+
}
76+
})
77+
return res;
78+
79+
}
80+
81+
export const goDown = (opId, subOpBaseRef, info) => {
82+
let collectedChildren = []
83+
collectChildren(info.indexedOps[opId], collectedChildren)
84+
console.log(collectedChildren)
85+
console.log(info)
86+
let res = []
87+
const descend = (curr)=>{
88+
let op = info.indexedOps[curr]
89+
if (op.id.startsWith(subOpBaseRef + ":")) {
90+
res.push(op.id)
91+
return
92+
}
93+
const next=info.edgesDown[curr]
94+
if(next){
95+
next.forEach(n=>{
96+
descend(n)
97+
})
98+
}
99+
100+
}
101+
collectedChildren.forEach((childId) => descend(childId))
102+
return res;
103+
}
104+
105+
export const analyzeLayers = (layers) => {
106+
107+
let tmpEdgesDown = new Map
108+
let tmpEdgesUp = new Map
109+
const newIndexOps = {}
110+
layers.forEach((pass) => {
111+
console.log(pass.parsed)
112+
enumEdges(pass.parsed, tmpEdgesDown, tmpEdgesUp)
113+
indexOps(pass.parsed, newIndexOps)
114+
})
115+
116+
console.log(tmpEdgesUp)
117+
return {edgesUp: tmpEdgesUp, edgesDown: tmpEdgesDown, indexedOps: newIndexOps};
118+
119+
}
120+
121+
export const getBaseReference = (file) => {
122+
return file.split("/").pop().split(".")[0]
123+
}

frontend/packages/common/PlanViewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const PlanViewer = memo(({
153153
<div style={{
154154
backgroundColor: "lightgray",
155155
position: "relative",
156-
}}>
156+
}} onClick={(e)=>{e.stopPropagation()}}>
157157
<svg style={{
158158
backgroundColor: "lightgray",
159159
userSelect: "none",

frontend/packages/common/SubOpPlanViewer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const Expression = ({data}) => {
5656
}
5757
}
5858

59-
const RenderedNode = ({data, x, y}) => {
59+
const RenderedNode = ({data, x, y, onOperatorSelect, selectedOps}) => {
6060
if (data.type==="col_arg"){
6161
return <div style={{
6262
transform: `translate(${x}px, ${y}px)`,
@@ -79,16 +79,16 @@ const RenderedNode = ({data, x, y}) => {
7979
transform: `translate(${x}px, ${y}px)`,
8080
position: "absolute",
8181
border: "1px solid black",
82-
backgroundColor: "white",
82+
backgroundColor: selectedOps.includes(data.ref) ? "yellow":"white",
8383
borderRadius: 5,
8484
minWidth: 100,
85-
}} id={`plan-${data.ref}`}>
86-
<Operator data={data}/>
85+
}} id={`plan-${data.ref}`} onClick={(e)=>{e.stopPropagation();console.log(e);onOperatorSelect(data.ref)}}>
86+
<Operator data={data} onOperatorSelect={onOperatorSelect} selectedOps={selectedOps} />
8787
</div>
8888
}
8989
}
9090

91-
const Operator = ({data}) => {
91+
const Operator = ({data, onOperatorSelect, selectedOps}) => {
9292

9393
if (data.type === "execution_step") {
9494
let nodes = data.subops
@@ -165,7 +165,7 @@ const Operator = ({data}) => {
165165
{inputs}
166166
</div>
167167
<PlanViewer nested={true} height={1000} width={700} nodes={nodes} edges={edges}
168-
renderNode={(node, x, y) => (<RenderedNode x={x} y={y} data={node}/>)}
168+
renderNode={(node, x, y) => (<RenderedNode x={x} y={y} data={node} onOperatorSelect={onOperatorSelect} selectedOps={selectedOps}/>)}
169169
renderEdge={(edge) => {
170170
let points = edge.points.map((point) => `${point.x},${point.y}`).join(" ");
171171

@@ -303,7 +303,7 @@ const Operator = ({data}) => {
303303
flex: 1
304304
}}>
305305
<PlanViewer nested={true} height={1000} width={700} nodes={nodes} edges={edges}
306-
renderNode={(node, x, y) => (<RenderedNode x={x} y={y} data={node}/>)}
306+
renderNode={(node, x, y) => (<RenderedNode x={x} y={y} data={node} onOperatorSelect={onOperatorSelect} selectedOps={selectedOps}/>)}
307307
renderEdge={(edge) => {
308308
let points = edge.points.map((point) => `${point.x},${point.y}`).join(" ");
309309

@@ -410,7 +410,7 @@ export const SubOpPlanViewer = ({height, width, input, onOperatorSelect, selecte
410410

411411

412412
return (nodes&&edges&&<PlanViewer nested={false} height={height} width={width} nodes={nodes} edges={edges}
413-
renderNode={(node, x, y) => (<RenderedNode x={x} y={y} data={node}/>)}
413+
renderNode={(node, x, y) => (<RenderedNode x={x} y={y} data={node} onOperatorSelect={onOperatorSelect} selectedOps={selectedOps}/>)}
414414
renderEdge={(edge, nodesPos) => {
415415
let edgePoints = edge.points.map((point) => {
416416
return {x: point.x, y: point.y}

0 commit comments

Comments
 (0)