Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGe00 committed Sep 14, 2023
1 parent bd30503 commit 08633fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ResponseEntity getIRVisualizations(@RequestBody VisualizationRequestBody
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(t.getMessage());
}

// Build response body
// Build response body
VisualizationResponseBody responseBody = new VisualizationResponseBody();
responseBody.setSqlNodeImageID(sqlNodeImageID);
responseBody.setRelNodeImageID(relNodeImageID);
Expand All @@ -76,7 +76,7 @@ public ResponseEntity getIRVisualizations(@RequestBody VisualizationRequestBody
public ResponseEntity<FileSystemResource> getImage(@PathVariable String imageId) {
String imagePath = imageDir + File.separator + imageId + ".svg";

if (isValidImageId(imagePath)) {
if (isValidImage(imagePath)) {
try {
Path path = new File(imagePath).toPath();
String contentType = Files.probeContentType(path);
Expand All @@ -97,9 +97,9 @@ public ResponseEntity<FileSystemResource> getImage(@PathVariable String imageId)
}
}

private boolean isValidImageId(String imagePath) {
File imageFile = new File(imagePath);
private boolean isValidImage(String imagePath) {
// Check if the file exists and is a regular file (not a directory)
File imageFile = new File(imagePath);
return imageFile.exists() && imageFile.isFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,15 @@ public static UUID generateSqlNodeVisualization(String query, String fromLanguag
sqlNode = new HiveToRelConverter(hiveMetastoreClient).toSqlNode(query);
}

if (incrementalRewrittenRelNode != null) {
switch (rewriteType) {
case INCREMENTAL:
// We want to instead generate the visualization of SqlNode2 of the RHS of Coral's translation
sqlNode = new CoralRelToSqlNodeConverter().convert(incrementalRewrittenRelNode);
break;
case DATAMASKING:
case NONE:
default:
break;
}
if (incrementalRewrittenRelNode != null && rewriteType == INCREMENTAL) {
// We want to instead generate the visualization of SqlNode2 of the RHS of Coral's translation
sqlNode = new CoralRelToSqlNodeConverter().convert(incrementalRewrittenRelNode);
}

assert sqlNode != null;
VisualizationUtil visualizationUtil = VisualizationUtil.create(imageDir);

// Generate graphviz svg using sqlNode
VisualizationUtil visualizationUtil = VisualizationUtil.create(imageDir);
UUID sqlNodeId = UUID.randomUUID();
visualizationUtil.visualizeSqlNodeToFile(sqlNode, "/" + sqlNodeId + ".svg");

Expand Down Expand Up @@ -82,8 +75,9 @@ public static UUID generateRelNodeVisualization(String query, String fromLanguag
}

assert relNode != null;
VisualizationUtil visualizationUtil = VisualizationUtil.create(imageDir);

// Generate graphviz svg using relNode
VisualizationUtil visualizationUtil = VisualizationUtil.create(imageDir);
UUID relNodeID = UUID.randomUUID();
visualizationUtil.visualizeRelNodeToFile(relNode, "/" + relNodeID + ".svg");

Expand Down

0 comments on commit 08633fa

Please sign in to comment.