use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testTriangle2Arrows.
@Test
public void testTriangle2Arrows() {
StringBuilder query = new StringBuilder();
query.append("match ");
query.append("{class:TriangleV, as: friend1}");
query.append(" -TriangleE->{class:TriangleV, as: friend2, where: (uid = 1)}");
query.append(" -TriangleE->{as: friend3},");
query.append("{class:TriangleV, as: friend1}");
query.append(" -TriangleE->{as: friend3}");
query.append("return $matches");
List<ODocument> result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(1, result.size());
ODocument doc = result.get(0);
ODocument friend1 = ((OIdentifiable) doc.field("friend1")).getRecord();
ODocument friend2 = ((OIdentifiable) doc.field("friend2")).getRecord();
ODocument friend3 = ((OIdentifiable) doc.field("friend3")).getRecord();
assertEquals(0, friend1.field("uid"));
assertEquals(1, friend2.field("uid"));
assertEquals(2, friend3.field("uid"));
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OMatchStatementExecutionTest method testCartesianProductLimit.
@Test
public void testCartesianProductLimit() {
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 LIMIT 1");
List<OIdentifiable> result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(1, 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 testOptional.
@Test
public void testOptional() throws Exception {
List<ODocument> qResult = db.command(new OCommandSQL("match {class:Person, as: person} -NonExistingEdge-> {as:b, optional:true} 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 testArraySingleSelectors2.
@Test
public void testArraySingleSelectors2() {
StringBuilder query = new StringBuilder();
query.append("match ");
query.append("{class:TriangleV, as: friend1, where: (uid = 0)}");
query.append("return friend1.out('TriangleE')[0,1] as foo");
List<?> result = db.command(new OCommandSQL(query.toString())).execute();
assertEquals(1, result.size());
ODocument doc = (ODocument) result.get(0);
Object foo = doc.field("foo");
assertNotNull(foo);
assertTrue(foo instanceof List);
assertEquals(2, ((List) foo).size());
}
use of com.orientechnologies.orient.core.record.impl.ODocument in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateEdgeTest method setUp.
@Before
public void setUp() throws Exception {
db = new ODatabaseDocumentTx("memory:" + OCommandExecutorSQLCreateEdgeTest.class.getSimpleName());
if (db.exists()) {
db.open("admin", "admin");
db.drop();
}
db.create();
final OSchema schema = db.getMetadata().getSchema();
schema.createClass("Owner", schema.getClass("V"));
schema.createClass("link", schema.getClass("E"));
owner1 = new ODocument("Owner");
owner1.field("id", 1);
owner1.save();
owner2 = new ODocument("Owner");
owner2.field("id", 2);
owner2.save();
}
Aggregations