Your SlideShare is downloading. ×
XQuery Rocks
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

XQuery Rocks

21,052

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
21,052
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
24
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 28 msec XQuery 3 Rocks http://www.zorba-xquery.com William Candillon - FOSDEM 2012
  • 2. Harnessing Flexible Data
  • 3. { "photos": { "page": 1, "pages": 94276, "total": "1414129", "photo": [{ "id": "3891667770", "owner": "354683133120"<kml> <Placemark> <name>Simple placemark</name> <Point><coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
  • 4. { "photos": { "page": 1, "pages": 94276, "total": "1414129", "photo": [{ "id": "3891667770", "owner": "354683133120" <kml>✔ <Placemark> <name>Simple placemark</name> <Point> <coordinates>-122.0822035425683,37.422289901 40251,0</coordinates>
  • 5. { "photos": { "page": 1, "pages": 94276, "total": "1414129", "photo": [{ "id": "3891667770", "owner": "354683133120" ? <kml>✔ <Placemark> <name>Simple placemark</name> <Point> <coordinates>-122.0822035425683,37.422289901 40251,0</coordinates>? ?
  • 6. Meet XQuery
  • 7. XQuery • Family of Specification from w3c • Most Complex Complete Data Model • Talks Natively to Web • Query, Store, Index, Update, Full-Text • Unified Framework • Optimization & Parallelization
  • 8. Meet Zorba Open Source XQuery Processor Contributors: Oracle, 28msec, FLWOR All Flavors Available Runs Everywhere Rich Module Libraries Developer Tools Pluggable Store Fun & Productive
  • 9. Zorba
  • 10. <div id=”entries”>{ for $entry in $entries let $title := string($entry/@title) where $entry/@author = “anonymous” order by $entry/@datetime return <h1>{$title}</h1>}</div>
  • 11. insert node <entry>Hello World</entry> into $entries
  • 12. let $x := <m>breakfast of champions</m>return $x contains text "meal" using thesaurus at "http://wordnet.princeton.edu" relationship "narrower term"
  • 13. let $handler := function($request){ let $world := $request/text() return <h1>Hello {$world}!</h1> }return mongoose:start($handler, 80);mongoose:cin();
  • 14. declare%http:get(“/hello/{$world}”)function html:hello($world){ <h1>Hello {$world}!</h1>};
  • 15. Client Server<script type="application/xquery">declare sequential function local:submit($loc, declare sequential function guestbook:add($evtObj) $author as xs:string, $entry as xs:string{ ){ let $date := fn:current-dateTime() let $name := s:id("author")/data(@value) let $entry := <entry author="{$author}" let $text := s:id("text")/text() datetime="{$date}">{$text}</entry> return return guestbook:add($name, $text); xqddf:insert-nodes-last($entries, $entry);}; };b:addEventListener(s:id("submit"), declare sequential function guestbook:list() { "onclick", <entries>{ local:submit#2); xqddf:collection($entries) }</entries>;guestbook:list(); };</script>
  • 16. Client Server<script type="application/xquery">declare sequential function local:submit($loc, declare sequential function guestbook:add($evtObj) $author as xs:string, $entry as xs:string{ ){ let $date := fn:current-dateTime() let $name := s:id("author")/data(@value) let $entry := <entry author="{$author}" let $text := s:id("text")/text() datetime="{$date}">{$text}</entry> return return guestbook:add($name, $text); xqddf:insert-nodes-last($entries, $entry);}; };b:addEventListener(s:id("submit"), declare sequential function guestbook:list(){ "onclick", <entries>{ local:submit#2); xqddf:collection($entries) }</entries>;guestbook:list(); };</script> Seamless Invocations
  • 17. AWS Libraries (2011) Java XQuery 8589 Lines of code 2905 2309 1469 572 455 S3 SimpleDB SNS
  • 18. AWS Libraries (2011) Java XQuery 13803 Lines of CodesLines of code - 80% 2496 AWS
  • 19. AWS Libraries (2011) PHP XQuery 6531 Lines of CodesLines of code 2496 - 62% AWS
  • 20. <html> <head> <script type=text/javascript> function buy(e) { newElement = document.createElement("p"); elementText = document.createTextNode (e.target.getAttribute(id)); newElement.appendChild(elementText); var res = document.evaluate( "//div[@id=shoppingcart]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, HTML null); res.snapshotItem(0).appendChild("newElement");} </script> JavaScript </head> <body> <div>Shopping cart</div> <div id="shoppingcart"></div> <% XPath // Code establishing connection ResultSet results = statement.executeQuery ("SELECT * FROM PRODUCTS"); while (results.next()) { out.println("<div>"); Java String prodName = results.getString(1); out.println(prodName); SQL out.println("<input type=button value=Buy"); out.println("id="+prodName+""); out.println("onclick=buy(event)/>"). out.println("</div>"); } results.close(); // Code closing connection %> </body></html>
  • 21. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type=application/xquery>declare updating function local:buy($evt, $obj) { insert node <p>{$obj/@id}</p> as first into //div[@id="shoppingcart"]};b:addEventListener(b:dom()//input, "onclick", xs:Qname("local:buy"));</script> </head> <body> <div>Shopping cart</div> <div id="shoppingcart">{ XQuery Everywhere for $p in doc("products.xml")//*:product return <div> {$p/*:name} <input type=button value=Buy id={$p/*:name}/> </div> }</div> </body></html>
  • 22. let $stats := [ { "response_time":0.05 ... } ...]for $stat in j:values($stats)let $url := $stat("http_action")order by $urlreturn{ "url": $url, "avg": avg($stat("response_time"))}
  • 23. $zorba -q jsoniq.xq -f{ "url" : "GET /docs/spec/en-US/html-single/index.html", "avg" : 0.05 }
  • 24. Take away • Powerful Data Model • Flexible Programming Model • Productivity • Performance
  • 25. 28 msec Thank you!

×