Artem Melentyev wrote:
  Hi, devs.
 I would like to discuss about the new xwiki query language.
 
http://dev.xwiki.org/xwiki/bin/view/Design/XWikiQueryLanguage
 We need to choose a syntax and data model of the query language
 There are some examples in
 
http://dev.xwiki.org/xwiki/bin/view/Design/XWiki+Query+Language+Specificati…
 I already have a prototype based on my JPQL parser (SableCC based) and
 hql generator. It is quite easy to modify syntax and generator. Results
 of my query parser research in the end of the message.
 I propose:
 0) Name: XWiki Query Language, XWQL as a name of the new language.
    
Why not XQL ? Does it conflict with something ?
  1) Data Model: Choose query method #1 from
specification
 
http://dev.xwiki.org/xwiki/bin/view/Design/XWiki+Query+Language+Specificati…
 with corrections:
 add Document as a virtual class for our XWikiDocument.
 use "docalias.XWiki.ClassName instead" of "XWiki.ClassName". docalias
is
 some alias for Document.
 add optional select clause.
 example:
 "select doc.fullName
   from Document as doc, doc.XWiki.XWikiUsers as user
   where user.email like '%xwiki.com' and  doc.author=:username"
    
sounds good.. +1 for method #1
  "select doc.fullName from Document as doc"
may be omitted. It will be
 added if there is no Document in query statement. So "from
 doc.XWiki.XWikiUsers as user" is correct query statement.
 It is possible to use several documents and objects in one query.
 Attachment, Class, and other xwiki entities will be added later if needed.
 2) Syntax: XWQL will be JPQL subset.
   (hint: JPQL is part of Java Persistance API standard, JSR#317. HQL is
 a superset of JPQL. Hibernate support JPA)
   All JPQL features and all hibernate data model will be accessible for
 hibernate store. But it is not true for JCR store.
   Only described data model will be available for XWQL on JCRStore. (But
 we may add some extensions later)
   In JCRv2 will not work (JCRSQL2 constraint):
    arithmetic expressions (+-*/)
    aggregation funtions (max,min,sum,avg)
    some other functions
   In JCRv1 also will not work (XPath constraint):
    query on several documents (from Document as doc1, Document as doc2)
   Some JPQL limitations compared with HQL:
    no arithmetic expressions (+-*/) in select clause
    aliases at from clause are mandatory (from Document as alias)
 So the main idea is to use simple JPQL preprocessor to rewrite virtual
 data model to real.
 This is quite easy for HQL and JCRSQL2. But it is hard(but doable) for
 JCRv1 XPath.
    
I'm not sure we need XPath.. It's deprecated in JCR v2 so we don't
really care.
The most important is to have a consitent query api XWQL or XQL working
the same way for HQL and JCRSQL2.
Ludovic
  WDYT?
 Appendix:
 I researched a many of query engines and found nothing appropriate. All
 query engines/parsers is either very specific or cannot be used
 standalone or cannot be used as a preprocessor. JCRSQL2 language parser
 from Jackrabbit is still unusable.
 Next I researched a parser generators and found that SableCC is best
 choose for my needs. Other tools (ANTLR, JavaCC, Cup, Beaver) requires
 much more hand work to write parse tree (AST) and preprocessors
 (Visitors and ast.toString). JTB and JJTree also generate AST and
 visitors, but SableCC generated code is much more clean.
 SableCC generate all of this from one clear grammar file. Maybe it is
 not as perfect as hand-written one, but it is quite suitable.
 Reason to choose sql-like syntax:
 XPath isn't still much spread. XPath language is deprecated in JCRv2.
 JCRv2 uses JCRSQL2 and criteria-like AQM instead. JCRSQL2 is much more
 powerful (in expression sense) than JCR's XPath and JCRSQL1.
 --
    Artem Melentyev
 _______________________________________________
 devs mailing list
 devs(a)xwiki.org
 
http://lists.xwiki.org/mailman/listinfo/devs
    
--
Ludovic Dubost
Blog: 
http://blog.ludovic.org/
XWiki: 
http://www.xwiki.com
Skype: ldubost GTalk: ldubost