2 Replies Latest reply on Dec 20, 2011 8:49 AM by jamat

    Query with PropertyExistence constraint

    jamat Newbie

      Hello,

       

      I wanted to use a query like this:

       

      "SELECT * FROM [nt:unstructured] AS a WHERE a.[xxx:yyy] IS NOT NULL"

       

      but it was failing:

       

      Caused by: java.util.NoSuchElementException: Property 'xxx:yyy' on selector 'a' is not used in query

              at org.modeshape.graph.query.process.QueryResultColumns.getColumnIndexForProperty(QueryResultColumns.java:508) [:2.7-SNAPSHOT]

              at org.modeshape.graph.query.process.SelectComponent.createChecker(SelectComponent.java:347) [:2.7-SNAPSHOT]

              at org.modeshape.graph.query.process.SelectComponent.<init>(SelectComponent.java:110) [:2.7-SNAPSHOT]

              at org.modeshape.graph.query.process.QueryProcessor.createComponent(QueryProcessor.java:305) [:2.7-SNAPSHOT]

              at org.modeshape.graph.query.process.QueryProcessor.createComponent(QueryProcessor.java:286) [:2.7-SNAPSHOT]

              at org.modeshape.graph.query.process.QueryProcessor.execute(QueryProcessor.java:90) [:2.7-SNAPSHOT]

              at org.modeshape.graph.query.QueryEngine.execute(QueryEngine.java:124) [:2.7-SNAPSHOT]

              at org.modeshape.jcr.RepositoryQueryManager$SelfContained.query(RepositoryQueryManager.java:435) [:2.7-SNAPSHOT]

              at org.modeshape.jcr.JcrQueryManager$SessionQueryContext.execute(JcrQueryManager.java:1422) [:2.7-SNAPSHOT]

              at org.modeshape.jcr.query.JcrQuery.execute(JcrQuery.java:103) [:2.7-SNAPSHOT]

       

      If I modify the query like that:

       

      "SELECT [xxx.yyy] FROM [nt:unstructured] AS a WHERE a.[xxx:yyy] IS NOT NULL"

       

      then it is working.

       

      Is this the expected behavior ?

       

      Thank you.

        • 1. Re: Query with PropertyExistence constraint
          Randall Hauch Master

          You're property is either a residual property (it corresponds to one of the property definitions named "*" on nt:unstructured), or it's a non-residual property on another mixin, which must be joined. So, yes this is the expected behavior. But you could file an issue to provide a more useful/meaningful error message. We could even try to improve our handling to be a bit smarter about how we're processing the query.

           

          BTW, "SELECT *" can never be expanded to include residual properties, so the way around this is to always specify the properties you want in the select clause. This is considered a best-practice (and is a best practice of SQL applications, too). See this section for a treatment on this topic.