Commit 8b47a198 authored by Georg Fette's avatar Georg Fette
Browse files

fixed refactoring bugs. CQL2CQL is now working

parent 20bd21e2
......@@ -120,6 +120,7 @@ public class CQL_2_Graph_Mapper extends Mapper {
parsingReturnRoot = false;
parsingRetrieveClause = false;
retrieveRoot = null;
aliasIndex = 0;
}
public void dispose() {
......@@ -286,13 +287,14 @@ public class CQL_2_Graph_Mapper extends Mapper {
QueryOperator queryOp = currentOp;
QueryOperator lastOp = currentOp;
QueryOperator thisOp = insertOp(OperatorType.SORT);
currentOp.addParameter(queryOp);
List<SortByItemContext> sortByItem = sortClause.sortByItem();
for (SortByItemContext anItem : sortByItem) {
ExpressionTermContext expressionTerm = anItem.expressionTerm();
// set the currentPath to point to the iterator of the surrounding query
QueryOperator asConcept = queryOp.getParameters().get(0).asConcept();
setCurrentPath(new GraphPath(asConcept));
// the first parameter is the operator returning the list to be sorted
String alias = queryOp.getParameters().get(0).alias;
startPathWithAliasRef(alias);
parseExpressionTerm(expressionTerm);
}
currentOp = lastOp;
......
......@@ -168,33 +168,33 @@ public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
return alias;
}
// private boolean isConnectedToAnotherConceptViaEquals(QueryOperator aConc) {
// boolean includedInEquals = false;
// for (QueryOperator aChildConc : aConc.getConceptsRecursive()) {
// for (QueryOperator anOp : aChildConc.parents) {
// if (anOp.type == OperatorType.EQUALS) {
// for (Expression aParam : anOp.getParameters()) {
// if ((aParam != aChildConc) && aParam.isConcept()) {
// return true;
// }
// }
// }
// }
// }
// return false;
// }
// private boolean isConnectedToAnotherConceptViaEquals(QueryOperator aConc) {
// boolean includedInEquals = false;
// for (QueryOperator aChildConc : aConc.getConceptsRecursive()) {
// for (QueryOperator anOp : aChildConc.parents) {
// if (anOp.type == OperatorType.EQUALS) {
// for (Expression aParam : anOp.getParameters()) {
// if ((aParam != aChildConc) && aParam.isConcept()) {
// return true;
// }
// }
// }
// }
// }
// return false;
// }
private Set<QueryOperator> getConceptsToBeAliased(Expression aQuery) {
Set<QueryOperator> result = new HashSet<QueryOperator>();
// for (QueryOperator aConc : root.getConceptsRecursive()) {
// if ((aConc.getChildConcepts().size() > 1) || isConnectedToAnotherConceptViaEquals(aConc)) {
// result.add(aConc);
// }
// }
// if (root.getRootConcepts().size() > 0) {
// result.add(root.getRootConcepts().get(0));
// }
// for (QueryOperator aConc : root.getConceptsRecursive()) {
// if ((aConc.getChildConcepts().size() > 1) || isConnectedToAnotherConceptViaEquals(aConc)) {
// result.add(aConc);
// }
// }
// if (root.getRootConcepts().size() > 0) {
// result.add(root.getRootConcepts().get(0));
// }
return result;
}
......@@ -240,12 +240,12 @@ public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
if (aConc.type == OperatorType.ALIAS_REF) {
return aConc.getParameters().get(0).asPrimitive().value;
} else if (aConc.type == OperatorType.FIELD) {
return getPath(aConc.getParameters().get(0).asOperator()) + "."
+ aConc.getParameters().get(1).asPrimitive().value;
String subPath = getPath(aConc.getParameters().get(0).asOperator());
return subPath + "." + aConc.getParameters().get(1).asPrimitive().value;
} else if (aConc.type == OperatorType.ITERATE) {
return "[" + aConc.getCode() + "]";
} else {
throw new RuntimeException("unexpected");
return writeOp(aConc);
}
}
......@@ -366,6 +366,10 @@ public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
return result;
}
private String writeAliasRef(QueryOperator anOp) {
return anOp.getParameters().get(0).asPrimitive().value;
}
private String writeOp(QueryOperator anOp) {
String result = "";
if (alreadyHandledInWith.contains(anOp)) {
......@@ -381,6 +385,9 @@ public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
} else if (anOp.type == OperatorType.FILTER) {
String queryString = writeFilter(anOp);
result += queryString;
} else if (anOp.type == OperatorType.ALIAS_REF) {
String string = writeAliasRef(anOp);
result += string;
} else if (anOp.type == OperatorType.INTERVAL) {
String intString = writeInterval(anOp);
result += intString;
......
......@@ -6,4 +6,6 @@ public class Mapper {
protected OperatorMap opMap = new OperatorMap();
public static String graphSystemName = "Graph";
}
......@@ -158,7 +158,8 @@ public class AQL_2_Graph_Mapper extends AqlBaseVisitor<Void> {
throw new ParseException("Errors while parsing AQL", 0);
}
String prettyPrint = prettyPrint(parseTree);
query.getParameters().add(new QueryOperator(OperatorType.FILTER));
query = new QueryOperator(OperatorType.RETURN);
currentOp = query;
visit(parseTree);
addModelLeafNodesToWhere();
return query;
......
......@@ -27,7 +27,7 @@ public class Test_AQL_2_AQL {
initialize();
QueryManager queryManager = new QueryManager();
for (MultiQuery aMultiQuery : queryManager.queries) {
if (aMultiQuery.name.equals("query_longPaths2")) {
if (aMultiQuery.name.equals("query_encounters")) {
processQuery(aMultiQuery);
}
}
......@@ -41,17 +41,22 @@ public class Test_AQL_2_AQL {
public static void main(String[] args) throws IOException, ParseException {
parseQueries();
Test_AQL_2_AQL test = new Test_AQL_2_AQL();
// test.debugTest();
test.testAQL_2_AQL();
test.debugTest();
// test.testAQL_2_AQL();
}
private void processQuery(MultiQuery aMultiQuery) throws ParseException {
String originalQuery = aMultiQuery.system2QueryString.get(AQL_2_Graph_Mapper.getSystem());
QueryOperator query = aql2Graph.parse(originalQuery);
String result = graph2AQL.visit(query);
if (!originalQuery.equals(result)) {
String graphString = query.toString();
String desiredGraphStringResult = aMultiQuery.system2QueryString.get(Mapper.graphSystemName);
if (!graphString.equals(desiredGraphStringResult)) {
throw new RuntimeException("query strings not equal");
}
// String result = graph2AQL.visit(query);
// if (!originalQuery.equals(result)) {
// throw new RuntimeException("query strings not equal");
// }
}
@Test
......
......@@ -26,7 +26,7 @@ public class Test_CQL_2_CQL {
initialize();
QueryManager queryManager = new QueryManager();
for (MultiQuery aMultiQuery : queryManager.queries) {
if (aMultiQuery.name.equals("query_CQL_Last")) {
if (aMultiQuery.name.equals("query_CQL_nestedExpr")) {
processQuery(aMultiQuery);
return;
}
......@@ -42,22 +42,28 @@ public class Test_CQL_2_CQL {
public static void main(String[] args) throws IOException, ParseException {
Test_CQL_2_CQL test = new Test_CQL_2_CQL();
// test.parseQueries();
test.debugTest();
// test.testCQL_2_CQL();
// test.debugTest();
test.testCQL_2_CQL();
}
private void processQuery(MultiQuery aMultiQuery) throws IOException {
try {
String originalQuery = aMultiQuery.system2QueryString.get(CQL_2_Graph_Mapper.getSystem());
String desiredResult = aMultiQuery.system2QueryString
.get(CQL_2_Graph_Mapper.getSystem() + "2");
if (originalQuery != null) {
QueryOperator query = cql2Graph.parse(originalQuery);
String graphString = query.toString();
String desiredGraphStringResult = aMultiQuery.system2QueryString
.get(Mapper.graphSystemName);
if (!graphString.equals(desiredGraphStringResult)) {
throw new RuntimeException("query strings not equal");
}
int x = 0;
// String result = graph2CQL.visit(query);
// if (!desiredResult.equals(result)) {
// throw new RuntimeException("query strings not equal");
// }
String result = graph2CQL.visit(query);
String desiredResult = aMultiQuery.system2QueryString
.get(CQL_2_Graph_Mapper.getSystem() + "2");
if (!desiredResult.equals(result)) {
throw new RuntimeException("query strings not equal");
}
}
} catch (Exception e) {
System.out.println("error processing query '" + aMultiQuery.name + "'");
......
*Comment
This query doesn't make sense. B is no list, so it cannot be a parameter of Last
*CQL
[Patient] A with [EpisodeOfCare] B such that B.patient = A and Last(B).period.start > @2014
*CQL2
[Patient] A with [EpisodeOfCare] B such that B.patient = A and Last(B).period.start > @2014
[Patient] A where exists([EpisodeOfCare] B where B.patient = A and Last(B).period.start > @2014)
*Graph
RETURN(FILTER(
ITERATE('Patient') as A,
EXISTS(
ITERATE('EpisodeOfCare') as B,
AND(
EQUALS(
FIELD(
ALIAS_REF('B'),
'patient'
),
ALIAS_REF('A')
),
MORE(
FIELD(
FIELD(
LAST(ALIAS_REF('B')),
'period'
),
'start'
),
@2014
)
)
)
))
*Cypher
......
......@@ -3,3 +3,10 @@ alltrue({ true, true, true })
*CQL2
alltrue({ true, true, true })
*Graph
RETURN(ALLTRUE(LIST(
true,
true,
true
)))
\ No newline at end of file
......@@ -3,3 +3,10 @@ anytrue({ false, true, false })
*CQL2
anytrue({ false, true, false })
*Graph
RETURN(ANYTRUE(LIST(
false,
true,
false
)))
\ No newline at end of file
......@@ -6,3 +6,11 @@ Avg({ 1, 2, 3, 4 })
*Comment
// is it correct to transform the decimals to ints ?
*Graph
RETURN(AVG(LIST(
1,
2,
3,
4
)))
\ No newline at end of file
......@@ -3,3 +3,12 @@ Avg({ 1, 2, 3, 4, 5 })
*CQL2
Avg({ 1, 2, 3, 4, 5 })
*Graph
RETURN(AVG(LIST(
1,
2,
3,
4,
5
)))
\ No newline at end of file
......@@ -4,3 +4,22 @@ Avg({ 1 'm', 2 'm', 3 'm', 4 'm' })
*CQL2
Avg({ 1 'm', 2 'm', 3 'm', 4 'm' })
*Graph
RETURN(AVG(LIST(
QUANTITY(
1,
'm'
),
QUANTITY(
2,
'm'
),
QUANTITY(
3,
'm'
),
QUANTITY(
4,
'm'
)
)))
\ No newline at end of file
......@@ -3,3 +3,12 @@ Count({ 1, 2, 3, 4, 5 })
*CQL2
Count({ 1, 2, 3, 4, 5 })
*Graph
RETURN(COUNT(LIST(
1,
2,
3,
4,
5
)))
\ No newline at end of file
......@@ -3,3 +3,11 @@ Max({ @2012-01-01T00:00:00, @2013-01-01T00:00:00, @2014-01-01T00:00:00, @2015-01
*CQL2
Max({ @2012-01-01T00:00:00, @2013-01-01T00:00:00, @2014-01-01T00:00:00, @2015-01-01T00:00:00 })
*Graph
RETURN(MAX(LIST(
@2012-01-01T00:00:00,
@2013-01-01T00:00:00,
@2014-01-01T00:00:00,
@2015-01-01T00:00:00
)))
\ No newline at end of file
......@@ -7,3 +7,10 @@ Max({ 1, 2, 3, 4 })
*Comment
// is it correct to transform the decimals to ints ?
*Graph
RETURN(MAX(LIST(
1,
2,
3,
4
)))
\ No newline at end of file
......@@ -3,3 +3,12 @@ Max({ 1, 2, 3, 4, 5 })
*CQL2
Max({ 1, 2, 3, 4, 5 })
*Graph
RETURN(MAX(LIST(
1,
2,
3,
4,
5
)))
\ No newline at end of file
......@@ -4,3 +4,22 @@ Max({ 1 'm', 2 'm', 3 'm', 4 'm' })
*CQL2
Max({ 1 'm', 2 'm', 3 'm', 4 'm' })
*Graph
RETURN(MAX(LIST(
QUANTITY(
1,
'm'
),
QUANTITY(
2,
'm'
),
QUANTITY(
3,
'm'
),
QUANTITY(
4,
'm'
)
)))
\ No newline at end of file
......@@ -4,3 +4,11 @@ Max({ 'a', 'b', 'c', 'd', 'e' })
*CQL2
Max({ 'a', 'b', 'c', 'd', 'e' })
*Graph
RETURN(MAX(LIST(
'a',
'b',
'c',
'd',
'e'
)))
\ No newline at end of file
......@@ -3,3 +3,11 @@ Max({ @T00:00:00, @T06:00:00, @T12:00:00, @T18:00:00 })
*CQL2
Max({ @T00:00:00, @T06:00:00, @T12:00:00, @T18:00:00 })
*Graph
RETURN(MAX(LIST(
@T00:00:00,
@T06:00:00,
@T12:00:00,
@T18:00:00
)))
\ No newline at end of file
......@@ -3,3 +3,11 @@ Min({ @2012-01-01T00:00:00, @2013-01-01T00:00:00, @2014-01-01T00:00:00, @2015-01
*CQL2
Min({ @2012-01-01T00:00:00, @2013-01-01T00:00:00, @2014-01-01T00:00:00, @2015-01-01T00:00:00 })
*Graph
RETURN(MIN(LIST(
@2012-01-01T00:00:00,
@2013-01-01T00:00:00,
@2014-01-01T00:00:00,
@2015-01-01T00:00:00
)))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment