Search in sources :

Example 41 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class CompositeIndexWithNullTest method testRangeQueryNullInTheMiddleInMiddleTx.

public void testRangeQueryNullInTheMiddleInMiddleTx() {
    if (database.getURL().startsWith("remote:"))
        return;
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("compositeIndexNullRangeQueryNullInTheMiddleInMiddleTxClass");
    clazz.createProperty("prop1", OType.INTEGER);
    clazz.createProperty("prop2", OType.INTEGER);
    clazz.createProperty("prop3", OType.INTEGER);
    final ODocument metadata = new ODocument();
    metadata.field("ignoreNullValues", false);
    clazz.createIndex("compositeIndexNullRangeQueryNullInTheMiddleInMiddleTxIndex", OClass.INDEX_TYPE.NOTUNIQUE.toString(), null, metadata, new String[] { "prop1", "prop2", "prop3" });
    for (int i = 0; i < 20; i++) {
        ODocument document = new ODocument("compositeIndexNullRangeQueryNullInTheMiddleInMiddleTxClass");
        document.field("prop1", i / 10);
        if (i % 2 == 0)
            document.field("prop2", i);
        document.field("prop3", i);
        document.save();
    }
    final String query = "select from compositeIndexNullRangeQueryNullInTheMiddleInMiddleTxClass where prop1 > 0";
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 10);
    for (int k = 0; k < 10; k++) {
        ODocument document = result.get(k);
        Assert.assertEquals(document.field("prop1"), 1);
    }
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("compositeIndexNullRangeQueryNullInTheMiddleInMiddleTxIndex"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) Set(java.util.Set) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 42 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class CompositeIndexWithNullTest method testPointQueryNullInTheMiddle.

public void testPointQueryNullInTheMiddle() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("compositeIndexNullPointQueryNullInTheMiddleClass");
    clazz.createProperty("prop1", OType.INTEGER);
    clazz.createProperty("prop2", OType.INTEGER);
    clazz.createProperty("prop3", OType.INTEGER);
    final ODocument metadata = new ODocument();
    metadata.field("ignoreNullValues", false);
    clazz.createIndex("compositeIndexNullPointQueryNullInTheMiddleIndex", OClass.INDEX_TYPE.NOTUNIQUE.toString(), null, metadata, null, new String[] { "prop1", "prop2", "prop3" });
    for (int i = 0; i < 20; i++) {
        ODocument document = new ODocument("compositeIndexNullPointQueryNullInTheMiddleClass");
        document.field("prop1", i / 10);
        if (i % 2 == 0)
            document.field("prop2", i);
        document.field("prop3", i);
        document.save();
    }
    String query = "select from compositeIndexNullPointQueryNullInTheMiddleClass where prop1 = 1";
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 10);
    for (int k = 0; k < 10; k++) {
        ODocument document = result.get(k);
        Assert.assertEquals(document.field("prop1"), 1);
    }
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("compositeIndexNullPointQueryNullInTheMiddleIndex"));
    query = "select from compositeIndexNullPointQueryNullInTheMiddleClass where prop1 = 1 and prop2 is null";
    result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) {
        Assert.assertEquals(document.field("prop1"), 1);
        Assert.assertNull(document.field("prop2"));
    }
    explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("compositeIndexNullPointQueryNullInTheMiddleIndex"));
    query = "select from compositeIndexNullPointQueryNullInTheMiddleClass where prop1 = 1 and prop2 is null and prop3 = 13";
    result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 1);
    explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("compositeIndexNullPointQueryNullInTheMiddleIndex"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) Set(java.util.Set) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 43 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class CompositeIndexWithNullTest method testRangeQueryNullInTheMiddle.

public void testRangeQueryNullInTheMiddle() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("compositeIndexNullRangeQueryNullInTheMiddleClass");
    clazz.createProperty("prop1", OType.INTEGER);
    clazz.createProperty("prop2", OType.INTEGER);
    clazz.createProperty("prop3", OType.INTEGER);
    final ODocument metadata = new ODocument();
    metadata.field("ignoreNullValues", false);
    clazz.createIndex("compositeIndexNullRangeQueryNullInTheMiddleIndex", OClass.INDEX_TYPE.NOTUNIQUE.toString(), null, metadata, new String[] { "prop1", "prop2", "prop3" });
    for (int i = 0; i < 20; i++) {
        ODocument document = new ODocument("compositeIndexNullRangeQueryNullInTheMiddleClass");
        document.field("prop1", i / 10);
        if (i % 2 == 0)
            document.field("prop2", i);
        document.field("prop3", i);
        document.save();
    }
    final String query = "select from compositeIndexNullRangeQueryNullInTheMiddleClass where prop1 > 0";
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 10);
    for (int k = 0; k < 10; k++) {
        ODocument document = result.get(k);
        Assert.assertEquals(document.field("prop1"), 1);
    }
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("compositeIndexNullRangeQueryNullInTheMiddleIndex"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) Set(java.util.Set) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 44 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class DateIndexTest method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    final OSchema schema = database.getMetadata().getSchema();
    OClass dateIndexTest = schema.createClass("DateIndexTest");
    dateIndexTest.createProperty("dateField", OType.DATE);
    dateIndexTest.createProperty("dateTimeField", OType.DATETIME);
    dateIndexTest.createProperty("dateList", OType.EMBEDDEDLIST, OType.DATE);
    dateIndexTest.createProperty("dateTimeList", OType.EMBEDDEDLIST, OType.DATETIME);
    dateIndexTest.createProperty("value", OType.STRING);
    dateIndexTest.createIndex("DateIndexTestDateIndex", OClass.INDEX_TYPE.UNIQUE, "dateField");
    dateIndexTest.createIndex("DateIndexTestValueDateIndex", OClass.INDEX_TYPE.UNIQUE, "value", "dateField");
    dateIndexTest.createIndex("DateIndexTestDateTimeIndex", OClass.INDEX_TYPE.UNIQUE, "dateTimeField");
    dateIndexTest.createIndex("DateIndexTestValueDateTimeIndex", OClass.INDEX_TYPE.UNIQUE, "value", "dateTimeField");
    dateIndexTest.createIndex("DateIndexTestValueDateListIndex", OClass.INDEX_TYPE.UNIQUE, "value", "dateList");
    dateIndexTest.createIndex("DateIndexTestValueDateTimeListIndex", OClass.INDEX_TYPE.UNIQUE, "value", "dateTimeList");
    dateIndexTest.createIndex("DateIndexTestDateHashIndex", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "dateField");
    dateIndexTest.createIndex("DateIndexTestValueDateHashIndex", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "value", "dateField");
    dateIndexTest.createIndex("DateIndexTestDateTimeHashIndex", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "dateTimeField");
    dateIndexTest.createIndex("DateIndexTestValueDateTimeHashIndex", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "value", "dateTimeField");
    dateIndexTest.createIndex("DateIndexTestValueDateListHashIndex", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "value", "dateList");
    dateIndexTest.createIndex("DateIndexTestValueDateTimeListHashIndex", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "value", "dateTimeList");
    schema.save();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 45 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class ClassIndexTest method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    final OSchema schema = database.getMetadata().getSchema();
    oClass = schema.createClass("ClassIndexTestClass");
    oSuperClass = schema.createClass("ClassIndexTestSuperClass");
    oClass.createProperty("fOne", OType.INTEGER);
    oClass.createProperty("fTwo", OType.STRING);
    oClass.createProperty("fThree", OType.BOOLEAN);
    oClass.createProperty("fFour", OType.INTEGER);
    oClass.createProperty("fSix", OType.STRING);
    oClass.createProperty("fSeven", OType.STRING);
    oClass.createProperty("fEight", OType.INTEGER);
    oClass.createProperty("fTen", OType.INTEGER);
    oClass.createProperty("fEleven", OType.INTEGER);
    oClass.createProperty("fTwelve", OType.INTEGER);
    oClass.createProperty("fThirteen", OType.INTEGER);
    oClass.createProperty("fFourteen", OType.INTEGER);
    oClass.createProperty("fFifteen", OType.INTEGER);
    oClass.createProperty("fEmbeddedMap", OType.EMBEDDEDMAP, OType.INTEGER);
    oClass.createProperty("fEmbeddedMapWithoutLinkedType", OType.EMBEDDEDMAP);
    oClass.createProperty("fLinkMap", OType.LINKMAP);
    oClass.createProperty("fLinkList", OType.LINKLIST);
    oClass.createProperty("fEmbeddedList", OType.EMBEDDEDLIST, OType.INTEGER);
    oClass.createProperty("fEmbeddedSet", OType.EMBEDDEDSET, OType.INTEGER);
    oClass.createProperty("fLinkSet", OType.LINKSET);
    oClass.createProperty("fRidBag", OType.LINKBAG);
    oSuperClass.createProperty("fNine", OType.INTEGER);
    oClass.setSuperClass(oSuperClass);
    schema.save();
    database.close();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)203 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)165 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)122 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)54 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)46 Test (org.testng.annotations.Test)35 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)31 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)23 Test (org.junit.Test)19 Before (org.junit.Before)16 ORID (com.orientechnologies.orient.core.id.ORID)15 OIndex (com.orientechnologies.orient.core.index.OIndex)15 Collection (java.util.Collection)15 Set (java.util.Set)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)9 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 BeforeClass (org.testng.annotations.BeforeClass)9 OStorage (com.orientechnologies.orient.core.storage.OStorage)6 ArrayList (java.util.ArrayList)5 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4