Mql to-sql - a json-based rdbms query language
Upcoming SlideShare
Loading in...5
×
 

Mql to-sql - a json-based rdbms query language

on

  • 4,411 views

 

Statistics

Views

Total Views
4,411
Views on SlideShare
3,624
Embed Views
787

Actions

Likes
1
Downloads
23
Comments
0

20 Embeds 787

http://todobi.blogspot.com 501
http://todobi.blogspot.com.es 128
http://todobi.blogspot.mx 55
http://en.oreilly.com 44
http://todobi.blogspot.com.ar 23
http://todobi.blogspot.co.il 9
http://todobi.blogspot.fr 6
http://translate.googleusercontent.com 4
http://todobi.blogspot.kr 2
http://todobi.blogspot.ch 2
http://todobi.blogspot.se 2
http://todobi.blogspot.hk 2
http://todobi.blogspot.com.br 2
http://todobi.blogspot.co.at 1
http://todobi.blogspot.be 1
http://todobi.blogspot.pt 1
http://todobi.blogspot.nl 1
http://todobi.blogspot.it 1
http://www.todobi.blogspot.com 1
http://todobi.blogspot.de 1
More...

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Mql to-sql - a json-based rdbms query language Mql to-sql - a json-based rdbms query language Presentation Transcript

  • MQL-to-SQL a JSON-based query language for RDBMS data access from AJAX applications
  • Welcome!
    • Roland Bouman, Leiden, the Netherlands
    • Ex-MySQL, ex-Sun Microsystems
    • Web & BI developer at Strukton Rail
    • Author
      • “Pentaho Solutions”
      • “Pentaho Kettle Solutions”
    • http://rpbouman.blogspot.com , @rolandbouman
  • Agenda
    • The data access problem
    • What's wrong with SQL?
    • The Metaweb Query Language (MQL)
    • MQL-to-SQL
    • Demo
    • Questions
  • Agenda
    • The data access problem
    • What's wrong with SQL?
    • The Metaweb Query Language (MQL)
    • MQL-to-SQL
    • Demo
    • Questions
  • The Data Access Problem
    • Web application
    • Classical Client/Server
    SQL Resultset SQL Resultset RDBMS HTTP Browser Desktop Application ?
  • The Data Access Problem
    • Build a service
      • Protocol on top of HTTP: REST, RPC
      • Data format: JSON, XML
    • Advantage: controlled data access
    • Disadvantage: controlled=limited
  • The Data Access Problem
    • Advantage: unlimited data access
    • Disadvantage: unlimited=uncontrolled
    SQL SQL Resultset JSON
    • Build a query service
      • Example: dbslayer
  • Agenda
    • The data access problem
    • What's wrong with SQL?
    • The Metaweb Query Language (MQL)
    • MQL-to-SQL
    • Demo
    • Questions
  • What's wrong with SQL?
    • Nothing of course, it's great!!!
      • very powerful
      • expressive syntax
      • declarative
      • designed for the RDBMS
      • portable
      • well supported
  • What's wrong with SQL?
    • SQL is very powerful
      • ...way too powerful
    • SQL has expressive syntax
      • ...and too hard to parse and generate
    • SQL is declarative
      • ...but not enough
    • SQL is designed for the RDBMS
      • ...can't escape relational model
  • SELECT f.title , f.description , f.release_year , f.length , f.rating , a.first_name , a.last_name , l.name FROM film f INNER JOIN language l ON f.language_id = l.id LEFT JOIN film_actor fa ON f.id = fa.film_id LEFT JOIN actor a ON fa.actor_id = a.id SQL not declarative enough Spoken in Has cast Starring in
  • SELECT f.title , f.description , f.release_year , f.length , f.rating , a.first_name , a.last_name , spoken_in.name FROM film f RELATE spoken_in language l , has_cast film_actor fa RELATE starring_in actor a SQL not declarative enough Spoken in Has cast Starring in
  • SQL can't escape the RM Unnormalized data Split off – multivalued attributes – repeating groups First normal form (1NF) Higher normal forms (>= 3NF) Remove redundancy Denormalized data (1NF) SQL queries: – JOIN operation ??? Header – line 1a – line 2b header line 1a line 2b header 1 2 line 1a line 2b header line 1a header line 2b
  • SQL can't escape the RM
  • SELECT f.* , l.*, ol.* , (SELECT * FROM film_category fc INNER JOIN category c ON fc.category_id = c.id WHERE fc.film_id = f.film_id) , (SELECT * FROM film_actor fa INNER JOIN actor a ON fa.actor_id = a.id WHERE fa.film_id = f.film_id) FROM film f INNER JOIN language l ON f.language_id = l.id INNER JOIN language ol ON f.original_language_id = ol.id SQL can't escape the RM
  • SELECT f.* , l.*, ol.* , c.*, a.* FROM film f INNER JOIN language l ON f.language_id = l.id INNER JOIN language ol ON f.original_language_id = ol.id LEFT JOIN film_category fc ON f.id = fc.film_id LEFT JOIN category c ON fc.category_id = c.id LEFT JOIN film_actor fa ON f.id = fa.film_id LEFT JOIN actor a ON fa.actor_id = a.id SQL can't escape the RM
  • How do we get rid of SQL?
    • Object relational mapper?
    • NoSQL?
      • Document databases
      • ACID
      • Schema flexibility
    • Can we preserve the RM?
  • Agenda
    • The data access problem
    • What's wrong with SQL?
    • The Metaweb Query Language (MQL)
    • MQL-to-SQL
    • Demo
    • Questions
  • The Metaweb Query Language
    • MQL – rhymes with “pickle”
    • Native query language of Freebase
      • http://www.freebase.com/
      • http://www.freebase.com/docs
    • JSON over HTTP
      • Natural fit for AJAX applications
  • Freebase MQL Services
    • http://api.freebase.com/api/service/mqlread? query ={"query":[{ Your MQL here }]}
    • http://api.freebase.com/api/service/mqlread? queries ={"q1": {"query":[{ Your MQL here }]}, "q2": {"query":[{ Your MQL here }]}}
    • http://api.freebase.com/api/service/mqlwrite
  • JSON
    • Subset of JavaScript
      • Object : set of property/value pairs
      • Scalar: boolean, null, number, string
      • Array: list of values
    { "type" : "/sakila/film" , "film_id" : 1 , "title" : "ACADAMY DINOSAUR" , "language" : { "language_id" : 1 , "language_name" : "English" } , "category" :[ "Action" , "Adventure" ] }
  • JSON is great for AJAX
    • Modern Web applications
      • Asynchronous JavaScript and XML
      • ...except it's JSON rather than XML
    • 1 to 1 runtime representation
      • XML requires mapping, DOM traversal
      • JSON support in all modern browsers
    • Cross-domain requests (JSONP)
      • <script> injection
  • MQL Queries
    • JSON-based
      • Both Query and Result
    • MQL is “query by example”
      • MQL Query is an object template
      • Finds objects matching the template
      • Fills in value placeholders in template
    • Query & Result symmetry
      • Easy to parse, easy to generate
  • Basic MQL query { &quot;type&quot; : &quot;/sakila/film&quot; , &quot;film_id&quot; : 1 , &quot;title&quot; : &quot;ACADAMY DINOSAUR&quot; , &quot;language&quot; : { &quot;language_id&quot; : 1 , &quot;language_name&quot; : &quot;English&quot; }, &quot;category&quot;: [ &quot;Action&quot; , &quot;Adventure&quot; ] } { &quot;type&quot; : &quot;/sakila/film&quot; , &quot;film_id&quot; : 1 , &quot;title&quot; : null , &quot;language&quot; : { &quot;language_id&quot; : null , &quot;name&quot; : null }, &quot;category&quot; : [] } Query: Result:
    • Property/value pairs act as filter
    • Value placeholders return data
  • Meta: Objects & Properties
    • Objects are bags of properties
    • Properties
      • name/value pairs
      • Single- or multi-valued (array)
      • Value can be scalar or object
    • No explicit relationships
      • Implicit: properties with object values
  • Meta: Types
    • Types define a bag of properties
      • Objects may have multiple types
      • Types are grouped in domains
    • In MQL, use the type property
      • type : &quot;/domainname/typename&quot;
    • Property has exactly 1 expected type
  • MQL Joins/subqueries
    • Implicit via object-type properties
    • Can't specify join conditions
  • MQL operators
    • Property/value act as equals operator
    • Explicit operators for advanced filters
    • != , < , <= , >= , >
      • Have their usual meaning
    • |= and !|= test for membership
      • &quot;one of&quot; and &quot;not one of&quot;
    • ~= for word pattern matching
  • MQL operators { &quot;type&quot; : &quot;/sakila/film&quot; , &quot;film_id&quot;: 1 } { &quot;type&quot; : &quot;/sakila/film&quot; , &quot;film_id < &quot; : 2 , &quot;title ~= &quot; : &quot;ACADEMY&quot; , &quot;language != &quot; : &quot;Danish&quot; , &quot;category |= &quot; : [ &quot;Action&quot;, &quot;Adventure&quot; ], &quot;film_id&quot; : null } Query: Result:
    • Operators follow the property name
    • Operations not returned in the result
  • MQL property aliases { &quot;type&quot; : &quot;/sakila/film&quot; , &quot;film_id&quot; : null , &quot;title&quot; : null , &quot;1:category&quot; : &quot;Action&quot;, &quot;2:category&quot; : &quot;Adventure&quot; } Query:
    • Implement an AND operation
  • MQL directives
    • Reserved property names
      • limit
      • return: count
      • cursor
      • * wildcard
  • Agenda
    • The data access problem
    • What's wrong with SQL?
    • The Metaweb Query Language (MQL)
    • MQL-to-SQ L
    • Demo
    • Questions
  • MQL-to-SQL
    • Implementation of mqlread service
      • PHP using PDO database access
      • MySQL, PostgreSQL, SQLite, Oracle
      • http://code.google.com/p/mql-to-sql
      • GPL
      • Lacks many features, has many bugs
      • don't use in hospitals and airplanes
  • MQL-to-SQL
    • MQL domain maps to a SQL schema
    • MQL type maps to a SQL table
    • MQL property maps to
      • SQL column
      • Relationship (foreign key)
    • Mappings defined in JSON file
  • MQL-to-SQL index.php config.php <?php include 'config.php' ; ...code... ?> <?php $connection_file_name = ''; $metadata_file_name = ''; ?>
  • MQL-to-SQL metadata file { &quot;domains&quot; : { &quot;sakila&quot; : { &quot;schema_name&quot; : &quot;&quot; , &quot;types&quot; : { &quot;actor&quot; : { &quot;properties&quot; : { &quot;actor_id&quot; : { &quot;column_name&quot; : &quot;actor_id&quot; , &quot;nullable&quot; : false , &quot;type&quot; : &quot;/type/int&quot; }, &quot;starring_in&quot; : { &quot;type&quot; : &quot;/sakila/film_actor&quot; , &quot;direction&quot; : &quot;referenced<-referencing&quot; , &quot;join_condition&quot; : [ { &quot;referencing_column&quot; : &quot;actor_id&quot; , &quot;referenced_column&quot; : &quot;actor_id&quot; },
  • Agenda
    • The data access problem
    • What's wrong with SQL?
    • The Metaweb Query Language (MQL)
    • MQL-to-SQL
    • Demo
    • Questions
  • Agenda
    • The data access problem
    • What's wrong with SQL?
    • The Metaweb Query Language (MQL)
    • MQL-to-SQL
    • Demo
    • Questions
  • Finally
    • I need your feedback
    • Love to see this inside a RDBMS
      • drizzle plugin?
      • MySQL plugin?
      • PostgreSQL SP language?
    • http://code.google.com/p/mql-to-sql/
    • Online query editor