SlideShare a Scribd company logo
YQL
whY QL?
YQL Tutorial
dev
dev
dev
dev
dev
dev
dev
dev
dev
dev
dev
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …



      …
      if (flickcurl_prepare(fc,
      "flickr.photos.geo.correctLocation",
      parameters, count)) { … }
      …
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …



      …
      if (flickcurl_prepare(fc,
      "flickr.photos.geo.correctLocation",
      parameters, count)) { … }
      …



      http://search.yahooapis.com/
      ImageSearchService/V1/imageSearch?
      appid=YahooDemo&query=Corvette&results=2
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …



      …
      if (flickcurl_prepare(fc,
      "flickr.photos.geo.correctLocation",
      parameters, count)) { … }
      …



      http://search.yahooapis.com/
      ImageSearchService/V1/imageSearch?
      appid=YahooDemo&query=Corvette&results=2




      http://weather.yahooapis.com/
      forecastrss?p=FRXX0076&u=c
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …



      …
      if (flickcurl_prepare(fc,
      "flickr.photos.geo.correctLocation",
      parameters, count)) { … }
      …



      http://search.yahooapis.com/
      ImageSearchService/V1/imageSearch?
      appid=YahooDemo&query=Corvette&results=2




      http://weather.yahooapis.com/
      forecastrss?p=FRXX0076&u=c
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …



      …
      if (flickcurl_prepare(fc,
      "flickr.photos.geo.correctLocation",
      parameters, count)) { … }
      …



      http://search.yahooapis.com/
      ImageSearchService/V1/imageSearch?
      appid=YahooDemo&query=Corvette&results=2




      http://weather.yahooapis.com/
      forecastrss?p=FRXX0076&u=c
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …



      …
      if (flickcurl_prepare(fc,
      "flickr.photos.geo.correctLocation",
      parameters, count)) { … }
      …



      http://search.yahooapis.com/
      ImageSearchService/V1/imageSearch?
      appid=YahooDemo&query=Corvette&results=2




      http://weather.yahooapis.com/
      forecastrss?p=FRXX0076&u=c
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …



      …
      if (flickcurl_prepare(fc,
      "flickr.photos.geo.correctLocation",
      parameters, count)) { … }
      …



      http://search.yahooapis.com/
      ImageSearchService/V1/imageSearch?
      appid=YahooDemo&query=Corvette&results=2




      http://weather.yahooapis.com/
      forecastrss?p=FRXX0076&u=c
var map = new
          YMap(document.getElementById('map'));
          …
dev       var currentGeoPoint = new
          YGeoPoint( _c.Lat, _c.Lon );
          map.addMarker(currentGeoPoint);


      ?
          …



          …
          if (flickcurl_prepare(fc,


      ?
          "flickr.photos.geo.correctLocation",
          parameters, count)) { … }
          …



      ?   http://search.yahooapis.com/
          ImageSearchService/V1/imageSearch?
          appid=YahooDemo&query=Corvette&results=2


      ?
          http://weather.yahooapis.com/
          forecastrss?p=FRXX0076&u=c
var map = new
          YMap(document.getElementById('map'));
          …
dev       var currentGeoPoint = new
          YGeoPoint( _c.Lat, _c.Lon );
          map.addMarker(currentGeoPoint);


      ?
          …



          …
          if (flickcurl_prepare(fc,


      ?
          "flickr.photos.geo.correctLocation",
          parameters, count)) { … }
          …



      ?   http://search.yahooapis.com/
          ImageSearchService/V1/imageSearch?
          appid=YahooDemo&query=Corvette&results=2


      ?
          http://weather.yahooapis.com/
          forecastrss?p=FRXX0076&u=c
var map = new
      YMap(document.getElementById('map'));
      …
dev   var currentGeoPoint = new
      YGeoPoint( _c.Lat, _c.Lon );
      map.addMarker(currentGeoPoint);
      …



      …
      if (flickcurl_prepare(fc,
      "flickr.photos.geo.correctLocation",
      parameters, count)) { … }
      …



      http://search.yahooapis.com/
      ImageSearchService/V1/imageSearch?
      appid=YahooDemo&query=Corvette&results=2




      http://weather.yahooapis.com/
      forecastrss?p=FRXX0076&u=c
dev




      YQL
dev




      YQL
dev



       Bindings




      YQL
Demo time
http://developer.yahoo.com/yql/console/
Exercise 1

• write a query to search the web for “free
  wifi” Washington DC
• find photos of kittens on flickr that were
  tagged with “awesome”
• find the weather at SFO (san francisco
  airport)
Solutions 1
• select * from search.web where query =
  '"washington dc" free wifi'
• select * from flickr.photos.search where
  text ="kittens" and tags="awesome"
• select * from weather.forecast where
  location in (select postal from geo.places
  where text="sfo")
Demo time part deux
  http://developer.yahoo.com/yql/console/
Exercise 2

• Get my (“sh1mmer”) twitter stream
• Find articles about Obama in the New York
  Times
• Google, Bing and Yahoo for dogs
Solutions 2
•   select * from twitter.user.timeline where id =
    "sh1mmer"
•   select * from nyt.article.search where query =
    "obama"
•   select * from query.multi where queries =
    'select * from microsoft.bing.web where
    query="dogs";select * from google.search
    where q = "dogs"; select * from search.web
    where query="dogs"'
YQL in Practice
20 tiny steps to a working application

             You’ll need:
               Firefox
               Firebug
             Text editor
Step 1.
Login to the console with your Yahoo! login
  http://developer.yahoo.com/yql/console
Step 2.
 Find the statement box and
run the first query with test.
Step 3.
Check out the formatted view.
Step 4.
Run the statement “desc html”
Step 5.
    Find the keys,
note the required keys.
Step 6.
               Get some HTML:
  select * from html where url = "http://
hubblesite.org/gallery/album/the_universe"
Step 7.
 Check out the result.
See the HTML in there?
Step 8.
Open http://hubblesite.org/gallery/album/the_universe
                      in Firefox.
Right click on a thumbnail and click “Inspect Element”
Step 9.
    Find the element in Firebug.
Right click and select “Copy XPath”
Step 10.
Add and xpath = "" to your query.
  Paste in the XPath from Firebug
Step 11.
Test your statement and
   refine your XPath.
Step 12.
Add limit 10 to your statement
Step 13.
      Let’s get out of the console.
Copy the “Rest Query” url into a new tab
Step 14.
        Let’s embed this in a web page.
            Download the files from
http://github.com/sh1mmer/dotnet-yql-tutorial
Step 15.
               Add
  <script type="text/javascript"
src="yql_js_widget.js"></script>
        to your HTML page.
Step 16.
                        Add some style:
<style type="text/css">
li.imgCnt{ list-style: none; background:#000000; margin: 3px; float:
left; }
li.imgCnt img{ border:0; margin:5px; }
li.imgCnt div.imgTitle{ padding: 5px; font-size: 11px; text-
align:center; }
</style>
Step 17.
Add another script node.
   Add config = {};
Step 18.
         Format the output:
var format = '<li class="imgCnt">
<img src="{src}" alt="{alt}"></li>';
Step 19.
          Add you query;
var yqlQuery = "" and add your query.
Step 20.
Add the render code:

yqlWidget.push(yqlQuery,config,format,'widge
tContainer');
yqlWidget.render();
Now in YUI 3
<script src="http://yui.yahooapis.com/3.1.0/build/yui/yui-min.js"></
    script>

    <script>

    YUI({
    //Last Gallery Build of this module
    gallery: 'gallery-2010.01.27-20'
}).use('gallery-yql', function(Y) {
    //Using events
    var q1 = new Y.yql('select * from github.user.info where (id =
"davglass")');
    q1.on('query', function(r) {
        //Do something here.
    });
    q1.on('error', function(r) {
        //Do something here.
    });
    //Or the callback approacha
    new Y.yql('select * from github.user.info where (id = "davglass")',
function(r) {
        //Do something here.
        r.query; //The result
        r.error; //The error message
    });
});

   </script>
Advanced
                YQL
Advanced Queries, I/U/D, Open Tables and Using YQL
                  with JavaScript
Basics
select * from {table} where {key1} =
"{value1}" and {key2} = {value2}



select * from flickr.photos.search where text
= "kittens" and tags = "domokun"
Remote vs. Local
select
     *
     from
     flickr.photos.search
     where
     text = "kittens"
     and
     tags = "domokun"

Remote
select
     *
     from
     flickr.photos.search
     where
     text = "kittens"
     and
     tags = "domokun"

Remote
select
     *
     from
     flickr.photos.search
     where
     text = "kittens"
     and
     tags = "domokun"

Remote
desc {table}
Local
select * from flickr.photos.search where text =
 "kittens" and tags = "domokun" and farm = 4
Limits and Paging
select * from flickr.photos.search where text =
"kittens" and tags = "domokun" and farm = 4 limit 10
WTF?!
select * from flickr.photos.search(10) where text =
   "kittens" and tags = "domokun" and farm = 4
OMG SRLY WTF?!
select * from flickr.photos.search(20) where text =
   "kittens" and tags = "domokun" and farm = 4
Ooo! 6 results... right...
select * from flickr.photos.search(0) where text =
"kittens" and tags = "domokun" and farm = 4 limit 10
Limit Summary

• limit 10 - give me max 10 results from the
  data you have
• {table}(10) - get ten results from server
• {table}(0) - get enough results from the
  server to fill my local limit with the local
  filters
Offset
select * from {table} (10) where foo = "bar" offset 10

                         vs.

   select * from {table} (10,10) where foo = "bar"
select * from {table} (10) where foo = "bar" offset 10




      <results>
        <result foo=”bar”>1</result>         <results>
        <result foo=”qux”>2</result>           <result foo=”bar”>1</result>

...                                    ...                                      <results>
                                                                                </results>
     <result foo=”qux”>8</result>           <result foo=”bar”>9</result>      </query>
     <result foo=”bar”>9</result>           <result foo=”bar”>10</result>
     <result foo=”bar”>10</result>       </results>
  </results>                           </query>
</query>
select * from {table} (10,10) where foo = "bar"




            <results>
              <result foo=”bar”>11</result>
                                                    <results>
              <result foo=”qux”>12</result>
                                                      <result foo=”bar”>11</result>
      ...
                                              ...
           <result foo=”qux”>18</result>
                                                   <result foo=”bar”>20</result>
           <result foo=”qux”>19</result>
                                                </results>
           <result foo=”bar”>20</result>
                                              </query>
        </results>
      </query>
Inner Queries
select * from {table1}
           where
         {key1} in
(select id from {table2});
select * from flickr.photos.info
              where
           photo_id in
            (select id
   from flickr.photos.search
     where text="kitten")
Multi-key
select * from {table1}
              where
       ({key1}, {key2}) in
(select foo, bar from {table2});
select * from flickr.places
                        where
                     (lat, lon) in
        (select match1, match2 from regex
                        where
                        text in
(select entry.point from usgs.earthquakes limit 10)
 and expression = "(-?d+.d+) (-?d+.d+)")
               and total != 0 limit 10
Filters
select * from {table}(20) |
     sort(field=”foo”,
  descending = “true”) |
        truncate 10
Filters are always
applied last, in order
select * from {table}(20) | sort(field=”foo”, descending = “true”) | truncate 10




        <results>                              <results>                               <results>
          <result foo=”bar”>1</result>           <result foo=”bar”>20</result>           <result foo=”bar”>20</result>
          <result foo=”qux”>2</result>           <result foo=”qux”>19</result>           <result foo=”qux”>19</result>

  ...                                    ...                                     ...

       <result foo=”qux”>18</result>          <result foo=”qux”>3</result>            <result foo=”qux”>13</result>
       <result foo=”bar”>19</result>          <result foo=”bar”>2</result>            <result foo=”bar”>12</result>
       <result foo=”bar”>20</result>          <result foo=”bar”>1</result>            <result foo=”bar”>11</result>
    </results>                             </results>                              </results>
  </query>                               </query>                                </query>
Super-secret Filters

• Xpath()
• Regex()
• ... there are more I can’t remember
I/U/D
I/U/D

• Personally, I like calling it DUI
I/U/D

• Personally, I like calling it DUI
• I’m always developing under the influence
I/U/D

• Personally, I like calling it DUI
• I’m always developing under the influence
• Insert / Update / Delete tables
Just like SQL except...

• INSERT - no where clause. period.
• UPDATE - only remote keys
• DELETE - only remote keys
INSERT INTO wordpress.post
    (title, description, blogurl,
  username, password) VALUES
("Test Title", "This is a test body",
 "http://yqltest.wordpress.com",
   "yqltestuser", "password");
It really is like SQL.
Building Tables
From this
To This
Tom Hughes-Croucher
          @sh1mmer
    croucher@yahoo-inc.com
YQL Tutorial

More Related Content

KEY
YQL and YUI - Javascript from server to user
PDF
Mobile Data: How to avoid the latency trap - SWDC 2010
PDF
DOCX
package org dev
PPT
Dojo and Adobe AIR
PDF
openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII
PDF
節子、それViewControllerやない...、FatViewControllerや...。
PDF
Java programs
YQL and YUI - Javascript from server to user
Mobile Data: How to avoid the latency trap - SWDC 2010
package org dev
Dojo and Adobe AIR
openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII
節子、それViewControllerやない...、FatViewControllerや...。
Java programs

What's hot (20)

PDF
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
KEY
Sbaw091117
PDF
Migrating from Flux to Redux. Why and how.
PDF
SOLID principles in practice: the Clean Architecture
TXT
manager
PDF
openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII
TXT
Vdtonline
PDF
Prototype UI
DOCX
Calculator code with scientific functions in java
PDF
The Ring programming language version 1.8 book - Part 65 of 202
TXT
Ştiri de ultima ora si ultimele ştiri Vdtonline.com
PDF
JavaScript Event Loop
PDF
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
PPT
Appcelerator droidcon15 TLV
PDF
The Ring programming language version 1.5.1 book - Part 64 of 180
PDF
Learning Rule Based Programming using Games @DecisionCamp 2016
PDF
Sequence diagrams
PDF
What's new in Drools 6 - London JBUG 2013
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
Sbaw091117
Migrating from Flux to Redux. Why and how.
SOLID principles in practice: the Clean Architecture
manager
openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII
Vdtonline
Prototype UI
Calculator code with scientific functions in java
The Ring programming language version 1.8 book - Part 65 of 202
Ştiri de ultima ora si ultimele ştiri Vdtonline.com
JavaScript Event Loop
Shift Remote FRONTEND: Reactivity in Vue.JS 3 - Marko Boskovic (Barrage)
Appcelerator droidcon15 TLV
The Ring programming language version 1.5.1 book - Part 64 of 180
Learning Rule Based Programming using Games @DecisionCamp 2016
Sequence diagrams
What's new in Drools 6 - London JBUG 2013
Ad

Viewers also liked (7)

ZIP
Accessibililty 101
PDF
Revista de Gestão Costeira Integrada
KEY
Innovateeurope
PPT
Health Synchronization
ZIP
Yahoo @ Nike
KEY
Mobile And The Latency Trap
PDF
100 abstracts of e patient. Fattori
Accessibililty 101
Revista de Gestão Costeira Integrada
Innovateeurope
Health Synchronization
Yahoo @ Nike
Mobile And The Latency Trap
100 abstracts of e patient. Fattori
Ad

Similar to YQL Tutorial (20)

KEY
Seti 09
PDF
Intro to HTML5
PDF
Webgl para JavaScripters
PPTX
Fact, Fiction, and FP
PPTX
Yahoo Query Language: Select * from Internet
PDF
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
PDF
Five things for you - Yahoo developer offers
PDF
Cross Domain Web
Mashups with JQuery and Google App Engine
PDF
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
KEY
Leaving Flatland: getting started with WebGL
PDF
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
ODP
Non Conventional Android Programming En
ODP
Non Conventional Android Programming (English)
PDF
H3 경쟁력있는 웹앱 개발을 위한 모바일 js 프레임웍
PDF
PDF
PDF
YQL: Select * from internet - Campus Party 2010
PPTX
Phone Gap
PDF
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...
Seti 09
Intro to HTML5
Webgl para JavaScripters
Fact, Fiction, and FP
Yahoo Query Language: Select * from Internet
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Five things for you - Yahoo developer offers
Cross Domain Web
Mashups with JQuery and Google App Engine
HTML pour le web mobile, Firefox OS - Devfest Nantes - 2014-11-07
Leaving Flatland: getting started with WebGL
HTML for the Mobile Web, Firefox OS - All Things Open - 2014-10-22
Non Conventional Android Programming En
Non Conventional Android Programming (English)
H3 경쟁력있는 웹앱 개발을 위한 모바일 js 프레임웍
YQL: Select * from internet - Campus Party 2010
Phone Gap
HTML, not just for desktops: Firefox OS - Congreso Universitario Móvil - 201...

More from Tom Croucher (20)

PDF
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
KEY
Streams are Awesome - (Node.js) TimesOpen Sep 2012
KEY
Using Node.js to improve the performance of Mobile apps and Mobile web
KEY
Writing robust Node.js applications
KEY
Creating the Internet of Things with JavaScript - Fluent Conf
KEY
Using Node.js to make HTML5 work for everyone
KEY
A million connections and beyond - Node.js at scale
KEY
OSCON 2011 - Node.js Tutorial
PDF
Lessons from a coding veteran - Web Directions @Media
KEY
Multi-tiered Node Architectures - JSConf 2011
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
PDF
How to stop writing spaghetti code
PDF
Doing Horrible Things with DNS - Web Directions South
PDF
Doing Horrible Things to DNS in the Name of Science - SF Performance Meetup
PDF
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
KEY
How to stop writing spaghetti code - JSConf.eu 2010
PDF
Sf perf
PDF
Node.js and How JavaScript is Changing Server Programming
PDF
Server Side JavaScript - You ain't seen nothing yet
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Using Node.js to improve the performance of Mobile apps and Mobile web
Writing robust Node.js applications
Creating the Internet of Things with JavaScript - Fluent Conf
Using Node.js to make HTML5 work for everyone
A million connections and beyond - Node.js at scale
OSCON 2011 - Node.js Tutorial
Lessons from a coding veteran - Web Directions @Media
Multi-tiered Node Architectures - JSConf 2011
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
How to stop writing spaghetti code
Doing Horrible Things with DNS - Web Directions South
Doing Horrible Things to DNS in the Name of Science - SF Performance Meetup
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
How to stop writing spaghetti code - JSConf.eu 2010
Sf perf
Node.js and How JavaScript is Changing Server Programming
Server Side JavaScript - You ain't seen nothing yet

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Big Data Technologies - Introduction.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Digital-Transformation-Roadmap-for-Companies.pptx
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
Programs and apps: productivity, graphics, security and other tools
Big Data Technologies - Introduction.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Per capita expenditure prediction using model stacking based on satellite ima...

YQL Tutorial

  • 1. YQL
  • 4. dev
  • 5. dev
  • 6. dev
  • 7. dev
  • 8. dev
  • 9. dev
  • 10. dev
  • 11. dev
  • 12. dev
  • 13. dev
  • 14. dev
  • 15. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); …
  • 16. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); … … if (flickcurl_prepare(fc, "flickr.photos.geo.correctLocation", parameters, count)) { … } …
  • 17. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); … … if (flickcurl_prepare(fc, "flickr.photos.geo.correctLocation", parameters, count)) { … } … http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2
  • 18. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); … … if (flickcurl_prepare(fc, "flickr.photos.geo.correctLocation", parameters, count)) { … } … http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2 http://weather.yahooapis.com/ forecastrss?p=FRXX0076&u=c
  • 19. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); … … if (flickcurl_prepare(fc, "flickr.photos.geo.correctLocation", parameters, count)) { … } … http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2 http://weather.yahooapis.com/ forecastrss?p=FRXX0076&u=c
  • 20. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); … … if (flickcurl_prepare(fc, "flickr.photos.geo.correctLocation", parameters, count)) { … } … http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2 http://weather.yahooapis.com/ forecastrss?p=FRXX0076&u=c
  • 21. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); … … if (flickcurl_prepare(fc, "flickr.photos.geo.correctLocation", parameters, count)) { … } … http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2 http://weather.yahooapis.com/ forecastrss?p=FRXX0076&u=c
  • 22. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); … … if (flickcurl_prepare(fc, "flickr.photos.geo.correctLocation", parameters, count)) { … } … http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2 http://weather.yahooapis.com/ forecastrss?p=FRXX0076&u=c
  • 23. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); ? … … if (flickcurl_prepare(fc, ? "flickr.photos.geo.correctLocation", parameters, count)) { … } … ? http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2 ? http://weather.yahooapis.com/ forecastrss?p=FRXX0076&u=c
  • 24. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); ? … … if (flickcurl_prepare(fc, ? "flickr.photos.geo.correctLocation", parameters, count)) { … } … ? http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2 ? http://weather.yahooapis.com/ forecastrss?p=FRXX0076&u=c
  • 25. var map = new YMap(document.getElementById('map')); … dev var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint); … … if (flickcurl_prepare(fc, "flickr.photos.geo.correctLocation", parameters, count)) { … } … http://search.yahooapis.com/ ImageSearchService/V1/imageSearch? appid=YahooDemo&query=Corvette&results=2 http://weather.yahooapis.com/ forecastrss?p=FRXX0076&u=c
  • 26. dev YQL
  • 27. dev YQL
  • 28. dev Bindings YQL
  • 30. Exercise 1 • write a query to search the web for “free wifi” Washington DC • find photos of kittens on flickr that were tagged with “awesome” • find the weather at SFO (san francisco airport)
  • 31. Solutions 1 • select * from search.web where query = '"washington dc" free wifi' • select * from flickr.photos.search where text ="kittens" and tags="awesome" • select * from weather.forecast where location in (select postal from geo.places where text="sfo")
  • 32. Demo time part deux http://developer.yahoo.com/yql/console/
  • 33. Exercise 2 • Get my (“sh1mmer”) twitter stream • Find articles about Obama in the New York Times • Google, Bing and Yahoo for dogs
  • 34. Solutions 2 • select * from twitter.user.timeline where id = "sh1mmer" • select * from nyt.article.search where query = "obama" • select * from query.multi where queries = 'select * from microsoft.bing.web where query="dogs";select * from google.search where q = "dogs"; select * from search.web where query="dogs"'
  • 35. YQL in Practice 20 tiny steps to a working application You’ll need: Firefox Firebug Text editor
  • 36. Step 1. Login to the console with your Yahoo! login http://developer.yahoo.com/yql/console
  • 37. Step 2. Find the statement box and run the first query with test.
  • 38. Step 3. Check out the formatted view.
  • 39. Step 4. Run the statement “desc html”
  • 40. Step 5. Find the keys, note the required keys.
  • 41. Step 6. Get some HTML: select * from html where url = "http:// hubblesite.org/gallery/album/the_universe"
  • 42. Step 7. Check out the result. See the HTML in there?
  • 43. Step 8. Open http://hubblesite.org/gallery/album/the_universe in Firefox. Right click on a thumbnail and click “Inspect Element”
  • 44. Step 9. Find the element in Firebug. Right click and select “Copy XPath”
  • 45. Step 10. Add and xpath = "" to your query. Paste in the XPath from Firebug
  • 46. Step 11. Test your statement and refine your XPath.
  • 47. Step 12. Add limit 10 to your statement
  • 48. Step 13. Let’s get out of the console. Copy the “Rest Query” url into a new tab
  • 49. Step 14. Let’s embed this in a web page. Download the files from http://github.com/sh1mmer/dotnet-yql-tutorial
  • 50. Step 15. Add <script type="text/javascript" src="yql_js_widget.js"></script> to your HTML page.
  • 51. Step 16. Add some style: <style type="text/css"> li.imgCnt{ list-style: none; background:#000000; margin: 3px; float: left; } li.imgCnt img{ border:0; margin:5px; } li.imgCnt div.imgTitle{ padding: 5px; font-size: 11px; text- align:center; } </style>
  • 52. Step 17. Add another script node. Add config = {};
  • 53. Step 18. Format the output: var format = '<li class="imgCnt"> <img src="{src}" alt="{alt}"></li>';
  • 54. Step 19. Add you query; var yqlQuery = "" and add your query.
  • 55. Step 20. Add the render code: yqlWidget.push(yqlQuery,config,format,'widge tContainer'); yqlWidget.render();
  • 57. <script src="http://yui.yahooapis.com/3.1.0/build/yui/yui-min.js"></ script> <script> YUI({ //Last Gallery Build of this module gallery: 'gallery-2010.01.27-20' }).use('gallery-yql', function(Y) { //Using events var q1 = new Y.yql('select * from github.user.info where (id = "davglass")'); q1.on('query', function(r) { //Do something here. }); q1.on('error', function(r) { //Do something here. }); //Or the callback approacha new Y.yql('select * from github.user.info where (id = "davglass")', function(r) { //Do something here. r.query; //The result r.error; //The error message }); }); </script>
  • 58. Advanced YQL Advanced Queries, I/U/D, Open Tables and Using YQL with JavaScript
  • 59. Basics select * from {table} where {key1} = "{value1}" and {key2} = {value2} select * from flickr.photos.search where text = "kittens" and tags = "domokun"
  • 61. select * from flickr.photos.search where text = "kittens" and tags = "domokun" Remote
  • 62. select * from flickr.photos.search where text = "kittens" and tags = "domokun" Remote
  • 63. select * from flickr.photos.search where text = "kittens" and tags = "domokun" Remote
  • 65. Local
  • 66. select * from flickr.photos.search where text = "kittens" and tags = "domokun" and farm = 4
  • 68. select * from flickr.photos.search where text = "kittens" and tags = "domokun" and farm = 4 limit 10
  • 69. WTF?!
  • 70. select * from flickr.photos.search(10) where text = "kittens" and tags = "domokun" and farm = 4
  • 72. select * from flickr.photos.search(20) where text = "kittens" and tags = "domokun" and farm = 4
  • 73. Ooo! 6 results... right...
  • 74. select * from flickr.photos.search(0) where text = "kittens" and tags = "domokun" and farm = 4 limit 10
  • 75. Limit Summary • limit 10 - give me max 10 results from the data you have • {table}(10) - get ten results from server • {table}(0) - get enough results from the server to fill my local limit with the local filters
  • 77. select * from {table} (10) where foo = "bar" offset 10 vs. select * from {table} (10,10) where foo = "bar"
  • 78. select * from {table} (10) where foo = "bar" offset 10 <results> <result foo=”bar”>1</result> <results> <result foo=”qux”>2</result> <result foo=”bar”>1</result> ... ... <results> </results> <result foo=”qux”>8</result> <result foo=”bar”>9</result> </query> <result foo=”bar”>9</result> <result foo=”bar”>10</result> <result foo=”bar”>10</result> </results> </results> </query> </query>
  • 79. select * from {table} (10,10) where foo = "bar" <results> <result foo=”bar”>11</result> <results> <result foo=”qux”>12</result> <result foo=”bar”>11</result> ... ... <result foo=”qux”>18</result> <result foo=”bar”>20</result> <result foo=”qux”>19</result> </results> <result foo=”bar”>20</result> </query> </results> </query>
  • 81. select * from {table1} where {key1} in (select id from {table2});
  • 82. select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where text="kitten")
  • 84. select * from {table1} where ({key1}, {key2}) in (select foo, bar from {table2});
  • 85. select * from flickr.places where (lat, lon) in (select match1, match2 from regex where text in (select entry.point from usgs.earthquakes limit 10) and expression = "(-?d+.d+) (-?d+.d+)") and total != 0 limit 10
  • 87. select * from {table}(20) | sort(field=”foo”, descending = “true”) | truncate 10
  • 88. Filters are always applied last, in order
  • 89. select * from {table}(20) | sort(field=”foo”, descending = “true”) | truncate 10 <results> <results> <results> <result foo=”bar”>1</result> <result foo=”bar”>20</result> <result foo=”bar”>20</result> <result foo=”qux”>2</result> <result foo=”qux”>19</result> <result foo=”qux”>19</result> ... ... ... <result foo=”qux”>18</result> <result foo=”qux”>3</result> <result foo=”qux”>13</result> <result foo=”bar”>19</result> <result foo=”bar”>2</result> <result foo=”bar”>12</result> <result foo=”bar”>20</result> <result foo=”bar”>1</result> <result foo=”bar”>11</result> </results> </results> </results> </query> </query> </query>
  • 90. Super-secret Filters • Xpath() • Regex() • ... there are more I can’t remember
  • 91. I/U/D
  • 92. I/U/D • Personally, I like calling it DUI
  • 93. I/U/D • Personally, I like calling it DUI • I’m always developing under the influence
  • 94. I/U/D • Personally, I like calling it DUI • I’m always developing under the influence • Insert / Update / Delete tables
  • 95. Just like SQL except... • INSERT - no where clause. period. • UPDATE - only remote keys • DELETE - only remote keys
  • 96. INSERT INTO wordpress.post (title, description, blogurl, username, password) VALUES ("Test Title", "This is a test body", "http://yqltest.wordpress.com", "yqltestuser", "password");
  • 97. It really is like SQL.
  • 101. Tom Hughes-Croucher @sh1mmer croucher@yahoo-inc.com

Editor's Notes

  • #4: Lets take an example of a developer trying
  • #5: Lets take an example of a developer trying
  • #6: Lets take an example of a developer trying
  • #7: Lets take an example of a developer trying
  • #8: Lets take an example of a developer trying
  • #9: Lets take an example of a developer trying
  • #10: Lets take an example of a developer trying
  • #11: Lets take an example of a developer trying
  • #12: Lets take an example of a developer trying
  • #13: Lets take an example of a developer trying
  • #14: Lets take an example of a developer trying
  • #72: remote keys are shown as keys