82
A Query Language for the Web YQL Nagesh Susarla

Yql Openhackday 2009

  • Upload
    nageshs

  • View
    2.993

  • Download
    2

Embed Size (px)

DESCRIPTION

Slides from my YQL (Yahoo Query Language) Talk @ OpenHackDay Bangalore held on 14th/15th Feb '09

Citation preview

Page 1: Yql Openhackday 2009

A Query Language for the Web

YQL

Nagesh Susarla

Page 2: Yql Openhackday 2009

Agenda

Why YQL?

YQL Statement Basics

Accessing YQL

Q&A

Page 3: Yql Openhackday 2009

Application ?

Page 4: Yql Openhackday 2009

Application ?

Page 5: Yql Openhackday 2009

Application ?

Page 6: Yql Openhackday 2009

Application ?

Page 7: Yql Openhackday 2009

Application ?

Page 8: Yql Openhackday 2009

Application =

Page 9: Yql Openhackday 2009

Application =data manipulation

Page 10: Yql Openhackday 2009

Application =data manipulation

data visualization+

Page 11: Yql Openhackday 2009

datadata

Page 12: Yql Openhackday 2009

datadata

Page 13: Yql Openhackday 2009

data

Page 14: Yql Openhackday 2009
Page 15: Yql Openhackday 2009

dev

Page 16: Yql Openhackday 2009

dev

Page 17: Yql Openhackday 2009

dev

Page 18: Yql Openhackday 2009

dev

Page 19: Yql Openhackday 2009

dev

Page 20: Yql Openhackday 2009

dev

Page 21: Yql Openhackday 2009

dev

Page 22: Yql Openhackday 2009

dev

Page 23: Yql Openhackday 2009

dev

Page 24: Yql Openhackday 2009

dev

Page 25: Yql Openhackday 2009

dev

Page 26: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint);…

Page 27: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint);…

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

Page 28: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

Page 29: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

Page 30: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

Page 31: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

Page 32: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

Page 33: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

Page 34: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

?

??

?

Page 35: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

?

??

?

Page 36: Yql Openhackday 2009

dev

var map = new YMap(document.getElementById('map'));…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

?

??

?

Yahoo! My Yahoo! Mail Welcome, guest Sign In

Introduction and Prerequisites

Examples

Display a Yahoo! Map

Add controls to your Yahoo! Map

Add a logger to a Yahoo! Map

Place a marker on a Yahoo! Map

Draw Polylines on a Yahoo! Map

Place Smart Markers on a Yahoo! Map

Add multiple custom markers on Yahoo! Map

Traffic information overlay

Yahoo! Pipes RSS output information overlay

Yahoo! Pipes JSON output information overlay

Local search results overlay

Overlay GeoRSS XML data

Overlay custom objects at YGeoPoint location

Overlay custom objects at YCoordPoint location

Overlay polyline on Yahoo! Map

Export Yahoo! Map in GeoRSS format

GeoRSS overlay with polyline

Get zoom level given radius from center

Custom position of controls

Change Marker Images Dynamically

Use YMapTypeControl to position map types

Other Features of the Yahoo! Maps AJAX API

Rate Limit

Terms of Service

Support & Community

Download all of the cheatsheets and example code in the Yahoo

Maps API Reference Bundle.

For detailed descriptions of the classes and methods in the API,

check out v3.8 Reference Manual.

Yahoo! Maps Cheatsheets

YMap

YEvent, YGeoRSS, YMarker

Remaining, Supporting Classes

Yahoo! Maps Web Services - AJAX API Getting

Started Guide

Learn the fundamentals of the Yahoo! Maps AJAX API and start creating your own maps. This page contains:

Introduction and Prerequisites

The Yahoo! AJAX Maps API lets developers add maps to their web sites using DHTML and JavaScript®. Maps

are fully embeddable and scriptable using the JavaScript programming language. Yahoo! Maps AS-Flash API's

built-in geocoder means that you can specify a physical address or latitude/longitude coordinates for your map's

location, as you like.

In order to create and test applications using Yahoo! Maps AJAX API, you'll need to use a supported web

browser: Firefox 2, Internet Explorer 6 or 7, Opera 9 or Safari 3. Newer versions of these browsers are also

supported. You can code your JavaScript applications using your favorite text editor or IDE.

An application ID is required to use the Yahoo! Maps AJAX API. You can get an application ID here.

For best results, you should launch your web pages from a web server. However, it's possible to run applications

directly from your hard drive by double-clicking on them. This can be done by lowering the security settings in

the Internet Explorer browser or by setting the UniversalBrowserRead property in Firefox.

Displaying a Yahoo! Map

All the API classes and methods necessary to interact with Yahoo! Maps are available to your application when

you include Yahoo! Maps AJAX API library in your web page.This example uses the demonstration application

ID "YD-eQRpTl0_JX2E95l_xAFs5UwZUlNQhhn7lj1H"; you cannot use this Application ID and must request one

here.

<html>

<head>

<b><script type="text/javascript"

src="http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=YD-eQRpTl0_JX2E95l_xAFs5UwZUlNQhhn7lj1H">

</script </b

YDN Maps Suite AJAX Maps

Leonardo da Vinci: Hacker

Whaddyathink? & the Yahoo! ApplicationPlatform

Making the new Yahoo! Currency Converteraccessible

Retrieving and displaying data fromWikipedia with YQL

RECENT BLOG ARTICLES

January 24, 2009

January 22, 2009

January 21, 2009

January 18, 2009

READY TO GET STARTED?

Get an App ID

Search

MY PROJECTS APIs & WEB SERVICES RESOURCES SUPPORT

You aren't signed in Sign In Help

Flickr ServicesAPI Documentation Feeds Your API Keys Apply for a new API Key

flickr.places.getPlaceTypes

Fetches a list of available place types for Flickr.

Authentication

This method does not require authentication.

Arguments

api_key (Required)

Your API application key. See here for more details.

Example Response

<place_types> <place_type place_type_id="22">neighbourhood</place_type> <place_type place_type_id="7">locality</place_type> <place_type place_type_id="9">county</place_type> <place_type place_type_id="8">region</place_type> <place_type place_type_id="12">country</place_type> <place_type place_type_id="29">continent</place_type></place_types>

Error Codes

100: Invalid API Key

The API key passed was not valid or has expired.

105: Service currently unavailable

The requested service is temporarily unavailable.

111: Format "xxx" not found

The requested response format was not found.

112: Method "xxx" not found

The requested method was not found.

114: Invalid SOAP envelope

The SOAP envelope send in the request could not be parsed.

115: Invalid XML-RPC Method Call

The XML-RPC request document could not be parsed.

API Explorer

API Explorer : flickr.places.getPlaceTypes

Home The Tour Sign Up Explore Search

Yahoo! My Yahoo! Mail Welcome, guest Sign In

Yahoo! Weather RSS Feed

The Weather RSS feed enables you to get up-to-date weather information for your location. You can save this

feed in My Yahoo! or your favorite feed aggregator, or incorporate the RSS data into your own web site or client

application. The Weather RSS feed is a dynamically-generated feed based on zip code or Location ID.

This page describes the format of the request URL and the RSS response for developers. It contains these

sections:

RSS Request

Summary

Request Parameters

RSS Response

Top-Level Elements

Channel Elements

Image Elements

Item Elements

Condition Codes

Examples

Terms of Use

RSS Request

The Weather RSS feed request follows simple HTTP GET syntax: start with a base URL and then add

parameters and values after a question mark (?). Multiple parameters are separated by an ampersand (&).

The base URL for the Weather RSS feed is

http://weather.yahooapis.com/forecastrss

In this section, Summary shows how to make an RSS request with different parameters; Request Parameters

shows a table summarizing those parameters.

SUMMARY

The Weather RSS feed request follows simple HTTP GET syntax: start with a base URL and then add

parameters and values after a question mark (?). Multiple parameters are separated by an ampersand (&). For

the Weather RSS feed there are two parameters:

p for location.

u for degrees units (Fahrenheit or Celsius).

The location parameter p is required. Use this parameter to indicate the location for the weather forecast as a

zip code or Location ID.

http://weather.yahooapis.com/forecastrss?p=location

For example, to get weather for Yahoo! Headquarters in Sunnyvale, CA, use the zip code for Sunnyvale

(94089):

http://weather.yahooapis.com/forecastrss?p=94089

Or use the Location ID for Sunnyvale (USCA1116):

http://weather.yahooapis.com/forecastrss?p=USCA1116

YDN Weather RSS Feed

Search

MY PROJECTS APIs & WEB SERVICES RESOURCES SUPPORT

Page 37: Yql Openhackday 2009

YQL

Page 38: Yql Openhackday 2009

dev

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

…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'));…var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon ); map.addMarker(currentGeoPoint);…

Page 39: Yql Openhackday 2009

dev

YQL

Page 40: Yql Openhackday 2009

dev

YQL

Page 41: Yql Openhackday 2009

dev

YQL

Bindings

Page 42: Yql Openhackday 2009

dev

YQL

Bindings

Page 43: Yql Openhackday 2009

dev

YQLYQL stmt

Bindings

Page 44: Yql Openhackday 2009

dev

YQLselectYQL stmt

Bindings

Page 45: Yql Openhackday 2009

dev

YQLselect

desc

YQL stmt

Bindings

Page 46: Yql Openhackday 2009

dev

YQLselect

desc

show

YQL stmt

Bindings

Page 47: Yql Openhackday 2009

Motivation Thousands of Web Services that provide valuable data

Requires developers to read documentation and form URLs/queries.

Data is isolated

Needs combining, tweaking, shaping even after it gets to the developer.

Page 48: Yql Openhackday 2009

YQLSQL-Like Language

Synonymous with Data access

Familiar to developers

Expressive enough to get the right data.

Self Describing - show, desc table

Allows you to query, filter and join data across WebServices.

Page 49: Yql Openhackday 2009

YQL Statement Basics

show: lists the supported tables

desc: describes the structure of a table

select: fetches data

use: use an Open Data Table *new*

Verbs

show tables

desc social.contacts

Page 50: Yql Openhackday 2009

YQL Statement

SELECT what

FROM collection

WHERE filter condition

IN (sub-select)

LIMIT n OFFSET n

Syntax

Page 51: Yql Openhackday 2009

YQL Statement Basics

FROM collection

Yahoo! WebServices

Social Dir, Upcoming, MyblogLog, Y!Local, Search(BOSS)

External DataSources

XML, Atom, RSS, JSON, CSV, HTML

Syntax -> Select -> Collection

Page 52: Yql Openhackday 2009

YQL Statement Basics

Table data can be filtered in the WHERE clause either

Remotely by the table data source

Locally by the YQL engine (dot notation)

Syntax -> Select -> WHERE clause

Page 53: Yql Openhackday 2009

YQL Statement Basics

WHERE <remote_key>=‘value’Tables require Keys in where clause

Specified in the describe

Correspond to query, path or matrix parameters for the Endpoint

Syntax -> WHERE clause -> Remote Filter

<query>

<key name=”guid” required=”true” .../>

</query>

Page 54: Yql Openhackday 2009

YQL Statement Basics

WHERE <local_filter> OP ‘value’Filter an element or an attribute

Syntax -> WHERE clause -> Local Filter

<movies>

<movie>Star Wars</movie>

<movie>StarTrek</movie>

</movies>

<, >, =, LIKE, matches, not matches, not like

AND, OR binary operator combinations

Dot notation:

movies.movie LIKE ‘%Star%’

Page 55: Yql Openhackday 2009

YQL Statement Basics

SELECT <what>

Uses the dot notation to project parts of matching item(s)

Syntax -> Select -> Projection

<results>

<movie>

<id>101</id>

<name>Star Wars</name>

</movie>

<movie>...</movie>

</results>

Projection: (relative to root)

select movie.id, movie.name from ...

Page 56: Yql Openhackday 2009

YQL Statement Basics

IN (SELECT ...)Join across data sources

field IN (select guid from ...)

Like SELECT but can return only N leaves

Syntax -> Select -> Sub-Select

Get the profile for all my connections:

select * from social.profile where guid in (select guid from social.connections where owner_guid = me)

Page 57: Yql Openhackday 2009

YQL Statement Basics

IN (SELECT ...)

(field, ...fieldN) IN (SELECT f1,...fn from table)

Syntax -> Select -> Sub-Select

Get the Location name of the given Photo:

select place.name from flickr.places where (lat, lon) in (select location.latitude, location.longitude from flickr.photos.info where photo_id='3030238604')

Page 58: Yql Openhackday 2009

YQL Statement Basics

Changing the Table Size

Yahoo! Tables are limited to a small number by default (10)

Increase set size as parameters to Collection

Syntax -> Select -> Table Size

select * from local.search where zip=‘94089’ and query=‘pizza’

select * from local.search(100) where zip=‘94089’ and query=‘pizza’

Page 59: Yql Openhackday 2009

YQL Statement Basics

Post Select processing using ‘pipe’ symbol.

Functions operate on return data.

Operations unrelated to table or data source.

Syntax -> Post Query Manipulation

select ... | sort(field=‘item.pubDate’)select ... | unique(field=‘item.title’)select ... | tail(count=10)

Page 60: Yql Openhackday 2009

YQL Statement Basics

Like Prepared Statements for YQL

Substitutes Query parameter

Can be used in sub-selects

http://<>?q=....&city=Bangalore&state=Karnataka

select * from table where city=@city and state=@state

select * from table where city in (@city, @city2, @city3)

Syntax -> YQL Variables (@var)

Page 61: Yql Openhackday 2009

YQL Statement Basics

Multi Valued variables

http://<>?q=....&city=Bangalore&city=Mumbai

select * from table where city in (@city)

Syntax -> YQL Variables (@var)

Page 62: Yql Openhackday 2009

Sounds Good. But what about my WebService?

Page 63: Yql Openhackday 2009

Can I add my data tables?

Page 64: Yql Openhackday 2009

Open Data Tables

YQL

Page 65: Yql Openhackday 2009

Open Data Tables

YQL

Page 66: Yql Openhackday 2009

Open Data Tables

YQL

Page 67: Yql Openhackday 2009

Open Data Tables

YQL

Page 68: Yql Openhackday 2009

Open Data Tables

YQL

Bindings

Page 69: Yql Openhackday 2009

Open Data Tables

YQL

Page 70: Yql Openhackday 2009

Open Data Tables

YQL

Page 71: Yql Openhackday 2009

Open Data Tables

YQL

Map YQL to Endpoint

Page 72: Yql Openhackday 2009

Open Data Tables

YQL

Page 73: Yql Openhackday 2009

Open Data Tables

YQL

Page 74: Yql Openhackday 2009

Open Data Tables

Page 75: Yql Openhackday 2009

Open Data Tables

Page 76: Yql Openhackday 2009

Open Data Tables

Schema defines mapping between YQL and Endpoint

Keys can either be query, path or matrix parameters

Keys can be marked as required

YQL Compiler validates existence of required keys

Page 77: Yql Openhackday 2009

USE Verb

Imports the Table defintion

Makes it available to following statements as tableName

desc tableName - describes the def

Acts like a First Class Data Source just like other YQL Tables.

use ‘http://url-to-def.xml’ as tableName;select * from tableName where key=‘value’...

Page 78: Yql Openhackday 2009

data

Page 79: Yql Openhackday 2009

One API : YQL

Page 81: Yql Openhackday 2009

Accessing YQL

YQL Via Pipes