Assert.assertTrue(result.size() > 0);
}
@Test
public void testIndexSQL() {
database.command(new OCommandSQL("create index idx unique")).execute();
database.getMetadata().getIndexManager().reload();
Assert.assertNotNull(database.getMetadata().getIndexManager().getIndex("idx"));
database.command(new OCommandSQL("insert into index:IDX (key,rid) values (10,#3:0)")).execute();
database.command(new OCommandSQL("insert into index:IDX (key,rid) values (20,#3:1)")).execute();
List<ODocument> result = database.command(new OCommandSQL("select from index:IDX")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 2);
for (ODocument d : result) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (d.field("key").equals(10))
Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:0"));
else if (d.field("key").equals(20))
Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:1"));
else
Assert.assertTrue(false);
}
result = database.command(new OCommandSQL("select key, rid from index:IDX")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 2);
for (ODocument d : result) {
Assert.assertTrue(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
if (d.field("key").equals(10))
Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:0"));
else if (d.field("key").equals(20))
Assert.assertEquals(d.rawField("rid"), new ORecordId("#3:1"));
else
Assert.assertTrue(false);
}
result = database.command(new OCommandSQL("select key from index:IDX")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 2);
for (ODocument d : result) {
Assert.assertTrue(d.containsField("key"));
Assert.assertFalse(d.containsField("rid"));
}
result = database.command(new OCommandSQL("select rid from index:IDX")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 2);
for (ODocument d : result) {
Assert.assertFalse(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));
}
result = database.command(new OCommandSQL("select rid from index:IDX where key = 10")).execute();
Assert.assertNotNull(result);
Assert.assertEquals(result.size(), 1);
for (ODocument d : result) {
Assert.assertFalse(d.containsField("key"));
Assert.assertTrue(d.containsField("rid"));