Indexes Not Working Java API

279 views
Skip to first unread message

Gordon Kristan

unread,
Aug 16, 2012, 9:36:34 PM8/16/12
to orient-...@googlegroups.com
I've run into the weirdest issue today. I decided to create an index for some of my classes after the fact. I just went and created a property for the classes (all strings) then created an automatic index on that property. Working from the console, it works fine. But when I get to the java API, I start to have problems. I have one index that works perfectly. It returns correctly all of the time. But then I have 2 other indexes that always return true for the .contains() function. It works fine from the console, and if I use the .key() function on the index, I can see that the key does not exist, but it returns true anyway. I can't seem to find anything like this, so I thought I'd ask here.

As some side information, I'm running that latest graph edition (from 2 days ago), and my L1 and L2 caches are disabled (I think).

This is the code that is failing on me:

OIndex<?> userIndex = rawGraph.getMetadata().getIndexManager().getIndex(user_index /* "Users.username" */);

if (userIndex.contains(username))
{
//username taken
}

No matter what, it always returns true. But if I were to do a rawGraph.query() with "SELECT FROM index...", it would return the correct result. Is this an API bug or a user error?

Thanks,
Gordon.

Gabriel Vince

unread,
Aug 17, 2012, 5:40:27 AM8/17/12
to orient-...@googlegroups.com
Hi Gordon,

correct usage of indexes in API is as follows:
OIndex idx = db.getMetadata().getIndexManager().getIndex(indexName);
ORID key = (ORecordId).get(indexKey);

where the key will be null in the index is not found

Carpe diem
            Gabriel
 

Gordon Kristan

unread,
Aug 17, 2012, 9:13:38 AM8/17/12
to orient-...@googlegroups.com
Checking the .get() call against null does work just fine, but I'm just curious as to why the .contains() method doesn't work. I'm not sure if it's a bug or just something wrong with my setup.

Andrey Lomakin

unread,
Aug 17, 2012, 1:03:44 PM8/17/12
to orient-...@googlegroups.com
Hi Gordon,
It has to work, could you provide test case for this bug ?

On Fri, Aug 17, 2012 at 4:13 PM, Gordon Kristan <gordon....@gmail.com> wrote:
Checking the .get() call against null does work just fine, but I'm just curious as to why the .contains() method doesn't work. I'm not sure if it's a bug or just something wrong with my setup.

--
 
 
 



--
With best regards,
Andrey Lomakin



Gordon Kristan

unread,
Aug 17, 2012, 5:10:33 PM8/17/12
to orient-...@googlegroups.com
I actually just came back to attempt to do that. I now have a similar issue with the .get() function. It's always returning false, even if the key does in fact exist. I'm pretty sure it's an issue with my DB, not the API. Since it seems to just be randomly not working. Sometimes it does, sometimes it doesn't. Is there something special I have to do with the indexes that I'm not realizing?

I have 4 indexes currently, all of which were created like this:

1. Create the class, insert data.
2. Execute "CREATE PROPERTY <classname>.<field> String" from the terminal, where I know that every document in the class has that field.
3. Execute "CREATE INDEX <classname>.<field> UNIQUE" from the terminal.
4. Execute "REBUILD INDEX index:<idx>" form the terminal.

After that, I can do a "SELECT FROM index:..." and it all shows up just fine. And then it sometimes works in the Java API, but sometimes not. For example, I have a class called InvitationTokens that has 118 documents in it, and therefore, 118 records in the corresponding index. This morning, everything was working perfectly. But now, it started failing. I go to the terminal and do a "SELECT FROM index:..." and I get 0 results. (I just had 118!) I do a rebuild and it works fine. 10 minutes later, I have the same problem with the RegistartionTokens index, but rebuilding it DOESN'T work this time.

I'm a little confused really. I know that I'm rambling and not helping much. Hopefully you get the idea. I'd be willing to upload my database too. (It's very small.) Also, just to check my sanity, how should I be using the indexes? Right now, I do it like this:

rawGraph = new OGraphDatabase("...");
rawGraph.open("...", "...");

OIndex<?> idx = rawGraph.getMetadata().getIndexManager().getIndex("...");

//Sometimes, I delete records too...
ODocument d = new ODocument(new ORecordId(idx.get("...").toString()));
rawGraph.delete(d);

rawGraph.close();

Am I not closing things out correctly? Is there some other save/shutdown procedure I should be doing to stop corruption?

Or could the problem be that I created my properties AFTER the classes? Should I go back, deleted the classes, create the properties, THEN add data?

Again, sorry for rambling. I'm just trying to provide as much information as possible. :/

Thanks,
Gordon.

Gabriel Vince

unread,
Aug 19, 2012, 6:20:12 AM8/19/12
to orient-...@googlegroups.com

Hi Gordon,

Just a thought -  if it doesn't have to do something with transactions.
In OrientDB, if you create new records in a transaction, all updates are kept in memory until commit. Indexes are checked / update at the commit time. So for example you are creating a set of records and you want to check a unique index for a value existence, you will have to "remember" the stored values yourself until commit. Or move your transaction boundaries.

If it's not the case, you rather prepare a test case :)

Have fun
         Gabriel


Andrey Lomakin

unread,
Aug 19, 2012, 9:29:14 AM8/19/12
to orient-...@googlegroups.com
Hi Gordon,

Problem that you describe is pretty strange , if you can upload your DB and describe/implement test case so I can reproduce it, it would be really helpful.
 


         Gabriel


--
 
 
 

Shishya

unread,
Mar 13, 2014, 7:22:08 AM3/13/14
to orient-...@googlegroups.com
Hi,

Can someone please help with getting/querying index by key. I m using 1.7rc2SS.
I created a notunique index on vertex with string property from console. 

Create index idxtest2 on myclass(ID) notunique

OrientGraphFactory factory = new OrientGraphFactory("remote:local/test2","root","password").setupPool(1, 10);
OrientGraph graph = factory.getTx();

Index idx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("idxtest2");
ORID key = idx.get("indexKey");
or 
Index<Vertex> index = graph.getIndex("idxtest2", Vertex.class);
Iterable<Vertex> results = index.get("ID","06615119"); OR Iterable<Vertex> results = index.get("key","06615119");


Errors on these scenarios are like
                ORID key = idx.get("indexKey");
                             
^
  required
: String,Object
  found
: String
  reason
: actual and formal argument lists differ in length
 
where T is a type-variable:
    T
extends Element declared in interface Index
2 errors

Exception in thread "main" java.lang.NullPointerException
at ClassConnect.main(ClassConnect.java:104)




Shishya

unread,
Mar 13, 2014, 8:58:08 AM3/13/14
to orient-...@googlegroups.com
This works fine now, but I am still looking for method of FAST access as claimed on Stackoverflow thread 

OIndex<?> nameIdx = graph.getRawGraph().getMetadata().getIndexManager().getIndex("idxtest2");
               
Object luke = (Object)nameIdx.get( "06615119" );
               
System.out.println(luke);

Andrey Lomakin

unread,
Mar 13, 2014, 9:07:29 AM3/13/14
to orient-database
HI,
Indexes are automatically used when you use SQL queries. 
Just issue query like "select from Class where prop = val"


--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Best regards,
Andrey Lomakin.

Orient Technologies
the Company behind OrientDB

prabhat

unread,
Mar 13, 2014, 9:50:33 AM3/13/14
to orient-...@googlegroups.com
Hi Andrey,

On a related issue, I am not able to create edges by RID retrieved from indexes. Please help
----------------_Error-------------------------------
 error: method addEdge in class OrientBaseGraph cannot be applied to given types;
                        graph.addEdge("class:e1", v1,clsVertex,"e1"); 
                             ^
  required: Object,Vertex,Vertex,String
  found: String,ORID,OrientVertex,String
-------------------------------------------------------

Code is Like:
-----------------------------------
OrientVertex clsVertex = graph.addVertex("class:mc1", "ID","data1f");
                        clsVertex.save();
graph.addEdge("class:e1", (ORID)luke.get(0),clsVertex,"e1"); 
--------------------------------------------



--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/PvrzygYRJd0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

Andrey Lomakin

unread,
Mar 14, 2014, 5:10:07 AM3/14/14
to orient-database
HI,
Do you use dynamic language ?

You can not use rids directly to make edges, at first load vertex by rid, and  then you can create edge between vertexes.
Reply all
Reply to author
Forward
0 new messages