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

feat: CLI tool for visualizing plans #8

Merged
merged 17 commits into from
Dec 7, 2023
Merged

Conversation

sanjibansg
Copy link
Contributor

This PR introduces the CLI tool for visualizing substrait plans in substraitJS.

@sanjibansg sanjibansg marked this pull request as ready for review September 26, 2023 15:05
"version": "2.12.2",
"resolved": "https://registry.npmjs.org/@types/commander/-/commander-2.12.2.tgz",
"integrity": "sha512-0QEFiR8ljcHp9bAbWxecjVRuAMr16ivPiGOw6KFQBVrVd0RQIcM3xKdRisH2EDWgVWujiYtHwhSkSUoAAGzH7Q==",
"deprecated": "This is a stub types definition for commander (https://github.com/tj/commander.js). commander provides its own type definitions, so you don't need @types/commander installed!",
Copy link
Member

Choose a reason for hiding this comment

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

Since types/commander is listed above is it needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a generated file when we run npm install for installing the npm packages, but AFAIK this is required in the project to correctly have the dependencies.

.gitignore Outdated Show resolved Hide resolved

const outputSvgContent = fs.readFileSync('plan.svg', 'utf-8');
const expectedSvgContent = fs.readFileSync('test/expected.svg', 'utf-8');
expect(outputSvgContent).toEqual(expectedSvgContent);
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 am not sure if this should be the way to test whether the tool generates the correct SVG file. Is there any better way for this?

Copy link
Member

Choose a reason for hiding this comment

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

An alternative would be to check that the file is there and then check its contents (which you could do with a string in a test file somewhere). But the input is coming from a separate test file. It seems appropriate to have a separate golden file to match. This could be changed to look for test files and compare them to golden ones (allowing it to check for multiple correct files) instead of being limited to a single file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, so what I understand is you suggest having multiple tests verifying the correctness of the tool instead of just limiting it to the one plan and its expected SVG. Is that correct?

Copy link
Member

Choose a reason for hiding this comment

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

Long term that's the way to go. But for now this is a step in that direction.

Copy link
Member

@westonpace westonpace left a comment

Choose a reason for hiding this comment

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

Looks like we moved away from d3? It is definitely much easier to understand now. A few minor suggestions but looks good otherwise.

Comment on lines +8 to +21
function renderGraph(edges: Link[]): Promise<string> {
const dom = new JSDOM();
global.document = dom.window.document;
global.DOMParser = new JSDOM().window.DOMParser;

return instance().then((viz) => {
const dotString = `digraph { ${edges
.map((edge) => `${edge.source} -> ${edge.target}`)
.join("; ")} }`;

const svg = viz.renderSVGElement(dotString);
return svg.outerHTML;
}) as Promise<string>;
}
Copy link
Member

@westonpace westonpace Dec 7, 2023

Choose a reason for hiding this comment

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

+1, This is definitely much simpler than the D3 approach.

Copy link
Contributor Author

@sanjibansg sanjibansg Dec 7, 2023

Choose a reason for hiding this comment

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

After my research, I had to remove d3 from the substrait-JS library, as d3 plots need a browser environment to render plots correctly and cannot do so on the server side with JSDOM, thus I had to move to graphviz. The fiddle can use the pre-processing functions defined here to render the d3 plot.

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
test/generate.test.js Show resolved Hide resolved
@westonpace westonpace merged commit 9b84f9b into substrait-io:main Dec 7, 2023
3 checks passed
@sanjibansg sanjibansg deleted the cli branch December 8, 2023 04:42
@sanjibansg sanjibansg mentioned this pull request Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants