IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Sql group by equivalence in Tamino XQuery

    Posted Wed June 18, 2008 06:02 PM

    Hello I’m working with tamino v4.2

    Having the following document structure:

    I’d like to perform a group by operation

    Sql syntax

    select username, count(username)
    from log
    where description = “App search” and date like “%06/2008%”
    group by username

    How the sql query above would be in xquery?

    I’ve tried the following one but count operation returns always 0 and I don’t know why …

    declare namespace tf=“http://namespaces.softwareag.com/tamino/TaminoFunction

    let $a := (
    for $b in log
    where (($b/description = “App search”) and (tf:containsText($b/date,“???06/2008*”)))
    return $b
    )
    for $d in distinct-values($a/username/text())
    return


    {$d}

    {
    let $z := (for $c in input()/log
    where (
    ($c/description = “App search”) and (tf:containsText($c/date,“???06/2008*”))
    and ($c/username = “$d/text()”)
    )

       return $c
    )return
    <cont>
    {count($z)}
    </cont>
    

    }

    Any help would be much appreciate.

    Thanks in advance.


    #API-Management
    #Tamino
    #webMethods


  • 2.  RE: Sql group by equivalence in Tamino XQuery

    Posted Mon June 23, 2008 08:02 PM

    Hi,

    staying as close as possible to your query, you would have to modify as follows:

    
    declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"
    
    let $a := (for $b in input()/log
    where (($b/description = "App search") and    
    (tf:containsText($b/date,"???06/2008*")))
    return $b)
    for $d in distinct-values($a/username/text())
    return
    <usu>
    <nom>{$d}</nom>
    {
    let $z := (for $c in input()/log
    where ($c/description = "App search") and  
    tf:containsText($c/date,"???06/2008*")
    and ($c/username = $d)
    )
    return $c
    )
    return  <cont>{count($z)}</cont>
    }
    </usu> 

    actually only minor changes (in particular, you cannot apply /text() to $d as $d is already a text node, and you must not quote $d)
    The query could be written more compact as

    
    declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"
    let $log:=input()/log[./description = "App search" and
    tf:containsText(./date,"???06/2008*")]
    for $d in distinct-values ($log/username/text()) return
    <usu>
    <nom>
    {$d}
    </nom>
    <cont>
    {count($log[username=$d])}
    </cont>
    </usu> 

    regards

    harald


    #webMethods
    #API-Management
    #Tamino


  • 3.  RE: Sql group by equivalence in Tamino XQuery

    Posted Sat May 29, 2010 02:47 PM

    hi,
    although there is an example i can’t create ‘group-by’-statment in tamino.

    i’f got a xml like:

    <files>
    <file>
    <owner></owner> 
    <name></name> 
    <size></size> 
    <extension></extension> 
    <creationTime></creationTime> 
    <lastWriteTime></lastWriteTime> 
    <lastAccessTime></lastAccessTime> 
    <path></path> 
    <parentDirectory></parentDirectory> 
    <rootDirectory></rootDirectory> 
    </file>
    </files>

    now i’m trying to get a ‘group-by’-stamtement like :

    select count(name), name
    from   files
    group by name

    my XQuery-statement looks like:

    let $a := input()/files
    for $d in distinct-values($a/file/name/text()) return ($d, count($a[file/name=$d]))

    does anyone see the error?!?

    Thanks for help.

    Strange, today it works.


    #webMethods
    #Tamino
    #API-Management


  • 4.  RE: Sql group by equivalence in Tamino XQuery

    Posted Mon May 31, 2010 03:25 PM

    try

    
    let $a := input()/files
    for $d in distinct-values($a/file/name/text()) return ($d, count($a/file[name=$d]))

    #API-Management
    #webMethods
    #Tamino