Skip to content

Commit

Permalink
Move PRUNE_TO_COLUMN to query_flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Cuddihy committed Jan 10, 2023
1 parent aff0a17 commit 366515d
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,7 @@ public JSONObject dispatchAnyJobById(@RequestBody DispatchByIdRequestBody reques
requestBody.getRuntimeConstraints(),
requestBody.getLimitOverride(),
requestBody.getOffsetOverride(),
targetId,
requestBody.getPruneToColumn());
targetId);

retval.setSuccess(true);
retval.addResult(SimpleResultSet.JOB_ID_RESULT_KEY, ngExecutor.getJobID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ public class DispatchByIdRequestBody extends DispatchRequestBody {
example = "-1")
private int offsetOverride = -1;

// This is custom optional field only available through straight REST
// for Saqib @ collins
@Schema(
description = "Prune select table return down to one column and uniquify.",
required = false,
example = "favorite_column")
private String pruneToColumn = null;

public int getLimitOverride() {
return limitOverride;
}
Expand All @@ -65,13 +57,6 @@ public String getNodeGroupId(){
return this.nodeGroupId;
}

public void setPruneToColumn(String val) {
this.pruneToColumn = val;
}
public String getPruneToColumn() {
return this.pruneToColumn;
}

/**
* Validate request contents. Throws an exception if validation fails.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
public class DispatchRequestBody extends SparqlConnRequestBody {
@Schema(
description = "EDC query constraints json",
required = false,
requiredMode = Schema.RequiredMode.NOT_REQUIRED,
example = "{ optional complex json }")
private String externalDataConnectionConstraints;

@Schema(
description = "Query flags array",
required = false,
example = "[\"FLAG1\", \"FLAG2\"]")
requiredMode = Schema.RequiredMode.NOT_REQUIRED,
example = "[\"PRUNE_TO_COLUMN:myCol\", \"UNOPTIONALIZE_CONSTRAINED\"]")
private String flags; // json array

@Schema(
description = "Runtime constraints json",
required = false,
requiredMode = Schema.RequiredMode.NOT_REQUIRED,
example = "\"[{\"SparqlID\":\"?id\",\"Operator\":\"MATCHES\",\"Operands\":[\"98243-T\"]}]\"")
private String runtimeConstraints;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.ge.research.semtk.springutillib.properties.EnvironmentProperties;
import com.ge.research.semtk.springutillib.properties.ServicesGraphProperties;
import com.ge.research.semtk.sparqlX.asynchronousQuery.AsynchronousNodeGroupBasedQueryDispatcher;
import com.ge.research.semtk.sparqlX.dispatch.QueryFlags;

@RestController
@RequestMapping("/dispatcher")
Expand Down Expand Up @@ -326,7 +327,11 @@ public JSONObject queryFromNodeGroup(@RequestBody QueryRequestBody requestBody,
try {
dsp = getDispatcher(props, jobId, (NodegroupRequestBody) requestBody, useAuth, true);
dsp.getJobTracker().incrementPercentComplete(dsp.getJobId(), 1, 10);
dsp.addPruneToColumn(requestBody.getPruneToColumn());

QueryFlags flags = requestBody.getFlags();
if (flags != null) {
dsp.addPruneToColumn(flags.get(QueryFlags.PRUNE_TO_COL));
}

WorkThread thread = new WorkThread(dsp, requestBody.getExternalConstraints(), requestBody.getFlags(), qt, rt);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,9 @@ public class QueryRequestBody extends NodegroupRequestBody {
@Schema(required = false, example = "[{\"SparqlID\":\"?name\",\"Operator\":\"MATCHES\",\"Operands\":[\"Fred\"]}]")
private String constraintSet;

@Schema(required = false, example = "[\"UNOPTIONALIZE_CONSTRAINED\"]")
@Schema(required = false, example = "[\"UNOPTIONALIZE_CONSTRAINED\", \"PRUNE_TO_COLUMN:myCol\"]")
private String flags; // a string parseable to a JSONArray

// This is custom optional field only available through straight REST
// for Saqib @ collins
@Schema(
description = "Prune select table return down to one column and uniquify.",
required = false,
example = "favorite_column")
private String pruneToColumn = null;

public void setConstraintSet(String constraintSet){
this.constraintSet = constraintSet;
Expand All @@ -67,11 +60,4 @@ public QueryFlags getFlags() throws Exception{
return new QueryFlags(Utility.getJsonArrayFromString(this.flags));
}

public void setPruneToColumn(String val) {
this.pruneToColumn = val;
}
public String getPruneToColumn() {
return this.pruneToColumn;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -302,39 +302,6 @@ public void dispatchRawSparqlUpdate(SparqlConnection sc, String sparqlQuery) thr
this.setJobID(simpleRes.getResult("requestID"));
}

/**
* Version without queryFlags or pruneToColumn
* @param qt
* @param rt
* @param sc
* @param ng
* @param externalConstraints
* @param runtimeConstraints
* @param targetObjectSparqlID
* @throws Exception
*/
public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt,SparqlConnection sc, NodeGroup ng, JSONObject externalConstraints, JSONArray runtimeConstraints, String targetObjectSparqlID) throws Exception{
this.dispatchJob(qt, rt, sc, ng, externalConstraints, null, runtimeConstraints, -1, -1, targetObjectSparqlID, null);
}

/**
* Version without pruneToColumn
* @param qt
* @param rt
* @param sc
* @param ng
* @param externalConstraints
* @param flags
* @param runtimeConstraints
* @param limitOverride
* @param offsetOverride
* @param targetObjectSparqlID
* @param pruneToColumn
* @throws Exception
*/
public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, SparqlConnection sc, NodeGroup ng, JSONObject externalConstraints, QueryFlags flags, JSONArray runtimeConstraints, int limitOverride, int offsetOverride, String targetObjectSparqlID) throws Exception{
this.dispatchJob(qt, rt, sc, ng, externalConstraints, flags, runtimeConstraints, -1, -1, targetObjectSparqlID, null);
}

/**
*
Expand All @@ -348,11 +315,10 @@ public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, Sparql
* @param limitOverride
* @param offsetOverride
* @param targetObjectSparqlID
* @param pruneToColumn - unusual special : prune a SELECT table result to only this column, uniquified
* @throws Exception
*/
@SuppressWarnings("unchecked")
public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, SparqlConnection sc, NodeGroup ng, JSONObject externalConstraints, QueryFlags flags, JSONArray runtimeConstraints, int limitOverride, int offsetOverride, String targetObjectSparqlID, String pruneToColumn) throws Exception{
public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, SparqlConnection sc, NodeGroup ng, JSONObject externalConstraints, QueryFlags flags, JSONArray runtimeConstraints, int limitOverride, int offsetOverride, String targetObjectSparqlID) throws Exception{
// externalConstraints as used by executeQueryFromNodeGroup

LocalLogger.logToStdOut("Sending a " + qt + " query to the dispatcher...");
Expand Down Expand Up @@ -396,7 +362,7 @@ public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, Sparql
SparqlGraphJson sgjson = new SparqlGraphJson(ng, sc);
SimpleResultSet simpleRes = null;

simpleRes = this.dispatchClient.executeQuery(sgjson, qt, rt, externalConstraints, flags, targetObjectSparqlID, pruneToColumn);
simpleRes = this.dispatchClient.executeQuery(sgjson, qt, rt, externalConstraints, flags, targetObjectSparqlID);
simpleRes.throwExceptionIfUnsuccessful();

// set up the Job ID
Expand All @@ -405,7 +371,7 @@ public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, Sparql
}

/**
* Version without queryFlags or pruneToColumn
* Version without queryFlags
* @param qt
* @param rt
* @param sc
Expand All @@ -416,26 +382,9 @@ public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, Sparql
* @throws Exception
*/
public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt,SparqlConnection sc, String storedNodeGroupId, JSONObject externalConstraints, JSONArray runtimeConstraints, String targetObjectSparqlID) throws Exception{
this.dispatchJob(qt, rt, sc, storedNodeGroupId, externalConstraints, null, runtimeConstraints, -1, -1, targetObjectSparqlID, null);
this.dispatchJob(qt, rt, sc, storedNodeGroupId, externalConstraints, null, runtimeConstraints, -1, -1, targetObjectSparqlID);
}

/**
* Version without pruneToColumn
* @param qt
* @param rt
* @param sc
* @param storedNodeGroupId
* @param externalConstraints
* @param flags
* @param runtimeConstraints
* @param limitOverride
* @param offsetOverride
* @param targetObjectSparqlID
* @throws Exception
*/
public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, SparqlConnection sc, String storedNodeGroupId, JSONObject externalConstraints, QueryFlags flags, JSONArray runtimeConstraints, int limitOverride, int offsetOverride, String targetObjectSparqlID) throws Exception{
this.dispatchJob(qt, rt, sc, storedNodeGroupId, externalConstraints, flags, runtimeConstraints, -1, -1, targetObjectSparqlID, null);
}
/**
*
* @param qt
Expand All @@ -446,7 +395,7 @@ public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, Sparql
* @param targetObjectSparqlID
* @throws Exception
*/
public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, SparqlConnection sc, String storedNodeGroupId, JSONObject externalConstraints, QueryFlags flags, JSONArray runtimeConstraints, int limitOverride, int offsetOverride, String targetObjectSparqlID, String pruneToColumn) throws Exception{
public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, SparqlConnection sc, String storedNodeGroupId, JSONObject externalConstraints, QueryFlags flags, JSONArray runtimeConstraints, int limitOverride, int offsetOverride, String targetObjectSparqlID) throws Exception{

// get the node group from the remote store
TableResultSet trs = this.storeClient.executeGetNodeGroupById(storedNodeGroupId);
Expand Down Expand Up @@ -491,7 +440,7 @@ public void dispatchJob(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, Sparql
}

// dispatch the job itself
this.dispatchJob(qt, rt, conn, ng, externalConstraints, flags, runtimeConstraints, limitOverride, offsetOverride, targetObjectSparqlID, pruneToColumn);
this.dispatchJob(qt, rt, conn, ng, externalConstraints, flags, runtimeConstraints, limitOverride, offsetOverride, targetObjectSparqlID);
}

public URL[] dispatchJobSynchronous(AutoGeneratedQueryTypes qt, SparqlResultTypes rt, SparqlConnection sc, String storedNodeGroupId, JSONObject externalConstraints, JSONArray runtimeConstraints, String targetObjectSparqlID) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public class NodeGroupExecutionClient extends SharedIngestNgeClient {
private static final String JSON_KEY_RUNTIME_CONSTRAINTS = "runtimeConstraints";
private static final String JSON_KEY_EDC_CONSTRAINTS = "externalDataConnectionConstraints";
private static final String JSON_KEY_FLAGS = "flags";
private static final String JSON_KEY_PRUNE_TO_COLUMN = "pruneToColumn";

// service mapping
private static final String mappingPrefix = "/nodeGroupExecution";
Expand Down Expand Up @@ -518,13 +517,12 @@ public Table execDispatchSelectByIdToTable(String nodegroupID, SparqlConnection
* @param runtimeConstraintsJson
* @param limitOverride
* @param offsetOverride
* @param pruneToColumn
* @return
* @throws Exception
*/
public Table execDispatchByIdToTable(String nodegroupID, SparqlConnection overrideConn, JSONObject edcConstraintsJson, JSONArray flagsJson, JSONArray runtimeConstraintsJson, int limitOverride, int offsetOverride, String pruneToColumn) throws Exception{
public Table execDispatchByIdToTable(String nodegroupID, SparqlConnection overrideConn, JSONObject edcConstraintsJson, JSONArray flagsJson, JSONArray runtimeConstraintsJson, int limitOverride, int offsetOverride) throws Exception{
// dispatch the job
String jobId = this.dispatchByIdToJobId(nodegroupID, overrideConn, edcConstraintsJson, flagsJson, runtimeConstraintsJson, limitOverride, offsetOverride, pruneToColumn);
String jobId = this.dispatchByIdToJobId(nodegroupID, overrideConn, edcConstraintsJson, flagsJson, runtimeConstraintsJson, limitOverride, offsetOverride);

try {
return this.waitForJobAndGetTable(jobId);
Expand Down Expand Up @@ -1638,12 +1636,11 @@ public Table getRuntimeConstraintsByNodeGroupID(String nodegroupID) throws Excep
* @param runtimeConstraintsJson
* @param limitOverride
* @param offsetOverride
* @param pruneToColumn
* @return String jobId
* @throws Exception
*/
public String dispatchByIdToJobId(String nodegroupID, SparqlConnection overrideConn, JSONObject edcConstraintsJson, JSONArray flagsJson, JSONArray runtimeConstraintsJson, int limitOverride, int offsetOverride, String pruneToColumn) throws Exception{
SimpleResultSet ret = this.execDispatchById(nodegroupID, overrideConn, edcConstraintsJson, flagsJson, runtimeConstraintsJson, limitOverride, offsetOverride, pruneToColumn);
public String dispatchByIdToJobId(String nodegroupID, SparqlConnection overrideConn, JSONObject edcConstraintsJson, JSONArray flagsJson, JSONArray runtimeConstraintsJson, int limitOverride, int offsetOverride) throws Exception{
SimpleResultSet ret = this.execDispatchById(nodegroupID, overrideConn, edcConstraintsJson, flagsJson, runtimeConstraintsJson, limitOverride, offsetOverride);
return ret.getResult("JobId");
}

Expand All @@ -1663,7 +1660,7 @@ public String dispatchByIdToJobId(String nodegroupID, SparqlConnection overrideC
}

/**
* Raw call to launch a select query: version without query flags or pruneToColumn
* Raw call to launch a select query: version without query flags
* @param nodegroupID
* @param overrideConn
* @param edcConstraintsJson
Expand All @@ -1672,22 +1669,10 @@ public String dispatchByIdToJobId(String nodegroupID, SparqlConnection overrideC
* @throws Exception
*/
public SimpleResultSet execDispatchById(String nodegroupID, SparqlConnection overrideConn, JSONObject edcConstraintsJson, JSONArray runtimeConstraintsJson) throws Exception{
return this.execDispatchById(nodegroupID, overrideConn, edcConstraintsJson, null, runtimeConstraintsJson, -1, -1, null);
return this.execDispatchById(nodegroupID, overrideConn, edcConstraintsJson, null, runtimeConstraintsJson, -1, -1);
}

/**
* Raw call to launch a select query: version without pruneToColumn
* @param nodegroupID
* @param overrideConn
* @param edcConstraintsJson
* @param flagsJson
* @param runtimeConstraintsJson
* @return
* @throws Exception
*/
public SimpleResultSet execDispatchById(String nodegroupID, SparqlConnection overrideConn, JSONObject edcConstraintsJson, JSONArray flagsJson, JSONArray runtimeConstraintsJson, int limitOverride, int offsetOverride) throws Exception{
return this.execDispatchById(nodegroupID, overrideConn, edcConstraintsJson, flagsJson, runtimeConstraintsJson, limitOverride, offsetOverride, null);
}


/**
* Raw call to launch a select query
Expand All @@ -1698,12 +1683,11 @@ public SimpleResultSet execDispatchById(String nodegroupID, SparqlConnection ove
* @param runtimeConstraintsJson
* @param limitOverride
* @param offsetOverride
* @param pruneToColumn
* @return SimpleResultSet containing "JobId"
* @throws Exception
*/
@SuppressWarnings("unchecked")
public SimpleResultSet execDispatchById(String nodegroupID, SparqlConnection overrideConn, JSONObject edcConstraintsJson, JSONArray flagsJson, JSONArray runtimeConstraintsJson, int limitOverride, int offsetOverride, String pruneToColumn) throws Exception{
public SimpleResultSet execDispatchById(String nodegroupID, SparqlConnection overrideConn, JSONObject edcConstraintsJson, JSONArray flagsJson, JSONArray runtimeConstraintsJson, int limitOverride, int offsetOverride) throws Exception{
SimpleResultSet retval = null;

conf.setServiceEndpoint(mappingPrefix + dispatchByIdEndpoint);
Expand All @@ -1716,8 +1700,6 @@ public SimpleResultSet execDispatchById(String nodegroupID, SparqlConnection ove
this.parametersJSON.put(JSON_KEY_EDC_CONSTRAINTS, edcConstraintsJson == null ? null : edcConstraintsJson.toJSONString());
this.parametersJSON.put(JSON_KEY_FLAGS, flagsJson == null ? null : flagsJson.toJSONString());
this.parametersJSON.put(JSON_KEY_RUNTIME_CONSTRAINTS, runtimeConstraintsJson == null ? null : runtimeConstraintsJson.toJSONString());
if (pruneToColumn != null)
this.parametersJSON.put(JSON_KEY_PRUNE_TO_COLUMN, pruneToColumn);

try{
LocalLogger.logToStdErr("sending executeDispatchById request");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* Base class for dispatchers.
*/
public abstract class AsynchronousNodeGroupBasedQueryDispatcher {
private String pruneToColumn;
private String pruneToColumn = null;

protected NodeGroup queryNodeGroup;
protected OntologyInfoClient oInfoClient;
Expand Down Expand Up @@ -335,6 +335,10 @@ public JobTracker getJobTracker() {
return this.jobTracker;
}

/**
* Add column name for prune feature (prune table to single unique column)
* @param pruneToColumn - column name or null
*/
public void addPruneToColumn(String pruneToColumn) {
this.pruneToColumn = pruneToColumn;

Expand Down
Loading

0 comments on commit 366515d

Please sign in to comment.