/** * Creates precomputed tables for the given query. * * @param q the Query for which to create the precomputed tables * @param category a String describing the category of the precomputed tables * @return the names of the new precomputed tables * @throws ObjectStoreException if anything goes wrong */ public List<String> precompute(Query q, String category) throws ObjectStoreException { return precompute(q, null, false, category); }
/** * Creates precomputed tables for the given query. * * @param q the Query for which to create the precomputed tables * @param category a String describing the category of the precomputed tables * @return the names of the new precomputed tables * @throws ObjectStoreException if anything goes wrong */ public List<String> precompute(Query q, String category) throws ObjectStoreException { return precompute(q, null, false, category); }
/** * Creates precomputed tables for the given query. * * @param q the Query for which to create the precomputed tables * @param indexes a Collection of QueryNode for which to create indexes * @return the names of the new precomputed tables * @param category a String describing the category of the precomputed tables * @throws ObjectStoreException if anything goes wrong */ public List<String> precompute(Query q, Collection<? extends QueryNode> indexes, String category) throws ObjectStoreException { return precompute(q, indexes, false, category); }
/** * Creates precomputed tables for the given query. * * @param q the Query for which to create the precomputed tables * @param allFields true if all fields of QueryClasses in the SELECT list should be included in * the precomputed table's SELECT list. * @param category a String describing the category of the precomputed tables * @return the names of the new precomputed tables * @throws ObjectStoreException if anything goes wrong */ public List<String> precompute(Query q, boolean allFields, String category) throws ObjectStoreException { return precompute(q, null, allFields, category); }
/** * Creates precomputed tables for the given query. * * @param q the Query for which to create the precomputed tables * @param indexes a Collection of QueryNode for which to create indexes * @return the names of the new precomputed tables * @param category a String describing the category of the precomputed tables * @throws ObjectStoreException if anything goes wrong */ public List<String> precompute(Query q, Collection<? extends QueryNode> indexes, String category) throws ObjectStoreException { return precompute(q, indexes, false, category); }
/** * Creates precomputed tables for the given query. * * @param q the Query for which to create the precomputed tables * @param allFields true if all fields of QueryClasses in the SELECT list should be included in * the precomputed table's SELECT list. * @param category a String describing the category of the precomputed tables * @return the names of the new precomputed tables * @throws ObjectStoreException if anything goes wrong */ public List<String> precompute(Query q, boolean allFields, String category) throws ObjectStoreException { return precompute(q, null, allFields, category); }
/** * Call ObjectStoreInterMineImpl.precompute() with the given Query. * * @param key the String describing the job, for logging * @param query the query to precompute * @param indexes the index QueryNodes * @param allFields whether to include all fields in the precomputed table * @param category the category of the precomputed table * @param threadNo the thread number, for logging * @throws ObjectStoreException if the query cannot be precomputed. */ protected void precomputeQuery(String key, Query query, Collection<? extends QueryNode> indexes, boolean allFields, String category, int threadNo) throws ObjectStoreException { LOG.info("Thread " + threadNo + " precomputing " + key + " - " + query + " with indexes " + indexes); long start = System.currentTimeMillis(); try { os.precompute(query, indexes, allFields, category); } catch (ObjectStoreException e) { LOG.error("Precompute failed for " + key, e); throw e; } LOG.info("Precompute took " + (System.currentTimeMillis() - start) + " ms for: " + key); } }
/** * Call ObjectStoreInterMineImpl.precompute() with the given Query. * * @param key the String describing the job, for logging * @param query the query to precompute * @param indexes the index QueryNodes * @param allFields whether to include all fields in the precomputed table * @param category the category of the precomputed table * @param threadNo the thread number, for logging * @throws ObjectStoreException if the query cannot be precomputed. */ protected void precomputeQuery(String key, Query query, Collection<? extends QueryNode> indexes, boolean allFields, String category, int threadNo) throws ObjectStoreException { LOG.info("Thread " + threadNo + " precomputing " + key + " - " + query + " with indexes " + indexes); long start = System.currentTimeMillis(); try { os.precompute(query, indexes, allFields, category); } catch (ObjectStoreException e) { LOG.error("Precompute failed for " + key, e); throw e; } LOG.info("Precompute took " + (System.currentTimeMillis() - start) + " ms for: " + key); } }
/** * Call ObjectStoreInterMineImpl.precompute() with the given Query. * @param query the query to precompute * @param indexes the index QueryNodes * @param name the name of the query we are precomputing (used for documentation is an exception * is thrown * @throws BuildException if the query cannot be precomputed. */ protected void precompute(Query query, Collection<QueryNode> indexes, String name) { long start = System.currentTimeMillis(); try { ObjectStoreInterMineImpl osInterMineImpl = ((ObjectStoreInterMineImpl) os); if (!osInterMineImpl.isPrecomputed(query, PRECOMPUTE_CATEGORY_TEMPLATE)) { osInterMineImpl.precompute(query, indexes, PRECOMPUTE_CATEGORY_TEMPLATE); } else { LOG.info("Skipping template " + name + " - already precomputed."); } } catch (ObjectStoreException e) { LOG.error("Exception while precomputing query: " + name + ", " + query + " with indexes " + indexes, e); } LOG.info("precompute(indexes) of took " + (System.currentTimeMillis() - start) / 1000 + " seconds for: " + query); }
/** * Call ObjectStoreInterMineImpl.precompute() with the given Query. * @param query the query to precompute * @param indexes the index QueryNodes * @param name the name of the query we are precomputing (used for documentation is an exception * is thrown * @throws BuildException if the query cannot be precomputed. */ protected void precompute(Query query, Collection<QueryNode> indexes, String name) { long start = System.currentTimeMillis(); try { ObjectStoreInterMineImpl osInterMineImpl = ((ObjectStoreInterMineImpl) os); if (!osInterMineImpl.isPrecomputed(query, PRECOMPUTE_CATEGORY_TEMPLATE)) { osInterMineImpl.precompute(query, indexes, PRECOMPUTE_CATEGORY_TEMPLATE); } else { LOG.info("Skipping template " + name + " - already precomputed."); } } catch (ObjectStoreException e) { LOG.error("Exception while precomputing query: " + name + ", " + query + " with indexes " + indexes, e); } LOG.info("precompute(indexes) of took " + (System.currentTimeMillis() - start) / 1000 + " seconds for: " + query); }
/** * Precomputes a template query if it is not already precomputed, returning whether precomputing * was necessary. * * @param t the TemplateQuery to precompute * @return true if the template was not already precomputed * @throws ObjectStoreException if there is a problem precomputing */ public boolean precomputeTemplate(TemplateQuery t) throws ObjectStoreException { List<QueryNode> indexes = new ArrayList<QueryNode>(); Query q = TemplatePrecomputeHelper.getPrecomputeQuery(t, indexes); ObjectStoreInterMineImpl osimi = (ObjectStoreInterMineImpl) os; if (!osimi.isPrecomputed(q, "template")) { osimi.precompute(q, indexes, "template"); return true; } return false; }
/** * Precomputes a template query if it is not already precomputed, returning whether precomputing * was necessary. * * @param t the TemplateQuery to precompute * @return true if the template was not already precomputed * @throws ObjectStoreException if there is a problem precomputing */ public boolean precomputeTemplate(TemplateQuery t) throws ObjectStoreException { List<QueryNode> indexes = new ArrayList<QueryNode>(); Query q = TemplatePrecomputeHelper.getPrecomputeQuery(t, indexes); ObjectStoreInterMineImpl osimi = (ObjectStoreInterMineImpl) os; if (!osimi.isPrecomputed(q, "template")) { osimi.precompute(q, indexes, "template"); return true; } return false; }
List<String> precomputes = objectStoreInterMineImpl.precompute(q, indexes, "test"); String tableName = String.valueOf(precomputes.get(0));
indexesToCreate.add(qcLoc); indexesToCreate.add(qcSub); ((ObjectStoreInterMineImpl) os).precompute(q, indexesToCreate, Constants.PRECOMPUTE_CATEGORY);
@Test public void testIsPrecomputed() throws Exception { Query q = new Query(); QueryClass qc = new QueryClass(Employee.class); QueryField qf = new QueryField(qc,"age"); SimpleConstraint sc = new SimpleConstraint(qf,ConstraintOp.GREATER_THAN,new QueryValue(new Integer(20))); q.addToSelect(qc); q.addFrom(qc); q.setConstraint(sc); Assert.assertFalse(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); ((ObjectStoreInterMineImpl)os).precompute(q, "template"); Assert.assertTrue(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); ObjectStoreBag osb = storeDataWriter.createObjectStoreBag(); storeDataWriter.addToBag(osb, new Integer(5)); Assert.assertTrue(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); storeDataWriter.store(data.get("EmployeeA1")); Assert.assertFalse(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); }
q.setConstraint(cs); ((ObjectStoreInterMineImpl) os).precompute(q, Constants .PRECOMPUTE_CATEGORY); Results res = os.execute(q, 5000, true, true, true);
long time2 = System.currentTimeMillis(); System.out.println("Access to results took " + (time2 - time1) + " ms"); ((ObjectStoreInterMineImpl) os).precompute(q2, "test"); long time3 = System.currentTimeMillis(); System.out.println("Precomputing took " + (time3 - time2) + " ms");
@Test public void testPrecomputeWithNegatives() throws Exception { Types t1 = new Types(); t1.setLongObjType(new Long(-765187651234L)); t1.setIntObjType(new Integer(278652)); t1.setName("Fred"); storeDataWriter.store(t1); Query q = new Query(); QueryClass qc = new QueryClass(Types.class); QueryField into = new QueryField(qc, "intObjType"); QueryField longo = new QueryField(qc, "longObjType"); q.addFrom(qc); q.addToSelect(into); q.addToSelect(longo); q.addToSelect(qc); q.setDistinct(false); ((ObjectStoreInterMineImpl) os).precompute(q, "test"); Results r = os.execute(q, 1, true, true, true); SqlGenerator.registerOffset(q, 1, ((ObjectStoreInterMineImpl) os).getSchema(), ((ObjectStoreInterMineImpl) os).db, new Integer(278651), new HashMap()); ResultsRow row = (ResultsRow) r.get(1); InterMineObject o = (InterMineObject) row.get(2); Assert.assertEquals("Expected " + t1.toString() + " but got " + o.toString(), t1.getId(), o.getId()); try { r.get(2); Assert.fail("Expected size to be 2"); } catch (Exception e) { } Assert.assertEquals(2, r.size()); storeDataWriter.delete(t1); }
q.addToSelect(qc); q.setDistinct(false); ((ObjectStoreInterMineImpl) os).precompute(q, "test");
pq.addFrom(qc); pq.addToSelect(qc); ((ObjectStoreInterMineImpl) os).precompute(pq, "Whatever"); Query q = new Query(); QueryClass qc1 = new QueryClass(Manager.class);