Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

From SQL to N1QL: structured querying for JSON – Couchbase Connect New York 2017

631 views

Published on

JSON is the lingua franca of flexible data management, used to define complex, variably structured data objects. SQL is the universally known structured query language, used for well defined, uniformly structured data. Can SQL be used to query JSON? Yes, it can when you use N1QL – Couchbase’s SQL query language for JSON.
In this session, we’ll explore how N1QL extends SQL to leverage the universality of SQL as a query language, while also leveraging the flexibility and agility inherent in JSON. See extensive examples of using SQL to directly query complex JSON objects that include arrays, sets, and nested objects. Learn about the powerful query expressiveness of N1QL, including the latest features that have been added to the language. Get practical examples of using N1QL to solve real-world application challenges, based on queries used by Couchbase customers.

Published in: Software
  • Be the first to comment

  • Be the first to like this

From SQL to N1QL: structured querying for JSON – Couchbase Connect New York 2017

  1. 1. ©2017 Couchbase Inc. FROM SQLTO N1QL: STRUCTURED QUERYING FOR JSON Kevin Holder,Vice President, Couchbase Pre-Sales & Services Keshav Murthy, Senior Director, Couchbase R&D 1
  2. 2. ©2017 Couchbase Inc. Agenda • SQL • JSON • Why JSON • Modeling • N1QL: SQL for JSON • Motivation • Language Details • Execution • Performance 2
  3. 3. ©2017 Couchbase Inc.©2017 Couchbase Inc. 3 SQL
  4. 4. ©2017 Couchbase Inc. ©2015 Couchbase Inc. 4
  5. 5. ©2017 Couchbase Inc. SQL Structured Query Language is a special-purpose programming language designed for managing data held in a relational database management system (RDBMS). Originally based upon relational algebra and tuple relational calculus, SQL consists of a data definition language, data manipulation language, and a data control language. Source: https://en.wikipedia.org/wiki/SQL
  6. 6. ©2017 Couchbase Inc. SQL: Core Features • Based on Relational Data Model • Declarative Query Language • SELECT, UPDATE, DELETE, INSERT, MERGE • Arithmetic, Logical, Set operators • Data types: Numerical, Character, Date, Time, etc. • Schema design & management Huge Impact of SQL on Business Applications
  7. 7. ©2017 Couchbase Inc. SQL: Database Features for Application Development • Transactions • ACID • Features that enrich SQL • Stored procedures, triggers, views, indexes, catalogs • Optimizers • 4GL • Extensions, integrations • Spatial, Text, JSON, Queues
  8. 8. ©2017 Couchbase Inc.©2017 Couchbase Inc. 8 JSON
  9. 9. ©2017 Couchbase Inc. Properties of Real-World Data • Rich structure • Attributes, Sub-structure • Relationships • To other data • Value evolution • Data is updated • Structure evolution • Data is reshaped Customer Name DOB Billing Connections Purchases
  10. 10. ©2017 Couchbase Inc. 10 Modeling Data in Relational World Billing ConnectionsPurchases Contacts Customer Rich structure  Normalize & JOIN Queries Relationships  JOINS and Constraints Value evolution  INSERT, UPDATE, DELETE Structure evolution  ALTER TABLE  Application Downtime  Application Migration  Application Versioning
  11. 11. ©2017 Couchbase Inc. Why NoSQL? Agility • Schema flexibility • Easier management of change • In the business requirements • In the structure of the data • Change is inevitable
  12. 12. ©2017 Couchbase Inc. JSON 101 { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" }, { "type" : "master", "cardnum" : "6274-2842-2847-3909", "expiry" : "2019-03" } ], "address" : { "Street" : "10, Downing Street", "City" : "San Francico", "State" : "California", "zip" :94401 } } • Used to represent object data in text • Representation • "Key":"Value" • Data Types: • Number, Strings, Boolean, objects, Arrays, NULL • Hierarchical
  13. 13. ©2017 Couchbase Inc. Using JSON For Real World Data CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30" } Customer DocumentKey: CBL2015 • The primary (CustomerID) becomes the DocumentKey • Column name-Column value become KEY-VALUE pair. { "Name" : { "fname": "Jane ", "lname": "Smith" } "DOB" : "1990-01-30" } OR
  14. 14. ©2017 Couchbase Inc. Using JSON to Store Data CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" } ] } Customer DocumentKey: CBL2015 CustomerID Type Cardnum Expiry CBL2015 visa 5827… 2019-03 Table: Billing • Rich Structure & Relationships • Billing information is stored as a sub-document • There could be more than a single credit card. So, use an array.
  15. 15. ©2017 Couchbase Inc. Using JSON to Store Data CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" }, { "type" : "master", "cardnum" : "6274-2542-5847-3949", "expiry" : "2018-12" } ] } Customer DocumentKey: CBL2015 CustomerID Type Cardnum Expiry CBL2015 visa 5827… 2019-03 CBL2015 master 6274… 2018-12 Table: Billing Value evolution  Simply add additional array element or update a value.
  16. 16. ©2017 Couchbase Inc. Using JSON to Store Data CustomerID ConnId Name CBL2015 XYZ987 Joe Smith CBL2015 SKR007 Sam Smith Table: Connections { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" }, { "type" : "master", "cardnum" : "6274-2542-5847-3949", "expiry" : "2018-12" } ], "Connections" : [ { "ConnId" : "XYZ987", "Name" : "Joe Smith" }, { "ConnId" : "SKR007", "Name" : "Sam Smith" } ] } Customer DocumentKey: CBL2015 Structure evolution  Simply add new key-value pairs  No downtime to add new KV pairs  Applications can validate data  Structure evolution over time. Relations via Reference
  17. 17. ©2017 Couchbase Inc. Using JSON to Store Data { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" }, { "type" : "master", "cardnum" : "6274-2842-2847-3909", "expiry" : "2019-03" } ], "Connections" : [ { "CustId" : "XYZ987", "Name" : "Joe Smith" }, { "CustId" : "PQR823", "Name" : "Dylan Smith" } { "CustId" : "PQR823", "Name" : "Dylan Smith" } ], "Purchases" : [ { "id":12, item: "mac", "amt": 2823.52 } { "id":19, item: "ipad2", "amt": 623.52 } ] } DocumentKey: CBL2015 CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Customer ID Type Cardnum Expiry CBL2015 visa 5827… 2019-03 CBL2015 maste r 6274… 2018-12 CustomerID ConnId Name CBL2015 XYZ987 Joe Smith CBL2015 SKR007 Sam Smith CustomerID item amt CBL2015 mac 2823.52 CBL2015 ipad2 623.52 CustomerID ConnId Name CBL2015 XYZ987 Joe Smith CBL2015 SKR007 Sam Smith Contacts Customer Billing ConnectionsPurchases
  18. 18. ©2017 Couchbase Inc. Models for Representing Data Data Concern Relational Model JSON Document Model (NoSQL) Rich Structure  Multiple flat tables  Constant assembly / disassembly  Documents  No assembly required! Relationships  Represented  Queried (SQL)  Represented  N1QL Value Evolution  Data can be updated  Data can be updated Structure Evolution  Uniform and rigid  Manual change, requires downtime  Flexible  Dynamic change
  19. 19. ©2017 Couchbase Inc.©2017 Couchbase Inc. 19 SQL for NoSQL: Considerations
  20. 20. ©2017 Couchbase Inc. Why NoSQL? •Agility •Scalability •Performance •Availability
  21. 21. ©2017 Couchbase Inc. Business Use Cases Drive Applications How many new customers we got last month? Process Order Checkout Search stores for the shoe customer is looking for? Generate a list of shipment due today Load the new inventory data Retrieve the customer order Merge the customer lists
  22. 22. ©2017 Couchbase Inc. ©2015 Couchbase Inc. 22 ResultSet
  23. 23. ©2017 Couchbase Inc. NoSQL Data Access • NoSQL systems provide specialized APIs • Key-Value get and set • Script based query APIs • Limited declarative query • Richer query is needed
  24. 24. ©2017 Couchbase Inc. ©2015 Couchbase Inc. 24 { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" }, { "type" : "master", "cardnum" : "6274-2842-2847-3909", "expiry" : "2019-03" } ], "Connections" : [ { "CustId" : "XYZ987", "Name" : "Joe Smith" }, { "CustId" : "PQR823", "Name" : "Dylan Smith" } { "CustId" : "PQR823", "Name" : "Dylan Smith" } ], "Purchases" : [ { "id":12, item: "mac", "amt": 2823.52 } { "id":19, item: "ipad2", "amt": 623.52 } ] } LoyaltyInfo ResultDocuments Orders CUSTOMER • NoSQL systems provide specialized APIs • Key-Value get and set • Each task requires custom built program • Should test & maintain it
  25. 25. ©2017 Couchbase Inc. Client Side Implementation of Query is Inadequate Find High-Value Customers with Orders > $10000 Query customer objects from database • Complex codes and logic • Inefficient processing on client side For each customer object Find all the order objects for the customer Calculate the total amount for each order Sum up the grand total amount for all orders If grand total amount > $10000, Extract customer data Add customer to the high-value customer list Sort the high-value customer list LOOPING OVER MILLIONS OF CUSTOMERS IN APPLICATION!!!
  26. 26. ©2017 Couchbase Inc. Why SQL for NoSQL?
  27. 27. ©2017 Couchbase Inc. Considerations • Flexible Schema • Cannot rely on predefined schema • columns, data types, data comparison • Nested Objects • support scalars, objects and array • SQL operators on nested objects • Work with distributed data store • Query Performance Optimization • Exploit data store performance • Design right kinds of indices • Optimizer { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" }, { "type" : "master", "cardnum" : "6274-2842-2847-3909", "expiry" : "2019-03" } ], "address" : { "Street" : "10, Downing Street", "City" : "San Francico", "State" : "California", "zip" :94401 } }
  28. 28. ©2017 Couchbase Inc. Industry Is Extending SQL to Query JSON • JSON support in SQL • IBM Informix • Oracle • PostgreSQL • MySQL • Microsoft: SQL for DocumentDB, Cosmos DB • UC San Diego: SQL++ • Couchbase: N1QL
  29. 29. ©2017 Couchbase Inc.©2017 Couchbase Inc. 29 N1QL: SQL for JSON
  30. 30. ©2017 Couchbase Inc. ©2015 Couchbase Inc. 30 ResultSet
  31. 31. ©2017 Couchbase Inc. ©2015 Couchbase Inc. 31 { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" }, { "type" : "master", "cardnum" : "6274-2842-2847-3909", "expiry" : "2019-03" } ], "Connections" : [ { "CustId" : "XYZ987", "Name" : "Joe Smith" }, { "CustId" : "PQR823", "Name" : "Dylan Smith" } { "CustId" : "PQR823", "Name" : "Dylan Smith" } ], "Purchases" : [ { "id":12, item: "mac", "amt": 2823.52 } { "id":19, item: "ipad2", "amt": 623.52 } ] } LoyaltyInfo ResultDocuments Orders CUSTOMER
  32. 32. ©2017 Couchbase Inc. N1QL: Approach SELECT c.name, c.address.zip, c.phone[0] FROM customer c WHERE c.address.zip = 94587 AND ANY s IN c.status SATISFIES s = "Premium" END AND purchases IS NOT MISSING; { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-2847-3909", "expiry" : "2019-03" }, { "type" : "master", "cardnum" : "6274-2842-2847-3909", "expiry" : "2019-03" } ], "address" : { "Street" : "10, Downing Street", "City" : "San Francico", "State" : "California", "zip" :94401 }, "phone" : [ "phone" :"415-847-2848", "phone" :"510-492-2984", "phone" :"650-292-9143", ] }
  33. 33. ©2017 Couchbase Inc. N1QL: Goal Give developers and enterprises an expressive, powerful, and complete language for querying, transforming, and manipulating JSON data.
  34. 34. ©2017 Couchbase Inc.©2017 Couchbase Inc. 34 N1QL: Features
  35. 35. ©2017 Couchbase Inc. N1QL: SELECT Statement SELECT customers.id, customers.NAME.lastname, customers.NAME.firstname Sum(orderline.amount) FROM orders UNNEST orders.lineitems AS orderline JOIN customers ON KEYS orders.custid WHERE customers.state = 'NY' GROUP BY customers.id, customers.NAME.lastname, customers.NAME.firstname HAVING sum(orderline.amount) > 10000 ORDER BY sum(orderline.amount) DESC Dotted sub-document reference Names are CASE-SENSITIVE Aggregate on a value within array Access bucket (keyspace) Flatten Array
  36. 36. ©2017 Couchbase Inc. N1QL: Examples INSERT INTO CUSTOMER VALUES("PQR847", {"C_ID":4723, "Name":"Joe"}); INSERT INTO CUSTOMER VALUES("key1", {"C_ID":4823, "Name":"Sam"}), VALUES("key2", {"C_ID":8282, "Name":"Dan"}), VALUES("key3", {"C_ID":4352, "Name":"Jane"}); UPDATE CUSTOMER c SET c.STATE="CA", c.C_ZIP = 94501 WHERE c.ID = 4723;
  37. 37. ©2017 Couchbase Inc. N1QL: Composable SELECT Statement SELECT * FROM ( SELECT a, b, c FROM us_cust WHERE x = 1 UNION ALL SELECT a, b, c FROM canada_cust WHERE y = 2 ) AS newtab LEFT OUTER JOIN contacts ON KEYS newtab.c.contactid ORDER BY a, b, c LIMIT 10 OFFSET 100
  38. 38. ©2017 Couchbase Inc. N1QL: SELECT Statement Highlights • Querying across relationships • JOINs • Subqueries • Aggregation • MIN, MAX • SUM, COUNT, AVG,ARRAY_AGG [ DISTINCT ] • Combining result sets using set operators • UNION, UNIONALL, INTERSECT, EXCEPT
  39. 39. ©2017 Couchbase Inc. N1QL : Query Operators [ 1 of 2 ] • USE KEYS … • Direct primary key lookup bypassing index scans • Ideal for hash-distributed datastore • Available in SELECT, UPDATE, DELETE • JOIN … ON KEYS … • Nested loop JOIN using key relationships • Ideal for hash-distributed datastore • Current implementation supports INNER and LEFT OUTER joins
  40. 40. ©2017 Couchbase Inc. N1QL : Query Operators [ 2 of 2 ] • NEST • Special JOIN that embeds external child documents under their parent • Ideal for JSON encapsulation • UNNEST • Flattening JOIN that surfaces nested objects as top-level documents • Ideal for decomposing JSON hierarchies JOIN, NEST, and UNNEST can be chained in any combination
  41. 41. ©2017 Couchbase Inc. N1QL : Expressions for JSON ©2014 Couchbase, Inc. 41 Ranging over collections • WHERE ANY c IN children SATISFIES c.age > 10 END • WHERE EVERY r IN ratings SATISFIES r > 3 END Mapping with filtering • ARRAY c.name FOR c IN children WHEN c.age > 10 END Deep traversal, SET, and UNSET • WHERE ANY node WITHIN request SATISFIES node.type = "xyz" END • UPDATE doc UNSET c.field1 FOR c WITHIN doc END Dynamic Construction • SELECT { "a": expr1, "b": expr2 } AS obj1, name FROM … // Dynamic object • SELECT [ a, b ] FROM … // Dynamic array Nested traversal • SELECT x.y.z, a[0] FROM a.b.c … IS [ NOT ] MISSING • WHERE name IS MISSING
  42. 42. ©2017 Couchbase Inc. N1QL : DataTypes from JSON N1QL supports all JSON data types • Numbers • Strings • Booleans • Null • Arrays • Objects
  43. 43. ©2017 Couchbase Inc. N1QL : DataType Handling Non-JSON data types • MISSING • Binary Data type handling • Date functions for string and numeric encodings • Total ordering across all data types • Well defined semantics for ORDER BY and comparison operators • Defined expression semantics for all input data types • No type mismatch errors
  44. 44. ©2017 Couchbase Inc. N1QL: Data Modification Statements • UPDATE … SET … WHERE … • DELETE FROM … WHERE … • INSERT INTO … ( KEY, VALUE ) VALUES … • INSERT INTO … ( KEY …, VALUE … ) SELECT … • MERGE INTO … USING … ON … WHEN [ NOT ] MATCHED THEN … Note: Couchbase provides per-document atomicity.
  45. 45. ©2017 Couchbase Inc. N1QL: Data Modification Statements INSERT INTO ORDERS (KEY, VALUE) VALUES ("1.ABC.X382", {"O_ID":482, "O_D_ID":3, "O_W_ID":4}); UPDATE ORDERS SET O_CARRIER_ID = "ABC987" WHERE O_ID = 482 AND O_D_ID = 3 AND O_W_ID = 4 DELETE FROM NEW_ORDER WHERE NO_D_ID = 291 AND NO_W_ID = 3482 AND NO_O_ID = 2483 JSON literals can be used in any expression
  46. 46. ©2017 Couchbase Inc.©2017 Couchbase Inc. 46 N1QL: Indexing
  47. 47. ©2017 Couchbase Inc. Index Statements • CREATE INDEX ON … • DROP INDEX … • EXPLAIN …
  48. 48. ©2017 Couchbase Inc. Index Overview: Secondary Index  Secondary Index can be created on any combination of attribute names.  CREATE INDEX idx_cust_cardnum customer(ccInfo.cardNumber, postalcode)  Useful in speeding up the queries.  Need to have matching indices with right key-ordering  (ccInfo.cardExpiry, postalCode)  (type, state, lastName, firstName) "customer": { "ccInfo": { "cardExpiry": "2015-11-11", "cardNumber":"1212-232-1234", "cardType": "americanexpress" }, "customerId": "customer534", "dateAdded": "2014-04-06", "dateLastActive":"2014-05-02", "emailAddress":"iles@kertz.name", "firstName": "Mckayla", "lastName": "Brown", "phoneNumber": "1-533-290-6403", "postalCode": "92341", "state": "VT", "type": "customer" } Document key: "customer534"
  49. 49. ©2017 Couchbase Inc. Index types and options 49 Index Type Description 1 Primary Index Index on the document key on the whole bucket 2 Named Primary Index Give name for the primary index. Allows multiple primary indexes in the cluster 3 Secondary Index Index on the key-value or document-key 4 Secondary Composite Index Index on more than one key-value 5 Functional Index Index on function or expression on key-values 6 Array Index Index individual elements of the arrays 7 Partial Index Index subset of items in the bucket 8 Covering Index Query able to answer using the the data from the index and skips retrieving the item. 9 Duplicate/Replica Index This is not type of index. Feature of indexing that allows load balancing. Thus providing scale-out, multi-dimensional scaling, performance, and high availability.
  50. 50. ©2017 Couchbase Inc.©2017 Couchbase Inc. 50 N1QL: Architecture
  51. 51. ©2017 Couchbase Inc. Couchbase Server Cluster Service Deployment 51 STORAGE Couchbase Server 1 SHARD 7 SHARD 9 SHARD 5 SHARDSHARDSHARD Managed Cache Cluster ManagerCluster Manager Managed Cache Storage Data Service STORAGE Couchbase Server 2 Managed Cache Cluster ManagerCluster Manager Data Service STORAGE Couchbase Server 3 SHARD 7 SHARD 9 SHARD 5 SHARDSHARDSHARD Managed Cache Cluster ManagerCluster Manager Data Service STORAGE Couchbase Server 4 SHARD 7 SHARD 9 SHARD 5 SHARDSHARDSHARD Managed Cache Cluster ManagerCluster Manager Query Service STORAGE Couchbase Server 5 SHARD 7 SHARD 9 SHARD 5 SHARDSHARDSHARD Managed Cache Cluster ManagerCluster Manager Query Service STORAGE Couchbase Server 6 SHARD 7 SHARD 9 SHARD 5 SHARDSHARDSHARD Managed Cache Cluster ManagerCluster Manager Index Service Managed Cache Storage Managed Cache Storage Storage STORAGE Couchbase Server 6 SHARD 7 SHARD 9 SHARD 5 SHARDSHARDSHARD Managed Cache Cluster ManagerCluster Manager Index Service Storage Managed Cache Managed Cache SDK JDBC
  52. 52. ©2017 Couchbase Inc. N1QL: Query Execution Flow Clients 1. Submit the query over REST API 8. Query result 2. Parse, Analyze, create Plan 7. Evaluate: Documents to results 3. Scan Request; index filters 6. Fetch the documents Index Service Query Service Data Service 4. Get qualified doc keys 5. Fetch Request, doc keys SELECT c_id, c_first, c_last, c_max FROM CUSTOMER WHERE c_id = 49165; { "c_first": "Joe", "c_id": 49165, "c_last": "Montana", "c_max" : 50000 }
  53. 53. ©2017 Couchbase Inc. N1QL: Inside the Query Service Client FetchParse Plan Join Filter Pre-Aggregate Offset Limit ProjectSortAggregateScan Query Service Index Service Data Service
  54. 54. ©2017 Couchbase Inc.©2017 Couchbase Inc. 54 N1QL: Ecosystem
  55. 55. ©2017 Couchbase Inc.©2016 Couchbase Inc. 55 Enterprise Ecosystem via JDBC/ODBC JDBC ODBC SDK
  56. 56. ©2017 Couchbase Inc.©2017 Couchbase Inc. 56 SQL to N1QL: Summary
  57. 57. ©2017 Couchbase Inc. ©2015 Couchbase Inc. 57 Find High-Value Customers with Orders > $10000 With SQL Without SQL Query customer objects from database • Proven and expressive query language • Leverage SQL skills and ecosystem • Extended for JSON • Complex codes and logic • Inefficient processing on client side For each customer object Find all the order objects for the customer Calculate the total amount for each order Sum up the grand total amount for all orders If grand total amount > $10000, Extract customer data Add customer to the high-value customer list Sort the high-value customer list SELECT Customers.ID, Customers.Name, SUM(OrderLine.Amount) FROM Orders UNNEST Orders.LineItems AS OrderLine JOIN Customers ON KEYS Orders.CustID GROUP BY Customers.ID, Customers.Name HAVING SUM(OrderLine.Amount) > 10000 ORDER BY SUM(OrderLine.Amount) DESC LOOPING OVER MILLIONS OF CUSTOMERS IN APPLICATION!!!
  58. 58. ©2017 Couchbase Inc. Mapping SQL to N1QL: Concepts 58 SQL Couchbase-N1QL Database Bucket Table Bucket, Keyspace Row JSON document Column Key-value attribute Index index SQL Data types JSON Data types JOIN JOIN – INNER JOIN, LEFT OUTER JOIN Primary key Document key
  59. 59. ©2017 Couchbase Inc. Mapping SQL to N1QL 59 SQL Couchbase-N1QL CREATE TABLE couchbase-cli bucket-create ALTER TABLE UPDATE customer SET, UNSET CREATE INDEX i1 on t(a, b, c DESC); CREATE INDEX i1 on t(a, b, c DESC); INSERT INTO INSERT INTO SELECT SELECT JOINS JOIN – INNER JOIN, LEFT OUTER JOIN GROUP BY, HAVING GROUP BY, HAVING ORDER BY a ASC, b DESC ORDER BY a ASC, b DESC OFFSET, LIMIT OFFSET, LIMIT Subqueries Subqueries DELETE FROM DELETE FROM UPDATE UPDATE MERGE MERGE
  60. 60. ©2017 Couchbase Inc. Mapping SQL to N1QL 60 SQL Couchbase-N1QL PREPARE PREPARE EXECUTE EXZECUTE GRANT GRANT ROLE REVOKE REVOKE ROLE EXPLAIN EXPLAIN DESCRIBE INFER
  61. 61. ©2017 Couchbase Inc. Bringing SQL to NoSQL 61 Query Features SQL on RDBMS SQL on NoSQL Statements  SELECT, INSERT, UPDATE, DELETE, MERGE  SELECT, INSERT, UPDATE, DELETE, MERGE Query Operations  Select, Join, Project, Subqueries  Strict Schema  Strict Type checking  Select, Join, Project, Subqueries  Nest & Unnest  Look Ma! No Type Mismatch Errors!  JSON keys act as columns Schema  Predetermined Columns  Fully addressable JSON  Flexible document structure Data Types  SQL Data types  Conversion Functions  JSON Data types  Conversion Functions Query Processing  INPUT: Sets of Tuples  OUPUT: Set of Tuples  INPUT: Sets of JSON  OUTPUT: Set of JSON
  62. 62. ©2017 Couchbase Inc. 62 Kevin Holder kevin@couchbase.com Keshav Murthy keshav@couchbase.com
  63. 63. ©2017 Couchbase Inc.©2017 Couchbase Inc. ThankYou! 63
  64. 64. ©2017 Couchbase Inc. 64 The CouchbaseConnect mobile app Take our in-app survey!
  65. 65. ©2017 Couchbase Inc. 65 Share your opinion on Couchbase 1. Go here: http://gtnr.it/2eRxYWn 2. Create a profile 3. Provide feedback (~15 minutes)
  66. 66. ©2017 Couchbase Inc.©2017 Couchbase Inc. Follow us on social media Twitter @couchbase Facebook /couchbase Instagram @couchbase Linkedin /company/couchbase

×