Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF Query 2]Issue to query in Xtext and Object format
[EMF Query 2]Issue to query in Xtext and Object format [message #651891] Tue, 01 February 2011 22:24 Go to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

I'm trying to follow this tutorial: http://wiki.eclipse.org/EMF/Query2/DevGuide#Sample_Queries:

For Object queries format:
I have no access to QueryProcessorImpl as it is an internal class.
Where is the getQueryContext method defined?
What is rs? ResourceSet? Which one I need to use?


For Xtext:

also no access to QueryProcessorImpl as it is an internal class.
Where is defined StandaloneSetup? Injector?

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: [EMF Query 2]Issue to query in Xtext and Object format [message #651906 is a reply to message #651891] Wed, 02 February 2011 03:03 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
Hi Aurelien,

Answers below.
Aurelien Pupier wrote on Tue, 01 February 2011 17:24
Hi,

I'm trying to follow this tutorial: http://wiki.eclipse.org/EMF/Query2/DevGuide#Sample_Queries:

For Object queries format:
I have no access to QueryProcessorImpl as it is an internal class.
Where is the getQueryContext method defined?
What is rs? ResourceSet? Which one I need to use?




Sorry we refactored QueryProcessorImpl.We forgot to update the developer guide.Now it can be accessed through QueryProcessorFacory.

like this

QueryProcessor createQueryProcessor = QueryProcessorFactory.getDefault().createQueryProcessor(index);  //index is the instance of the index against which you are querying.
resultSet = createQueryProcessor.execute(query, getQueryContext());



The QueryContext class has to be provided by the client.It needs to be implemented by the client .There you need to provide implementation for two methods.

getResourceSet(): must return the resource set which is actually is in the context of the query.Any resource loaded will be in this resource set

getResourceScope(): must return the scope of the query context.It can be all the resources in your index.It can be the resources only which you want to explicitly specify.

Check the following implementation from one of our test classes. TestQueryBugs.java

	private QueryContext getQueryContext() {
		return new QueryContext() {

			public URI[] getResourceScope() {
				final List<URI> result = new ArrayList<URI>();
				IndexFactory.getInstance().executeQueryCommand(new QueryCommand() {

					public void execute(QueryExecutor queryExecutor) {
						ResourceQuery<ResourceDescriptor> resourceQuery = IndexQueryFactory.createResourceQuery();
						for (ResourceDescriptor desc : queryExecutor.execute(resourceQuery)) {
							result.add(desc.getURI());
						}
					}

				});
				return result.toArray(new URI[0]);

			}

			public ResourceSet getResourceSet() {
				return rs;
			}
		};
	}


Suggest you to have a look at the BaseSyntheticQueryTests and TestQueryBugs class for more references.

Quote:

For Xtext:

also no access to QueryProcessorImpl as it is an internal class.
Where is defined StandaloneSetup? Injector?

Regards,


QueryStandalonesetup class is in the org.eclipse.emf.query2.stringsyntax plug-in

Apart from the developer guide you can also follow LibraryTransformation.java class in the org.eclipse.emf.query2.librarytest plug-in which has the code for how to setup XText environment for Query2.

And yes we will also update the developer guide Razz

cheers,
Saurav


Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652132 is a reply to message #651891] Wed, 02 February 2011 18:14 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

For now,

I manage to use Object format but cannot make working with Xtext:

I have this error:
org.eclipse.emf.query2.QueryFormatException: Error : The alias pool, whose type is represented by MRI platform:/plugin/org.bonitasoft.studio.common/bonita.query#xtextLink_:://@namedQueries.0/@query/@fromEntries.0::http://www.eclipse.org/emf/query2/Query«FromEntry«0::/1, is not referring to an instance of MofClass or StructureType
Finished with 1 errors and 0 warnings.

	at org.eclipse.emf.query2.internal.moinql.preprocessor.TypeCheckerImpl.reportFatal(TypeCheckerImpl.java:167)
	at org.eclipse.emf.query2.internal.moinql.preprocessor.TypeCheckerImpl.convertFromEntry(TypeCheckerImpl.java:407)
	at org.eclipse.emf.query2.internal.moinql.preprocessor.TypeCheckerImpl.convertFromEntries(TypeCheckerImpl.java:318)
	at org.eclipse.emf.query2.internal.moinql.preprocessor.TypeCheckerImpl.convertQuery(TypeCheckerImpl.java:245)
	at org.eclipse.emf.query2.internal.moinql.preprocessor.TypeCheckerImpl.convert(TypeCheckerImpl.java:144)
	at org.eclipse.emf.query2.internal.moinql.controller.QueryProcessorImpl.prepareInternal(QueryProcessorImpl.java:363)
	at org.eclipse.emf.query2.internal.moinql.controller.QueryProcessorImpl.executeInternal(QueryProcessorImpl.java:553)
	at org.eclipse.emf.query2.internal.moinql.controller.QueryProcessorImpl.execute(QueryProcessorImpl.java:613)
	at org.bonitasoft.studio.common.emf.tools.ModelHelper.newwayFindProcessesWithXtextQuery(ModelHelper.java:203)
	at org.bonitasoft.studio.common.emf.tools.ModelHelper.findAllProcesses(ModelHelper.java:152)
	at org.bonitasoft.studio.common.emf.tools.ModelHelper.getAllProcesses(ModelHelper.java:143)
	at org.bonitasoft.studio.properties.sections.message.wizards.AddMessageEventWizardPage.createControl(AddMessageEventWizardPage.java:253)
	at org.eclipse.jface.wizard.Wizard.createPageControls(Wizard.java:170)
	at org.eclipse.jface.wizard.WizardDialog.createPageControls(WizardDialog.java:734)
	at org.eclipse.jface.wizard.WizardDialog.createContents(WizardDialog.java:606)
	at org.eclipse.jface.window.Window.create(Window.java:431)
	at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
	at org.eclipse.jface.window.Window.open(Window.java:790)
	at org.bonitasoft.studio.properties.sections.message.ThrowEventSection$6.handleEvent(ThrowEventSection.java:210)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.bonitasoft.studio.application.BonitaStudioApplication.start(BonitaStudioApplication.java:99)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
	at org.eclipse.core.launcher.Main.main(Main.java:34)



Any ideas why I am doing wrong?

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652154 is a reply to message #651891] Wed, 02 February 2011 19:16 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
Hi Aurelien,

This error is coming from the TypeChecker component of the Query core.TypeChecker component checks the type safety of the query with the model entities.

Exception says that the the type of the From Entry object is not resolved as an EClass type.In this case the FromEntry of whose alias is 'pool'.

Can you please check your From entry or I suspect the XText setup is missing something.If possible please share your queries or let me know the XText setup in your code.

cheers,
Saurav


[Updated on: Wed, 02 February 2011 19:17]

Report message to a moderator

Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652156 is a reply to message #651891] Wed, 02 February 2011 19:20 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

my query:
searchAllProcesses:
from Pool as pool
	select pool


my setup:
private static Model model;

private static ResultSet newwayFindProcessesWithXtextQuery(final Element element) {
	
		MQLquery query = findQuery("searchAllProcesses");
		Query internalQuery = QueryTransformer.transform(query);
		Index indexFactory = IndexFactory.getInstance();
		QueryProcessor queryProcessor = QueryProcessorFactory.getDefault().createQueryProcessor(indexFactory);
		final ResultSet result = queryProcessor.execute(internalQuery, new QueryContext() {
			
			public ResourceSet getResourceSet() {
				return element.eResource().getResourceSet();
			}
			
			public URI[] getResourceScope() {
				return new URI[]{element.eResource().getURI()};
			}
		});
		
		return result;
	}
	
	private static MQLquery findQuery(String queryName) {
		if(model == null){
			new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("..");
			Injector injector = new QueryStandaloneSetup().createInjectorAndDoEMFRegistration();
			XtextResourceSet set = injector.getInstance(XtextResourceSet.class);
			set.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
			URI resourceURI = URI.createURI(
			         "platform:/plugin/org.bonitasoft.studio.common/bonita.query");
			URI normalized = set.getURIConverter().normalize(resourceURI);
			LazyLinkingResource xtextResource = (LazyLinkingResource) set.getResource(normalized, true);
			model = (Model) xtextResource.getContents().get(0);
		}
		if (queryName == null) {
			return model.getDefaultQuery();
		}
		for (NamedQuery query : model.getNamedQueries()) {
			if (query.getName().equals(queryName)) {
				return query.getQuery();
			}
		}
		return null;
	}





Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652160 is a reply to message #651891] Wed, 02 February 2011 19:39 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
Hi Aurelien,

Two things can be checked here.

(a) If you have mentioned the proper ns uri of your model's ecore in the import statement of your .qurey file.
(b) If the model plug-in (generated classes) are there in the target platform of your workbench.

On this note i would like to mention we have also done a prototype where user can express the Xtext based queries as normal string in the code.So user may wish to not use .query file.Though this code has not yet been submitted.

cheers,
Saurav


[Updated on: Wed, 02 February 2011 20:14]

Report message to a moderator

Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652181 is a reply to message #651891] Wed, 02 February 2011 21:53 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Thanks again and again for your answer.

I change import in the .query files and it works like a charm (use ns package uri instead of referencing .ecore)

Can you confirm:

- XText take more time to initialize than Object format
- Xtext is quicker than Object format

The real advantage of EMF query comes when the EMF resource is not yet loaded, otherwise browsing model via EMF API is faster. or perhaps, it really depends on the query?

EDIT: in fact, after more investigation, if I use a more "complex" query (get also two attributes of the queried elements), the EMF resource API is better. perhaps it is because I don't have enough data? i have only thousands.

Another point:
To execute the query, we need to provide a QueryContext. What is the recommended and efficient way to calculate ResourceSet when I wanty to do a request on all the indexed files? Same for URI of ResourceScope?

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team

[Updated on: Wed, 02 February 2011 23:20]

Report message to a moderator

Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652219 is a reply to message #652181] Thu, 03 February 2011 07:29 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
Hi Aurelien,

Answers below.
Aurelien Pupier wrote on Wed, 02 February 2011 16:53
Thanks again and again for your answer.

I change import in the .query files and it works like a charm (use ns package uri instead of referencing .ecore)

Can you confirm:

- XText take more time to initialize than Object format
- Xtext is quicker than Object format




Definitely XText execution takes a longer time than the Object based format because extra transformation from XText strings to XText AST to Query AST is needed.
Whereas in case of Object based format it is not required.

Quote:

The real advantage of EMF query comes when the EMF resource is not yet loaded, otherwise browsing model via EMF API is faster. or perhaps, it really depends on the query?




Yes , considering the resource navigation aspects the main advantage lies in scability of the model, where the resources are not needed to be loaded.

Query Test UI,SQL like string syntax,type safety of queries and dirty state awareness are the other key features if the whole package of Querying aspects are concerned.

Quote:

EDIT: in fact, after more investigation, if I use a more "complex" query (get also two attributes of the queried elements), the EMF resource API is better. perhaps it is because I don't have enough data? i have only thousands.




Does that mean nested query or query with multiple joins ?

Quote:

Another point:
To execute the query, we need to provide a QueryContext. What is the recommended and efficient way to calculate ResourceSet when I wanty to do a request on all the indexed files? Same for URI of ResourceScope?

Regards,



Most of the cases we have seen passing all the resource uris available in the index as the resource scope.
This can be achieved by firing a resource query over the index to get all the resource URIs.

following code does that
public URI[] getResourceScope() {
				final List<URI> result = new ArrayList<URI>();
				IndexFactory.getInstance().executeQueryCommand(new QueryCommand() {

					public void execute(QueryExecutor queryExecutor) {
						ResourceQuery<ResourceDescriptor> resourceQuery = IndexQueryFactory.createResourceQuery();
						for (ResourceDescriptor desc : queryExecutor.execute(resourceQuery)) {
							result.add(desc.getURI());
						}
					}

				});
				return result.toArray(new URI[0]);

			}


Empty resource set can be passed if the querying scenario only concerns about the non-dirty resources.
In case of dirty scenarios, user may wish to load some modified resources in the resource set.

Please let us know if you need more clarification on this topic.

Cheers,
Saurav


[Updated on: Thu, 03 February 2011 07:30]

Report message to a moderator

Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652225 is a reply to message #652219] Thu, 03 February 2011 08:43 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

Thanks for your answer.
Comments below.

saurav wrote on Thu, 03 February 2011 08:29
Hi Aurelien,
Quote:

EDIT: in fact, after more investigation, if I use a more "complex" query (get also two attributes of the queried elements), the EMF resource API is better. perhaps it is because I don't have enough data? i have only thousands.


Does that mean nested query or query with multiple joins ?


I mean this kind:
searchAllProcesses:
from Pool as pool
	select pool,pool.name,pool.version


saurav wrote on Thu, 03 February 2011 08:29

Quote:

Another point:
To execute the query, we need to provide a QueryContext. What is the recommended and efficient way to calculate ResourceSet when I wanty to do a request on all the indexed files? Same for URI of ResourceScope?



Most of the cases we have seen passing all the resource uris available in the index as the resource scope.
This can be achieved by firing a resource query over the index to get all the resource URIs.

following code does that
public URI[] getResourceScope() {
				final List<URI> result = new ArrayList<URI>();
				IndexFactory.getInstance().executeQueryCommand(new QueryCommand() {

					public void execute(QueryExecutor queryExecutor) {
						ResourceQuery<ResourceDescriptor> resourceQuery = IndexQueryFactory.createResourceQuery();
						for (ResourceDescriptor desc : queryExecutor.execute(resourceQuery)) {
							result.add(desc.getURI());
						}
					}

				});
				return result.toArray(new URI[0]);

			}


Empty resource set can be passed if the querying scenario only concerns about the non-dirty resources.
In case of dirty scenarios, user may wish to load some modified resources in the resource set.



Ok it is finally what I use by looking into some query tests.


Most of the time, when I make a research, the EMF resource is yet loaded.
I think that my main use case when it is not loaded, I will use the request that is upside in this post, get all Pool and take two of these attributes.
I need to determine from which amount of data I will gain time.

EDIT: it seems to be too much data than I have. Is there a way to configure indexation as I will have always the same types of query?

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team

[Updated on: Thu, 03 February 2011 10:09]

Report message to a moderator

Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652253 is a reply to message #652225] Thu, 03 February 2011 11:02 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
Hi Aurelien,

For your query it will defintely try to load all the resources of that type only as it is the select all of that type statement.

In case of Resource APIs you need to load all the resources of all types and then filter.

In this case also Query2 has an advantage.

Also Query2 indexes the URI and an attribute of model class with 'name' Name.So for that the resources need not be loaded.

Quote:

EDIT: it seems to be too much data than I have. Is there a way to configure indexation as I will have always the same types of query?



I did not get the question clearly.But please check my comments above that might help.

cheers,
Saurav


Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652274 is a reply to message #652253] Thu, 03 February 2011 12:42 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

saurav wrote on Thu, 03 February 2011 12:02

For your query it will defintely try to load all the resources of that type only as it is the select all of that type statement.

In case of Resource APIs you need to load all the resources of all types and then filter.

In this case also Query2 has an advantage.

Also Query2 indexes the URI and an attribute of model class with 'name' Name.So for that the resources need not be loaded.



In fact, I notice using TPTP in my casee that it takes more time using query2 then my own manual algorithm using EMF API. An dI don't understand either it can be possible.
I need to take a deeper look at it but I don't know when I will have time to do it. But you should be aware of that coz' I'm pretty sure that I will ask you for some help Wink

saurav wrote on Thu, 03 February 2011 12:02

Quote:

EDIT: it seems to be too much data than I have. Is there a way to configure indexation as I will have always the same types of query?



I did not get the question clearly.But please check my comments above that might help.



Is there a possibility to prepare indexation for some specific queries?

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: [EMF Query 2]Issue to query in Xtext and Object format [message #652290 is a reply to message #652274] Thu, 03 February 2011 13:40 Go to previous message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
Aurelien,

Comments below,

Aurelien Pupier wrote on Thu, 03 February 2011 07:42

In fact, I notice using TPTP in my casee that it takes more time using query2 then my own manual algorithm using EMF API. An dI don't understand either it can be possible.
I need to take a deeper look at it but I don't know when I will have time to do it. But you should be aware of that coz' I'm pretty sure that I will ask you for some help Wink




Sure i am there for any kind of help and asisstance needed Smile.

But have you taken the indexing time also into the account ? then it will surely take much time.

On another note if it takes much time i am sure on memory consumption wise Query2 holds an edge.

Quote:


Is there a possibility to prepare indexation for some specific queries?

Regards,


If i am able to understand your query, then here are my comments

Generally there is always a single instance of index which is always passed to the Query processor.

If you want to load some resources or want to modify some resource during some specific query you can always take the advantage of dirty state awareness of the Query engine.
So that particular state of resources can be only made available to that specific execution of query.


cheers,
Saurav


Previous Topic:[EMF Query2]first steps with EMF query2
Next Topic:Handling saving/ dirty state over multiple files
Goto Forum:
  


Current Time: Fri Apr 26 22:23:03 GMT 2024

Powered by FUDForum. Page generated in 0.04303 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top