
op:exists-join( $leftPlan as map:map, $rightPlan as map:map, [$keys as map:map*], [$condition as map:map?] ) as map:map
This method is a filtering join that filters based on whether the join exists or not but doesn't add any columns.
It filters the left row set to the rows that have a join in the right row set.
| Parameters | |
|---|---|
| $leftPlan | The row set from the left view. |
| $rightPlan | The row set from the right view. |
| $keys | Equality condition(s) expressed using one or more calls to the function op:on. These conditions are used to compare the left and right rows. |
| $condition | A boolean expression used to compare the left and right rows. See Boolean Expression Functions for the list of functions used to build boolean expressions. |
keys and condition are used to specify
the join condition. keys allows for a simplified syntax
for equality join condition. While condition allows for
inequality and complex join conditions.
This method combines keys and condition
using an AND operator such that:
$view
=> op:exists-join (
$other-view,
op:on(op:view-col('view', 'column1'), op:view-col('other-view', 'column2')),
op:ge(op:view-col('view', 'column3'), op:view-col('other-view', 'column4'))
)
is the same as
$view
=> op:exists-join (
$other-view,
(),
op:and(
op:eq(op:view-col('view', 'column1'), op:view-col('other-view', 'column2')),
op:ge(op:view-col('view', 'column3'), op:view-col('other-view', 'column4'))
)
)
(: It filters out {'r1':1, 'k1':'a'},{'r1':2, 'k1':'a'} in p1 as value 'a' exists in column 'k2' of p2 :)
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
let $p1:= op:from-literals((
map:entry("r1", 1) => map:with("k1", "a"),
map:entry("r1", 2) => map:with("k1", "a"),
map:entry("r1", 3) => map:with("k1", "b")
))
let $p2:= op:from-literals((
map:entry("r2", 3) => map:with("k2", "a"),
map:entry("r2", 4) => map:with("k2", "c")
))
return op:exists-join(
$p1,$p2,
op:on("k1", "k2")
) => op:result()
(: It filters out {'r1':2, 'k1':'a'} in p1 where r1 equals to 2, as value 'a' exists in column 'k2' of p2 :)
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
let $p1:= op:from-literals((
map:entry("r1", 1) => map:with("k1", "a"),
map:entry("r1", 2) => map:with("k1", "a"),
map:entry("r1", 3) => map:with("k1", "b")
))
let $p2:= op:from-literals((
map:entry("r2", 3) => map:with("k2", "a"),
map:entry("r2", 4) => map:with("k2", "c")
))
return op:exists-join(
$p1,$p2,
op:on("k1", "k2"),
op:eq(op:col("r1"),2)
) => op:result()
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
let $fruits :=
op:from-literals((
map:entry("fruit", "mango") => map:with("count", 10),
map:entry("fruit", "apple") => map:with("count", 7),
map:entry("fruit", "orange") => map:with("count", 9)
))
let $orders :=
op:from-literals((
map:entry("flavor", "apple") => map:with("cups", 5),
map:entry("flavor", "orange") => map:with("cups", 14)
))
return $fruits
=> op:exists-join(
$orders,
op:on(op:col('fruit'), op:col('flavor')),
op:ge(op:col('count'), op:col('cups'))
)
=> op:result()
(:
row with fruit of 'apple' will be returned without data from orders
:)
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.