I'm writing the following query which streams fine:
let $raw-data as xs:string := http:send-request(<http:request
href="http://cf.zorba-xquery.com.s3.amazonaws.com/forecasts.xml"
method="GET" override-media-type="text/plain" />)[2]
let $data := p:parse($raw-data,
<opt:options><opt:parse-external-parsed-entity
opt:skip-root-nodes="1"/></opt:options>)
for $node in $data
where $node/@site-id = "3"
return
$node
However if I write:
let $result :=
let $raw-data as xs:string := http:send-request(<http:request
href="http://cf.zorba-xquery.com.s3.amazonaws.com/forecasts.xml"
method="GET" override-media-type="text/plain" />)[2]
let $data := p:parse($raw-data,
<opt:options><opt:parse-external-parsed-entity
opt:skip-root-nodes="1"/></opt:options>)
for $node in $data
where $node/@site-id = "3"
return
$node
return subsequence($result, 1, 1)
The query result is extremely long to compute.
The problem is not string-streaming but related to inlining a let variable that is only used once. The problem can be reproduced using the following much smaller query:
let $result := (1 to 10000000) $result, 1, 1)
return subsequence(
The plan for this query is (note materialize="true" in the LetVariable)
<flwor: :FLWORIterator id="1006"> by="1003" > SingletonIterat or value=" xs:integer( 1)" id="1000"/> SingletonIterat or value=" xs:integer( 100000000) " id="1001"/> SingletonIterat or value=" xs:integer( 1)" id="1004"/> SingletonIterat or value=" xs:integer( 1)" id="1005"/> rator> :FLWORIterator>
<LetVariable name="result" materialize="true" referenced-
<OpToIterator id="1002">
<
<
</OpToIterator>
</LetVariable>
<ReturnClause>
<LetVarIterator varname="result" id="1003">
<
<
</LetVarIte
</ReturnClause>
</flwor:
I'm assigning this to Markos for further investigation.