SlideShare a Scribd company logo
1 of 49
Download to read offline
Cutting Edge Data Processing
            with PHP & XQuery
28   msec   William Candillon {candillon@28msec.com}
            PHP Tour Lille 2011
A Rich Ecosystem
       Platforms            Frameworks       Libraries




Code

Data


  PDO
   PHP Data Objects   ?                  ?        ?
  Relational          XML            JSON         Text
A Rich Ecosystem
       Platforms            Frameworks      Libraries




Code

Data


  PDO
   PHP Data Objects
                                X Query
  Relational          XML            JSON        Text
Our Goal




    Contribute the features from
relational APIs to unstructured data
Data APIs

              PDO        SimpleXML Zend JSON    XQuery

  Data      Relational     XML       JSON      XML/JSON

Queries       ✔           XPath       X          ✔
Updates       ✔             X         X          ✔
Streaming     ✔             X         X          ✔
Full-Text     ✔             X         X          ✔
Meet XQuery


 • Family of specifications from W3C
   - XQuery 3.0
   - Update Facility
   - Scripting Extension
   - Full-Text

 • EXPath: de-facto standard libraries
Meet Zorba

         Open Source XQuery Processor
         Contributors: Oracle, 28msec, FLWOR


   All Flavors Available      Runs Everywhere


   Rich Module Libraries      Developer Tools


   Pluggable Store            Fun & Productive
Zorba
<?php
require_once ‘ZorbaXQueryProcessor.php’;

$xquery = new XQueryProcessor();

$xquery->importQuery(‘1+1’);

echo $xquery->execute();
?>
<?php
require_once ‘ZorbaXQueryProcessor.php’;

$xquery = new XQueryProcessor();

$query = <<<‘XQ’
  let $world := ‘World’
  return <h1>Hello {$world}</h1>
XQ;

$xquery->importQuery($query);

echo $xquery->execute();
?>
<?php
require_once ‘ZorbaXQueryProcessor.php’;

$xquery = new XQueryProcessor();

$xquery->importQueryFromURI(‘hello.xq’);

echo $xquery->execute();
?>
<?php
require_once ‘ZorbaXQueryProcessor.php’;

$xquery = new XQueryProcessor();

$query = <<<‘XQ’
  declare variable $world external;

  <h1>Hello {$world}</h1>
XQ;

$xquery->importQuery($query);

$xquery->setVariable(‘world’, ‘World!’);

echo $xquery->execute();
?>
$xquery = new XQueryProcessor();

$query = <<<‘XQ’
declare variable   $foo as xs:string external;
declare variable   $bar as xs:integer external;
declare variable   $doc1 as document-node() external;
declare variable   $doc2 as document-node() external;

$foo, $bar, $doc1, $doc2
XQ;

$xquery->importQuery($query);

$xquery->setVariable(‘foo’, ‘bar’);
$xquery->setVariable(‘bar’, 3);

$doc = simplexml_load_file ('data/sessions.xml');
$xquery->setVariable("doc1", $doc);

$doc = $xquery->parseXML ("<root />");
$xquery->setVariable("doc2", $doc);

echo $xquery->execute();
Queries
Updates
Full-Text
Streaming
Queries
Updates
Full-Text
Streaming
import module namespace functx = "http://www.functx.com/";
import module namespace html = "http://example.com/html";

declare variable $sessions   external;

<html lang="en">
  <body>
  {$html:header}

  <div id="main">{
    html:sessions($sessions/*)
  }</div>

  {$html:footer}
</body>
</html>
<div id=”sessions”>{
  for $session in $sessions
  let $title := string($session/@title)
  where $session/@conf = “PHP Tour Lille”
  order by $session/@starts ascending
  return <div>
    <h1>{$title}</h1>
  </div>
}</div>
<div id=”sessions”>{
for $day-sessions in $sessions
let $starts := dateTime($day-sessions/@starts)
let $day    := xs:day($starts)
group by $day
order by $starts ascending
return <div>
  <h1>{$day}</h1>
  {
    for $session in $day-sessions
    return <h2>{string($session/@title)}</h2>
  }
  </div>
}</div>
Queries
Updates
Full-Text
Streaming
insert node $bios[@id=”wcandilllon”]
       into $sessions[@id=”xquery”]
replace value of node $session/@starts
        with “2011-11-24T10:15:00”

replace value of node $session/@ends
        with “2011-11-24T10:15:00”
let $session := $sessions[id="XQuery"]
return
  if ($session/rating) then
    replace value of node $session/rating
                     with "B"
    else
      insert node <rating>B</rating>
             into $session
Queries
Updates
Full-Text
Streaming
let $sessions := $sessions/session[
                   . contains text {$search-term}
                   all words
                   distance at most 8 words]
return
  if(empty($sessions)) then
    <h1>No Results found</h1>
  else html:sessions($sessions)
let $x := <msg>breakfast of champions</msg>
return $x contains text "meal"
let $x := <msg>breakfast of champions</msg>
return $x contains text "meal"
  using thesaurus at "http://wordnet.princeton.edu"
  relationship "narrower term"
let $doc := doc(“doc.xml”)
for $token in ft:tokenize($doc)
return
  concat($token/@value, “ at ”,
         $token/@paragraph,
         $token/@sentence
  )
Demo
Queries
Updates
Full-Text
Streaming
Forecast Data


  - 1 Day of Forecast data: 727MB
  - Get data for a specific site
  - Send selected temperatures to clients
  - Display chart
<?php
$siteId = 3;
$forecasts = simplexml_load_file('forecasts.xml');
$forecasts = $forecasts->xpath(
      "/forecast-list/forecast[@site-id='$siteId']");

foreach($forecasts as $forecast) {
  $time = $forecast->xpath("@time-step");
  $value = $forecast->xpath(
    "//weather-elements/weather-element"
   ."[@name = 'ScreenTemperature']/text()");

!    echo "<temperature time='"
           .$time[0]
           ."'value='"
           .$value[0]."' />n";
}
?>
<?php
$siteId = 3;
$forecasts = simplexml_load_file('forecasts.xml');
$forecasts = $forecasts->xpath(
      "/forecast-list/forecast[@site-id='$siteId']");

foreach($forecasts as $forecast) {
  $time = $forecast->xpath("@time-step");
  $value = $forecast->xpath(
    "//weather-elements/weather-element"
   ."[@name = 'ScreenTemperature']/text()");

!    echo "<temperature time='"
           .$time[0]                      Oups ?!?
           ."'value='"
           .$value[0]."' />n";
}
?>
<?php
$siteId = 3;
$forecasts = simplexml_load_file('forecasts.xml');
$forecasts = $forecasts->xpath(
      "/forecast-list/forecast[@site-id='$siteId']");

foreach($forecasts as $forecast) {
  $time = $forecast->xpath("@time-step");
  $value = $forecast->xpath(
    "//weather-elements/weather-element"
   ."[@name = 'ScreenTemperature']/text()");

!    echo "<temperature time='"
           .$time[0]
           ."'value='"
           .$value[0]."' />n";




                             9GB
}
?>


Memory Footprint:
for $forecast in z:parse-xml(file:read-text("forecasts.xml"),
                             <opt:options>
                               <opt:parseExternalParsedEntity
                                 opt:skipRootNodes="1"/>
                             </opt:options>)
where $forecast/@site-id = "3"
let $time := string($forecast/@time-step)
let $value := $forecast/weather-elements/weather-element
                         [@name = 'ScreenTemperature']/text()
return
  <temperature time="{$time}" value="{$value}" />




Memory Footprint: 19MB
Demo
Results


                 SimpleXML XMLReader   XQuery



   Streaming       X          ✔         ✔

  Productivity     ✔          X         ✔
Pubzone (2009)

                                  Model              View
                                  Controler

                           4100
    Lines of code



                    3100



                                                     1830

                                                             1210
                                    900
                                              450


                           Java                     XQuery
AWS Libraries

                                       Java               XQuery

                    8589
    Lines of code




                                          2905
                                                             2309
                                1469
                                                    572                   455


                           S3                 SimpleDB              SNS
AWS Libraries

                Java            XQuery

                 13803



                                         Lines of Codes
Lines of code




                                             - 80%
                               2496




                         AWS
<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);
         out.println("<input type='button' value='Buy'");
         out.println("id='"+prodName+"'");                    SQL
         out.println("onclick='buy(event)'/>").
         out.println("</div>");
       }
       results.close();
       // Code closing connection
    %>
  </body>
</html>
<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>
http://www.youtube.com/watch?v=ql2TLTsilo8
XQuery in the Browser




• Open Source Project from ETH
• http://xqib.org
• XQuery in the browser without a plug-in
• Processor compiled to JavaScript
• DOM as the processor store
! <script type="application/xquery">
! declare updating function local:onclick(
    $loc, $evtObj
  ) {
!   insert node <hr color="red"/>
!   as last into b:dom()//body
!  };

  b:addEventListener(
    b:dom()//input, "onclick", local:onclick#2
  )
! </script>
<script type="text/javascript">
foo = function (arg){
        return 'the text was '+ arg;
};
</script>

<script type="application/xquery">
! let $x := b:js-call('window.foo', “Foo”)
! return
     b:alert($x)
</script>
Demo
Wrap-Up Clip
 http://www.youtube.com/watch?v=6oY5ctVHEck
28   msec
            Thank you!

More Related Content

What's hot

Cassandra 3.0 - JSON at scale - StampedeCon 2015
Cassandra 3.0 - JSON at scale - StampedeCon 2015Cassandra 3.0 - JSON at scale - StampedeCon 2015
Cassandra 3.0 - JSON at scale - StampedeCon 2015StampedeCon
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012sullis
 
Squeak DBX
Squeak DBXSqueak DBX
Squeak DBXESUG
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORPESUG
 
MongoDB's New Aggregation framework
MongoDB's New Aggregation frameworkMongoDB's New Aggregation framework
MongoDB's New Aggregation frameworkChris Westin
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun..."ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...Julia Cherniak
 
MongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksMongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksScott Hernandez
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETTomas Jansson
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Scott Leberknight
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSMongoDB
 
Building data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyBuilding data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyRoger Barnes
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Rebecca Grenier
 
Realm.io par Clement Sauvage
Realm.io par Clement SauvageRealm.io par Clement Sauvage
Realm.io par Clement SauvageCocoaHeads France
 

What's hot (20)

Cassandra 3.0 - JSON at scale - StampedeCon 2015
Cassandra 3.0 - JSON at scale - StampedeCon 2015Cassandra 3.0 - JSON at scale - StampedeCon 2015
Cassandra 3.0 - JSON at scale - StampedeCon 2015
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
 
Squeak DBX
Squeak DBXSqueak DBX
Squeak DBX
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your DataMongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
 
OneRing @ OSCamp 2010
OneRing @ OSCamp 2010OneRing @ OSCamp 2010
OneRing @ OSCamp 2010
 
How and Where in GLORP
How and Where in GLORPHow and Where in GLORP
How and Where in GLORP
 
MongoDB's New Aggregation framework
MongoDB's New Aggregation frameworkMongoDB's New Aggregation framework
MongoDB's New Aggregation framework
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
Polyglot Persistence
Polyglot PersistencePolyglot Persistence
Polyglot Persistence
 
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun..."ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
 
MongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksMongoDB: tips, trick and hacks
MongoDB: tips, trick and hacks
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
Cassandra 3.0
Cassandra 3.0Cassandra 3.0
Cassandra 3.0
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
Building data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyBuilding data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemy
 
Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
Realm.io par Clement Sauvage
Realm.io par Clement SauvageRealm.io par Clement Sauvage
Realm.io par Clement Sauvage
 

Similar to Cutting Edge Data Processing with PHP & XQuery

Red Hat Agile integration Workshop Labs
Red Hat Agile integration Workshop LabsRed Hat Agile integration Workshop Labs
Red Hat Agile integration Workshop LabsJudy Breedlove
 
Serverless archtiectures
Serverless archtiecturesServerless archtiectures
Serverless archtiecturesIegor Fadieiev
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Michelangelo van Dam
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETGianluca Carucci
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
점진적인 레거시 웹 애플리케이션 개선 과정
점진적인 레거시 웹 애플리케이션 개선 과정점진적인 레거시 웹 애플리케이션 개선 과정
점진적인 레거시 웹 애플리케이션 개선 과정Arawn Park
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz KhambatiReactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz KhambatiAziz Khambati
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english versionSabino Labarile
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersJeremy Lindblom
 
Open Source Ajax Solution @OSDC.tw 2009
Open Source Ajax  Solution @OSDC.tw 2009Open Source Ajax  Solution @OSDC.tw 2009
Open Source Ajax Solution @OSDC.tw 2009Robbie Cheng
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkIndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Frameworkvhazrati
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWAREFIWARE
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesRaimonds Simanovskis
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access RunbookTaha Shakeel
 

Similar to Cutting Edge Data Processing with PHP & XQuery (20)

Red Hat Agile integration Workshop Labs
Red Hat Agile integration Workshop LabsRed Hat Agile integration Workshop Labs
Red Hat Agile integration Workshop Labs
 
Serverless archtiectures
Serverless archtiecturesServerless archtiectures
Serverless archtiectures
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
점진적인 레거시 웹 애플리케이션 개선 과정
점진적인 레거시 웹 애플리케이션 개선 과정점진적인 레거시 웹 애플리케이션 개선 과정
점진적인 레거시 웹 애플리케이션 개선 과정
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz KhambatiReactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz Khambati
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english version
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
 
Open Source Ajax Solution @OSDC.tw 2009
Open Source Ajax  Solution @OSDC.tw 2009Open Source Ajax  Solution @OSDC.tw 2009
Open Source Ajax Solution @OSDC.tw 2009
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
 

Recently uploaded

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Recently uploaded (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Cutting Edge Data Processing with PHP & XQuery

  • 1. Cutting Edge Data Processing with PHP & XQuery 28 msec William Candillon {candillon@28msec.com} PHP Tour Lille 2011
  • 2. A Rich Ecosystem Platforms Frameworks Libraries Code Data PDO PHP Data Objects ? ? ? Relational XML JSON Text
  • 3. A Rich Ecosystem Platforms Frameworks Libraries Code Data PDO PHP Data Objects X Query Relational XML JSON Text
  • 4. Our Goal Contribute the features from relational APIs to unstructured data
  • 5. Data APIs PDO SimpleXML Zend JSON XQuery Data Relational XML JSON XML/JSON Queries ✔ XPath X ✔ Updates ✔ X X ✔ Streaming ✔ X X ✔ Full-Text ✔ X X ✔
  • 6. Meet XQuery • Family of specifications from W3C - XQuery 3.0 - Update Facility - Scripting Extension - Full-Text • EXPath: de-facto standard libraries
  • 7. 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. <?php require_once ‘ZorbaXQueryProcessor.php’; $xquery = new XQueryProcessor(); $xquery->importQuery(‘1+1’); echo $xquery->execute(); ?>
  • 10. <?php require_once ‘ZorbaXQueryProcessor.php’; $xquery = new XQueryProcessor(); $query = <<<‘XQ’ let $world := ‘World’ return <h1>Hello {$world}</h1> XQ; $xquery->importQuery($query); echo $xquery->execute(); ?>
  • 11. <?php require_once ‘ZorbaXQueryProcessor.php’; $xquery = new XQueryProcessor(); $xquery->importQueryFromURI(‘hello.xq’); echo $xquery->execute(); ?>
  • 12. <?php require_once ‘ZorbaXQueryProcessor.php’; $xquery = new XQueryProcessor(); $query = <<<‘XQ’ declare variable $world external; <h1>Hello {$world}</h1> XQ; $xquery->importQuery($query); $xquery->setVariable(‘world’, ‘World!’); echo $xquery->execute(); ?>
  • 13. $xquery = new XQueryProcessor(); $query = <<<‘XQ’ declare variable $foo as xs:string external; declare variable $bar as xs:integer external; declare variable $doc1 as document-node() external; declare variable $doc2 as document-node() external; $foo, $bar, $doc1, $doc2 XQ; $xquery->importQuery($query); $xquery->setVariable(‘foo’, ‘bar’); $xquery->setVariable(‘bar’, 3); $doc = simplexml_load_file ('data/sessions.xml'); $xquery->setVariable("doc1", $doc); $doc = $xquery->parseXML ("<root />"); $xquery->setVariable("doc2", $doc); echo $xquery->execute();
  • 16. import module namespace functx = "http://www.functx.com/"; import module namespace html = "http://example.com/html"; declare variable $sessions external; <html lang="en"> <body> {$html:header} <div id="main">{ html:sessions($sessions/*) }</div> {$html:footer} </body> </html>
  • 17. <div id=”sessions”>{ for $session in $sessions let $title := string($session/@title) where $session/@conf = “PHP Tour Lille” order by $session/@starts ascending return <div> <h1>{$title}</h1> </div> }</div>
  • 18. <div id=”sessions”>{ for $day-sessions in $sessions let $starts := dateTime($day-sessions/@starts) let $day := xs:day($starts) group by $day order by $starts ascending return <div> <h1>{$day}</h1> { for $session in $day-sessions return <h2>{string($session/@title)}</h2> } </div> }</div>
  • 20. insert node $bios[@id=”wcandilllon”] into $sessions[@id=”xquery”]
  • 21. replace value of node $session/@starts with “2011-11-24T10:15:00” replace value of node $session/@ends with “2011-11-24T10:15:00”
  • 22. let $session := $sessions[id="XQuery"] return if ($session/rating) then replace value of node $session/rating with "B" else insert node <rating>B</rating> into $session
  • 24. let $sessions := $sessions/session[ . contains text {$search-term} all words distance at most 8 words] return if(empty($sessions)) then <h1>No Results found</h1> else html:sessions($sessions)
  • 25. let $x := <msg>breakfast of champions</msg> return $x contains text "meal"
  • 26. let $x := <msg>breakfast of champions</msg> return $x contains text "meal" using thesaurus at "http://wordnet.princeton.edu" relationship "narrower term"
  • 27. let $doc := doc(“doc.xml”) for $token in ft:tokenize($doc) return concat($token/@value, “ at ”, $token/@paragraph, $token/@sentence )
  • 28. Demo
  • 30. Forecast Data - 1 Day of Forecast data: 727MB - Get data for a specific site - Send selected temperatures to clients - Display chart
  • 31. <?php $siteId = 3; $forecasts = simplexml_load_file('forecasts.xml'); $forecasts = $forecasts->xpath( "/forecast-list/forecast[@site-id='$siteId']"); foreach($forecasts as $forecast) { $time = $forecast->xpath("@time-step"); $value = $forecast->xpath( "//weather-elements/weather-element" ."[@name = 'ScreenTemperature']/text()"); ! echo "<temperature time='" .$time[0] ."'value='" .$value[0]."' />n"; } ?>
  • 32. <?php $siteId = 3; $forecasts = simplexml_load_file('forecasts.xml'); $forecasts = $forecasts->xpath( "/forecast-list/forecast[@site-id='$siteId']"); foreach($forecasts as $forecast) { $time = $forecast->xpath("@time-step"); $value = $forecast->xpath( "//weather-elements/weather-element" ."[@name = 'ScreenTemperature']/text()"); ! echo "<temperature time='" .$time[0] Oups ?!? ."'value='" .$value[0]."' />n"; } ?>
  • 33. <?php $siteId = 3; $forecasts = simplexml_load_file('forecasts.xml'); $forecasts = $forecasts->xpath( "/forecast-list/forecast[@site-id='$siteId']"); foreach($forecasts as $forecast) { $time = $forecast->xpath("@time-step"); $value = $forecast->xpath( "//weather-elements/weather-element" ."[@name = 'ScreenTemperature']/text()"); ! echo "<temperature time='" .$time[0] ."'value='" .$value[0]."' />n"; 9GB } ?> Memory Footprint:
  • 34. for $forecast in z:parse-xml(file:read-text("forecasts.xml"), <opt:options> <opt:parseExternalParsedEntity opt:skipRootNodes="1"/> </opt:options>) where $forecast/@site-id = "3" let $time := string($forecast/@time-step) let $value := $forecast/weather-elements/weather-element [@name = 'ScreenTemperature']/text() return <temperature time="{$time}" value="{$value}" /> Memory Footprint: 19MB
  • 35. Demo
  • 36. Results SimpleXML XMLReader XQuery Streaming X ✔ ✔ Productivity ✔ X ✔
  • 37. Pubzone (2009) Model View Controler 4100 Lines of code 3100 1830 1210 900 450 Java XQuery
  • 38. AWS Libraries Java XQuery 8589 Lines of code 2905 2309 1469 572 455 S3 SimpleDB SNS
  • 39. AWS Libraries Java XQuery 13803 Lines of Codes Lines of code - 80% 2496 AWS
  • 40. <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); out.println("<input type='button' value='Buy'"); out.println("id='"+prodName+"'"); SQL out.println("onclick='buy(event)'/>"). out.println("</div>"); } results.close(); // Code closing connection %> </body> </html>
  • 41. <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>
  • 43. XQuery in the Browser • Open Source Project from ETH • http://xqib.org • XQuery in the browser without a plug-in • Processor compiled to JavaScript • DOM as the processor store
  • 44. ! <script type="application/xquery"> ! declare updating function local:onclick( $loc, $evtObj ) { ! insert node <hr color="red"/> ! as last into b:dom()//body ! }; b:addEventListener( b:dom()//input, "onclick", local:onclick#2 ) ! </script>
  • 45. <script type="text/javascript"> foo = function (arg){ return 'the text was '+ arg; }; </script> <script type="application/xquery"> ! let $x := b:js-call('window.foo', “Foo”) ! return b:alert($x) </script>
  • 46. Demo
  • 48.
  • 49. 28 msec Thank you!