Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions estore/src/main/java/org/estore/Estore.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public HashMap<String, ClassInfo> getLabelClassInfoMap() {
return labelClassInfoMap;
}

public Estore(String name) throws Exception {
public Estore(String name) {
this(name, EstoreOptions.getDefaultOptions());
}

public Estore(String name, EstoreOptions options) throws Exception {
public Estore(String name, EstoreOptions options) {
this.name = name;
this.options = options;
this.id = 0;
Expand Down
3 changes: 2 additions & 1 deletion estore/src/main/java/org/estore/compiler/ImplCodeGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.antlr.v4.runtime.CharStreams;
Expand Down Expand Up @@ -133,7 +134,7 @@ private static String getDefaultOutputFilePath(String inputFilePath) {
return Paths.get(parentDir, "Transformed" + fileName).toString();
}

public static void main(String[] args) throws Exception {
public static void main(String[] args) throws IOException {
String inputFilePath = args.length > 0 ? args[0] : DEFAULT_INPUT_FILE_PATH;
String outputFilePath = args.length > 1 ? args[1] : getDefaultOutputFilePath(inputFilePath);
CompilationUnit cu = StaticJavaParser.parse(Files.newInputStream(Paths.get(inputFilePath)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,14 @@ public Object visitOC_MapLiteral(CypherParser.OC_MapLiteralContext ctx) {
return null;
}

@Override
public Object visitOC_Atom(CypherParser.OC_AtomContext ctx) {
if (ctx.COUNT() != null) {
return new CountFunctionExpr();
}
return visitChildren(ctx);
}

@Override
public Object visitOC_FunctionInvocation(CypherParser.OC_FunctionInvocationContext ctx) {
LogicalExpr expr = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public CountFunctionSingleExpr(CountFunctionExpr expr) {

@Override
public Table evaluate(Table v) {
String keyName = getName();
Table result = new Table(Arrays.asList(new String[] {keyName}));
if (arg instanceof VarExpr) {
String keyName = getName();
Table result = new Table(Arrays.asList(new String[] {keyName}));
String variable = ((VarExpr) arg).evaluate(null);

result.get(keyName).add(v.get(variable).size());
return result;
}
if (arg == null) {
result.get(keyName).add(v.getSize());
return result;
}
return null;
}

Expand Down
10 changes: 5 additions & 5 deletions estore/src/test/java/org/estore/AggregateFunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AggregateFunctionTest {
private Estore db;

@BeforeEach
void setUp() throws Exception {
void setUp() throws EstoreException {
db = new Estore(AggregateFunctionTest.class.getName());
Person c = new Person("C", 30);
Person b = new Person("B", 40, c);
Expand All @@ -20,25 +20,25 @@ void setUp() throws Exception {
}

@Test
void maxReturnsLargestAge() throws Exception {
void maxReturnsLargestAge() {
Table result = db.query("MATCH (p:`org.estore.example.Person`) RETURN max(p.age)");
assertEquals(40, result.get("MAX(p.age)").get(0));
}

@Test
void minReturnsSmallestAge() throws Exception {
void minReturnsSmallestAge() {
Table result = db.query("MATCH (p:`org.estore.example.Person`) RETURN min(p.age)");
assertEquals(20, result.get("MIN(p.age)").get(0));
}

@Test
void sumReturnsTotalAge() throws Exception {
void sumReturnsTotalAge() {
Table result = db.query("MATCH (p:`org.estore.example.Person`) RETURN sum(p.age)");
assertEquals(90, result.get("SUM(p.age)").get(0));
}

@Test
void avgReturnsMeanAge() throws Exception {
void avgReturnsMeanAge() {
Table result = db.query("MATCH (p:`org.estore.example.Person`) RETURN avg(p.age)");
assertEquals(30.0, result.get("AVG(p.age)").get(0));
}
Expand Down
4 changes: 2 additions & 2 deletions estore/src/test/java/org/estore/AnonymousRelationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public class AnonymousRelationTest {
private Estore db;

@BeforeEach
void setUp() throws Exception {
void setUp() {
db = new Estore(AnonymousRelationTest.class.getName());
}

@Test
void bareArrowMatchesEmptyBrackets() throws Exception {
void bareArrowMatchesEmptyBrackets() throws EstoreException {
Person bob = new Person("Bob", 30);
Person alice = new Person("Alice", 28, bob);
db.captureAll(alice);
Expand Down
4 changes: 2 additions & 2 deletions estore/src/test/java/org/estore/ArithmeticTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class ArithmeticTest {
private Estore db;

@BeforeEach
void setUp() throws Exception {
void setUp() {
db = new Estore(ArithmeticTest.class.getName());
}

@Test
void fourOperationsAndCountDivide() throws Exception {
void fourOperationsAndCountDivide() {
db.query("CREATE (n:`ArithNode`)");
db.query("CREATE (n:`ArithNode`)");

Expand Down
49 changes: 49 additions & 0 deletions estore/src/test/java/org/estore/CaptureModeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.estore;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.estore.example.Person;
import org.estore.planner.util.Table;
import org.junit.jupiter.api.Test;

public class CaptureModeTest {

@Test
void iterativeDfsCapturesPersonChain() throws EstoreException {
Estore db = new Estore(CaptureModeTest.class.getName(), new EstoreOptions().useDfs(true));
Person charlie = new Person("Charlie", 25);
Person bob = new Person("Bob", 30, charlie);
Person alice = new Person("Alice", 28, bob);
db.captureAll(alice);

Table result = db.query("MATCH (p:`org.estore.example.Person`) RETURN p");
assertEquals(3, result.getSize());
}

@Test
void recursiveDfsCapturesPersonChain() throws EstoreException {
Estore db =
new Estore(
CaptureModeTest.class.getName(),
new EstoreOptions().useDfs(true).useRecursion(true));
Person charlie = new Person("Charlie", 25);
Person bob = new Person("Bob", 30, charlie);
Person alice = new Person("Alice", 28, bob);
db.captureAll(alice);

Table result = db.query("MATCH (p:`org.estore.example.Person`) RETURN p");
assertEquals(3, result.getSize());
}

@Test
void depthLimitedCaptureStops() throws EstoreException {
Estore db = new Estore(CaptureModeTest.class.getName());
Person charlie = new Person("Charlie", 25);
Person bob = new Person("Bob", 30, charlie);
Person alice = new Person("Alice", 28, bob);
db.captureAll(alice, 2, 0);

Table result = db.query("MATCH (p:`org.estore.example.Person`) RETURN p");
assertEquals(2, result.getSize());
}
}
22 changes: 19 additions & 3 deletions estore/src/test/java/org/estore/CaseExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,40 @@ public class CaseExpressionTest {
private Estore db;

@BeforeEach
void setUp() throws Exception {
void setUp() throws EstoreException {
db = new Estore(CaseExpressionTest.class.getName());
db.captureAll(new Person("A", 20));
}

@Test
void caseReturnsElseWhenPredicateIsFalse() throws Exception {
void caseReturnsElseWhenPredicateIsFalse() {
Table result =
db.query(
"MATCH (p:`org.estore.example.Person`) RETURN CASE WHEN p.age > 25 THEN 1 ELSE 0 END");
assertEquals(0L, result.get("CASE").get(0));
}

@Test
void caseReturnsThenWhenPredicateIsTrue() throws Exception {
void caseReturnsThenWhenPredicateIsTrue() {
Table result =
db.query(
"MATCH (p:`org.estore.example.Person`) RETURN CASE WHEN p.age > 15 THEN 1 ELSE 0 END");
assertEquals(1L, result.get("CASE").get(0));
}

@Test
void caseMatchesSubject() {
Table result =
db.query(
"MATCH (p:`org.estore.example.Person`) RETURN CASE p.name WHEN 'A' THEN 1 ELSE 0 END");
assertEquals(1L, result.get("CASE").get(0));
}

@Test
void caseWithoutElseIsNullWhenNoWhenMatches() {
Table result =
db.query(
"MATCH (p:`org.estore.example.Person`) RETURN CASE WHEN p.age > 99 THEN 1 END");
assertEquals(null, result.get("CASE").get(0));
}
}
4 changes: 2 additions & 2 deletions estore/src/test/java/org/estore/CountDistinctTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public class CountDistinctTest {
private Estore db;

@BeforeEach
void setUp() throws Exception {
void setUp() {
db = new Estore(CountDistinctTest.class.getName());
}

@Test
void countDistinctIsOneWhenCountIsTwo() throws Exception {
void countDistinctIsOneWhenCountIsTwo() throws EstoreException {
// Keanu -> Carrie -> Guy
// Keanu -> Liam -> Guy
Person guy = new Person("Guy", 40);
Expand Down
38 changes: 16 additions & 22 deletions estore/src/test/java/org/estore/CreateInstanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ public class CreateInstanceTest {

@BeforeEach
public void initDatabase() {
try {
estore =
new Estore(
CreateInstanceTest.class.getName(), new EstoreOptions().useDfs(false));
} catch (Exception e) {
e.printStackTrace();
}
estore = new Estore(CreateInstanceTest.class.getName(), new EstoreOptions().useDfs(false));
}

/*
Expand All @@ -47,7 +41,7 @@ public void initDatabase() {
* }
*
* @RepeatedTest(50)
* void testNodeAddPropertyESTOREEval() throws Exception {
* void testNodeAddPropertyESTOREEval() {
* long t1 = System.currentTimeMillis();
* estore.add(A.class);
*/
Expand All @@ -67,7 +61,7 @@ public void initDatabase() {
* }
*
* @Test
* void createDropNodeLongStringPropertyESTOREEval() throws Exception {
* void createDropNodeLongStringPropertyESTOREEval() {
* String testPropertyKey = "testProperty";
* String propertyValue = RandomStringUtils.randomAlphanumeric(255);
*
Expand All @@ -82,7 +76,7 @@ public void initDatabase() {
* }
*
* @Test
* void createObjectWithJ() throws Exception {
* void createObjectWithJ() {
* estore.add("create (n: `Val` {value: 30}) return n");
* Object[] objs = estore.query(true, "match (n: `Val`) return n");
*
Expand All @@ -95,7 +89,7 @@ public void initDatabase() {
* }
*
* @Test
* void createObjectWithD() throws Exception {
* void createObjectWithD() {
* estore.add("create (n: `Val` {value: 30.0}) return n");
* Object[] objs = estore.query(true, "match (n: `Val`) return n");
*
Expand All @@ -108,7 +102,7 @@ public void initDatabase() {
* }
*
* @Test
* void createObjectWithString() throws Exception {
* void createObjectWithString() {
* estore.add("create (n: `Val` {value: 'something'}) return n");
* Object[] objs = estore.query(true, "match (n: `Val`) return n");
*
Expand All @@ -122,7 +116,7 @@ public void initDatabase() {
* }
*
* @Test
* void createObjectWithManyTypes() throws Exception {
* void createObjectWithManyTypes() {
* estore.add("create (n: `Val` {i: 30, d: 30.0, s: 'something'}) return n");
* Object[] objs = estore.query(true, "match (n: `Val`) return n");
*
Expand Down Expand Up @@ -422,7 +416,7 @@ void testNodeAddPropertyCypher() {
}

@Test
void testNodeAddPropertyCypher2() throws Exception {
void testNodeAddPropertyCypher2() throws ReflectiveOperationException {
Table result = estore.query("CREATE (n:`DummyClass3` {name:'Uki', age:30}) RETURN n");
Object obj = result.get("n").get(0);
Class objClass = obj.getClass();
Expand All @@ -433,7 +427,7 @@ void testNodeAddPropertyCypher2() throws Exception {
}

@Test
void testArrayList() throws Exception {
void testArrayList() throws EstoreException {
ArrayList<Long> a = new ArrayList<Long>();
a.add(10L);
a.add(20L);
Expand All @@ -447,7 +441,7 @@ void testArrayList() throws Exception {
}

@Test
void testLinkedList() throws Exception {
void testLinkedList() throws EstoreException {
LinkedList<Long> a = new LinkedList<Long>();
ThreadLocalRandom rand = ThreadLocalRandom.current();
for (long j = 0; j < 10000; j++) {
Expand All @@ -465,7 +459,7 @@ void testLinkedList() throws Exception {
}

@Test
void testLinkedList2() throws Exception {
void testLinkedList2() throws EstoreException {
LinkedList<Long> a = new LinkedList<Long>();
ThreadLocalRandom rand = ThreadLocalRandom.current();
for (int j = 0; j < 100000; j++) {
Expand All @@ -485,7 +479,7 @@ void testLinkedList2() throws Exception {
}

@Test
void testLinkedList3() throws Exception {
void testLinkedList3() throws EstoreException {
LinkedList<Long> a = new LinkedList<Long>();
ThreadLocalRandom rand = ThreadLocalRandom.current();
for (int j = 0; j < 50; j++) {
Expand All @@ -504,7 +498,7 @@ void testLinkedList3() throws Exception {
}

@Test
void testArrayDeque() throws Exception {
void testArrayDeque() throws EstoreException {
ArrayDeque<Long> a = new ArrayDeque<Long>();
a.add(10L);
a.add(20L);
Expand Down Expand Up @@ -537,7 +531,7 @@ void testArrayListIteration() {
}

@Test
void testVector() throws Exception {
void testVector() throws EstoreException {
Vector<Long> a = new Vector<Long>();
a.add(10L);
a.add(20L);
Expand All @@ -550,7 +544,7 @@ void testVector() throws Exception {
}

@Test
void testHashMap() throws Exception {
void testHashMap() throws EstoreException {
HashMap<Long, Long> a = new HashMap<Long, Long>();
a.put(10L, 10L);
a.put(20L, 20L);
Expand All @@ -563,7 +557,7 @@ void testHashMap() throws Exception {
}

@Test
void testConcurrentHashMap() throws Exception {
void testConcurrentHashMap() throws EstoreException {
ConcurrentHashMap<String, Long> a = new ConcurrentHashMap<String, Long>();
a.put("TABLE1", 10L);
a.put("TABLE2", 20L);
Expand Down
Loading
Loading