Skip to content

Commit

Permalink
Improvement to generic query: return resultType properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Cuddihy committed Nov 11, 2021
1 parent edf7b06 commit c5716db
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
public class NodeGroupExecutionRestController {

static final String SERVICE_NAME = "nodeGroupExecutionService";
static final String JOB_ID_RESULT_KEY = SimpleResultSet.JOB_ID_RESULT_KEY;

// updated
@Autowired
Expand Down Expand Up @@ -523,10 +522,10 @@ public JSONObject dispatchAnyJobById(@RequestBody DispatchByIdRequestBody reques
requestBody.getLimitOverride(),
requestBody.getOffsetOverride(),
targetId);
String id = ngExecutor.getJobID();

retval.setSuccess(true);
retval.addResult(JOB_ID_RESULT_KEY, id);
retval.addResult(SimpleResultSet.JOB_ID_RESULT_KEY, ngExecutor.getJobID());
retval.addResult(SimpleResultSet.RESULT_TYPE_KEY, ngExecutor.getResultType().toString());

}
catch(Exception e){
Expand Down Expand Up @@ -718,7 +717,7 @@ public JSONObject dispatchSelectByIdSync(@RequestBody DispatchByIdRequestBody re
ret = new TableResultSet(simpleJson);
} else {
// wait for job to complete
String jobId = jobIdRes.getResult(JOB_ID_RESULT_KEY);
String jobId = jobIdRes.getResult(SimpleResultSet.JOB_ID_RESULT_KEY);
JobTracker tracker = this.getJobTracker();
int percentComplete = tracker.waitForPercentOrMsec(jobId, 100, TIMEOUT_SEC * 1000);
if (percentComplete < 100) {
Expand Down Expand Up @@ -926,7 +925,7 @@ public JSONObject dispatchSelectInstanceDataPredicates(@RequestBody InstanceData
String id = ngExecutor.getJobID();

retval.setSuccess(true);
retval.addResult(JOB_ID_RESULT_KEY, id);
retval.addResult(SimpleResultSet.JOB_ID_RESULT_KEY, id);

}
catch(Exception e){
Expand Down Expand Up @@ -982,7 +981,7 @@ public JSONObject dispatchSelectInstanceDataSubjects(@RequestBody InstanceDataCl
String id = ngExecutor.getJobID();

retval.setSuccess(true);
retval.addResult(JOB_ID_RESULT_KEY, id);
retval.addResult(SimpleResultSet.JOB_ID_RESULT_KEY, id);

}
catch(Exception e){
Expand Down Expand Up @@ -1023,7 +1022,7 @@ public JSONObject constructConnectedData(@RequestBody ConstructConnectedDataRequ
constructor.start();

retval.setSuccess(true);
retval.addResult(JOB_ID_RESULT_KEY, constructor.getJobId());
retval.addResult(SimpleResultSet.JOB_ID_RESULT_KEY, constructor.getJobId());

} catch(Exception e){
retval.setSuccess(false);
Expand Down Expand Up @@ -1100,7 +1099,7 @@ public JSONObject dispatchRawSparql(@RequestBody DispatchRawSparqlRequestBody re
String id = ngExecutor.getJobID();

retval.setSuccess(true);
retval.addResult(JOB_ID_RESULT_KEY, id);
retval.addResult(SimpleResultSet.JOB_ID_RESULT_KEY, id);

}
catch(Exception e){
Expand Down Expand Up @@ -1144,7 +1143,7 @@ public JSONObject dispatchRawSparqlUpdate(@RequestBody DispatchRawSparqlRequestB
String id = ngExecutor.getJobID();

retval.setSuccess(true);
retval.addResult(JOB_ID_RESULT_KEY, id);
retval.addResult(SimpleResultSet.JOB_ID_RESULT_KEY, id);

}
catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ public JSONObject query(@RequestBody TypedQueryRequestBody requestBody, @Request
qt = ngQt != null ? ngQt : AutoGeneratedQueryTypes.SELECT_DISTINCT;
}
if (rt == null) {
SparqlResultTypes ngRt = ng.getReturnTypeOverride();
rt = ngRt != null ? ngRt : SparqlResultTypes.TABLE;
rt = ng.getResultType();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.json.simple.parser.ParseException;

import com.ge.research.semtk.belmont.NodeGroup;
import com.ge.research.semtk.load.utility.SparqlGraphJson;
import com.ge.research.semtk.utility.LocalLogger;

import io.swagger.annotations.ApiModelProperty;
Expand All @@ -41,7 +42,12 @@ public String getJsonRenderedNodeGroup(){
public NodeGroup buildNodeGroup() throws Exception{
JSONParser prsr = new JSONParser();
JSONObject jNodeGroup = (JSONObject) prsr.parse(this.jsonRenderedNodeGroup);
return NodeGroup.getInstanceFromJson(jNodeGroup);
if (SparqlGraphJson.isSparqlGraphJson(jNodeGroup)) {
SparqlGraphJson sgJson = new SparqlGraphJson(jNodeGroup);
jNodeGroup = sgJson.getSNodeGroupJson();
}

return NodeGroup.getInstanceFromJson(jNodeGroup);
}

public JSONObject buildNodeGroupJson(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class NodeGroupExecutor {
private IngestorRestClient ingestClient = null;
// internal data.
private String currentJobId = null;
private SparqlResultTypes resultType = null;

// the Stored Query Executor will be the heart of the stored Query Executor Service.
// all of the most important actions will occur in this class
Expand Down Expand Up @@ -93,7 +94,6 @@ public static SparqlConnection get_USE_NODEGROUP_CONN() throws Exception {
return new SparqlConnection(USE_NODEGROUP_CONN_STR);
}

//Job ID related
public String getJobID(){
return this.currentJobId;
}
Expand All @@ -102,6 +102,14 @@ public void setJobID(String jobID){
this.currentJobId = jobID;
}

public SparqlResultTypes getResultType() {
return resultType;
}

public void setResultType(SparqlResultTypes resultType) {
this.resultType = resultType;
}




Expand Down Expand Up @@ -309,6 +317,13 @@ public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, Sparql

LocalLogger.logToStdOut("Sending a " + qt + " query to the dispatcher...");

// Determine and set resultType
if (rt != null) {
this.setResultType(rt);
} else {
this.setResultType(ng.getResultType());
}

if(externalConstraints != null){
LocalLogger.logToStdOut("Setting external constraints: " + externalConstraints.toJSONString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ public static AutoGeneratedQueryTypes getMatchingValue(String s) throws Exceptio
return AutoGeneratedQueryTypes.valueOf(lookup);
}

public SparqlResultTypes getDefaultResultType() {
switch (this) {
case SELECT_DISTINCT:
case FILTER_CONSTRAINT:
case COUNT:
case ASK:
return SparqlResultTypes.TABLE;
case DELETE:
return SparqlResultTypes.CONFIRM;
case CONSTRUCT:
return SparqlResultTypes.GRAPH_JSONLD;
default:
return SparqlResultTypes.TABLE;
}
}

public void throwExceptionIfIncompatible(SparqlResultTypes rt) throws Exception {
switch (this) {
case SELECT_DISTINCT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,20 @@ public SparqlResultTypes getReturnTypeOverride() {
public void setReturnTypeOverride(SparqlResultTypes returnTypeOverride) {
this.returnTypeOverride = returnTypeOverride;
}

/**
* Get the result type that will be returned by this query
* @return
*/
public SparqlResultTypes getResultType() {
if (this.returnTypeOverride != null) {
return this.returnTypeOverride;
} else if (this.queryType != null) {
return this.queryType.getDefaultResultType();
} else {
return SparqlResultTypes.TABLE;
}
}

public void clearOrderBy() {
this.orderBy = new ArrayList<OrderElement>();
Expand Down

0 comments on commit c5716db

Please sign in to comment.