不带 FLWOR 的 xquery 括号

发布于 2024-08-14 02:32:16 字数 279 浏览 1 评论 0原文

嗨,我有一个有点蹩脚的问题,但找不到答案。

如果我将构造函数括号留空会发生什么?

例如,

{data(doc("somedata.xml")//node[0])}

我的意思是,我知道会发生什么,但是解析时它被认为是什么?

是这样吗?

{
    for $i in "0"
    return
    data(doc("somedata.xml")//node[0])
}

hi I have a bit lame question, can't find the answer though.

what happens if I leave the constructor brackets void?

e.g.

{data(doc("somedata.xml")//node[0])}

I mean, I know what happens, but what is it considered as when being parsed?

is it like ?

{
    for $i in "0"
    return
    data(doc("somedata.xml")//node[0])
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ㄟ。诗瑗 2024-08-21 02:32:16

人们普遍误解任何 XQuery 都是 FLWOR 表达式。当人们从 SQL 角度处理 XQuery,将其视为 SELECT 时,就会出现这种误解。

事实上并非如此; FLWOR 表达式在很多方面只是另一个表达式。 FLWOR 表达式可能作为 SQL 表达式执行,但情况不一定如此。

XQuery 可以被视为一种函数式编程语言(如 Haskell),它恰好具有一些声明性结构(如 where 和 order by)。

表达式 1+2 只是一个将数字 1 和 2 相加的 XQuery 表达式,不需要在其周围有隐式 FLWOR 表达式。

如果您想在完全基于元组的代数中考虑 XQuery,那么您可以将输入视为单个空元组。我的意思如下。

看一下这个查询:

for $x in ...
for $y in ...
where $x/@name=$y/@name
return $x

如果您在基于元组的代数中考虑这一点,则 for 表达式的输入将是定义 $x$y 的元组流。很明显这与数据库查询有何关系。这对应于一个包含两列 $x$y 的表,以及每对具有相同名称的行。

您可以将以下查询

//foo

视为对没有值的单个元组进行操作。这有点像没有 fors 或 let 的 FLWOR 表达式(只有一个 return 表达式,如果允许的话)。在关系领域中,这将是一张没有列和一行的表。然而,这只是一个逻辑抽象,大多数(如果不是全部)XQuery 实现将其表示为一个表达式。

It is a common misconception that any XQuery is a FLWOR expression. This misconception comes when people approach XQuery from a SQL perspective, treating it as a SELECT.

This is in fact not the case; a FLWOR expression is in many ways just another expression. It may be that a FLWOR expression is executed as a SQL expression, but this doesn't have to be the case.

XQuery can be viewed as a functional programming language (like Haskell) that happens to have some declarative constructs (like where and order by).

The expression 1+2 is just an XQuery expression that adds the numbers 1 and 2, there does not need to be an implicit FLWOR expression around it.

If you wanted to consider XQuery in a fully tuple-based algebra then you could consider the input to be a single empty tuple. By this I mean the following.

Look at this query:

for $x in ...
for $y in ...
where $x/@name=$y/@name
return $x

If you were considering this in a tuple based algebra, the input to the for expression would be a stream of tuples defining $x and $y. It is obvious how this could relate to a database query. This corresponds to a table with two columns $x and $y and a row for each pair that have equal names.

You could consider the following query

//foo

as operating on a single tuple with no values. This would be a little bit like a FLWOR expression with no fors or lets (just a return expression, if that were allowed). In relational land this would be a table with no columns and one row. However this is just a logical abstraction, and most (if not all) XQuery implementations represent this as just an expression.

静谧幽蓝 2024-08-21 02:32:16

我不太明白你的问题。 “让构造函数括号无效”是什么意思?

您给出的查询是一个节点,其内容是一个表达式。它是这样解析的。每个表达式都是 FLWOR 表达式是一个常见的误解。 FLWOR 表达式只是另一个表达式。

因此,

<p> {data(doc("somedata.xml")//node[0])}</p>

它被简单地解析为

<p> {data(doc("somedata.xml")//node[0])}</p>

how

Console.WriteLine("foo");

不被解析一样

foreach (int x in new string[] {"0"})
  Console.WriteLine("foo")

就像C# 中的

。如果您想要完整的形式语义扩展(这是解释查询的一种方式),那么它看起来像这样:

element {p}
{
  fs:item-sequence-to-node-sequence(
    fn:data(
      fs:distinct-doc-order-or-atomic-sequence(
        let $fs:sequence :=
          fs:distinct-doc-order-or-atomic-sequence(
            let $fs:sequence := doc("somedata.xml")
            let $fs:count := count($sequence)
            for $fs:dot at $fs:position in $fs:sequence
            return $fs:dot/descendant-or-self::node())
        let $fs:count := count($fs:sequence)
        for $fs:dot at $fs:position in $fs:sequence
        return item-at($fs:dot/child::node, 0)
      )
    )
  )
} 

I don't really understand your question. What do you mean by "leave the constructor brackets void"?

The query you gave is an node whose contents are an expression. It is parsed as such. It is a common misconception that every expression is a FLWOR expression. A FLWOR expression is just another expression.

So,

<p> {data(doc("somedata.xml")//node[0])}</p>

is simply parsed as

<p> {data(doc("somedata.xml")//node[0])}</p>

Just like how

Console.WriteLine("foo");

is not interpreted as

foreach (int x in new string[] {"0"})
  Console.WriteLine("foo")

in C#.

If you want the full Formal Semantics expansion, which is one way in which the query can be interpreted, then it looks something like this:

element {p}
{
  fs:item-sequence-to-node-sequence(
    fn:data(
      fs:distinct-doc-order-or-atomic-sequence(
        let $fs:sequence :=
          fs:distinct-doc-order-or-atomic-sequence(
            let $fs:sequence := doc("somedata.xml")
            let $fs:count := count($sequence)
            for $fs:dot at $fs:position in $fs:sequence
            return $fs:dot/descendant-or-self::node())
        let $fs:count := count($fs:sequence)
        for $fs:dot at $fs:position in $fs:sequence
        return item-at($fs:dot/child::node, 0)
      )
    )
  )
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文