From 8d83eea97643c28d508f0a81f724983366ca4a5b Mon Sep 17 00:00:00 2001 From: Dario Del Piano Date: Mon, 17 Jun 2019 14:02:29 +0100 Subject: [PATCH 1/6] Fixed the mergeResults in the query visitor, now taking all the results processed --- .../datasources/ExecuteQueryVisitor.java | 60 ++++++++++++++----- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java b/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java index a0e7a62..050fef0 100644 --- a/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java +++ b/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java @@ -2,7 +2,9 @@ package org.geppetto.datasources; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import org.eclipse.emf.ecore.EObject; import org.geppetto.core.common.GeppettoHTTPClient; @@ -18,6 +20,7 @@ import org.geppetto.model.datasources.CompoundQuery; import org.geppetto.model.datasources.CompoundRefQuery; import org.geppetto.model.datasources.DataSource; +import org.geppetto.model.datasources.DatasourcesFactory; import org.geppetto.model.datasources.ProcessQuery; import org.geppetto.model.datasources.Query; import org.geppetto.model.datasources.QueryResults; @@ -257,9 +260,22 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour { throw new GeppettoDataSourceException("Cannot merge without an ID in the results"); } - + + QueryResults mergedResults = DatasourcesFactory.eINSTANCE.createQueryResults(); + Set idsList = new HashSet(); + int baseId = results.getHeader().indexOf(ID); int mergeId = processedResults.getHeader().indexOf(ID); + + for(AQueryResult result : results.getResults()) + { + idsList.add(((SerializableQueryResult) result).getValues().get(baseId)); + } + + for(AQueryResult result : processedResults.getResults()) + { + idsList.add(((SerializableQueryResult) result).getValues().get(mergeId)); + } for(String column : processedResults.getHeader()) { @@ -268,27 +284,41 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour results.getHeader().add(column); } } - - for(AQueryResult result : results.getResults()) + + for(String column : results.getHeader()) { - String currentId = ((SerializableQueryResult) result).getValues().get(baseId); - for(AQueryResult mergeResult : processedResults.getResults()) - { - if(((SerializableQueryResult) mergeResult).getValues().get(mergeId).equals(currentId)) - { - // we are in the right row - for(String column : processedResults.getHeader()) - { - if(!column.equals(ID)) + mergedResults.getHeader().add(column); + } + + for(String id : idsList) { + SerializableQueryResult newRecord = null; + for(AQueryResult result : results.getResults()) { + if(((SerializableQueryResult) result).getValues().get(baseId).equals(id)) { + newRecord = (SerializableQueryResult) result; + } + } + + for(AQueryResult result : processedResults.getResults()) { + if(((SerializableQueryResult) result).getValues().get(mergeId).equals(id)) { + if(newRecord == null) { + newRecord = (SerializableQueryResult) result; + } else { + for(String column : processedResults.getHeader()) { - int columnId = processedResults.getHeader().indexOf(column); - ((SerializableQueryResult) result).getValues().add(((SerializableQueryResult) mergeResult).getValues().get(columnId)); + if(!column.equals(ID)) + { + int columnId = processedResults.getHeader().indexOf(column); + ((SerializableQueryResult) newRecord).getValues().add(((SerializableQueryResult) result).getValues().get(columnId)); + } } + break; } - break; } } + + mergedResults.getResults().add(newRecord); } + results = mergedResults; } else { From b7f34fd8931018a04cf775bfaa48d3d66e0b736b Mon Sep 17 00:00:00 2001 From: Dario Del Piano Date: Mon, 1 Jul 2019 13:24:44 +0200 Subject: [PATCH 2/6] merged results with multiple queries and not only limited to 2 compounds --- .../datasources/ExecuteQueryVisitor.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java b/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java index 050fef0..b83ae83 100644 --- a/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java +++ b/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java @@ -43,6 +43,7 @@ public class ExecuteQueryVisitor extends DatasourcesSwitch private boolean count = false; // true if we want to execute a count private QueryResults results = null; + private QueryResults mergedResults = DatasourcesFactory.eINSTANCE.createQueryResults(); private Variable variable; @@ -261,7 +262,6 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour throw new GeppettoDataSourceException("Cannot merge without an ID in the results"); } - QueryResults mergedResults = DatasourcesFactory.eINSTANCE.createQueryResults(); Set idsList = new HashSet(); int baseId = results.getHeader().indexOf(ID); @@ -290,7 +290,10 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour mergedResults.getHeader().add(column); } + int lastId = mergedResults.getHeader().indexOf(ID); + for(String id : idsList) { + Boolean resultAdded = false; SerializableQueryResult newRecord = null; for(AQueryResult result : results.getResults()) { if(((SerializableQueryResult) result).getValues().get(baseId).equals(id)) { @@ -316,7 +319,17 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour } } - mergedResults.getResults().add(newRecord); + for(AQueryResult result : mergedResults.getResults()) { + if((((SerializableQueryResult) result).getValues().get(lastId).equals(id)) && newRecord != null) { + result = newRecord; + resultAdded = true; + break; + } + } + + if(!resultAdded) { + mergedResults.getResults().add(newRecord); + } } results = mergedResults; } From 348e55cd8f17fe5aa2553520b138ef2511548c67 Mon Sep 17 00:00:00 2001 From: Dario Del Piano Date: Tue, 2 Jul 2019 17:44:56 +0200 Subject: [PATCH 3/6] merge results function commented on every step, added a small fix as well --- .../datasources/ExecuteQueryVisitor.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java b/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java index b83ae83..e3f249f 100644 --- a/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java +++ b/src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java @@ -254,7 +254,8 @@ private void processResponse(String response, ADataSourceService dataSourceServi */ private void mergeResults(QueryResults processedResults) throws GeppettoDataSourceException { - + // if this arrives from a first query results should be empty, so we automatically assign + // processedResults to results if(results != null) { if(!results.getHeader().contains(ID) || !processedResults.getHeader().contains(ID)) @@ -264,9 +265,12 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour Set idsList = new HashSet(); + // Extract the index of the id for each list of results int baseId = results.getHeader().indexOf(ID); int mergeId = processedResults.getHeader().indexOf(ID); + // add all the ids from results and processedResults to idsList, a Set that will contain all + // unique ids that we can iterate to do a merge of the data for(AQueryResult result : results.getResults()) { idsList.add(((SerializableQueryResult) result).getValues().get(baseId)); @@ -277,6 +281,7 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour idsList.add(((SerializableQueryResult) result).getValues().get(mergeId)); } + // Extract all the headers contained in results and processedResults and put all in mergedResults for(String column : processedResults.getHeader()) { if(!column.equals(ID)) @@ -293,18 +298,27 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour int lastId = mergedResults.getHeader().indexOf(ID); for(String id : idsList) { + // This is the real deal, here we iterate all the ids and for each id Boolean resultAdded = false; SerializableQueryResult newRecord = null; for(AQueryResult result : results.getResults()) { + // if the id is found in one of the records contained in results then we set newRecord + // to the result found if(((SerializableQueryResult) result).getValues().get(baseId).equals(id)) { newRecord = (SerializableQueryResult) result; } } - + + // Then we check the same id in processedResults for(AQueryResult result : processedResults.getResults()) { + // If this is found if(((SerializableQueryResult) result).getValues().get(mergeId).equals(id)) { + // and was not found in the results iteration, then newRecord will be set to this result if(newRecord == null) { newRecord = (SerializableQueryResult) result; + // differently we iterate this results per column and we add whatever is present here + // that was not present in the previous check, keep in mind that we overwrite also the + // columns that were already present } else { for(String column : processedResults.getHeader()) { @@ -319,18 +333,30 @@ private void mergeResults(QueryResults processedResults) throws GeppettoDataSour } } + // Finally we check if this id is present also in mergedResults, that carry over all the results + // from previous queries/compound, if this was already present then we overwrite all the + // previous informations with the coming one for(AQueryResult result : mergedResults.getResults()) { if((((SerializableQueryResult) result).getValues().get(lastId).equals(id)) && newRecord != null) { - result = newRecord; + for(String column : mergedResults.getHeader()) + { + if(!column.equals(ID)) + { + int columnId = mergedResults.getHeader().indexOf(column); + ((SerializableQueryResult) result).getValues().add(((SerializableQueryResult) newRecord).getValues().get(columnId)); + } + } resultAdded = true; break; } } + // Instead if the id was not present in mergedResult we simply add this record if(!resultAdded) { mergedResults.getResults().add(newRecord); } } + // Then we re-initialize results as mergedResults that contains all the results to pass to frontend results = mergedResults; } else From 22675e7436cc899786d951484d97bba6c8dfecc0 Mon Sep 17 00:00:00 2001 From: Dario Del Piano Date: Tue, 9 Jul 2019 13:39:38 +0100 Subject: [PATCH 4/6] queryTemplate modified to handle the new queries from the xmi --- src/main/resources/templates/neo4j/queryTemplate.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/neo4j/queryTemplate.vm b/src/main/resources/templates/neo4j/queryTemplate.vm index d0e0e55..dd0a369 100644 --- a/src/main/resources/templates/neo4j/queryTemplate.vm +++ b/src/main/resources/templates/neo4j/queryTemplate.vm @@ -1,7 +1,7 @@ { "statements":[ { - "statement":"$QUERY", + $QUERY , "resultDataContents":[ "row" ], From 3b011aa778e1ff6a635e30a0aab54a5580acc7ce Mon Sep 17 00:00:00 2001 From: rodriguez-facundo Date: Wed, 23 Oct 2019 14:22:24 -0300 Subject: [PATCH 5/6] Add flexible version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 21bc173..4319720 100644 --- a/pom.xml +++ b/pom.xml @@ -16,12 +16,12 @@ org.geppetto core - ${project.version} + [1.0, 2.0) org.geppetto simulation - ${project.version} + [1.0, 2.0) org.springframework From 5f768499310158e2209d73c628517b89e32f89ea Mon Sep 17 00:00:00 2001 From: rodriguez-facundo Date: Wed, 23 Oct 2019 14:47:59 -0300 Subject: [PATCH 6/6] update version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4319720..554533f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.geppetto datasources Geppetto Data Sources bundle - 1.0.0 + 1.0.1 bundle 4.3.9.RELEASE