/** * Returns a String representation of this SubQuery object, auitable for forming part of an SQL * query. * * @return the String representation */ @Override public String getSQLString() { return "(" + query.getSQLString() + ") AS " + alias; }
/** * Gets the best query String found so far * * @return the best Query, or null if no Queries added to this object */ @Override public String getBestQueryString() { return (query == null ? queryString : query.getSQLString()); }
/** * Returns the String query of this Candidate, converting from Query if necessary. * * @return a String */ public String getQueryString() { return (queryString == null ? query.getSQLString() : queryString); }
/** * Returns the String query of this Candidate, converting from Query if necessary. * * @return a String */ public String getQueryString() { return (queryString == null ? query.getSQLString() : queryString); }
/** * Overrides Object.toString(). * * @return a String representation of this Query */ @Override public String toString() { return getSQLString(); }
/** * Overrides Object.toString(). * * @return a String representation of this Query */ @Override public String toString() { return getSQLString(); }
/** * Constructs an instance of PostgresExplainResult for a given Query and * database Connection. * * @param query the org.intermine.sql.query.Query to be explained * @param database a java.sql.Connection by which to access the database * @throws SQLException if a database error occurs * @throws NullPointerException if either query or database are null */ public PostgresExplainResult(Query query, Connection database) throws SQLException { this(query.getSQLString(), database); }
/** * Gets the best query String found so far * * @return the best Query, or null if no Queries added to this object */ @Override public String getBestQueryString() { return (query == null ? queryString : query.getSQLString()); }
/** * Allows a Query to be logged * * @param q a Query to be logged * @param w the Writer on which to log the Query * @throws IOException if unable to log correctly */ public static void log(Query q, Writer w) throws IOException { synchronized (lock) { w.write(new Date().toString() + "\t" + q.getSQLString()); } }
/** * Allows a Query to be logged * * @param q a Query to be logged * @param w the Writer on which to log the Query * @throws IOException if unable to log correctly */ public static void log(Query q, Writer w) throws IOException { synchronized (lock) { w.write(new Date().toString() + "\t" + q.getSQLString()); } }
/** * Allows a Query to be added to this tracker. * * @param q a Query to be added to the tracker * @throws BestQueryException when adding should stop * @throws SQLException if error occurs in the underlying database */ @Override public void add(Query q) throws BestQueryException, SQLException { bestQuery.add(beginning + q.getSQLString() + end); }
public void testMergeGroupByExtraSelect() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, table1.e AS t1_e, count(*) as stuff from table as table1, somethingelse as table2 WHERE table1.c = table2.a GROUP BY table1.a, table1.b, table1.d HAVING table1.d = 'five' ORDER BY table1.a LIMIT 100 OFFSET 0"); Query pq1 = new Query("SELECT table3.a AS sahjg, table3.b AS aytq, count(*) AS hksf, table3.d AS fdjsa FROM table AS table3, somethingelse AS table4 WHERE table3.c = table4.a GROUP BY table3.a, table3.b, table3.d"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set eSet = new HashSet(); Set newSet = QueryOptimiser.mergeGroupBy(pt1, q1, q1); assertEquals(eSet, newSet); }
public void testMergeGroupByWrongHaving() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, count(*) as stuff from table as table1, somethingelse as table2 WHERE table1.c = table2.a GROUP BY table1.a, table1.b, table1.d HAVING table1.d = 'five' ORDER BY table1.a LIMIT 100 OFFSET 0"); Query pq1 = new Query("SELECT table3.a AS sahjg, table3.b AS aytq, count(*) AS hksf, table3.d AS fdjsa FROM table AS table3, somethingelse AS table4 WHERE table3.c = table4.a GROUP BY table3.a, table3.b, table3.d HAVING table3.b = 'five'"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set eSet = new HashSet(); Set newSet = QueryOptimiser.mergeGroupBy(pt1, q1, q1); assertEquals(eSet, newSet); }
public void testMergeWrongSelect() throws Exception { Query q1 = new Query("SELECT table1.c AS t1_c, table1.b AS t1_b from table as table1"); Query pq1 = new Query("SELECT table2.a AS kjfd, table2.b AS ddfw FROM table as table2"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set eSet = new HashSet(); Set newSet = QueryOptimiser.merge(pt1, q1, q1); assertEquals(eSet, newSet); }
public void testMergeGroupByDifferentGroupBy() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, count(*) as stuff from table as table1, somethingelse as table2 WHERE table1.c = table2.a GROUP BY table1.a, table1.b, table1.d, table1.e HAVING table1.d = 'five' ORDER BY table1.a LIMIT 100 OFFSET 0"); Query pq1 = new Query("SELECT table3.a AS sahjg, table3.b AS aytq, count(*) AS hksf, table3.d AS fdjsa FROM table AS table3, somethingelse AS table4 WHERE table3.c = table4.a GROUP BY table3.a, table3.b, table3.d"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set eSet = new HashSet(); Set newSet = QueryOptimiser.mergeGroupBy(pt1, q1, q1); assertEquals(eSet, newSet); }
public void testMergeWrongDistinct() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b from table as table1 WHERE table1.c = 'five'"); Query pq1 = new Query("SELECT DISTINCT table2.a AS kjfd, table2.b AS ddfw FROM table as table2 WHERE table2.c = 'five'"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set eSet = new HashSet(); Set newSet = QueryOptimiser.merge(pt1, q1, q1); assertEquals(eSet, newSet); }
public void testMergeGroupByWrongTables() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, count(*) as stuff from table as table1, somethingdifferent as table2 WHERE table1.c = table2.a GROUP BY table1.a, table1.b, table1.d HAVING table1.d = 'five' ORDER BY table1.a LIMIT 100 OFFSET 0"); Query pq1 = new Query("SELECT table3.a AS sahjg, table3.b AS aytq, count(*) AS hksf, table3.d AS fdjsa FROM table AS table3, somethingelse AS table4 WHERE table3.c = table4.a GROUP BY table3.a, table3.b, table3.d"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set eSet = new HashSet(); Set newSet = QueryOptimiser.mergeGroupBy(pt1, q1, q1); assertEquals(eSet, newSet); }
public void testMergeOkayDistinct2() throws Exception { Query q1 = new Query("SELECT DISTINCT table1.a AS t1_a, table1.b AS t1_b from table as table1 WHERE table1.c = 'five'"); Query pq1 = new Query("SELECT DISTINCT table2.a AS kjfd, table2.b AS ddfw FROM table as table2 WHERE table2.c = 'five'"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Query eq1 = new Query("SELECT DISTINCT P42.kjfd AS t1_a, P42.ddfw AS t1_b FROM precomp1 AS P42"); Set eSet = new HashSet(); eSet.add(eq1); StringUtil.setNextUniqueNumber(42); Set newSet = QueryOptimiser.merge(pt1, q1, q1); assertEquals(eSet, newSet); }
public void testMergeSimple() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b from table as table1 WHERE table1.c = 'five'"); Query pq1 = new Query("SELECT table2.a AS kjfd, table2.b AS ddfw FROM table as table2 WHERE table2.c = 'five'"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Query eq1 = new Query("SELECT P42.kjfd AS t1_a, P42.ddfw AS t1_b FROM precomp1 AS P42"); Set eSet = new HashSet(); eSet.add(eq1); StringUtil.setNextUniqueNumber(42); Set newSet = QueryOptimiser.merge(pt1, q1, q1); assertEquals(eSet, newSet); }
public void testMergeOkayDistinct1() throws Exception { Query q1 = new Query("SELECT DISTINCT table1.a AS t1_a, table1.b AS t1_b from table as table1 WHERE table1.c = 'five'"); Query pq1 = new Query("SELECT table2.a AS kjfd, table2.b AS ddfw FROM table as table2 WHERE table2.c = 'five'"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Query eq1 = new Query("SELECT DISTINCT P42.kjfd AS t1_a, P42.ddfw AS t1_b FROM precomp1 AS P42"); Set eSet = new HashSet(); eSet.add(eq1); StringUtil.setNextUniqueNumber(42); Set newSet = QueryOptimiser.merge(pt1, q1, q1); assertEquals(eSet, newSet); }