Search in sources :

Example 81 with ODocument

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"));
}
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 82 with ODocument

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);
    }
}
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 83 with ODocument

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"));
    }
}
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 84 with ODocument

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

Example 85 with ODocument

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();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Before(org.junit.Before)

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