You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by "Ottinger, Joseph" <jo...@techtarget.com> on 2007/04/18 17:51:47 UTC

count of nodes?

Hi. I'm trying to get a count of nodes under a specific node. To
explain, imagine the following tree:
 
<foo>
    <bar>
        <baz />
    </bar>
</foo>
 
Given a path to /foo (via UUID), what I want to do is get a count
including both <bar> and <baz> -- i.e., I want to get a result of "2". 
 
Using XPath, the query should be something like -- pardon me my horrible
syntax, k? -- 
 
count(//*[jcr:uuid=$uuid]/*)
 
However, count() is unsupported. So I'm kinda stuck, unless I want to
walk the tree under /foo, and I don't unless I have no choice.
 
Any suggestions?

Re: count of nodes?

Posted by David Nuescheler <da...@gmail.com>.
Hi Joe,

"_" is acceptable for a node name.
I don't really know what you could be referring to.

I frequently use http://jcr.day.com to validate
things like that.

http://jcr.day.com/ exposes a public test
web gui on top of JCR and lets you perform all the
JCR calls by "clicking buttons" ;)

I created a node "_" in the default workspace and queried
for it, everything seems to work as expected.
You can go to the "Content Explorer" to test things if
you like.

regards,
david


On 4/19/07, Ottinger, Joseph <jo...@techtarget.com> wrote:
> Incidentally... Is there any real reason that "_" isn't lexically
> acceptable for a node name?
>
> -----Original Message-----
> From: David Nuescheler [mailto:david.nuescheler@gmail.com]
> Sent: Thursday, April 19, 2007 10:32 AM
> To: users@jackrabbit.apache.org
> Subject: Re: count of nodes?
>
> hi joe,
>
> thanks for the feedback.
> i could imagine that there is still quite a bit of room for performance
> improvement for queries that are just interested in the number of nodes
> that match, so if you run into performance issues please be sure to let
> us know.
>
> regards,
> david
>
> On 4/19/07, Ottinger, Joseph <jo...@techtarget.com> wrote:
> > Done, and it works - confirmed kill. However...
> >
> > What I did in the absence of taking the time to learn Xpath well
> > enough to get the actual correct query down was walk the tree
> > recursively. For a simple tree:
> >
> > <foo>
> >         <bar>
> >                 <baz />
> >         </bar>
> >         <bletch />
> > </foo>
> >
> > ... The recursive method was faster, ever-so-slightly. I don't have a
> > dataset large enough to test more complicated trees yet; when I do,
> > I'll let you know what I find.
> >
> > -----Original Message-----
> > From: David Nuescheler [mailto:david.nuescheler@gmail.com]
> > Sent: Thursday, April 19, 2007 9:03 AM
> > To: users@jackrabbit.apache.org
> > Subject: Re: count of nodes?
> >
> > Hi Joe,
> >
> > > But wouldn't getSize() on the getNodes() call only get the immediate
>
> > > child nodes?
> > No. It would include everything that matched your query which would
> > include all the nodes in the QueryResult.
> > So the node iterator returned from QueryResult.getNodes() will contain
>
> > all the nodes that matched the query.
> > In your case:
> >
> > /jcr:root/foo//*
> > ... will return the nodes
> >
> > /foo/bar
> > /foo/bar/baz
> >
> > ... and the QueryResult.getNodes().getSize() should return 2
> >
> > > I'll keep investigating - I still find the Xpath rules a problem. :/
> > What do you find a problem about it?
> > Do you prefer the SQL syntax?
> >
> > regards,
> > david
> >
>

Re: count of nodes?

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi Joseph,

that's probably a bug in the SQL parser. Could you please created a jira issue 
for this?

as a workaround you can enclose the underscore in double quote, that should work.

regards
  marcel

Ottinger, Joseph wrote:
> Incidentally... Is there any real reason that "_" isn't lexically
> acceptable for a node name? 
> 
> -----Original Message-----
> From: David Nuescheler [mailto:david.nuescheler@gmail.com] 
> Sent: Thursday, April 19, 2007 10:32 AM
> To: users@jackrabbit.apache.org
> Subject: Re: count of nodes?
> 
> hi joe,
> 
> thanks for the feedback.
> i could imagine that there is still quite a bit of room for performance
> improvement for queries that are just interested in the number of nodes
> that match, so if you run into performance issues please be sure to let
> us know.
> 
> regards,
> david
> 
> On 4/19/07, Ottinger, Joseph <jo...@techtarget.com> wrote:
>> Done, and it works - confirmed kill. However...
>>
>> What I did in the absence of taking the time to learn Xpath well 
>> enough to get the actual correct query down was walk the tree 
>> recursively. For a simple tree:
>>
>> <foo>
>>         <bar>
>>                 <baz />
>>         </bar>
>>         <bletch />
>> </foo>
>>
>> ... The recursive method was faster, ever-so-slightly. I don't have a 
>> dataset large enough to test more complicated trees yet; when I do, 
>> I'll let you know what I find.
>>
>> -----Original Message-----
>> From: David Nuescheler [mailto:david.nuescheler@gmail.com]
>> Sent: Thursday, April 19, 2007 9:03 AM
>> To: users@jackrabbit.apache.org
>> Subject: Re: count of nodes?
>>
>> Hi Joe,
>>
>>> But wouldn't getSize() on the getNodes() call only get the immediate
> 
>>> child nodes?
>> No. It would include everything that matched your query which would 
>> include all the nodes in the QueryResult.
>> So the node iterator returned from QueryResult.getNodes() will contain
> 
>> all the nodes that matched the query.
>> In your case:
>>
>> /jcr:root/foo//*
>> ... will return the nodes
>>
>> /foo/bar
>> /foo/bar/baz
>>
>> ... and the QueryResult.getNodes().getSize() should return 2
>>
>>> I'll keep investigating - I still find the Xpath rules a problem. :/
>> What do you find a problem about it?
>> Do you prefer the SQL syntax?
>>
>> regards,
>> david
>>
> 

RE: count of nodes?

Posted by "Ottinger, Joseph" <jo...@techtarget.com>.
Incidentally... Is there any real reason that "_" isn't lexically
acceptable for a node name? 

-----Original Message-----
From: David Nuescheler [mailto:david.nuescheler@gmail.com] 
Sent: Thursday, April 19, 2007 10:32 AM
To: users@jackrabbit.apache.org
Subject: Re: count of nodes?

hi joe,

thanks for the feedback.
i could imagine that there is still quite a bit of room for performance
improvement for queries that are just interested in the number of nodes
that match, so if you run into performance issues please be sure to let
us know.

regards,
david

On 4/19/07, Ottinger, Joseph <jo...@techtarget.com> wrote:
> Done, and it works - confirmed kill. However...
>
> What I did in the absence of taking the time to learn Xpath well 
> enough to get the actual correct query down was walk the tree 
> recursively. For a simple tree:
>
> <foo>
>         <bar>
>                 <baz />
>         </bar>
>         <bletch />
> </foo>
>
> ... The recursive method was faster, ever-so-slightly. I don't have a 
> dataset large enough to test more complicated trees yet; when I do, 
> I'll let you know what I find.
>
> -----Original Message-----
> From: David Nuescheler [mailto:david.nuescheler@gmail.com]
> Sent: Thursday, April 19, 2007 9:03 AM
> To: users@jackrabbit.apache.org
> Subject: Re: count of nodes?
>
> Hi Joe,
>
> > But wouldn't getSize() on the getNodes() call only get the immediate

> > child nodes?
> No. It would include everything that matched your query which would 
> include all the nodes in the QueryResult.
> So the node iterator returned from QueryResult.getNodes() will contain

> all the nodes that matched the query.
> In your case:
>
> /jcr:root/foo//*
> ... will return the nodes
>
> /foo/bar
> /foo/bar/baz
>
> ... and the QueryResult.getNodes().getSize() should return 2
>
> > I'll keep investigating - I still find the Xpath rules a problem. :/
> What do you find a problem about it?
> Do you prefer the SQL syntax?
>
> regards,
> david
>

Re: count of nodes?

Posted by David Nuescheler <da...@gmail.com>.
hi joe,

thanks for the feedback.
i could imagine that there is still quite a bit of room for performance
improvement for queries that are just interested in the number of
nodes that match, so if you run into performance issues please be
sure to let us know.

regards,
david

On 4/19/07, Ottinger, Joseph <jo...@techtarget.com> wrote:
> Done, and it works - confirmed kill. However...
>
> What I did in the absence of taking the time to learn Xpath well enough
> to get the actual correct query down was walk the tree recursively. For
> a simple tree:
>
> <foo>
>         <bar>
>                 <baz />
>         </bar>
>         <bletch />
> </foo>
>
> ... The recursive method was faster, ever-so-slightly. I don't have a
> dataset large enough to test more complicated trees yet; when I do, I'll
> let you know what I find.
>
> -----Original Message-----
> From: David Nuescheler [mailto:david.nuescheler@gmail.com]
> Sent: Thursday, April 19, 2007 9:03 AM
> To: users@jackrabbit.apache.org
> Subject: Re: count of nodes?
>
> Hi Joe,
>
> > But wouldn't getSize() on the getNodes() call only get the immediate
> > child nodes?
> No. It would include everything that matched your query which would
> include all the nodes in the QueryResult.
> So the node iterator returned from QueryResult.getNodes() will contain
> all the nodes that matched the query.
> In your case:
>
> /jcr:root/foo//*
> ... will return the nodes
>
> /foo/bar
> /foo/bar/baz
>
> ... and the QueryResult.getNodes().getSize() should return 2
>
> > I'll keep investigating - I still find the Xpath rules a problem. :/
> What do you find a problem about it?
> Do you prefer the SQL syntax?
>
> regards,
> david
>

RE: count of nodes?

Posted by "Ottinger, Joseph" <jo...@techtarget.com>.
Done, and it works - confirmed kill. However...

What I did in the absence of taking the time to learn Xpath well enough
to get the actual correct query down was walk the tree recursively. For
a simple tree:

<foo>
	<bar>
		<baz />
	</bar>
	<bletch />
</foo>

... The recursive method was faster, ever-so-slightly. I don't have a
dataset large enough to test more complicated trees yet; when I do, I'll
let you know what I find. 

-----Original Message-----
From: David Nuescheler [mailto:david.nuescheler@gmail.com] 
Sent: Thursday, April 19, 2007 9:03 AM
To: users@jackrabbit.apache.org
Subject: Re: count of nodes?

Hi Joe,

> But wouldn't getSize() on the getNodes() call only get the immediate 
> child nodes?
No. It would include everything that matched your query which would
include all the nodes in the QueryResult.
So the node iterator returned from QueryResult.getNodes() will contain
all the nodes that matched the query.
In your case:

/jcr:root/foo//*
... will return the nodes

/foo/bar
/foo/bar/baz

... and the QueryResult.getNodes().getSize() should return 2

> I'll keep investigating - I still find the Xpath rules a problem. :/
What do you find a problem about it?
Do you prefer the SQL syntax?

regards,
david

Re: count of nodes?

Posted by David Nuescheler <da...@gmail.com>.
Hi Joe,

> But wouldn't getSize() on the getNodes() call only get the immediate
> child nodes?
No. It would include everything that matched your query which would
include all the nodes in the QueryResult.
So the node iterator returned from QueryResult.getNodes() will
contain all the nodes that matched the query.
In your case:

/jcr:root/foo//*
... will return the nodes

/foo/bar
/foo/bar/baz

... and the QueryResult.getNodes().getSize() should return 2

> I'll keep investigating - I still find the Xpath rules a problem. :/
What do you find a problem about it?
Do you prefer the SQL syntax?

regards,
david

RE: count of nodes?

Posted by "Ottinger, Joseph" <jo...@techtarget.com>.
But wouldn't getSize() on the getNodes() call only get the immediate
child nodes?

I'll keep investigating - I still find the Xpath rules a problem. :/ 

-----Original Message-----
From: David Nuescheler [mailto:david.nuescheler@gmail.com] 
Sent: Thursday, April 19, 2007 2:52 AM
To: users@jackrabbit.apache.org
Subject: Re: count of nodes?

Hi Joe,

I think the lack of count is probably not the issue, since I think you
could use the .getSize() on the ResultSet.getNodes() iterator, right?

I think the one thing that you would need to do is resolve the UUID to a
path using Session.getNodeByUUID(uuid).getPath()
and then pass something like

/jcr:root/<path>//*

or

SELECT * FROM nt:base WHERE jcr:path LIKE '/<path>/%'

...and then call the said .getSize().

does that make sense?

regards,
david

On 4/18/07, Ottinger, Joseph <jo...@techtarget.com> wrote:
> Hi. I'm trying to get a count of nodes under a specific node. To 
> explain, imagine the following tree:
>
> <foo>
>     <bar>
>         <baz />
>     </bar>
> </foo>
>
> Given a path to /foo (via UUID), what I want to do is get a count 
> including both <bar> and <baz> -- i.e., I want to get a result of "2".
>
> Using XPath, the query should be something like -- pardon me my 
> horrible syntax, k? --
>
> count(//*[jcr:uuid=$uuid]/*)
>
> However, count() is unsupported. So I'm kinda stuck, unless I want to 
> walk the tree under /foo, and I don't unless I have no choice.
>
> Any suggestions?
>

Re: count of nodes?

Posted by David Nuescheler <da...@gmail.com>.
Hi Joe,

I think the lack of count is probably not the issue, since I think
you could use the .getSize() on the ResultSet.getNodes() iterator,
right?

I think the one thing that you would need to do is resolve the
UUID to a path using Session.getNodeByUUID(uuid).getPath()
and then pass something like

/jcr:root/<path>//*

or

SELECT * FROM nt:base WHERE jcr:path LIKE '/<path>/%'

...and then call the said .getSize().

does that make sense?

regards,
david

On 4/18/07, Ottinger, Joseph <jo...@techtarget.com> wrote:
> Hi. I'm trying to get a count of nodes under a specific node. To
> explain, imagine the following tree:
>
> <foo>
>     <bar>
>         <baz />
>     </bar>
> </foo>
>
> Given a path to /foo (via UUID), what I want to do is get a count
> including both <bar> and <baz> -- i.e., I want to get a result of "2".
>
> Using XPath, the query should be something like -- pardon me my horrible
> syntax, k? --
>
> count(//*[jcr:uuid=$uuid]/*)
>
> However, count() is unsupported. So I'm kinda stuck, unless I want to
> walk the tree under /foo, and I don't unless I have no choice.
>
> Any suggestions?
>