Skip to content

Commit 0bab4b0

Browse files
committed
Bug fixes and minor improvments
1 parent 1a4353a commit 0bab4b0

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed

backend/backend.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -99,41 +99,43 @@ def run_sql_query(query_str, db):
9999
async def analyze(database: str = Body(...), query: str = Body(...), real_card: bool = Body(...)):
100100
if database not in ["tpch-1", "tpcds-1", "uni", "job"]:
101101
raise RuntimeError("Unknown Database")
102-
with tempfile.NamedTemporaryFile(mode="w", delete=True) as f:
103-
f.write(query)
104-
query_file = f.name
105-
f.flush()
106-
with tempfile.TemporaryDirectory() as snapshotdir:
107-
print(BINARY_DIR + "run-sql " + query_file + " " + DATA_ROOT + database)
108-
output = subprocess.check_output([BINARY_DIR + "run-sql", query_file, DATA_ROOT + database],
109-
universal_newlines=True, stderr=subprocess.STDOUT, timeout=20,
110-
env={**os.environ,"LINGODB_SNAPSHOT_DIR": snapshotdir,
111-
"LINGODB_SNAPSHOT_PASSES": "true",
112-
"LINGODB_SNAPSHOT_LEVEL": "important",
113-
"LINGODB_EXECUTION_MODE": "NONE"})
114-
result = subprocess.run(
115-
f"bash {SCRIPT_DIR}/clean-snapshot.sh {BINARY_DIR} {snapshotdir}/important-snapshot-qopt.mlir {snapshotdir}/important-snapshot-qopt.mlir.alt",
116-
universal_newlines=True, stderr=subprocess.STDOUT, shell=True)
117-
print(result)
118-
result = subprocess.run(
119-
f"bash {SCRIPT_DIR}/clean-snapshot.sh {BINARY_DIR} {snapshotdir}/important-snapshot-subop-opt.mlir {snapshotdir}/important-snapshot-subop-opt.mlir.alt",
120-
universal_newlines=True, stderr=subprocess.STDOUT, shell=True)
121-
print(os.listdir(snapshotdir))
122-
123-
relalg_plan = subprocess.check_output(
124-
[BINARY_DIR + "mlir-to-json", snapshotdir + "/important-snapshot-qopt.mlir.alt"] + (
125-
[DATA_ROOT + database] if real_card else []),
126-
universal_newlines=True, stderr=subprocess.STDOUT)
127-
subop_plan = subprocess.check_output(
128-
[BINARY_DIR + "mlir-subop-to-json", snapshotdir + "/important-snapshot-subop-opt.mlir.alt"],
129-
universal_newlines=True)
130-
analyzed_snapshots = subprocess.check_output(
131-
[BINARY_DIR + "mlir-analyze-snapshots", snapshotdir + "/important-snapshot-info.json"],
132-
universal_newlines=True)
133-
print(os.listdir(snapshotdir))
134-
return {"plan": json.loads(relalg_plan.split("\n")[0]), "subopplan": json.loads(subop_plan.split("\n")[0]),
135-
"mlir": json.loads(analyzed_snapshots)}
136-
102+
try:
103+
with tempfile.NamedTemporaryFile(mode="w", delete=True) as f:
104+
f.write(query)
105+
query_file = f.name
106+
f.flush()
107+
with tempfile.TemporaryDirectory() as snapshotdir:
108+
print(BINARY_DIR + "run-sql " + query_file + " " + DATA_ROOT + database)
109+
output = subprocess.check_output([BINARY_DIR + "run-sql", query_file, DATA_ROOT + database],
110+
universal_newlines=True, stderr=subprocess.STDOUT, timeout=20,
111+
env={**os.environ,"LINGODB_SNAPSHOT_DIR": snapshotdir,
112+
"LINGODB_SNAPSHOT_PASSES": "true",
113+
"LINGODB_SNAPSHOT_LEVEL": "important",
114+
"LINGODB_EXECUTION_MODE": "NONE"})
115+
result = subprocess.run(
116+
f"bash {SCRIPT_DIR}/clean-snapshot.sh {BINARY_DIR} {snapshotdir}/important-snapshot-qopt.mlir {snapshotdir}/important-snapshot-qopt.mlir.alt",
117+
universal_newlines=True, stderr=subprocess.STDOUT, shell=True)
118+
print(result)
119+
result = subprocess.run(
120+
f"bash {SCRIPT_DIR}/clean-snapshot.sh {BINARY_DIR} {snapshotdir}/important-snapshot-subop-opt.mlir {snapshotdir}/important-snapshot-subop-opt.mlir.alt",
121+
universal_newlines=True, stderr=subprocess.STDOUT, shell=True)
122+
print(os.listdir(snapshotdir))
123+
124+
relalg_plan = subprocess.check_output(
125+
[BINARY_DIR + "mlir-to-json", snapshotdir + "/important-snapshot-qopt.mlir.alt"] + (
126+
[DATA_ROOT + database] if real_card else []),
127+
universal_newlines=True, stderr=subprocess.STDOUT)
128+
subop_plan = subprocess.check_output(
129+
[BINARY_DIR + "mlir-subop-to-json", snapshotdir + "/important-snapshot-subop-opt.mlir.alt"],
130+
universal_newlines=True)
131+
analyzed_snapshots = subprocess.check_output(
132+
[BINARY_DIR + "mlir-analyze-snapshots", snapshotdir + "/important-snapshot-info.json"],
133+
universal_newlines=True)
134+
print(os.listdir(snapshotdir))
135+
return {"plan": json.loads(relalg_plan.split("\n")[0]), "subopplan": json.loads(subop_plan.split("\n")[0]),
136+
"mlir": json.loads(analyzed_snapshots)}
137+
except Exception as e:
138+
raise HTTPException(status_code=400, detail="Error during query analyze")
137139
return {}
138140

139141

frontend/packages/common/RelationalPlanViewer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,19 @@ const Operator = ({data}) => {
121121
const joinImpl = data.joinImpl === "hash" ? "HashJoin" : (data.joinImpl === "nested" ? "NestedLoopJoin" : "IndexNestedLoopJoin")
122122
return <OperatorContainer heading={`${joinSymbol(data.joinType)}\u2003 ${joinImpl}`}>
123123
<div><b>Comparisons:</b> {data.comparisons.map((comp) => <div><Expression data={comp}/></div>)}</div>
124-
<div><b>Condition:</b> <Expression data={data.condition}/></div>
124+
{data.condition&&(<div><b>Condition:</b> <Expression data={data.condition}/></div>)}
125+
</OperatorContainer>
126+
} else if (data.operator === "markJoin") {
127+
const joinImpl = data.joinImpl === "hash" ? "HashJoin" : (data.joinImpl === "nested" ? "NestedLoopJoin" : "IndexNestedLoopJoin")
128+
return <OperatorContainer heading={`${joinSymbol(data.joinType)}\u2003 ${joinImpl}`}>
129+
<div><b>Comparisons:</b> {data.comparisons.map((comp) => <div><Expression data={comp}/></div>)}</div>
130+
{data.condition && (<div><b>Condition:</b> <Expression data={data.condition}/></div>)}
131+
<div><b>Marker:</b> <Expression data={data.markColumn}/></div>
132+
125133
</OperatorContainer>
126134
} else if (data.operator === "map") {
127135
return <OperatorContainer heading={`\u2254\u2003 Map`}>
128-
{data.computed.map((comp) => <div><Expression data={comp.computed}/>: <Expression data={comp.expression}/>
136+
{data.computed.map((comp) => <div><Expression data={comp.computed}/>: <Expression data={comp.expression}/>
129137
</div>)}
130138
</OperatorContainer>
131139
} else if (data.operator == "window") {

frontend/packages/interface/src/App.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ function App() {
339339
<Tab eventKey="queryPlan" title="QueryPlan">
340340

341341
</Tab>
342-
{false&&(<Tab eventKey="subopPlan" title="SubOperators">
343-
</Tab>)}
342+
<Tab eventKey="subopPlan" title="SubOperators">
343+
</Tab>
344344
<Tab eventKey="mlir" title="MLIR (RelAlg)"/>
345345
<Tab eventKey="mlir2" title="MLIR (SubOp)"/>
346346
<Tab eventKey="mlir3" title="MLIR (HL. Imperative)"/>
@@ -360,14 +360,14 @@ function App() {
360360
selectedOps={selectedRelAlgOps}/>
361361
</div>
362362
</div>
363-
{false&&(<div eventKey="subopPlan" title="SubOperatorPlan"
363+
<div eventKey="subopPlan" title="SubOperatorPlan"
364364
style={{visibility: activeTab === "subopPlan" ? "visible" : "hidden", position: 'absolute'}}>
365365
<div style={{height: '50vh', backgroundColor: "gray"}}>
366366
<SubOpPlanViewerWithLoading input={subOpPlan} loading={queryPlanLoading}
367367
error={queryPlanError} selectedOps={selectedSubOpOps}
368368
onOperatorSelect={handleSubOpOpSelection}/>
369369
</div>
370-
</div>)}
370+
</div>
371371
<div eventKey="mlir" title="MLIR"
372372
style={{
373373
visibility: activeTab === "mlir" ? "visible" : "hidden",

lingodb-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9d1f45690e557d0101cb14f785df2df9b4afc9a7
1+
d2e01b80ee8ea83d4c76d255133b6415bd29d88f

0 commit comments

Comments
 (0)