Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the operator "=>" in XQuery do?

When I look up XQuery examples i sometimes see the operator =>used.

I tried searching for the meaning of it, but could not find anything. Since i am using MarkLogic, it is possible that it is only for MarkLogic, but i doubt that.

From the examples i am aware that it somehow chains functions together, but i would like to know what is happening.

These are some examples i have found:

let $map := map:map()
  =>map:with("some-key",<info>45683</info>)
return <result>{$map}</result>
let $employees := op:from-view("main", "employees")
let $expenses  := op:from-view("main", "expenses")
let $totalexpenses  := op:col("totalexpenses")
return $employees
   => op:join-inner($expenses, op:on(
                    op:view-col("employees", "EmployeeID"),
                    op:view-col("expenses", "EmployeeID")))
   => op:group-by(op:view-col("employees", "EmployeeID"),
                 ("FirstName", "LastName", 
                  op:view-col("expenses", "Category"),
                  op:sum($totalexpenses, 
                  op:view-col("expenses", "Amount"))))
   => op:order-by(op:view-col("employees", "EmployeeID")) 
   => op:result() 
like image 263
Alexander Holland Avatar asked May 13 '20 13:05

Alexander Holland


People also ask

What are XQuery functions?

XQuery (like XSLT and XPath before it) has extended the concept of XML names and namespaces by using namespace-qualified names not only for elements and attributes, but also for variables and functions. The namespace prefix "local" is just a shorthand for the real name of the namespace.

Which of the following is used to compare values in XQuery?

XQuery provides the following types of comparison operators: General comparison operators. Value comparison operators. Node comparison operators.

Which is not a mapping *?

Every mapping is a relation but every relation is not a mapping.


1 Answers

It is the Arrow Operator, which lets you supply the first argument to a function call from the outside.So if you have a function call foo($a, $b, $c), you can equivalently write it as $a => foo($b, $c). This is handy if you have lots of nested function calls as first arguments:

string-join(reverse(tokenize(upper-case('a;b;c'), ';')), '_')

With the arrow operator this can be written as a nice pipeline

'a;b;c' => upper-case() => tokenize(';') => reverse() => string-join('_')

giving the same result "C_B_A".

One disadvantage of the arrow operator is that you have to take it into account when you want to find out at a glance which function is referenced by a function call in XQuery code. If you declared the two functions local:foo($seq) {...} and local:foo($seq, $accum) {...}, then $asdf => local:foo($x) looks like it calls the one-argument version, but actually calls the two-argument variant.

like image 177
Leo Wörteler Avatar answered Oct 24 '22 05:10

Leo Wörteler