-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: init optimizer trace * update: logical optimizer * tweak: optimizer trace layout * fix: index * update: icon * update: deps * tweak: some styles * udpate: step interface * tweak: logical optimization step * tweak: final * tweak: unselected candidates style * update: unselected candates style * deps: use d3-graphviz * chore: remove webpack chunk name comment * tweak: error boundary * chore: clear some deps * tweak: action info tooltip
- Loading branch information
Showing
13 changed files
with
656 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
ui/lib/apps/OptimizerTrace/components/LogicalOperatorTree.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import { graphviz } from 'd3-graphviz' | ||
|
||
import styles from './OperatorTree.module.less' | ||
|
||
interface LogicalOperatorTreeProps { | ||
data: LogicalOperatorNode[] | ||
labels?: any | ||
className?: string | ||
} | ||
|
||
export interface LogicalOperatorNode { | ||
id: number | ||
children: number[] // children id | ||
type: string | ||
cost: number | ||
selected: boolean | ||
property: string | ||
info: string | ||
} | ||
|
||
export default function LogicalOperatorTree({ | ||
data, | ||
labels = {}, | ||
className, | ||
}: LogicalOperatorTreeProps) { | ||
const containerRef = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
const containerEl = containerRef.current | ||
if (!containerEl) { | ||
return | ||
} | ||
|
||
const define = data | ||
.map( | ||
(n) => | ||
`${n.id} ${createLabels({ | ||
label: `${n.type}_${n.id}`, | ||
color: labels.color || '', | ||
tooltip: `info: ${n.info}`, | ||
})};\n` | ||
) | ||
.join('') | ||
const link = data | ||
.map((n) => | ||
(n.children || []) | ||
.map((c) => `${n.id} -> ${c} ${createLabels(labels)};\n`) | ||
.join('') | ||
) | ||
.join('') | ||
|
||
graphviz(containerEl).renderDot( | ||
`digraph { | ||
node [shape=ellipse fontsize=8 fontname="Verdana"]; | ||
${define}\n${link}\n}` | ||
) | ||
}, [containerRef, data, labels]) | ||
|
||
return ( | ||
<div | ||
ref={containerRef} | ||
className={`${styles.operator_tree} ${className || ''}`} | ||
></div> | ||
) | ||
} | ||
|
||
export function createLabels(labels: { [props: string]: string } = {}): string { | ||
const ls = Object.entries(labels).filter(([k, v]) => !!v) | ||
if (!ls.length) { | ||
return '' | ||
} | ||
return `[${ls.map(([k, v]) => `${k}="${v}"`).join(' ')}]` | ||
} |
9 changes: 9 additions & 0 deletions
9
ui/lib/apps/OptimizerTrace/components/OperatorTree.module.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.operator_tree { | ||
height: 300px; | ||
width: 200px; | ||
|
||
svg { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
ui/lib/apps/OptimizerTrace/components/PhysicalOperatorTree.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import { graphviz } from 'd3-graphviz' | ||
|
||
import styles from './OperatorTree.module.less' | ||
import { LogicalOperatorNode, createLabels } from './LogicalOperatorTree' | ||
|
||
export interface PhysicalOperatorNode extends LogicalOperatorNode { | ||
parentNode: null | PhysicalOperatorNode | ||
childrenNodes: PhysicalOperatorNode[] | ||
mapping: string | ||
} | ||
|
||
interface PhysicalOperatorTreeProps { | ||
data: PhysicalOperatorNode | ||
className?: string | ||
} | ||
|
||
export default function PhysicalOperatorTree({ | ||
data, | ||
className, | ||
}: PhysicalOperatorTreeProps) { | ||
const containerRef = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
const containerEl = containerRef.current | ||
if (!containerEl) { | ||
return | ||
} | ||
|
||
const allDatas = [data, ...(data.childrenNodes || [])] | ||
const define = allDatas | ||
.map( | ||
(n) => | ||
`${n.id} ${createLabels({ | ||
label: `${n.type}_${n.id}\ncost: ${n.cost.toFixed(4)}`, | ||
color: n.selected ? 'blue' : '', | ||
tooltip: `info: ${n.info}`, | ||
})};\n` | ||
) | ||
.join('') | ||
const link = allDatas | ||
.map((n) => | ||
(n.children || []) | ||
.map( | ||
(c) => | ||
`${n.id} -- ${c} ${createLabels({ | ||
color: n.selected ? 'blue' : '', | ||
})};\n` | ||
) | ||
.join('') | ||
) | ||
.join('') | ||
|
||
graphviz(containerEl).renderDot( | ||
`graph { | ||
node [shape=ellipse fontsize=8 fontname="Verdana"]; | ||
${define}\n${link}\n}` | ||
) | ||
}, [containerRef, data]) | ||
|
||
return ( | ||
<div | ||
ref={containerRef} | ||
className={`${styles.operator_tree} ${className || ''}`} | ||
></div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import translations from './translations' | ||
|
||
export default { | ||
id: 'optimizer_trace', | ||
routerPrefix: '/optimizer_trace', | ||
translations, | ||
reactRoot: () => import('.'), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.container { | ||
overflow: auto; | ||
} | ||
.operator_tree { | ||
flex-shrink: 0; | ||
} | ||
|
||
.logical_optimize { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.arrow { | ||
margin: 0 10px; | ||
} | ||
|
||
.physical_operator_tree_container { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.unselected_candidates { | ||
border: dashed 1px #ccc; | ||
margin-left: 10px; | ||
padding: 5px; | ||
} | ||
|
||
.steps { | ||
width: 200px; | ||
} | ||
|
||
.step_info { | ||
max-height: 90px; | ||
width: 200px; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} |
Oops, something went wrong.