Search in sources :

Example 71 with OCommandSQL

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

the class BetweenConversionTest method testBetweenRightIncluded.

public void testBetweenRightIncluded() {
    final String query = "select from BetweenConversionTest where a > 1 and a <= 3";
    final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 2);
    List<Integer> values = new ArrayList<Integer>(Arrays.asList(2, 3));
    for (ODocument document : result) {
        Assert.assertTrue(values.remove((Integer) document.field("a")));
    }
    Assert.assertTrue(values.isEmpty());
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertEquals(explain.field("rangeQueryConvertedInBetween"), 1);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 72 with OCommandSQL

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

the class BetweenConversionTest method testBetweenRightLeftIncludedReverseOrder.

public void testBetweenRightLeftIncludedReverseOrder() {
    final String query = "select from BetweenConversionTest where a <= 3 and a >= 1";
    final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 3);
    List<Integer> values = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
    for (ODocument document : result) {
        Assert.assertTrue(values.remove((Integer) document.field("a")));
    }
    Assert.assertTrue(values.isEmpty());
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertEquals(explain.field("rangeQueryConvertedInBetween"), 1);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 73 with OCommandSQL

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

the class BetweenConversionTest method testBetweenRightIncludedReverse.

public void testBetweenRightIncludedReverse() {
    final String query = "select from BetweenConversionTest where a <= 3 and a > 1";
    final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 2);
    List<Integer> values = new ArrayList<Integer>(Arrays.asList(2, 3));
    for (ODocument document : result) {
        Assert.assertTrue(values.remove((Integer) document.field("a")));
    }
    Assert.assertTrue(values.isEmpty());
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertEquals(explain.field("rangeQueryConvertedInBetween"), 1);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 74 with OCommandSQL

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

the class BetweenConversionTest method testBetweenIndex.

public void testBetweenIndex() {
    final String query = "select from BetweenConversionTest where ai > 1 and ai < 3";
    final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 1);
    List<Integer> values = new ArrayList<Integer>(Arrays.asList(2));
    for (ODocument document : result) {
        Assert.assertTrue(values.remove((Integer) document.field("ai")));
    }
    Assert.assertTrue(values.isEmpty());
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertEquals(explain.field("rangeQueryConvertedInBetween"), 1);
    Assert.assertTrue(((Set<String>) explain.field("involvedIndexes")).contains("BetweenConversionTestIndex"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 75 with OCommandSQL

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

the class BetweenConversionTest method testBetweenRightLeftIncludedBothFieldsRight.

public void testBetweenRightLeftIncludedBothFieldsRight() {
    final String query = "select from BetweenConversionTest where a >= 1 and a <= ai";
    final List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 9);
    List<Integer> values = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9));
    for (ODocument document : result) {
        Assert.assertTrue(values.remove((Integer) document.field("a")));
    }
    Assert.assertTrue(values.isEmpty());
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertNull(explain.field("rangeQueryConvertedInBetween"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)621 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)422 Test (org.junit.Test)97 Test (org.testng.annotations.Test)93 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)83 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)79 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)78 ORID (com.orientechnologies.orient.core.id.ORID)64 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)61 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)54 Set (java.util.Set)53 HashMap (java.util.HashMap)45 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)42 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)41 List (java.util.List)25 Before (org.junit.Before)24 OStorage (com.orientechnologies.orient.core.storage.OStorage)23 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)23 ORecordId (com.orientechnologies.orient.core.id.ORecordId)21 Vertex (com.tinkerpop.blueprints.Vertex)19