# SpaceIndexing at runtime

Hello,

I have a question on how to dynamically add SpaceIndexes using the API instead on Nested Properties for a Map. Take the following example where the key that I want the index on in the map is “ExternalId”

package com.myclass

public class MyBaseClass {

  private Map<String, String> nestedMap;

// getter/setters


}

public class MyNextParentClass extends MyBaseClass {

}

public class MyChildClass extends MyNextParentClass { }

Now when I use the following SpaceIndex annotation

@SpaceIndex (path=nestedMap.ExternalId)

Any searches I do on MyChildClass on key “ExternalId” use the index. I can see the from the new logging that was added to 10.x release, all is good.

However, using the annotation really isn't an option for me because the key that I am searching on could be different depending on the context. Instead, I want to use the GigaSpaceTypeManager api to allow me to customize the indexes at runtime. However when I use the following code, searching never hits the index

I can see in the GS GUI that the index shows up, but looking at the logging I can clearly see the index doesn't work (I can tell by the search times too). I also tried using “com.myclass.MyBaseClass” instead but that also didn't work.

Can someone point me to better documentation or an example of how to make this work using the API? The documentation is very limited on this

http://docs.gigaspaces.com/xap102/ind...

Thanks

Rich

edit retag close merge delete

Sort by » oldest newest most voted

Hi John,

Yea I waited about 1 min, I had about 125K objects in the map of which about 20% of those were the key I was looking for (the rest were other keys).

So you are saying my test case worked for you? I even tried it from GS Gui and got the same result. My test case was simplified some. I have many other classes that inherit from the same hierarchy but none of those objects were in the space.

So you are saying the API calls I am making are correct? The test case I gave you was just a simplified version of my real case so I never tried it. I used it more for explanation, never actually tried it. I wanted to make sure I was suppose to use the child class on the API call even though the map is on a parent.

Rich

more

Rich

It doesn't take long, but the index can take a second or more to be built. Are you waiting for the process to complete? We can't reproduce this with a simple test using a three-class hierarchy such as you described. Here are the results (2,000,000 objects - 200,000 of type = 5):

read multiple took 1883 milliseconds unindexed read multiple for type = 5 took 322 milliseconds waiting for index completion . indexed read multiple for type = 5 took 31 milliseconds

Regards

John

more

Hi John,

Yea I waited about 1 min, I had about 125K objects in the map of which about 20% of those were the key I was looking for (the rest were other keys).

So you are saying my test case worked for you? I even tried it from GS Gui and got the same result. My test case was simplified some. I have many other classes that inherit from the same hierarchy but none of those objects were in the space.

So you are saying the API calls I am making are correct? The test case I gave you was just a simplified version of my real case so I never tried it. I used it more for explanation, never actually tried it. I wanted to make sure I was suppose to use the child class on the API call even though the map is on a parent.

Rich

( 2016-03-10 15:31:57 -0600 )edit

One other question. Did you create the indexes before the data was inserted or can it be done either way. What i noticed about the annotations, it added that index to every level of the hierarchy. How is that done with the API? Do you have to invoke the API at every level of the hierarchy? If so, does order matter (i.e. leaf to parent or parent to leaf)?

( 2016-03-10 15:34:13 -0600 )edit

Rich

Here is the actual code used for an _exact_ reproduction. The map<string, string=""> class 'nestedMap' is a member variable of the base class 'IndexBase', with an intermediate class 'IndexClass'. Output is at the bottom.

    start = System.currentTimeMillis();
SQLQuery query = new SQLQuery<IndexChild>(IndexChild.class, "nestedMap.Zero = 'number'");
stop =  System.currentTimeMillis();
System.out.println("unindexed read multiple took " + (stop-start) + " milliseconds");

GigaSpaceTypeManager manager = space.getTypeManager();
SpaceIndex index = SpaceIndexFactory.createPropertyIndex("nestedMap.Zero", SpaceIndexType.BASIC);

System.out.print("waiting for index completion ");
while (! result.isDone()) {
System.out.print(".");
try {
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println();

start = System.currentTimeMillis();
stop =  System.currentTimeMillis();
System.out.println("indexed read multiple took " + (stop-start) + " milliseconds");


unindexed read multiple took 601 milliseconds
waiting for index completion .
indexed read multiple took 160 milliseconds

more

One thing I forgot to mention, the SQLQuery is actually being done on MyBaseClass not the leaf. Would that make a difference?

( 2016-03-10 16:32:20 -0600 )edit