Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Equinox/p2/Query Language for p2"

< Equinox‎ | p2
(New page: ===Background=== p2 has a query mechanism today that makes it very hard to create an implementation that is based on a database. It is also very hard to create an efficient client/server s...)
 
Line 3: Line 3:
  
 
We discussed this at length on the p2 meeting on November 9. This resulted in the bugzilla [https://bugs.eclipse.org/bugs/show_bug.cgi?id=294691 Create a QueryLanguage for p2]. I've spend some time on this now and today I have a fully functional IQuery implementation.
 
We discussed this at length on the p2 meeting on November 9. This resulted in the bugzilla [https://bugs.eclipse.org/bugs/show_bug.cgi?id=294691 Create a QueryLanguage for p2]. I've spend some time on this now and today I have a fully functional IQuery implementation.
 +
 +
===Considerations===
 +
When designing the language I tried to consider two things. Who is the primary user and which are the most common queries?
 +
 +
The primary user is typically well aqquinted with Java so I opted for using java operators such as '&&' and '||' rather then SQL'ish keywords like OR and AND. I also use '.' for member access and '[' ']' to get indexed access. The latter can also be used to get keyed access.
 +
 +
A large amount of queries involve versions, version ranges, and capability matching. So managing that is important. Another thing is to make sure the result of a query only contains the latest version of each found IU. I added a special keyword 'latest' to make that possible. A third thing that is important is to be able to support filtering based on ID's. This is now also built in to the language.
 +
 +
It must also be possible to combine queries (hence && and ||).
 +
 +
The query must be parameterised so that expression parsing can be done once and then executed multiple times.
 +
 +
===Examples===
 +
Query for all IU's that has an id:
 +
<pre>id = :1</pre>
 +
Query for the latest IU of some specific id:
 +
<pre>latest id = :1</pre>
 +
Java code to query for the latest ID that matches a specific version range
 +
<pre>IQuery query = queryFactory.createQuery("latest id = :1 and version ~= :2", id, range);</pre>
 +
  
 
===The [http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form BNF]===
 
===The [http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form BNF]===

Revision as of 10:25, 13 November 2009

Background

p2 has a query mechanism today that makes it very hard to create an implementation that is based on a database. It is also very hard to create an efficient client/server solution. The reason for this is that most of the queries are written as java code in a callback and there is often no good way to extract the semantics of the query.

We discussed this at length on the p2 meeting on November 9. This resulted in the bugzilla Create a QueryLanguage for p2. I've spend some time on this now and today I have a fully functional IQuery implementation.

Considerations

When designing the language I tried to consider two things. Who is the primary user and which are the most common queries?

The primary user is typically well aqquinted with Java so I opted for using java operators such as '&&' and '||' rather then SQL'ish keywords like OR and AND. I also use '.' for member access and '[' ']' to get indexed access. The latter can also be used to get keyed access.

A large amount of queries involve versions, version ranges, and capability matching. So managing that is important. Another thing is to make sure the result of a query only contains the latest version of each found IU. I added a special keyword 'latest' to make that possible. A third thing that is important is to be able to support filtering based on ID's. This is now also built in to the language.

It must also be possible to combine queries (hence && and ||).

The query must be parameterised so that expression parsing can be done once and then executed multiple times.

Examples

Query for all IU's that has an id:

id = :1

Query for the latest IU of some specific id:

latest id = :1

Java code to query for the latest ID that matches a specific version range

IQuery query = queryFactory.createQuery("latest id = :1 and version ~= :2", id, range);


The BNF

p2query : ('latest' | 'distinct')? orExpression ;

orExpression : andExpression ( '||' andExpression )* ;

andExpression : notExpression ( '&&' notExpression )* ;

notExpression
   : '!' notExpression
   | binaryExpression
   ;

op : '=' | '!=' | '>' | '>=' | '<' | '<=' | '~=' ;

binaryExpression : sideExpression op sideExpression ;

sideExpression : ('any' | 'all')? memberExpression ;

memberExpression : unaryExpression ( ( '.' ID ) | ( '[' memberExpression ']' ) )* ;

unaryExpression
   : '(' orExpression ')'
   | '[' memberExpression ( ',' memberExpression )* ']' // #array construct
   | '/' regexpPattern '/'
   | STRING
   | INT
   | parameter
   | 'self'
   | 'null'
   | 'true'
   | 'false'
   | ID // # implies self.identifier
   ;

   parameter
   : ':' INT
   ;

Copyright © Eclipse Foundation, Inc. All Rights Reserved.