
Yahoo! Query Language Service (YQL) Jonathan Trevor, Nagesh Susarla, Joshua Gordineer, Brad Clawsie, Paul Donnelly, Sam Pullara 1! 2! What’s it all about? •! SQL-like language for accessing, filtering and mashing-up Yahoo! web services and any URL-addressable structured data sources •! Like Yahoo! Pipes but with a simple text- based language 3! The language and service •! Provides three SQL-like statements: SELECT, SHOW, DESC !SELECT * FROM social.profile ! !WHERE guid=me •! Single URL endpoint for executing everything –! Mix and match external data and Yahoo! APIs 4! Demo •! http://hackday.developer.yahoo.com/yql 5! The SELECT statement SELECT what FROM collection WHERE filter condition IN (sub-select ) OFFSET n LIMIT n 6! FROM <collection>: Data tables and sources •! Collections of structured documents –! Pictures, events, connections, rss items… •! Yahoo! specific sets of tables –! Social, Upcoming, Flickr, Geo, Local, Search •! External data source tables –! XML (ATOM, RSS), JSON, CSV, HTML 7! WHERE <filter condition>: Remote and Local filtering •! Table data can be filtered in the WHERE clause either: •! Remotely by the table data source provider or •! Locally by the YQL engine 8! WHERE <remote key>: Remote filtering •! Most tables require keys in the where clause before any data is available to YQL for processing –! E.g. “guid” for social.profiles –! DESC’ing a table shows “keys” for filtering remotely •! Correspond to query parameters for that services REST-endpoint 9! WHERE <local filter>: Local filtering •! Works on anything in the data •! >, <, = and so on •! Multiple operators can be combined using AND or OR •! Support for string and integer types •! Uses “dot” syntax for addressing parts of the XML structure 10 ! SELECT <what>: Projecting the data you need •! Uses the dot syntax to project only the parts of each matching data item in the results !SELECT guid " FROM social.connections " WHERE owner_guid=me ! 11 ! IN (SELECT…): Joining across data sources •! Get my friends profile information? SELECT * " FROM social.profile " WHERE guid IN " (SELECT guid " !FROM social.connections WHERE !owner_guid=me) ! •! Sub-select works the same as normal select except it can only return a “leaf” element value or attribute 12 ! Changing the table size •! Yahoo! tables are limited to a small number of results by default (10) select * from local.search where zip='94085' and query='pizza’ " •! If you want more data, you can expand the data set size that the source is providing: select * from local.search(1000) where zip='94085' and query='pizza’ " •! If you want the query to work over the maximum allowable set size: –! <table>(0) 13 ! Post-query manipulation •! Simple post-SELECT processing can be performed by appending the “pipe” symbol to the end of the statement: SELECT … |sort(field=item.date)" SELECT … |unique(field=item.title)| … •! Functions only operate on the data being returned by the query, nothing to do with the tables or data sources themselves 14 ! Using YQL in your applications •! YQL can be accessed at: http://query.yahooapis.com/v1/yql?q=… " •! oauth 1.1. protected –! You’ll need an oauth ck+cks and (optionally) a user access token and access token secret to execute calls 15 ! From PHP or YAP/PHP <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http:// www.w3.org/TR/html4/strict.dtd"> ! <html> ! <body> ! <pre> ! <?php ! require_once(“Yahoo.inc"); ! // Require that a session be present. ! $session=YahooSession::requireSession(" CONSUMER_KEY,CONSUMER_SECRET,APPID, true,false); ! $me = $session->getSessionedUser(); ! $client = new YahooClient($session); ! var_dump( $client->query('select * from social.profile where guid=me') ); ! ?> ! </pre> ! </body> ! </html> 16 ! From YAP/javascript <script type="text/javascript"> ! (function() { ! var toQueryString = function(obj) { ! var parts = []; ! for(var each in obj) if (obj.hasOwnProperty(each)) { ! parts.push(encodeURIComponent(each) + '=' + encodeURIComponent(obj[each])); ! } ! return parts.join('&'); ! }; ! var BASE_URI = 'http://query.yahooapis.com/v1/yql'; ! var runQuery = function(query, handler) { ! gadgets.io.makeRequest(BASE_URI, handler, { ! METHOD: 'POST', ! POST_DATA: toQueryString({q: query, format: 'json'}), ! CONTENT_TYPE: 'JSON', ! AUTHORIZATION: 'OAUTH' ! }); ! }; ! runQuery("select * from geo.places where text='SFO'", function(resp) { ! !document.getElementById('results').innerHTML = gadgets.json.stringify(resp.data); ! }); ! })(); ! </script> ! 17 ! 18 ! Where now? •! Main page http://hackday.developer.yahoo.com/yql •! Testing console http://hackday.developer.yahoo.com/yql/ console •! Documentation http://hackday.developer.yahoo.com/yql/docs 19 ! Q&A 20 ! Testing your queries hackday.developer.yahoo.com/yql/console/ 21 !.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages21 Page
-
File Size-