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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

3,967
views

Published on


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,967
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
26
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. MQL-to-SQL a JSON-based query language for RDBMS data access from AJAX applications
  • 2. Welcome!
    • Roland Bouman, Leiden, the Netherlands
    • 3. Ex-MySQL, ex-Sun Microsystems
    • 4. Web & BI developer at Strukton Rail
    • 5. Author
      • “Pentaho Solutions”
      • 6. “Pentaho Kettle Solutions”
    • http://rpbouman.blogspot.com , @rolandbouman
  • 7. Agenda
    • The data access problem
    • 8. What's wrong with SQL?
    • 9. The Metaweb Query Language (MQL)
    • 10. MQL-to-SQL
    • 11. Demo
    • 12. Questions
  • 13. Agenda
    • The data access problem
    • 14. What's wrong with SQL?
    • 15. The Metaweb Query Language (MQL)
    • 16. MQL-to-SQL
    • 17. Demo
    • 18. Questions
  • 19. The Data Access Problem
    • Web application
    • Classical Client/Server
    SQL Resultset SQL Resultset RDBMS HTTP Browser Desktop Application ?
  • 20. The Data Access Problem
    • Build a service
      • Protocol on top of HTTP: REST, RPC
      • 21. Data format: JSON, XML
    • Advantage: controlled data access
    • 22. Disadvantage: controlled=limited
  • 23. The Data Access Problem
    • Advantage: unlimited data access
    • 24. Disadvantage: unlimited=uncontrolled
    SQL SQL Resultset JSON
    • Build a query service
      • Example: dbslayer
  • 25. Agenda
    • The data access problem
    • 26. What's wrong with SQL?
    • 27. The Metaweb Query Language (MQL)
    • 28. MQL-to-SQL
    • 29. Demo
    • 30. Questions
  • 31. What's wrong with SQL?
    • Nothing of course, it's great!!!
  • 37. 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
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. SQL can't escape the RM
  • 42. 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
  • 43. 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
  • 44. How do we get rid of SQL?
    • Object relational mapper?
    • 45. NoSQL?
      • Document databases
      • 46. ACID
      • 47. Schema flexibility
    • Can we preserve the RM?
  • 48. Agenda
    • The data access problem
    • 49. What's wrong with SQL?
    • 50. The Metaweb Query Language (MQL)
    • 51. MQL-to-SQL
    • 52. Demo
    • 53. Questions
  • 54. The Metaweb Query Language
    • MQL – rhymes with “pickle”
    • 55. Native query language of Freebase
      • http://www.freebase.com/
      • 56. http://www.freebase.com/docs
    • JSON over HTTP
      • Natural fit for AJAX applications
  • 57. Freebase MQL Services
    • http://api.freebase.com/api/service/mqlread? query ={"query":[{ Your MQL here }]}
    • 58. http://api.freebase.com/api/service/mqlread? queries ={"q1": {"query":[{ Your MQL here }]}, "q2": {"query":[{ Your MQL here }]}}
    • 59. http://api.freebase.com/api/service/mqlwrite
  • 60. JSON
    • Subset of JavaScript
      • Object : set of property/value pairs
      • 61. Scalar: boolean, null, number, string
      • 62. Array: list of values
    { "type" : "/sakila/film" , "film_id" : 1 , "title" : "ACADAMY DINOSAUR" , "language" : { "language_id" : 1 , "language_name" : "English" } , "category" :[ "Action" , "Adventure" ] }
  • 63. JSON is great for AJAX
    • Modern Web applications
      • Asynchronous JavaScript and XML
      • 64. ...except it's JSON rather than XML
    • 1 to 1 runtime representation
      • XML requires mapping, DOM traversal
      • 65. JSON support in all modern browsers
    • Cross-domain requests (JSONP)
      • <script> injection
  • 66. MQL Queries
    • JSON-based
      • Both Query and Result
    • MQL is “query by example”
      • MQL Query is an object template
      • 67. Finds objects matching the template
      • 68. Fills in value placeholders in template
    • Query & Result symmetry
      • Easy to parse, easy to generate
  • 69. 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
    • 70. Value placeholders return data
  • 71. Meta: Objects & Properties
    • Objects are bags of properties
    • 72. Properties
      • name/value pairs
      • 73. Single- or multi-valued (array)
      • 74. Value can be scalar or object
    • No explicit relationships
      • Implicit: properties with object values
  • 75. Meta: Types
    • Types define a bag of properties
      • Objects may have multiple types
      • 76. Types are grouped in domains
    • In MQL, use the type property
      • type : &quot;/domainname/typename&quot;
    • Property has exactly 1 expected type
  • 77. MQL Joins/subqueries
    • Implicit via object-type properties
    • 78. Can't specify join conditions
  • 79. MQL operators
    • Property/value act as equals operator
    • 80. Explicit operators for advanced filters
    • 81. != , < , <= , >= , >
      • Have their usual meaning
    • |= and !|= test for membership
      • &quot;one of&quot; and &quot;not one of&quot;
    • ~= for word pattern matching
  • 82. 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
    • 83. Operations not returned in the result
  • 84. 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
  • 85. MQL directives
  • 89. Agenda
    • The data access problem
    • 90. What's wrong with SQL?
    • 91. The Metaweb Query Language (MQL)
    • 92. MQL-to-SQ L
    • 93. Demo
    • 94. Questions
  • 95. MQL-to-SQL
    • Implementation of mqlread service
      • PHP using PDO database access
      • 96. MySQL, PostgreSQL, SQLite, Oracle
      • 97. http://code.google.com/p/mql-to-sql
      • 98. GPL
      • 99. Lacks many features, has many bugs
      • 100. don't use in hospitals and airplanes
  • 101. MQL-to-SQL
    • MQL domain maps to a SQL schema
    • 102. MQL type maps to a SQL table
    • 103. MQL property maps to
      • SQL column
      • 104. Relationship (foreign key)
    • Mappings defined in JSON file
  • 105. MQL-to-SQL index.php config.php <?php include 'config.php' ; ...code... ?> <?php $connection_file_name = ''; $metadata_file_name = ''; ?>
  • 106. 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; },
  • 107. Agenda
  • 113. Agenda
  • 119. Finally
    • I need your feedback
    • 120. Love to see this inside a RDBMS
      • drizzle plugin?
      • 121. MySQL plugin?
      • 122. PostgreSQL SP language?
    • http://code.google.com/p/mql-to-sql/
    • 123. Online query editor

×