Search in sources :

Example 11 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testDistinctLimit.

@Test
public void testDistinctLimit() {
    OSQLSynchQuery sql = new OSQLSynchQuery("select distinct(name) from DistinctLimit limit 1");
    List<ODocument> results = db.query(sql);
    assertEquals(results.size(), 1);
    sql = new OSQLSynchQuery("select distinct(name) from DistinctLimit limit 2");
    results = db.query(sql);
    assertEquals(results.size(), 2);
    sql = new OSQLSynchQuery("select distinct(name) from DistinctLimit limit 3");
    results = db.query(sql);
    assertEquals(results.size(), 2);
    sql = new OSQLSynchQuery("select distinct(name) from DistinctLimit limit -1");
    results = db.query(sql);
    assertEquals(results.size(), 2);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 12 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testDatesListContainsString.

@Test
public void testDatesListContainsString() {
    // issue #3526
    OSQLSynchQuery sql = new OSQLSynchQuery("select from OCommandExecutorSQLSelectTest_datesSet where foo contains '2015-10-21'");
    List<ODocument> results = db.query(sql);
    assertEquals(results.size(), 1);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 13 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testSkipAndLimitMinusOneOrdered.

@Test
public void testSkipAndLimitMinusOneOrdered() {
    OSQLSynchQuery sql = new OSQLSynchQuery("SELECT from alphabet ORDER BY letter SKIP 7 LIMIT -1");
    List<ODocument> results = db.query(sql);
    assertEquals(19, results.size());
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 14 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testNullProjection.

@Test
public void testNullProjection() {
    OSQLSynchQuery sql = new OSQLSynchQuery("SELECT 1 AS integer, 'Test' AS string, NULL AS nothing, [] AS array, {} AS object");
    List<ODocument> results = db.query(sql);
    assertEquals(results.size(), 1);
    ODocument doc = results.get(0);
    assertEquals(doc.field("integer"), 1);
    assertEquals(doc.field("string"), "Test");
    assertNull(doc.field("nothing"));
    boolean nullFound = false;
    for (String s : doc.fieldNames()) {
        if (s.equals("nothing")) {
            nullFound = true;
            break;
        }
    }
    assertTrue(nullFound);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 15 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method testMassiveOrderAscSkipLimit.

@Test
public void testMassiveOrderAscSkipLimit() {
    int skip = 1000;
    OSQLSynchQuery sql0 = new OSQLSynchQuery("SELECT from MassiveOrderSkipLimit order by nnum asc limit " + skip);
    List<ODocument> results0 = db.query(sql0);
    assertEquals(results0.size(), 1000);
    for (int i = 0; i < results0.size(); i++) {
        ODocument doc = results0.get(i);
        assertEquals(doc.field("nnum"), i);
    }
    OSQLSynchQuery sql = new OSQLSynchQuery("SELECT from MassiveOrderSkipLimit order by nnum asc skip " + skip + " limit 5");
    List<ODocument> results = db.query(sql);
    assertEquals(results.size(), 5);
    for (int i = 0; i < results.size(); i++) {
        ODocument doc = results.get(i);
        assertEquals(doc.field("nnum"), skip + i);
        assertFalse(results0.contains(doc));
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)530 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)445 Test (org.testng.annotations.Test)287 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)83 Test (org.junit.Test)73 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)59 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)53 ORID (com.orientechnologies.orient.core.id.ORID)36 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)32 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)23 HashMap (java.util.HashMap)23 List (java.util.List)22 ORecordId (com.orientechnologies.orient.core.id.ORecordId)19 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)19 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)16 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)15 Collection (java.util.Collection)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)14 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)12