use of org.apache.jena.sparql.exec.RowSet in project jena by apache.
the class Service method exec.
public static QueryIterator exec(OpService op, Context context) {
if (context == null)
context = emptyContext;
if (context != null && context.isFalse(httpServiceAllowed))
throw new QueryExecException("SERVICE execution disabled");
if (!op.getService().isURI())
throw new QueryExecException("Service URI not bound: " + op.getService());
boolean silent = op.getSilent();
// [QExec] Add getSubOpUnmodified();
if (!op.getService().isURI())
throw new QueryExecException("Service URI not bound: " + op.getService());
String serviceURL = op.getService().getURI();
Op opRemote = op.getSubOp();
Query query;
if (false) {
// ***** Interacts with substitution.
Element el = op.getServiceElement().getElement();
if (el instanceof ElementSubQuery)
query = ((ElementSubQuery) el).getQuery();
else {
query = QueryFactory.create();
query.setQueryPattern(el);
query.setResultVars();
}
}
// This relies on the observation that the query was originally correct,
// so reversing the scope renaming is safe (it merely restores the
// algebra expression).
//
// Any variables that reappear should be internal ones that were hidden
// by renaming in the first place.
//
// Any substitution is also safe because it replaces variables by
// values.
//
// It is safer to rename/unrename than skipping SERVICE during rename
// to avoid substituting hidden variables.
Op opRestored = Rename.reverseVarRename(opRemote, true);
query = OpAsQuery.asQuery(opRestored);
// Transforming: Same object means "no change"
boolean requiresRemapping = false;
Map<Var, Var> varMapping = null;
if (!opRestored.equals(opRemote)) {
varMapping = new HashMap<>();
Set<Var> originalVars = OpVars.visibleVars(op);
Set<Var> remoteVars = OpVars.visibleVars(opRestored);
for (Var v : originalVars) {
if (v.getName().contains("/")) {
// A variable which was scope renamed so has a different name
String origName = v.getName().substring(v.getName().lastIndexOf('/') + 1);
Var remoteVar = Var.alloc(origName);
if (remoteVars.contains(remoteVar)) {
varMapping.put(remoteVar, v);
requiresRemapping = true;
}
} else {
// A variable which does not have a different name
if (remoteVars.contains(v))
varMapping.put(v, v);
}
}
}
// -- Setup
// boolean withCompression = context.isTrueOrUndef(httpQueryCompression);
long timeoutMillis = timeoutFromContext(context);
// RegistryServiceModifier is applied by QueryExecHTTP
Params serviceParams = getServiceParamsFromContext(serviceURL, context);
HttpClient httpClient = chooseHttpClient(serviceURL, context);
QuerySendMode querySendMode = chooseQuerySendMode(serviceURL, context, QuerySendMode.asGetWithLimitBody);
// -- End setup
// Build the execution
QueryExecHTTP qExec = QueryExecHTTP.newBuilder().endpoint(serviceURL).timeout(timeoutMillis, TimeUnit.MILLISECONDS).query(query).params(serviceParams).context(context).httpClient(httpClient).sendMode(querySendMode).build();
try {
// Detach from the network stream.
RowSet rowSet = qExec.select().materialize();
QueryIterator qIter = QueryIterPlainWrapper.create(rowSet);
if (requiresRemapping)
qIter = QueryIter.map(qIter, varMapping);
return qIter;
} catch (HttpException ex) {
throw QueryExceptionHTTP.rewrap(ex);
}
}
use of org.apache.jena.sparql.exec.RowSet in project jena by apache.
the class QueryExecHTTP method select.
@Override
public RowSet select() {
checkNotClosed();
check(QueryType.SELECT);
RowSet rs = execRowSet();
return rs;
}
use of org.apache.jena.sparql.exec.RowSet in project jena by apache.
the class TestProtobufResultSet method test.
private static ResultSetRewindable test(ResultSetRewindable resultSet) {
resultSet.reset();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ResultSetFormatter.output(out, resultSet, ResultSetLang.RS_Protobuf);
resultSet.reset();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
RowSet rs$ = ProtobufRDF.readRowSet(in);
ResultSetRewindable resultSet2 = ResultSetFactory.makeRewindable(rs$);
// Includes bnode labels.
ResultSetCompare.equalsExact(resultSet, resultSet2);
resultSet.reset();
resultSet2.reset();
return resultSet2;
}
use of org.apache.jena.sparql.exec.RowSet in project jena by apache.
the class RowSetReaderJSON method process.
private static QueryExecResult process(InputStream in, Context context) {
if (context == null)
context = ARQ.getContext();
RowSetJSON exec = new RowSetJSON(context);
exec.parse(in);
if (exec.rows != null) {
// RowSet rs = RowSetStream.create(exec.vars, exec.rows.iterator());
RowSet rs = RowSetStream.create(exec.vars, exec.rows.iterator());
return new QueryExecResult(rs);
} else
return new QueryExecResult(exec.booleanResult);
}
use of org.apache.jena.sparql.exec.RowSet in project jena by apache.
the class TestSolverTDB method solve_04.
@Test
public void solve_04() {
// Below everything.
RowSet rs1 = exec("(bgp (:a :p :a))");
RowSet rs2 = results("empty");
equals(rs1, rs2);
}
Aggregations