public static List<String> findAuthoritativeAtoms(Dependency egd, Scenario scenario) {
   List<String> result = new ArrayList<String>();
   for (String sourceTable : findSourceAtoms(egd, scenario)) {
     if (scenario.getAuthoritativeSources().contains(sourceTable)) {
       result.add(sourceTable);
     }
   }
   return result;
 }
示例#2
0
 public void testLoadFunction() {
   try {
     Scenario scenario = UtilityTest.loadScenarioFromResources(References.employees_rew);
     Assert.assertNotNull(scenario);
     Assert.assertNotNull(scenario.getSource());
     Assert.assertEquals(1, scenario.getSource().getTableNames().size());
     Assert.assertTrue(scenario.getSource().getTableNames().contains("S_Employee"));
     Assert.assertEquals(8, UtilityTest.getSize(scenario.getSource().getTable("S_Employee")));
     Assert.assertNotNull(scenario.getTarget());
     Assert.assertEquals(1, scenario.getTarget().getTableNames().size());
     Assert.assertEquals(0, UtilityTest.getSize(scenario.getTarget().getTable("T_Employee")));
     Assert.assertNotNull(scenario.getPartialOrder());
     if (logger.isDebugEnabled()) logger.debug(scenario.toString());
   } catch (Exception ex) {
     ex.printStackTrace();
     Assert.fail(ex.getLocalizedMessage());
   }
 }
 public void test07() throws Exception {
   String scenarioName = "persons-deps-07";
   Scenario scenario =
       UtilityTest.loadScenarioFromResources(References.persons_deps_07_dbms, true);
   if (logger.isDebugEnabled()) logger.debug(scenario.toString());
   setConfigurationForTest(scenario);
   scenario.getCostManagerConfiguration().setType(LunaticConstants.COST_MANAGER_SIMILARITY);
   scenario.getCostManagerConfiguration().setDoPermutations(false);
   scenario.getConfiguration().setRemoveDuplicates(false);
   DeltaChaseStep result = ChaserFactory.getChaser(scenario).doChase(scenario);
   if (logger.isDebugEnabled()) logger.debug("Scenario " + scenarioName);
   if (logger.isDebugEnabled()) logger.debug(result.toStringWithSort());
   if (logger.isDebugEnabled())
     logger.debug("Number of solutions: " + resultSizer.getPotentialSolutions(result));
   if (logger.isDebugEnabled())
     logger.debug("Number of duplicate solutions: " + resultSizer.getDuplicates(result));
   Assert.assertEquals(1, resultSizer.getPotentialSolutions(result));
   checkSolutions(result);
   //        exportResults("/Temp/expected-" + scenarioName, result);
   checkExpectedSolutions("expected-" + scenarioName, result);
 }
示例#4
0
 public void testLoadXML() {
   try {
     Scenario scenario = UtilityTest.loadScenarioFromResources(References.bookPublisher);
     Assert.assertNotNull(scenario);
     Assert.assertNotNull(scenario.getSource());
     Assert.assertEquals(4, scenario.getSource().getTableNames().size());
     Assert.assertEquals(3, UtilityTest.getSize(scenario.getSource().getTable("IBDBookSet")));
     Assert.assertEquals(2, UtilityTest.getSize(scenario.getSource().getTable("LOCSet")));
     Assert.assertEquals(2, UtilityTest.getSize(scenario.getSource().getTable("IBLBookSet")));
     Assert.assertEquals(2, UtilityTest.getSize(scenario.getSource().getTable("IBLPublisherSet")));
     Assert.assertNotNull(scenario.getTarget());
     Assert.assertEquals(2, scenario.getTarget().getTableNames().size());
     Assert.assertEquals(0, UtilityTest.getSize(scenario.getTarget().getTable("BookSet")));
     Assert.assertEquals(0, UtilityTest.getSize(scenario.getTarget().getTable("PublisherSet")));
     Assert.assertNotNull(scenario.getPartialOrder());
     if (logger.isDebugEnabled()) logger.debug(scenario.toString());
   } catch (Exception ex) {
     ex.printStackTrace();
     Assert.fail(ex.getLocalizedMessage());
   }
 }
示例#5
0
 public void testLoadOnlyTarget() {
   try {
     Scenario scenario = UtilityTest.loadScenarioFromResources(References.expenseDB);
     Assert.assertNotNull(scenario);
     Assert.assertNotNull(scenario.getSource());
     Assert.assertEquals(0, scenario.getSource().getTableNames().size());
     Assert.assertNotNull(scenario.getTarget());
     Assert.assertEquals(3, scenario.getTarget().getTableNames().size());
     Assert.assertEquals(3, UtilityTest.getSize(scenario.getTarget().getTable("companies")));
     Assert.assertEquals(3, UtilityTest.getSize(scenario.getTarget().getTable("projects")));
     Assert.assertEquals(4, UtilityTest.getSize(scenario.getTarget().getTable("grants")));
     Assert.assertNotNull(scenario.getPartialOrder());
     if (logger.isDebugEnabled()) logger.debug(scenario.toString());
   } catch (Exception ex) {
     ex.printStackTrace();
     Assert.fail(ex.getLocalizedMessage());
   }
 }
示例#6
0
 public void testLoadNegation() {
   try {
     Scenario scenario = UtilityTest.loadScenarioFromResources(References.companies_rew);
     Assert.assertNotNull(scenario);
     Assert.assertNotNull(scenario.getSource());
     Assert.assertEquals(5, scenario.getSource().getTableNames().size());
     Assert.assertNotNull(scenario.getTarget());
     Assert.assertEquals(2, scenario.getTarget().getTableNames().size());
     Assert.assertNotNull(scenario.getPartialOrder());
     if (logger.isDebugEnabled()) logger.debug(scenario.toString());
   } catch (Exception ex) {
     ex.printStackTrace();
     Assert.fail(ex.getLocalizedMessage());
   }
 }
 @Override
 public NewChaseSteps chaseDependency(
     DeltaChaseStep currentNode,
     Dependency egd,
     IAlgebraOperator premiseQuery,
     Scenario scenario,
     IChaseState chaseState,
     IDatabase databaseForStep) {
   if (logger.isDebugEnabled())
     logger.debug("***** Step: " + currentNode.getId() + " - Chasing dependency: " + egd);
   if (logger.isTraceEnabled()) logger.trace(databaseForStep.printInstances());
   this.lastTuple = null;
   this.lastTupleHandled = false;
   if (logger.isDebugEnabled()) logger.debug("Executing premise query: " + premiseQuery);
   if (logger.isTraceEnabled())
     logger.debug(
         "Result:\n"
             + LunaticUtility.printIterator(
                 queryRunner.run(premiseQuery, scenario.getSource(), databaseForStep)));
   long violationQueryStart = new Date().getTime();
   ITupleIterator it = queryRunner.run(premiseQuery, scenario.getSource(), databaseForStep);
   long violationQueryEnd = new Date().getTime();
   ChaseStats.getInstance()
       .addStat(ChaseStats.EGD_VIOLATION_QUERY_TIME, violationQueryEnd - violationQueryStart);
   List<Repair> repairsForDependency = new ArrayList<Repair>();
   try {
     while (true) {
       long equivalenceClassStart = new Date().getTime();
       EquivalenceClassForSymmetricEGD equivalenceClass =
           readNextEquivalenceClass(
               it, egd, currentNode.getDeltaDB(), currentNode.getId(), chaseState, scenario);
       long equivalenceClassEnd = new Date().getTime();
       ChaseStats.getInstance()
           .addStat(
               ChaseStats.EGD_EQUIVALENCE_CLASS_TIME, equivalenceClassEnd - equivalenceClassStart);
       if (equivalenceClass == null) {
         break;
       }
       ICostManager costManager = CostManagerFactory.getCostManager(egd, scenario);
       long choosingRepairStart = new Date().getTime();
       List<Repair> repairsForEquivalenceClass =
           costManager.chooseRepairStrategy(
               new EquivalenceClassForEGDProxy(equivalenceClass),
               currentNode.getRoot(),
               repairsForDependency,
               scenario,
               currentNode.getId(),
               occurrenceHandler);
       long choosingRepairEnd = new Date().getTime();
       ChaseStats.getInstance()
           .addStat(ChaseStats.EGD_CHOOSING_REPAIR_TIME, choosingRepairEnd - choosingRepairStart);
       if (logger.isDebugEnabled())
         logger.debug(
             "Repairs for equivalence class: "
                 + LunaticUtility.printCollection(repairsForEquivalenceClass));
       repairsForDependency =
           ChaseUtility.accumulateRepairs(repairsForDependency, repairsForEquivalenceClass);
       if (noMoreTuples(it)) {
         break;
       }
       if (logger.isDebugEnabled())
         logger.debug("Repairs for equivalence classes so far: " + repairsForDependency.size());
     }
   } catch (ChaseFailedException e) {
     throw e;
   } finally {
     it.close();
   }
   if (logger.isDebugEnabled())
     logger.debug(
         "Total repairs for dependency: " + LunaticUtility.printCollection(repairsForDependency));
   long repairStart = new Date().getTime();
   NewChaseSteps newSteps = applyRepairs(currentNode, repairsForDependency, egd, scenario);
   long repairEnd = new Date().getTime();
   ChaseStats.getInstance().addStat(ChaseStats.EGD_REPAIR_TIME, repairEnd - repairStart);
   return newSteps;
 }
 private EquivalenceClassForSymmetricEGD readNextEquivalenceClass(
     ITupleIterator it,
     Dependency egd,
     IDatabase deltaDB,
     String stepId,
     IChaseState chaseState,
     Scenario scenario) {
   if (!it.hasNext() && (this.lastTupleHandled || this.lastTuple == null)) {
     return null;
   }
   EquivalenceClassForSymmetricEGD equivalenceClass = createEquivalenceClass(egd);
   if (lastTuple != null && !this.lastTupleHandled) {
     if (logger.isDebugEnabled())
       logger.debug("Reading tuple : " + this.lastTuple.toStringWithOIDAndAlias());
     addTuple(
         this.lastTuple,
         equivalenceClass,
         scenario.getCostManagerConfiguration(),
         deltaDB,
         stepId,
         scenario);
     this.lastTupleHandled = true;
   }
   if (logger.isDebugEnabled()) logger.debug("Reading next equivalence class...");
   while (it.hasNext()) {
     if (chaseState.isCancelled())
       ChaseUtility.stopChase(
           chaseState); // throw new ChaseException("Chase interrupted by user");
     Tuple tuple = it.next();
     if (logger.isDebugEnabled())
       logger.debug("Reading tuple : " + tuple.toStringWithOIDAndAlias());
     if (lastTuple == null
         || equivalenceClass.isEmpty()
         || EquivalenceClassUtility.sameEquivalenceClass(tuple, this.lastTuple, egd)) {
       addTuple(
           tuple,
           equivalenceClass,
           scenario.getCostManagerConfiguration(),
           deltaDB,
           stepId,
           scenario);
       this.lastTuple = tuple;
       this.lastTupleHandled = true;
     } else {
       if (logger.isDebugEnabled()) logger.debug("Equivalence class is finished...");
       if (equivalenceClass.isEmpty()) {
         throw new IllegalArgumentException(
             "Unable to create equivalence class for egd:\n"
                 + egd
                 + "\nLast tuple: \n"
                 + lastTuple
                 + "\nCurrent tuple: \n"
                 + tuple);
       }
       this.lastTuple = tuple;
       this.lastTupleHandled = false;
       break;
     }
   }
   if (logger.isDebugEnabled()) logger.debug("Equivalence class loaded");
   if (logger.isDebugEnabled())
     logger.debug("-------- Equivalence class:\n" + equivalenceClass + "\n---------------");
   return equivalenceClass;
 }