use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testOptional2.
@Test
public void testOptional2() throws Exception {
List<ODocument> qResult = db.command(new OCommandSQL("match {class:Person, as: person} --> {as:b, optional:true, where:(nonExisting = 12)} return person, b.name")).execute();
assertEquals(6, qResult.size());
for (ODocument doc : qResult) {
assertTrue(doc.fieldNames().length == 2);
OIdentifiable personId = doc.field("person");
ODocument person = personId.getRecord();
String name = person.field("name");
assertTrue(name.startsWith("n"));
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testSimple.
@Test
public void testSimple() throws Exception {
List<ODocument> qResult = db.command(new OCommandSQL("match {class:Person, as: person} return person")).execute();
assertEquals(6, qResult.size());
for (ODocument doc : qResult) {
assertTrue(doc.fieldNames().length == 1);
OIdentifiable personId = doc.field("person");
ODocument person = personId.getRecord();
String name = person.field("name");
assertTrue(name.startsWith("n"));
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testManaged2.
@Test
public void testManaged2() {
// people managed by a manager are people who belong to his department or people who belong to sub-departments without a manager
List<OIdentifiable> managedByA = getManagedBy2("a");
assertEquals(1, managedByA.size());
assertEquals("p1", ((ODocument) managedByA.get(0).getRecord()).field("name"));
List<OIdentifiable> managedByB = getManagedBy2("b");
assertEquals(5, managedByB.size());
Set<String> expectedNames = new HashSet<String>();
expectedNames.add("p2");
expectedNames.add("p3");
expectedNames.add("p6");
expectedNames.add("p7");
expectedNames.add("p11");
Set<String> names = new HashSet<String>();
for (OIdentifiable id : managedByB) {
ODocument doc = id.getRecord();
String name = doc.field("name");
names.add(name);
}
assertEquals(expectedNames, names);
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testCartesianProduct.
@Test
public void testCartesianProduct() {
StringBuilder query = new StringBuilder();
query.append("match ");
query.append("{class:TriangleV, as: friend1, where:(uid = 1)},");
query.append("{class:TriangleV, as: friend2, where:(uid = 2 or uid = 3)}");
query.append("return $matches");
List<OIdentifiable> result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(2, result.size());
for (OIdentifiable d : result) {
assertEquals(((ODocument) ((ODocument) d.getRecord()).field("friend1")).field("uid"), 1);
}
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testUnique.
@Test
public void testUnique() {
StringBuilder query = new StringBuilder();
query.append("match ");
query.append("{class:DiamondV, as: one, where: (uid = 0)}.out('DiamondE').out('DiamondE'){as: two} ");
query.append("return one, two");
List<ODocument> result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(1, result.size());
query = new StringBuilder();
query.append("match ");
query.append("{class:DiamondV, as: one, where: (uid = 0)}.out('DiamondE').out('DiamondE'){as: two} ");
query.append("return one.uid, two.uid");
result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(1, result.size());
// ODocument doc = result.get(0);
// assertEquals("foo", doc.field("name"));
// assertEquals(0, doc.field("sub[0].uuid"));
}
Aggregations