Evaluates a query as job. @param query query @param options job options @param qc query context @return resulting value @throws QueryException query exception
(final IOContent query, final JobOptions options, final QueryContext qc)
| 35 | * @throws QueryException query exception |
| 36 | */ |
| 37 | final Str eval(final IOContent query, final JobOptions options, final QueryContext qc) |
| 38 | throws QueryException { |
| 39 | |
| 40 | final HashMap<String, Value> bindings = toBindings(arg(1), qc); |
| 41 | options.set(JobOptions.BASE_URI, toBaseUri(query.url(), options, JobOptions.BASE_URI)); |
| 42 | |
| 43 | final boolean service = Boolean.TRUE.equals(options.get(JobOptions.SERVICE)); |
| 44 | if(service) { |
| 45 | if(!bindings.isEmpty()) throw JOBS_SERVICE.get(info); |
| 46 | // invalidate option (not relevant for next steps, i.e., if services are written to disk) |
| 47 | options.put(JobOptions.SERVICE, null); |
| 48 | } |
| 49 | |
| 50 | // copy variable values |
| 51 | for(final Entry<String, Value> it : bindings.entrySet()) { |
| 52 | bindings.put(it.getKey(), it.getValue().materialize(n -> false, info, qc)); |
| 53 | } |
| 54 | |
| 55 | final QueryJobSpec spec = new QueryJobSpec(options, bindings, query); |
| 56 | final QueryJob job = new QueryJob(spec, qc.context, info, null); |
| 57 | |
| 58 | // add service |
| 59 | if(service) { |
| 60 | if(!bindings.isEmpty()) throw JOBS_SERVICE.get(info); |
| 61 | try { |
| 62 | final Jobs jobs = new Jobs(qc.context); |
| 63 | jobs.add(spec); |
| 64 | jobs.write(); |
| 65 | } catch(final IOException ex) { |
| 66 | throw JOBS_SERVICE_X_X.get(info, ex); |
| 67 | } |
| 68 | } |
| 69 | return Str.get(job.jc().id()); |
| 70 | } |
| 71 | } |