Search in sources :

Example 76 with ODocument

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"));
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 77 with ODocument

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"));
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 78 with ODocument

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);
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 79 with ODocument

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);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 80 with ODocument

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"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2200 Test (org.testng.annotations.Test)651 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)426 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)422 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)277 Test (org.junit.Test)267 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)257 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)244 ORID (com.orientechnologies.orient.core.id.ORID)196 ORecordId (com.orientechnologies.orient.core.id.ORecordId)139 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)122 ArrayList (java.util.ArrayList)118 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)103 HashMap (java.util.HashMap)103 HashSet (java.util.HashSet)96 ORecord (com.orientechnologies.orient.core.record.ORecord)80 Set (java.util.Set)76 OETLBaseTest (com.orientechnologies.orient.etl.OETLBaseTest)75 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)68 Collection (java.util.Collection)55