Skip to content

Commit

Permalink
[IR Compiler] fix error when creating json file (#1743)
Browse files Browse the repository at this point in the history
* [IR Compiler] attach jobId to the name of each json file and write it to /tmp instead of current to have access to

* [IR Compiler] get tmp directory from system properties
  • Loading branch information
shirly121 committed Jun 23, 2022
1 parent b3f9afe commit 2cba970
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@
// represent ir plan as a chain of operators
public class IrPlan implements Closeable {
private static IrCoreLibrary irCoreLib = IrCoreLibrary.INSTANCE;
private static String PLAN_JSON_FILE = "plan.json";
// get tmp directory from system properties, which is accessible from common users
private static String JSON_PLAN_DIR = System.getProperty("java.io.tmpdir");
private Pointer ptrPlan;
private IrMeta meta;
// to identify a unique json file which contains the logic plan from ir_core
private String planName;

// call libc to transform from InterOpBase to c structure
private enum TransformFactory implements Function<InterOpBase, Pointer> {
Expand Down Expand Up @@ -566,8 +569,9 @@ public Pointer createParams(QueryParams params) {
}
}

public IrPlan(IrMeta meta, InterOpCollection opCollection) {
public IrPlan(IrMeta meta, InterOpCollection opCollection, String planName) {
this.meta = meta;
this.planName = planName;
irCoreLib.setSchema(meta.getSchema());
this.ptrPlan = irCoreLib.initLogicalPlan();
// add snapshot to QueryParams
Expand Down Expand Up @@ -609,11 +613,12 @@ public byte[] toPhysicalBytes(Configs configs) throws BuildPhysicalException {
public String getPlanAsJson() throws IOException {
String json = "";
if (ptrPlan != null) {
File file = new File(PLAN_JSON_FILE);
String fileName = JSON_PLAN_DIR + File.separator + planName + ".json";
File file = new File(fileName);
if (file.exists()) {
file.delete();
}
irCoreLib.writePlanToJson(ptrPlan, PLAN_JSON_FILE);
irCoreLib.writePlanToJson(ptrPlan, fileName);
json = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
if (file.exists()) {
file.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ protected void processTraversal(Traversal traversal, ResultProcessor resultProce
// add sink operator
InterOpCollection.process(opCollection);

IrPlan irPlan = new IrPlan(irMeta, opCollection);
long jobId = JOB_ID_COUNTER.incrementAndGet();
String jobName = "ir_plan_" + jobId;

IrPlan irPlan = new IrPlan(irMeta, opCollection, jobName);
logger.info("{}", irPlan.getPlanAsJson());

byte[] physicalPlanBytes = irPlan.toPhysicalBytes(configs);
irPlan.close();

long jobId = JOB_ID_COUNTER.incrementAndGet();
String jobName = "ir_plan_" + jobId;

PegasusClient.JobRequest request = PegasusClient.JobRequest.parseFrom(physicalPlanBytes);
PegasusClient.JobConfig jobConfig =
PegasusClient.JobConfig.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public static IrPlan getTestIrPlan(InterOpBase op, InterOpBase... ops) {
opCollection.appendInterOp(op1);
}
}
return new IrPlan(new IrMeta(""), opCollection);
return new IrPlan(new IrMeta(""), opCollection, "");
}
}

0 comments on commit 2cba970

Please sign in to comment.