/** * Constructor for a ConstraintSet object. * Add AbstractConstraint objects to this object with the add method. */ public ConstraintSet() { cons = new ConsistentSet<AbstractConstraint>(); }
/** * Constructor for a ConstraintSet object. * Add AbstractConstraint objects to this object with the add method. */ public ConstraintSet() { cons = new ConsistentSet<AbstractConstraint>(); }
/** * Construct a new Query. */ public Query() { select = new ArrayList<SelectValue>(); from = new ConsistentSet<AbstractTable>(); where = new ConsistentSet<AbstractConstraint>(); groupBy = new ConsistentSet<AbstractValue>(); having = new ConsistentSet<AbstractConstraint>(); orderBy = new ArrayList<AbstractValue>(); limit = 0; offset = 0; explain = false; distinct = false; queriesInUnion = new ArrayList<Query>(); queriesInUnion.add(this); aliasToSelect = new HashMap<String, AbstractValue>(); this.aliasToTable = null; this.originalAliasToTable = null; }
/** * Construct a new Query. */ public Query() { select = new ArrayList<SelectValue>(); from = new ConsistentSet<AbstractTable>(); where = new ConsistentSet<AbstractConstraint>(); groupBy = new ConsistentSet<AbstractValue>(); having = new ConsistentSet<AbstractConstraint>(); orderBy = new ArrayList<AbstractValue>(); limit = 0; offset = 0; explain = false; distinct = false; queriesInUnion = new ArrayList<Query>(); queriesInUnion.add(this); aliasToSelect = new HashMap<String, AbstractValue>(); this.aliasToTable = null; this.originalAliasToTable = null; }
public void testAdd() throws Exception { Object o1 = "string1"; Object o2 = "string2"; Set set = new ConsistentSet(); set.add(o1); set.add(o2); assertEquals(2, set.size()); assertTrue(set.contains(o1)); assertTrue(set.contains(o2)); }
public void testAddingSame() throws Exception { Object o1 = "string1"; Object o2 = "string2"; Object o3 = "string2"; Set set = new ConsistentSet(); set.add(o1); set.add(o2); set.add(o3); assertEquals(2, set.size()); assertTrue(set.contains(o1)); assertTrue(set.contains(o2)); assertTrue(set.contains(o3)); }
public void testEqualsHashSet() throws Exception { TestObject o1 = new TestObject("string1"); TestObject o2 = new TestObject("string2"); Set set1 = new ConsistentSet(); Set set2 = new HashSet(); set1.add(o1); set1.add(o2); set2.add(o2); set2.add(o1); assertEquals(set1.hashCode(), set2.hashCode()); assertEquals(set1, set2); assertEquals(set2.hashCode(), set1.hashCode()); assertEquals(set2, set1); } }
public void testOutOfOrderEquals() throws Exception { TestObject o1 = new TestObject("string1"); TestObject o2 = new TestObject("string2"); TestObject o3 = new TestObject("string3"); TestObject o4 = new TestObject("string4"); Set set1 = new ConsistentSet(); Set set2 = new ConsistentSet(); set1.add(o1); set1.add(o2); set2.add(o3); set2.add(o4); o3.a = "string2"; o4.a = "string1"; assertEquals(set1.hashCode(), set2.hashCode()); assertEquals(set1, set2); }
public void testAlteringContents() throws Exception { TestObject o1 = new TestObject("string1"); TestObject o2 = new TestObject("string2"); TestObject o3 = new TestObject("string2"); TestObject o4 = new TestObject("somethingelse"); Set set = new ConsistentSet(); set.add(o1); set.add(o2); o2.a = "somethingelse"; assertTrue(set.contains(o1)); assertTrue(!set.contains(o3)); assertTrue(set.contains(o4)); }
public void testKimsBug4() throws Exception { try { con.createStatement().execute("CREATE TABLE SequenceFeature (id int)"); con.createStatement().execute("CREATE TABLE OverlapRelation (id int);"); Query q1 = new Query("SELECT a1_.id AS a1_id, a2_.id AS a2_id, a3_.id AS a3_id FROM SequenceFeature AS a1_, OverlapRelation AS a2_, SequenceFeature AS a3_, BioEntitiesRelations AS indirect0, BioEntitiesRelations AS indirect1 WHERE a2_.id = indirect0.BioEntities AND indirect0.Relations = a1_.id AND a2_.id = indirect1.BioEntities AND indirect1.Relations = a3_.id AND a1_.id > 24081631 ORDER BY a1_.id, a2_.id, a3_.id"); Query pq1 = new Query("SELECT a1_.id AS a1_id, a2_.id AS a2_id, a3_.id AS a3_id FROM SequenceFeature AS a1_, OverlapRelation AS a2_, SequenceFeature AS a3_, BioEntitiesRelations AS indirect0, BioEntitiesRelations AS indirect1 WHERE a2_.id = indirect0.BioEntities AND indirect0.Relations = a1_.id AND a2_.id = indirect1.BioEntities AND indirect1.Relations = a3_.id ORDER BY a1_.id, a2_.id, a3_.id"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set precomps = new LinkedHashSet(); precomps.add(pt1); //System.out.println(pt1.getSQLString() + " ---- " + pt1.getOrderByField()); StringUtil.setNextUniqueNumber(42); BestQueryStorer bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q1, bestQuery); Set eSet = new ConsistentSet(); eSet.add(new Query("SELECT P46.a1_id, P46.a2_id, P46.a3_id FROM precomp1 AS P46 WHERE 24081631 < P46.a1_id ORDER BY P46.orderby_field")); eSet.add(new Query("SELECT P49.a3_id AS a1_id, P49.a2_id, P49.a1_id AS a3_id FROM precomp1 AS P49 WHERE 24081631 < P49.a3_id ORDER BY P49.a3_id, P49.a2_id, P49.a1_id")); assertEquals(eSet, bestQuery.getQueries()); } finally { try { con.createStatement().execute("DROP TABLE SequenceFeature"); } catch (SQLException e) { } try { con.createStatement().execute("DROP TABLE OverlapRelation"); } catch (SQLException e) { } } }
public void testKimsBug5() throws Exception { try { con.createStatement().execute("CREATE TABLE SequenceFeature (id int NOT NULL)"); con.createStatement().execute("CREATE TABLE OverlapRelation (id int NOT NULL);"); Query q1 = new Query("SELECT a1_.id AS a1_id, a2_.id AS a2_id, a3_.id AS a3_id FROM SequenceFeature AS a1_, OverlapRelation AS a2_, SequenceFeature AS a3_, BioEntitiesRelations AS indirect0, BioEntitiesRelations AS indirect1 WHERE a2_.id = indirect0.BioEntities AND indirect0.Relations = a1_.id AND a2_.id = indirect1.BioEntities AND indirect1.Relations = a3_.id AND a1_.id > 24081631 ORDER BY a1_.id, a2_.id, a3_.id"); Query pq1 = new Query("SELECT a1_.id AS a1_id, a2_.id AS a2_id, a3_.id AS a3_id FROM SequenceFeature AS a1_, OverlapRelation AS a2_, SequenceFeature AS a3_, BioEntitiesRelations AS indirect0, BioEntitiesRelations AS indirect1 WHERE a2_.id = indirect0.BioEntities AND indirect0.Relations = a1_.id AND a2_.id = indirect1.BioEntities AND indirect1.Relations = a3_.id ORDER BY a1_.id, a2_.id, a3_.id"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set precomps = new LinkedHashSet(); precomps.add(pt1); //System.out.println(pt1.getSQLString() + " ---- " + pt1.getOrderByField()); StringUtil.setNextUniqueNumber(42); BestQueryStorer bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q1, bestQuery); Set eSet = new ConsistentSet(); eSet.add(new Query("SELECT P46.a1_id, P46.a2_id, P46.a3_id FROM precomp1 AS P46 WHERE 240816315000000000000000000050000000000000000000 < P46.orderby_field ORDER BY P46.orderby_field")); eSet.add(new Query("SELECT P49.a3_id AS a1_id, P49.a2_id, P49.a1_id AS a3_id FROM precomp1 AS P49 WHERE 24081631 < P49.a3_id ORDER BY P49.a3_id, P49.a2_id, P49.a1_id")); assertEquals(eSet, bestQuery.getQueries()); } finally { try { con.createStatement().execute("DROP TABLE SequenceFeature"); } catch (SQLException e) { } try { con.createStatement().execute("DROP TABLE OverlapRelation"); } catch (SQLException e) { } } }
public void testRemapAliases() throws Exception { AbstractTable t1 = new Table("table1", "alias1"); AbstractTable t2 = new Table("table2", "alias2"); AbstractTable t3 = new Table("table3", "alias3"); AbstractTable t4 = new Table("table1", "alias4"); AbstractTable t5 = new Table("table2", "alias5"); AbstractTable t6 = new Table("table3", "alias6"); AbstractTable t7 = new Table("table4", "alias1"); Map map = new HashMap(); map.put(t1, t4); map.put(t2, t5); map.put(t3, t6); Set tables = new ConsistentSet(); tables.add(t4); tables.add(t5); tables.add(t6); tables.add(t7); QueryOptimiser.remapAliases(map, tables); assertEquals(t1, map.get(t1)); assertEquals(t2, map.get(t2)); assertEquals(t3, map.get(t3)); assertTrue(!"alias1".equals(t7.getAlias())); }
public void testRecursiveOptimise2() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, table2.a AS t2_a, table2.b AS t2_b FROM table AS table1, table AS table2 WHERE table1.c = 'five' AND table2.c = 'five'"); Query pq1 = new Query("SELECT table1.a AS fhjs, table1.b AS sjhf FROM table AS table1 WHERE table1.c = 'five'"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); Set precomps = new LinkedHashSet(); precomps.add(pt1); Query eq3 = new Query("SELECT P44.fhjs AS t1_a, P44.sjhf AS t1_b, table1.a AS t2_a, table1.b AS t2_b FROM precomp1 AS P44, table AS table1 WHERE table1.c = 'five'"); Query eq1 = new Query("SELECT P45.fhjs AS t1_a, P45.sjhf AS t1_b, P47.fhjs AS t2_a, P47.sjhf AS t2_b FROM precomp1 AS P47, precomp1 AS P45"); Query eq2 = new Query("SELECT P46.a AS t1_a, P46.b AS t1_b, P48.fhjs AS t2_a, P48.sjhf AS t2_b FROM precomp1 AS P48, table AS P46 WHERE P46.c = 'five'"); Set eSet = new ConsistentSet(); eSet.add(eq1); eSet.add(eq2); eSet.add(eq3); StringUtil.setNextUniqueNumber(42); BestQueryStorer bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q1, bestQuery); assertEquals(eSet, bestQuery.getQueries()); }
public void testRecursiveOptimise3() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, table2.a AS t2_a, table2.b AS t2_b FROM table1, table2 WHERE table1.c = 'five' AND table2.c = 'six' AND table1.d = table2.d"); Query pq1 = new Query("SELECT table1.a AS fhjs, table1.b AS sjhf, table1.d AS kjhds FROM table1 WHERE table1.c = 'five'"); Query pq2 = new Query("SELECT table2.a AS kjsd, table2.b AS hjas, table2.d AS kjhsd FROM table2 WHERE table2.c = 'six'"); Query pq3 = new Query("SELECT table2.a AS kjsd, table2.b AS hjas, table2.d AS jsdff FROM table2 WHERE table2.c = 'seven'"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); PrecomputedTable pt2 = new PrecomputedTable(pq2, pq2.getSQLString(), "precomp2", null, con); PrecomputedTable pt3 = new PrecomputedTable(pq3, pq3.getSQLString(), "precomp3", null, con); Set precomps = new LinkedHashSet(); precomps.add(pt1); precomps.add(pt2); precomps.add(pt3); Query eq1 = new Query("SELECT P42.fhjs AS t1_a, P42.sjhf AS t1_b, table2.a AS t2_a, table2.b AS t2_b FROM precomp1 AS P42, table2 WHERE table2.c = 'six' AND P42.kjhds = table2.d"); Query eq2 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, P43.kjsd AS t2_a, P43.hjas AS t2_b FROM table1, precomp2 AS P43 WHERE table1.c = 'five' AND table1.d = P43.kjhsd"); Query eq3 = new Query("SELECT P44.fhjs AS t1_a, P44.sjhf AS t1_b, P43.kjsd AS t2_a, P43.hjas AS t2_b FROM precomp1 AS P44, precomp2 AS P43 WHERE P44.kjhds = P43.kjhsd"); Set eSet = new ConsistentSet(); eSet.add(eq1); eSet.add(eq2); eSet.add(eq3); StringUtil.setNextUniqueNumber(42); BestQueryStorer bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q1, bestQuery); assertEquals(eSet, bestQuery.getQueries()); }
public void testRecursiveOptimise1() throws Exception { Query q1 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, table2.a AS t2_a, table2.b AS t2_b FROM table1, table2 WHERE table1.c = 'five' AND table2.c = 'six'"); Query pq1 = new Query("SELECT table1.a AS fhjs, table1.b AS sjhf FROM table1 WHERE table1.c = 'five'"); Query pq2 = new Query("SELECT table2.a AS kjsd, table2.b AS hjas FROM table2 WHERE table2.c = 'six'"); Query pq3 = new Query("SELECT table2.a AS kjsd, table2.b AS hjas FROM table2 WHERE table2.c = 'seven'"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); PrecomputedTable pt2 = new PrecomputedTable(pq2, pq2.getSQLString(), "precomp2", null, con); PrecomputedTable pt3 = new PrecomputedTable(pq3, pq3.getSQLString(), "precomp3", null, con); Set precomps = new LinkedHashSet(); precomps.add(pt1); precomps.add(pt2); precomps.add(pt3); Query eq1 = new Query("SELECT P42.fhjs AS t1_a, P42.sjhf AS t1_b, table2.a AS t2_a, table2.b AS t2_b FROM precomp1 AS P42, table2 WHERE table2.c = 'six'"); Query eq2 = new Query("SELECT table1.a AS t1_a, table1.b AS t1_b, P43.kjsd AS t2_a, P43.hjas AS t2_b FROM table1, precomp2 AS P43 WHERE table1.c = 'five'"); Query eq3 = new Query("SELECT P44.fhjs AS t1_a, P44.sjhf AS t1_b, P43.kjsd AS t2_a, P43.hjas AS t2_b FROM precomp1 AS P44, precomp2 AS P43"); Set eSet = new ConsistentSet(); eSet.add(eq1); eSet.add(eq2); eSet.add(eq3); StringUtil.setNextUniqueNumber(42); BestQueryStorer bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q1, bestQuery); assertEquals(eSet, bestQuery.getQueries()); }
public void testKimsBug3() throws Exception { Query q1 = new Query("SELECT a1_.a AS a2_ FROM Chromosome AS a1_ ORDER BY a1_.a"); Query q2 = new Query("SELECT a1_.a AS a2_ FROM Chromosome AS a1_ WHERE a1_.a > 5325019 ORDER BY a1_.a"); Query pq1 = new Query("SELECT a1_.a AS a2_ FROM Chromosome AS a1_ ORDER BY a1_.a"); Query pq2 = new Query("SELECT a1_.a AS a2_ FROM Chromosome AS a1_ WHERE a1_.a = 10669827 ORDER BY a1_.a"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); PrecomputedTable pt2 = new PrecomputedTable(pq2, pq2.getSQLString(), "precomp2", null, con); Set precomps = new LinkedHashSet(); precomps.add(pt1); precomps.add(pt2); Query eq1 = new Query("SELECT P42.a2_ FROM precomp1 AS P42 ORDER BY P42.a2_"); Set eSet = new ConsistentSet(); eSet.add(eq1); StringUtil.setNextUniqueNumber(42); BestQueryStorer bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q1, bestQuery); assertEquals(eSet, bestQuery.getQueries()); Query eq2 = new Query("SELECT P42.a2_ FROM precomp1 AS P42 WHERE P42.a2_ > 5325019 ORDER BY P42.a2_"); eSet = new ConsistentSet(); eSet.add(eq2); StringUtil.setNextUniqueNumber(42); bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q2, bestQuery); assertEquals(eSet, bestQuery.getQueries()); }
public void testKimsBug() throws Exception { Query q1 = new Query("SELECT a1_.id AS a2_, a3_.OBJECT AS a3_, a3_.id AS a3_id, a4_.OBJECT AS a4_, a4_.id AS a4_id FROM Chromosome AS a1_, BioEntity AS a3_, Location AS a4_ WHERE a4_.locatedOnId = a1_.id AND a4_.featureId = a3_.id ORDER BY a1_.id, a3_.id, a4_.id"); Query q2 = new Query("SELECT a1_.id AS a2_, a3_.OBJECT AS a3_, a3_.id AS a3_id, a4_.OBJECT AS a4_, a4_.id AS a4_id FROM Chromosome AS a1_, BioEntity AS a3_, Location AS a4_ WHERE (a4_.locatedOnId = a1_.id AND a4_.featureId = a3_.id) AND a1_.id > 5325019 ORDER BY a1_.id, a3_.id, a4_.id"); Query pq1 = new Query("SELECT a1_.id AS a2_, a3_.OBJECT AS a3_, a3_.id AS a3_id, a4_.OBJECT AS a4_, a4_.id AS a4_id FROM Chromosome AS a1_, BioEntity AS a3_, Location AS a4_ WHERE a4_.locatedOnId = a1_.id AND a4_.featureId = a3_.id ORDER BY a1_.id, a3_.id, a4_.id"); Query pq2 = new Query("SELECT a1_.id AS a2_, a3_.OBJECT AS a3_, a3_.id AS a3_id, a4_.OBJECT AS a4_, a4_.id AS a4_id FROM Chromosome AS a1_, BioEntity AS a3_, Location AS a4_ WHERE a4_.locatedOnId = a1_.id AND a4_.featureId = a3_.id AND a1_.id = 10669827 ORDER BY a1_.id, a3_.id, a4_.id"); PrecomputedTable pt1 = new PrecomputedTable(pq1, pq1.getSQLString(), "precomp1", null, con); PrecomputedTable pt2 = new PrecomputedTable(pq2, pq2.getSQLString(), "precomp2", null, con); Set precomps = new LinkedHashSet(); precomps.add(pt1); precomps.add(pt2); Query eq1 = new Query("SELECT P42.a2_, P42.a3_, P42.a3_id, P42.a4_, P42.a4_id FROM precomp1 AS P42 ORDER BY P42.a2_, P42.a3_id, P42.a4_id"); Set eSet = new ConsistentSet(); eSet.add(eq1); StringUtil.setNextUniqueNumber(42); BestQueryStorer bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q1, bestQuery); assertEquals(eSet, bestQuery.getQueries()); Query eq2 = new Query("SELECT P42.a2_, P42.a3_, P42.a3_id, P42.a4_, P42.a4_id FROM precomp1 AS P42 WHERE P42.a2_ > 5325019 ORDER BY P42.a2_, P42.a3_id, P42.a4_id"); eSet = new ConsistentSet(); eSet.add(eq2); StringUtil.setNextUniqueNumber(42); bestQuery = new BestQueryStorer(); QueryOptimiser.recursiveOptimiseCheckSubquery(precomps, q2, bestQuery); assertEquals(eSet, bestQuery.getQueries()); }
= new ConsistentSet<Map<AbstractTable, AbstractTable>>(); Collection<Map<AbstractTable, AbstractTable>> c = MappingUtil.findCombinations(precompQuery .getFrom(), query.getFrom(), new AbstractTableComparator(),
= new ConsistentSet<Map<AbstractTable, AbstractTable>>(); Collection<Map<AbstractTable, AbstractTable>> c = MappingUtil.findCombinations(precompQuery .getFrom(), query.getFrom(), new AbstractTableComparator(),
eSet = new ConsistentSet(); eSet.add(eq); StringUtil.setNextUniqueNumber(42); eSet = new ConsistentSet(); eSet.add(eq); StringUtil.setNextUniqueNumber(42); eSet = new ConsistentSet(); eSet.add(eq); StringUtil.setNextUniqueNumber(42); eSet = new ConsistentSet(); eSet.add(eq); StringUtil.setNextUniqueNumber(42); eSet = new ConsistentSet(); eSet.add(eq); StringUtil.setNextUniqueNumber(42);