[英]Marklogic - Optic API: Joining views by value (op:on does not support values, only column-references)
I'm trying to join two views " A " and " B " using the op:join-left-outer
function.我正在尝试使用
op:join-left-outer
function 加入两个视图“ A ”和“ B ”。
I have two "ON-conditions" for the JOIN:对于 JOIN,我有两个“开启条件”:
op:on
function.op:on
function 上。 (And not a part of my problem) $myValue
).$myValue
) 连接列的 ON 条件。 But op:on
does not support values, only column-references.op:on
不支持值,只支持列引用。 So the following code doesn't work:let $aView := op:from-view("foobar", "A")
let $bView := op:from-view("foobar", "B")
let $myValue := "42"
let $opticQuery := op:join-left-outer(
$aView,
$bView,
(
op:on(op:view-col("A", "SOME_COLUMN"), op:view-col("B", "SOME_COLUMN")),
(: Not working pseudo code following :)
op:on(op:view-col("B", "SOME_OTHER_COLUMN"), $myValue)
)
)
In SQL I would write something like this:在 SQL 我会这样写:
SELECT * FROM A
LEFT JOIN B
ON A.SOME_COLUMN = B.SOME_COLUMN
AND B.SOME_OTHER_COLUMN = '42'
My question: Is there a way to do the same in Optic API or am I doing something wrong?我的问题:有没有办法在光学 API 中做同样的事情,还是我做错了什么?
Interestingly enough, when trying to use a second op:on()
with column references on left and right (by binding 42 as a new column on aView), I also did not get expected results.有趣的是,当尝试使用第二个
op:on()
与左右列引用(通过将 42 绑定为 aView 上的新列)时,我也没有得到预期的结果。
However, the Optic API does seem to allow you to do what you want if expressed in a different way:但是,如果以不同的方式表示,光学 API 似乎确实允许您做您想做的事情:
Therefore, I would expect that you can remove your second op:on()
and use the following as the 4th param: op:eq(op:view-col("B", "SOME_OTHER_COLUMN"), $myValue)
因此,我希望您可以删除第二个
op:on()
并将以下内容用作第四个参数: op:eq(op:view-col("B", "SOME_OTHER_COLUMN"), $myValue)
A free-standing sample is below -where the resulting second row has null values for the outer joined table下面是一个独立的示例-生成的第二行具有外部连接表的 null 值
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
let $myVal := 42
let $plan-table-1 := op:from-literals((
map:entry("col1", 1) => map:with("val", "a"),
map:entry("col1", 2) => map:with("val", "b")
), "table1")
let $plan-table-2 := op:from-literals((
map:entry("col1", 1) => map:with("val2", "c") => map:with("someOtherCol", 42),
map:entry("col1", 2) => map:with("val2", "d") => map:with("someOtherCol", 8)
), "table2")
return op:join-left-outer(
$plan-table-1,
$plan-table-2,
op:on(op:view-col("table1", "col1"), op:view-col("table2", "col1")),
op:eq(op:view-col("table2", "someOtherCol"), $myVal)
)=>op:result()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.