SlideShare a Scribd company logo
Querying NoSQL with SQL
HAVINGYour JSON Cake and SELECTing it too
Matthew D. Groves, @mgroves
©2017 Couchbase Inc. 2
Agenda
Why NoSQL?
JSON Data Modeling
SQL for JSON
Ecosystem and convergence
©2017 Couchbase Inc. 3
Where am I?
• MIGANG – Great Lakes Area .NET User Group
• http://migang.org/
• https://www.meetup.com/Great-Lakes-Area-NET-User-Group-
MIGANG/
©2017 Couchbase Inc. 4
Who am I?
• Matthew D. Groves
• Developer Advocate for Couchbase
• @mgroves onTwitter
• Podcast and blog: http://crosscuttingconcerns.com
• “I am not an expert, but I am an enthusiast.” – Alan Stevens
Querying NoSQL with SQL
HAVINGYour JSON Cake and
SELECTing it too
Matthew D. Groves, @mgroves
©2017 Couchbase Inc. 6
Major Enterprises Across Industries are Adopting NoSQL
6
CommunicationsTechnology
Travel & Hospitality Media &
Entertainment
E-Commerce &
Digital Advertising
Retail & Apparel
Games & GamingFinance &
Business Services
©2017 Couchbase Inc. 7
Why NoSQL?
©2017 Couchbase Inc. 8
NoSQL Landscape
Document
• Couchbase
• MongoDB
• DynamoDB
• DocumentDB
Graph
• OrientDB
• Neo4J
• DEX
• GraphBase
Key-Value
• Couchbase
• Riak
• BerkeleyDB
• Redis
• … Wide Column
• Hbase
• Cassandra
• Hypertable
©2017 Couchbase Inc. 9
NoSQL Landscape
Document
• Couchbase
• MongoDB
• DynamoDB
• DocumentDB
• Get by key(s)
• Set by key(s)
• Replace by key(s)
• Delete by key(s)
• Map/Reduce
©2017 Couchbase Inc. 10
Why NoSQL? Scalability
©2017 Couchbase Inc. 11
Why NoSQL? Scalability
©2017 Couchbase Inc. 12
Why NoSQL? Flexibility
©2017 Couchbase Inc. 13
Why NoSQL? Performance
©2017 Couchbase Inc. 14
Why NoSQL? Availability
©2017 Couchbase Inc. 15
JSON Data Modeling
©2017 Couchbase Inc. 16
Models for Representing Data
Data Concern Relational Model JSON Document Model
Rich Structure
Relationships
Value Evolution
Structure Evolution
©2017 Couchbase Inc. 17
Properties of Real-World Data
©2017 Couchbase Inc. 18
Modeling Data in RelationalWorld
Billing
ConnectionsPurchases
Contacts
Customer
CustomerID Name DOB
CBL2015 Jane Smith 1990-01-30
Table: Customer
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30”
}
Customer DocumentKey: CBL2015
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
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
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
{
"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 master 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
©2017 Couchbase Inc. 24
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
 Queried? Not until now…
Value Evolution  Data can be updated  Data can be updated
Structure Evolution
 Uniform and rigid
 Manual change (disruptive)
 Flexible
 Dynamic change
©2017 Couchbase Inc. 25
SQL for JSON
©2017 Couchbase Inc. 26
Why SQL for JSON?
©2017 Couchbase Inc. 27
Client Side Querying is Inadequate
Example: Find High-Value Customers with Orders > $10000
Query ‘customer’
objects from
database
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
©2017 Couchbase Inc. 28
Goal of Query for JSON
Give developers and enterprises an expressive,
powerful, and complete language for querying,
transforming, and manipulating JSON data.
©2017 Couchbase Inc. 29
SELECT: JOIN
©2017 Couchbase Inc. 30
SELECT: Aggregation
©2017 Couchbase Inc. 31
SELECT: Aggregation
MIN
MAX
SUM
COUNT
AVG
ARRAY_AGG [ DISTINCT ]
©2017 Couchbase Inc. 32
SELECT: UNION, UNION ALL, INTERSECT, EXCEPT
©2017 Couchbase Inc. 33
USE KEYS
©2017 Couchbase Inc. 34
UNNEST (aka JOIN)
©2017 Couchbase Inc. 35
UNNEST (aka JOIN)
©2017 Couchbase Inc. 36
UNNEST (aka JOIN)
©2017 Couchbase Inc. 37
UNNEST (aka JOIN)
©2017 Couchbase Inc. 38
NEST
©2017 Couchbase Inc. 39
NEST
©2017 Couchbase Inc. 40
NEST
©2017 Couchbase Inc. 41
Composability
JOIN, NEST, and UNNEST
can be chained in any combination
©2017 Couchbase Inc. 42
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
HAVING sum(orderline.amount) > 10000
ORDER BY sum(orderline.amount) DESC
• Dotted sub-document reference
• Names are CASE-SENSITIVE
• UNNEST to flatten the arrays
JOINS with Document KEY of
customers
©2017 Couchbase Inc. 43
SELECT: Subqueries
©2017 Couchbase Inc. 44
ResultSet
©2017 Couchbase Inc. 45
{
"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
CosmosDb
SQL
©2017 Couchbase Inc. 46
N1QL (Couchbase)
©2017 Couchbase Inc. 47
SQL (DocumentDb CosmosDb)
 https://www.documentdb.com/sql/demo
©2017 Couchbase Inc. 48
SQL CosmosDb SQL
SQL standard JSON stuff
©2017 Couchbase Inc. 49
Demo: N1QL
©2017 Couchbase Inc. 50
Other JSON "Stuff"
©2014 Couchbase, Inc. 50
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
DynamicConstruction
• 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
©2017 Couchbase Inc. 51
DataTypes in JSON
N1QL supports all JSON data types
 Numbers
 Strings
 Booleans
 Null
 Arrays
 Objects
©2017 Couchbase Inc. 52
DataType Handling
Non-JSON data types: MISSING and Binary
©2017 Couchbase Inc. 53
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 ] MATCHEDTHEN …
©2017 Couchbase Inc. 54
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
©2017 Couchbase Inc. 55
Index Statements
 CREATE INDEX ON …
 DROP INDEX …
 EXPLAIN …
https://dzone.com/articles/index-first-and-query-faster
©2017 Couchbase Inc. 56
Index Overview: Secondary Index
CREATE INDEX idx_cust_cardnum
customer(ccInfo.cardNumber, postalcode)
…(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”
©2017 Couchbase Inc. 57
Find High-Value Customers with Orders > $10000
Query customer
objects from
database
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
©2017 Couchbase Inc. 58
Summary: SQL & SQL for JSON
Query Features SQL SQL for JSON
Statements
 SELECT, INSERT, UPDATE, DELETE,
MERGE
 SELECT, INSERT, UPDATE, DELETE,
MERGE
Query Operations
 Select, Join, Project, Subqueries
 Strict Schema
 StrictType checking
 Select, Join, Project, Subqueries
 Nest & Unnest
 Look Ma! NoType Mismatch Errors!
 JSON keys act as columns
Schema  Predetermined Columns
 Fully addressable JSON
 Flexible document structure
DataTypes
 SQL Data types
 Conversion Functions
 JSON Data types
 Conversion Functions
Query Processing
 INPUT: Sets ofTuples
 OUPUT: Set ofTuples
 INPUT: Sets of JSON
 OUTPUT: Set of JSON
©2017 Couchbase Inc. 59
Summary: N1QL and CosmosDB SQL
Query Features N1QL CosmosDB SQL
SELECT Yes Yes
INSERT, UPDATE, DELETE, MERGE Yes No
Intra-document join Yes: UNNEST Yes: JOIN
Inter-document join Yes: JOIN, NEST No
Aggregation (GROUP BY, SUM,MAX,MIN) Yes No GROUP BY
Stored Procedures,Triggers, UDF No Kinda (JavaScript)
©2017 Couchbase Inc. 60
SQL for JSON
SQL++
N1QL
http://tinyurl.com/UCSDsql
©2017 Couchbase Inc. 61
Couchbase Analytics (CBAS) and SQL++
©2017 Couchbase Inc. 62
©2017 Couchbase Inc. 63
Industry is Choosing SQL to Query JSON
©2017 Couchbase Inc. 64
JSON in SQL Server
©2017 Couchbase Inc. 65
Ecosystem
©2017 Couchbase Inc. 66
Ecosystem Integration
+
©2017 Couchbase Inc. 67
Ecosystem Integration
ottoman
©2017 Couchbase Inc. 68
Ecosystem Integration
©2017 Couchbase Inc. 69
Try SQL for JSON
http://query.pub.couchbase.com/tutorial/
https://www.documentdb.com/sql/demo
©2017 Couchbase Inc. 70
Podcast
https://blog.couchbase.com/tag/podcast/
©2017 Couchbase Inc. 71
Couchbase, everybody!
©2017 Couchbase Inc. 72
Where do you find us?
• blog.couchbase.com
• @couchbasedev
• @mgroves
©2017 Couchbase Inc. 73
Frequently Asked Questions
1. How is Couchbase different than Mongo?
2. Is Couchbase the same thing as CouchDb?
3. How did you get to be both incredibly handsome and
tremendously intelligent?
4. What is the Couchbase licensing situation?
5. Is Couchbase a Managed Cloud Service?

More Related Content

PPTX
Query in Couchbase. N1QL: SQL for JSON
PPTX
Querying NoSQL with SQL - KCDC - August 2017
PPTX
N1QL workshop: Indexing & Query turning.
PPTX
Tuning for Performance: indexes & Queries
PPTX
IBM Db2 JSON 11.5
PPTX
SQL for JSON: Rich, Declarative Querying for NoSQL Databases and Applications 
PPTX
Introducing N1QL: New SQL Based Query Language for JSON
PPTX
Json data modeling june 2017 - pittsburgh tech fest
Query in Couchbase. N1QL: SQL for JSON
Querying NoSQL with SQL - KCDC - August 2017
N1QL workshop: Indexing & Query turning.
Tuning for Performance: indexes & Queries
IBM Db2 JSON 11.5
SQL for JSON: Rich, Declarative Querying for NoSQL Databases and Applications 
Introducing N1QL: New SQL Based Query Language for JSON
Json data modeling june 2017 - pittsburgh tech fest

Similar to Querying NoSQL with SQL - MIGANG - July 2017 (20)

PPTX
Bringing SQL to NoSQL: Rich, Declarative Query for NoSQL
PPTX
JSON Data Modeling - GDG Indy - April 2020
PPTX
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
PPTX
JSON Data Modeling - July 2018 - Tulsa Techfest
PPTX
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
PPTX
From SQL to NoSQL: Structured Querying for JSON
PPTX
Couchbase N1QL: Language & Architecture Overview.
PPTX
Utilizing Arrays: Modeling, Querying and Indexing
PPTX
N1QL+GSI: Language and Performance Improvements in Couchbase 5.0 and 5.5
PPTX
N1QL: What's new in Couchbase 5.0
PDF
Data Modeling and Relational to NoSQL
PPTX
NoSQL Data Modeling using Couchbase
PPTX
Mis04
PPTX
Docker Summit MongoDB - Data Democratization
PPTX
Application Development & Database Choices: Postgres Support for non Relation...
 
PDF
Slides: Moving from a Relational Model to NoSQL
PPTX
Back to the future : SQL 92 for Elasticsearch ? @nosqlmatters Dublin 2014
PPTX
Putting the SQL Back in NoSQL - October 2022 - All Things Open
PDF
MongoDB Stitch Introduction
PDF
JSON Data Modeling in Document Database
Bringing SQL to NoSQL: Rich, Declarative Query for NoSQL
JSON Data Modeling - GDG Indy - April 2020
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
JSON Data Modeling - July 2018 - Tulsa Techfest
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
From SQL to NoSQL: Structured Querying for JSON
Couchbase N1QL: Language & Architecture Overview.
Utilizing Arrays: Modeling, Querying and Indexing
N1QL+GSI: Language and Performance Improvements in Couchbase 5.0 and 5.5
N1QL: What's new in Couchbase 5.0
Data Modeling and Relational to NoSQL
NoSQL Data Modeling using Couchbase
Mis04
Docker Summit MongoDB - Data Democratization
Application Development & Database Choices: Postgres Support for non Relation...
 
Slides: Moving from a Relational Model to NoSQL
Back to the future : SQL 92 for Elasticsearch ? @nosqlmatters Dublin 2014
Putting the SQL Back in NoSQL - October 2022 - All Things Open
MongoDB Stitch Introduction
JSON Data Modeling in Document Database
Ad

More from Matthew Groves (20)

PPTX
CREAM - That Conference Austin - January 2024.pptx
PPTX
FluentMigrator - Dayton .NET - July 2023
PPTX
Cache Rules Everything Around Me - DevIntersection - December 2022
PPTX
Cache Rules Everything Around Me - Momentum - October 2022.pptx
PPTX
Don't Drop ACID (July 2021)
PPTX
Don't Drop ACID - Data Love - April 2021
PPTX
Demystifying NoSQL - All Things Open - October 2020
PPTX
Autonomous Microservices - Manning - July 2020
PPTX
CONDG April 23 2020 - Baskar Rao - GraphQL
PPTX
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
PPTX
Intro to SQL++ - Detroit Tech Watch - June 2019
PPTX
Autonomous Microservices - CodeMash - January 2019
PPTX
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
PPTX
5 NoSQL Options - Toronto - May 2018
PPTX
Full stack development with node and NoSQL - All Things Open - October 2017
PPTX
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
PPTX
I Have a NoSQL toaster - DC - August 2017
PPTX
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
PDF
I have a NoSQL Toaster - ConnectJS - October 2016
PDF
Full stack development with Node and NoSQL - Austin Node.JS Group - October ...
CREAM - That Conference Austin - January 2024.pptx
FluentMigrator - Dayton .NET - July 2023
Cache Rules Everything Around Me - DevIntersection - December 2022
Cache Rules Everything Around Me - Momentum - October 2022.pptx
Don't Drop ACID (July 2021)
Don't Drop ACID - Data Love - April 2021
Demystifying NoSQL - All Things Open - October 2020
Autonomous Microservices - Manning - July 2020
CONDG April 23 2020 - Baskar Rao - GraphQL
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
Intro to SQL++ - Detroit Tech Watch - June 2019
Autonomous Microservices - CodeMash - January 2019
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
5 NoSQL Options - Toronto - May 2018
Full stack development with node and NoSQL - All Things Open - October 2017
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
I Have a NoSQL toaster - DC - August 2017
I Have a NoSQL Toaster - Troy .NET User Group - July 2017
I have a NoSQL Toaster - ConnectJS - October 2016
Full stack development with Node and NoSQL - Austin Node.JS Group - October ...
Ad

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation theory and applications.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Cloud computing and distributed systems.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation theory and applications.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
MIND Revenue Release Quarter 2 2025 Press Release
Diabetes mellitus diagnosis method based random forest with bat algorithm
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
Reach Out and Touch Someone: Haptics and Empathic Computing
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
Big Data Technologies - Introduction.pptx

Querying NoSQL with SQL - MIGANG - July 2017

  • 1. Querying NoSQL with SQL HAVINGYour JSON Cake and SELECTing it too Matthew D. Groves, @mgroves
  • 2. ©2017 Couchbase Inc. 2 Agenda Why NoSQL? JSON Data Modeling SQL for JSON Ecosystem and convergence
  • 3. ©2017 Couchbase Inc. 3 Where am I? • MIGANG – Great Lakes Area .NET User Group • http://migang.org/ • https://www.meetup.com/Great-Lakes-Area-NET-User-Group- MIGANG/
  • 4. ©2017 Couchbase Inc. 4 Who am I? • Matthew D. Groves • Developer Advocate for Couchbase • @mgroves onTwitter • Podcast and blog: http://crosscuttingconcerns.com • “I am not an expert, but I am an enthusiast.” – Alan Stevens
  • 5. Querying NoSQL with SQL HAVINGYour JSON Cake and SELECTing it too Matthew D. Groves, @mgroves
  • 6. ©2017 Couchbase Inc. 6 Major Enterprises Across Industries are Adopting NoSQL 6 CommunicationsTechnology Travel & Hospitality Media & Entertainment E-Commerce & Digital Advertising Retail & Apparel Games & GamingFinance & Business Services
  • 7. ©2017 Couchbase Inc. 7 Why NoSQL?
  • 8. ©2017 Couchbase Inc. 8 NoSQL Landscape Document • Couchbase • MongoDB • DynamoDB • DocumentDB Graph • OrientDB • Neo4J • DEX • GraphBase Key-Value • Couchbase • Riak • BerkeleyDB • Redis • … Wide Column • Hbase • Cassandra • Hypertable
  • 9. ©2017 Couchbase Inc. 9 NoSQL Landscape Document • Couchbase • MongoDB • DynamoDB • DocumentDB • Get by key(s) • Set by key(s) • Replace by key(s) • Delete by key(s) • Map/Reduce
  • 10. ©2017 Couchbase Inc. 10 Why NoSQL? Scalability
  • 11. ©2017 Couchbase Inc. 11 Why NoSQL? Scalability
  • 12. ©2017 Couchbase Inc. 12 Why NoSQL? Flexibility
  • 13. ©2017 Couchbase Inc. 13 Why NoSQL? Performance
  • 14. ©2017 Couchbase Inc. 14 Why NoSQL? Availability
  • 15. ©2017 Couchbase Inc. 15 JSON Data Modeling
  • 16. ©2017 Couchbase Inc. 16 Models for Representing Data Data Concern Relational Model JSON Document Model Rich Structure Relationships Value Evolution Structure Evolution
  • 17. ©2017 Couchbase Inc. 17 Properties of Real-World Data
  • 18. ©2017 Couchbase Inc. 18 Modeling Data in RelationalWorld Billing ConnectionsPurchases Contacts Customer
  • 19. CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30” } Customer DocumentKey: CBL2015
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. { "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 master 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
  • 24. ©2017 Couchbase Inc. 24 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  Queried? Not until now… Value Evolution  Data can be updated  Data can be updated Structure Evolution  Uniform and rigid  Manual change (disruptive)  Flexible  Dynamic change
  • 25. ©2017 Couchbase Inc. 25 SQL for JSON
  • 26. ©2017 Couchbase Inc. 26 Why SQL for JSON?
  • 27. ©2017 Couchbase Inc. 27 Client Side Querying is Inadequate Example: Find High-Value Customers with Orders > $10000 Query ‘customer’ objects from database 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
  • 28. ©2017 Couchbase Inc. 28 Goal of Query for JSON Give developers and enterprises an expressive, powerful, and complete language for querying, transforming, and manipulating JSON data.
  • 29. ©2017 Couchbase Inc. 29 SELECT: JOIN
  • 30. ©2017 Couchbase Inc. 30 SELECT: Aggregation
  • 31. ©2017 Couchbase Inc. 31 SELECT: Aggregation MIN MAX SUM COUNT AVG ARRAY_AGG [ DISTINCT ]
  • 32. ©2017 Couchbase Inc. 32 SELECT: UNION, UNION ALL, INTERSECT, EXCEPT
  • 33. ©2017 Couchbase Inc. 33 USE KEYS
  • 34. ©2017 Couchbase Inc. 34 UNNEST (aka JOIN)
  • 35. ©2017 Couchbase Inc. 35 UNNEST (aka JOIN)
  • 36. ©2017 Couchbase Inc. 36 UNNEST (aka JOIN)
  • 37. ©2017 Couchbase Inc. 37 UNNEST (aka JOIN)
  • 41. ©2017 Couchbase Inc. 41 Composability JOIN, NEST, and UNNEST can be chained in any combination
  • 42. ©2017 Couchbase Inc. 42 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 HAVING sum(orderline.amount) > 10000 ORDER BY sum(orderline.amount) DESC • Dotted sub-document reference • Names are CASE-SENSITIVE • UNNEST to flatten the arrays JOINS with Document KEY of customers
  • 43. ©2017 Couchbase Inc. 43 SELECT: Subqueries
  • 44. ©2017 Couchbase Inc. 44 ResultSet
  • 45. ©2017 Couchbase Inc. 45 { "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 CosmosDb SQL
  • 46. ©2017 Couchbase Inc. 46 N1QL (Couchbase)
  • 47. ©2017 Couchbase Inc. 47 SQL (DocumentDb CosmosDb)  https://www.documentdb.com/sql/demo
  • 48. ©2017 Couchbase Inc. 48 SQL CosmosDb SQL SQL standard JSON stuff
  • 49. ©2017 Couchbase Inc. 49 Demo: N1QL
  • 50. ©2017 Couchbase Inc. 50 Other JSON "Stuff" ©2014 Couchbase, Inc. 50 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 DynamicConstruction • 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
  • 51. ©2017 Couchbase Inc. 51 DataTypes in JSON N1QL supports all JSON data types  Numbers  Strings  Booleans  Null  Arrays  Objects
  • 52. ©2017 Couchbase Inc. 52 DataType Handling Non-JSON data types: MISSING and Binary
  • 53. ©2017 Couchbase Inc. 53 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 ] MATCHEDTHEN …
  • 54. ©2017 Couchbase Inc. 54 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
  • 55. ©2017 Couchbase Inc. 55 Index Statements  CREATE INDEX ON …  DROP INDEX …  EXPLAIN … https://dzone.com/articles/index-first-and-query-faster
  • 56. ©2017 Couchbase Inc. 56 Index Overview: Secondary Index CREATE INDEX idx_cust_cardnum customer(ccInfo.cardNumber, postalcode) …(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”
  • 57. ©2017 Couchbase Inc. 57 Find High-Value Customers with Orders > $10000 Query customer objects from database 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
  • 58. ©2017 Couchbase Inc. 58 Summary: SQL & SQL for JSON Query Features SQL SQL for JSON Statements  SELECT, INSERT, UPDATE, DELETE, MERGE  SELECT, INSERT, UPDATE, DELETE, MERGE Query Operations  Select, Join, Project, Subqueries  Strict Schema  StrictType checking  Select, Join, Project, Subqueries  Nest & Unnest  Look Ma! NoType Mismatch Errors!  JSON keys act as columns Schema  Predetermined Columns  Fully addressable JSON  Flexible document structure DataTypes  SQL Data types  Conversion Functions  JSON Data types  Conversion Functions Query Processing  INPUT: Sets ofTuples  OUPUT: Set ofTuples  INPUT: Sets of JSON  OUTPUT: Set of JSON
  • 59. ©2017 Couchbase Inc. 59 Summary: N1QL and CosmosDB SQL Query Features N1QL CosmosDB SQL SELECT Yes Yes INSERT, UPDATE, DELETE, MERGE Yes No Intra-document join Yes: UNNEST Yes: JOIN Inter-document join Yes: JOIN, NEST No Aggregation (GROUP BY, SUM,MAX,MIN) Yes No GROUP BY Stored Procedures,Triggers, UDF No Kinda (JavaScript)
  • 60. ©2017 Couchbase Inc. 60 SQL for JSON SQL++ N1QL http://tinyurl.com/UCSDsql
  • 61. ©2017 Couchbase Inc. 61 Couchbase Analytics (CBAS) and SQL++
  • 63. ©2017 Couchbase Inc. 63 Industry is Choosing SQL to Query JSON
  • 64. ©2017 Couchbase Inc. 64 JSON in SQL Server
  • 65. ©2017 Couchbase Inc. 65 Ecosystem
  • 66. ©2017 Couchbase Inc. 66 Ecosystem Integration +
  • 67. ©2017 Couchbase Inc. 67 Ecosystem Integration ottoman
  • 68. ©2017 Couchbase Inc. 68 Ecosystem Integration
  • 69. ©2017 Couchbase Inc. 69 Try SQL for JSON http://query.pub.couchbase.com/tutorial/ https://www.documentdb.com/sql/demo
  • 70. ©2017 Couchbase Inc. 70 Podcast https://blog.couchbase.com/tag/podcast/
  • 71. ©2017 Couchbase Inc. 71 Couchbase, everybody!
  • 72. ©2017 Couchbase Inc. 72 Where do you find us? • blog.couchbase.com • @couchbasedev • @mgroves
  • 73. ©2017 Couchbase Inc. 73 Frequently Asked Questions 1. How is Couchbase different than Mongo? 2. Is Couchbase the same thing as CouchDb? 3. How did you get to be both incredibly handsome and tremendously intelligent? 4. What is the Couchbase licensing situation? 5. Is Couchbase a Managed Cloud Service?

Editor's Notes

  • #3: Spend just a little time on why people are using NoSQL Talk about how data is modeled differently in JSON Let’s talk about why SQL is good and why SQL for JSON is needed Let’s talk about the exciting stuff happening in the database ecosystem Including but not limited to the stuff Couchbase is doing If we have time, we’ll look at how a .NET developer (or Java developer, etc) would interact with SQL for JSON
  • #7: What’s also interesting is that we’re seeing the use of NoSQL expand inside many of these companies. Orbitz, the online travel company, is a great example – they started using Couchbase to store their hotel rate data, and now they use Couchbase in many other ways. Same with ebay, they recently presented at the Couchbase conference with a chart tracking how many instances of various nosql databases are in use, and we see growth in Cassandra, mongo, and couchbase has actually surpassed them within ebay This very hotel brand is using Couchbase, so you may be interacting with it right now
  • #8: SQL (relational) databases are great. They give you LOT OF functionality. Great set of abstractions (tables, columns, data types, constraints, triggers, SQL, ACID TRANSACTIONS, stored procedures and more) at a highly reasonable cost. Change is inevitable One thing RDBMS does not handle well is CHANGE. Change of schema (both logical and physical), change of hardware, change of capacity. NoSQL databases ESPECIALLY ONES DESIGNED TO BE DISTRIBUTED tend to help solve problems with: agility, scalability, performance, and availability
  • #9: Let’s talk about what NoSQL is, first. NoSQL generally refers to databases which lack SQL or don’t use a relational model Once the SQL language, transaction became optional, flurry of databases were created using distinct approaches for common use-cases. KEY-Value simply provided quick access to data for a given KEY. Wide Column databases can store large number of arbitrary columns in each row Graph databases store data and relationships as first class concepts Document databases aggregate data into a hierarchical structure. With JSON is a means to the end. Document databases provide flexible schema,built-in data types, rich structure, implicit relationships using JSON.
  • #10: When we look at document databases, they originally came with a Minimal set of APIs and features But as they continue to mature, we’re seeing more features being added And generally I’m seeing a convergent trend between SQL and NoSQL But anyway, this set of minimal features, lacking a SQL language and tables gives us the buzzword “nosql”
  • #11: Elastic scaling Size your cluster for today Scale out on demand Cost effective scaling Commodity hardware On premise or on cloud Scale OUT instead of Scale UP [example: changing the channel to a soccer game or Game of Thrones, everyone makes the same API request in the same 5 minutes] [example: TV show lets watchers vote during some period of the week, so you can scale up during that period of time] [example: black Friday]
  • #12: Elastic scaling Size your cluster for today Scale out on demand Cost effective scaling Commodity hardware On premise or on cloud Scale OUT instead of Scale UP [example: changing the channel to a soccer game or Game of Thrones, everyone makes the same API request in the same 5 minutes] [example: TV show lets watchers vote during some period of the week, so you can scale up during that period of time] [example: black Friday]
  • #13: Schema flexibility Easier management of change in the business requirements Easier management of change in the structure of the data Sometimes you're pulling together data, integrating from different sources (e.g. ELT) and that flexibility helps Document database means that you have no rigid schema. You can do whatever the heck you want. That being said, you SHOULDN’T. You should still have discipline about your data.
  • #14: NoSQL systems are optimized for specific access patterns Low response time for web & mobile user experience Millisecond latency Consistently high throughput to handle growth [perf measures can be subjective – talk about architecture, integrated cache, maybe mention MDS too]
  • #15: If one tap for pepsi goes out, there’s others available. If one db node goes down, the others will compensate. This is related to scaling Built-in replication and fail-over No application downtime when hardware fails Online maintenance & upgrade No application downtime
  • #16: Let’s talk about data modeling a bit, because storing data in JSON Is different that storing in tables.
  • #17: So I want to compare the approaches over 4 key areas. I’m going to fill in this table, traditional SQL on the left and JSON on the right
  • #18: Let’s look at modeling Customer data. This is an example of what a customer might look like There is a rich structure: attributes, potentially sub-attributes (first name and last name) Relationships: to other data (other customers, to products perhaps) Value evolution: Maybe we’d start with one billing option, change to multiple (data is updated) Structure evolution: Maybe we start without connections and add those later, or we evolve name field to be more than first and last name (data is reshaped)
  • #19: Rich Structure In relational database, this customers data would be stored in five normalized tables. Each time you want to construct a customer object, you JOIN the data in these tables; Each time you persist, you find the appropriate rows in relevant tables and insert/update. Relationship Enforcement is via referential constraints. Objects are constructed by JOINS, EACH time. Value Evolution Additional values of the SAME TYPE (e.g. additional phone, additional address) is managed by additional ROWS in one of the tables. Customer:contacts will have 1:n relationship. Structure Evolution: Imagine we didn't start with a billing table. This is the most difficult part. Changing the structure is difficult, within a table, across tables. While you can do these via ALTER TABLE, requires downtime, migration and application versioning. This is one of the problem document databases try to handle by representing data in JSON.
  • #20: Let’s see how to represent customer data in JSON. The primary (CustomerID) becomes the DocumentKey Column name-Column value becomes KEY-VALUE pair.
  • #21: We aren’t normal form anymore Rich Structure & Relationships Billing information is stored as a sub-document There could be more than a single credit card. So, use an array.
  • #22: Value evolution Simply add additional array element or update a value.
  • #23: 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
  • #24: So, finally, you have a JSON document that represents a CUSTOMER. In a single JSON document, relationship between the data is implicit by use of sub-structures and arrays and arrays of sub-structures.
  • #25: Reference slide
  • #27: I think there's a piece that's missing in many NoSQL databases: robust query capabilities NoSQL systems provide specialized APIs Key-Value get and set Script based query APIs Limited declarative query Map/reduce can be nice, but it does make certain operations harder. Plus it may not feel as natural as SQL if you’ve been using that for decades. (joins, unions, etc)
  • #28: This is how you might have to do it WITHOUT a query language like SQL Complex code and logic Inefficient processing on client side I can do this with k/v calls, map/reduce calls sure, but it’s more complex, and maybe inefficient Less complex, more natural to do this in SQL, more readable
  • #29: SQL is meant for normalized data so what do we do when we have denormalized data, like JSON documents?
  • #30: Go fast over these, since it’s just SQL
  • #31: Go fast over these, since it’s just SQL
  • #32: ARRAY_AGG – array of the non MISSING values in the group, including nulls ARRAY_AGG can optionally use DISTINCT
  • #33: Go fast over these, since it’s just SQL
  • #34: USE is like WHERE for document keys Direct primary key lookup bypassing index scans Ideal for hash-distributed datastore Available in SELECT, UPDATE, DELETE
  • #35: UNNEST is an “intra-document” join UNNEST, flattens it out to the same level Flattening JOIN that surfaces nested objects as top-level documents Ideal for decomposing JSON hierarchies
  • #36: UNNEST is an “intra-document” join UNNEST, flattens it out to the same level Flattening JOIN that surfaces nested objects as top-level documents Ideal for decomposing JSON hierarchies
  • #37: UNNEST is an “intra-document” join UNNEST, flattens it out to the same level Flattening JOIN that surfaces nested objects as top-level documents Ideal for decomposing JSON hierarchies
  • #38: UNNEST is an “intra-document” join UNNEST, flattens it out to the same level Flattening JOIN that surfaces nested objects as top-level documents Ideal for decomposing JSON hierarchies
  • #39: NEST, create a json array in the query result, it’s like the opposite of UNNEST Special JOIN that embeds external child documents under their parent Ideal for JSON encapsulation
  • #40: NEST, create a json array in the query result, it’s like the opposite of UNNEST Special JOIN that embeds external child documents under their parent Ideal for JSON encapsulation
  • #41: NEST, create a json array in the query result, it’s like the opposite of UNNEST Special JOIN that embeds external child documents under their parent Ideal for JSON encapsulation
  • #43: Dot notation for json documents, hierarchy JOIN only works on document keys right now UNNEST to flatten array, kinda like a join within a document itself… flattening
  • #44: Go fast over these, since it’s just SQL
  • #45: SQL language operates on set of relations (table) and then projects another relation (table) Resultset, needs to be mapped to something in application (could be complex, or maybe not), and then you have to map that to complex objects, and then to json Not as natural
  • #46: N1QL is a superset of SQL designed for JSON. Input is set of related sets of JSON documents. It operates on these documents and produces another set of JSON documents.
  • #48: DocumentDb is Microsoft’s document database azure offering It has a SQL syntax available, and it’s pretty good (side note: It has JOIN in its syntax but it’s an intra-document join so it’s more like UNNEST)
  • #49: N1QL is a superset of SQL Additionally, N1QL extends the language to support: -- Fully address, access and modify any part of the JSON document. -- Handle the full flexible schema where schema is self-described by each document. -- key-value pairs could be missing, data types could change and structure could change!
  • #51: These are the additions to SQL to deal with JSON Mention MISSING, it’s semantically different from a field with a null value. A field isn’t there (which is possible with a flexible schema) Ranging over collections, deep traversal might not be in CosmosDb yet
  • #52: Arrays and Objects are not in traditional SQL -- -There are date function for string and numeric encodings - There is no “date” type in JSON, so we store as UNIX timestamp and N1QL has functions for that - Well-defined semantics for ORDER BY and comparison operators - Defined JSON expression semantics for all input data types, so goodbye type mismatch errors - You can SELECT a string as an integer (conversion functions)
  • #53: I’ve already mentioned the concept of “missing” Couchbase can be used to store binary data, and there is some limited N1QL functionality associated with that But that’s a pretty non-typical use case
  • #54: Note: Couchbase provides per-document atomicity. So the UPDATE is not all-or-nothing, failure/success is per document We don’t have transactions CosmosDb doesn't offer these
  • #55: JSON in, JSON out
  • #56: Indexes are important, just like in SQL https://dzone.com/articles/index-first-and-query-faster Functional indexes: on any data expression Partial indexes Some other profiling/monitoring tools coming in 5.0, you can check out a developer build of 5.0 now Indexing in CosmosDb doesn’t use SQL, but it is available with, say, the .NET SDK
  • #57: Just like SQL (primary index is on the document key) Secondary Index can be created on any combination of attribute names. Useful in speeding up the queries. Need to have matching indices with right key-ordering Dotted notation here, CosmosDb uses a different syntax for indexing, which is more like xpath for json
  • #58: Top: Complex code and logic Inefficient processing on client side Bottom: Proven and expressive query language Leverage SQL skills and ecosystem Extended for JSON - More readable
  • #59: Reference/summary slide
  • #60: This chart is not exhaustive, but I think it identifies key points of difference Sprocs on CosmosDb are in Javascript, not SQL
  • #61: UC San Diego: SQL++ Couchbase: N1QL SQL++ is a paper that UC San Diego produced N1QL is pretty much the first implementation of SQL++, validating their paper in a real database
  • #62: Couchbase Analytics is currently a standalone developer preview of a feature that is coming to Couchbase Server. This uses a language that looks like N1QL, is going to converge with N1QL, but has some additional features. It’s intended for analytics, reports, trend analysis, so Couchbase Analytics is not meant to be operational: no direct reads and writes. You can join any field to any other field It’s a public PREVIEW right now, so it is available for you to get, but lots of stuff will change and we don’t recommend it for production.
  • #64: JSON support in SQL IBM Informix Oracle PostgreSQL MySQL All the sql vendors are introducing JSON features
  • #65: SQL Server 2016 introduced JSON_VALUE and some other JSON functions It’s not quite a SQL for JSON implementation, but it’s a step in that direction Here’s a table with two rows, one is an nvarchar with a JSON string JSON_VALUE can be applied to it to parse the JSON and get specific values
  • #67: All of these tools are using JDBC/ODBC driver provided by Simba to connect to Couchbase ODBC opens the door to a ton of integrations, these are just a few Maybe mention Crystal Reports too
  • #68: Couchbase can integrate directly with big data tools using DCP/XDCR instead of a query These don't rely on ODBC but are built specifically to connect to Couchbase For mongo to couchbase, we have ottoman, which has a very close API to mongoose
  • #69: DocumentDb doesn't have any native integrations that I'm aware of yet No ODBC driver afaik (yet) But there are some interesting APIs being provided by DocumentDb and now by CosmosDb DocumentDb provides a mongo API, so you can switch seamlessly With CosmosDb, it's multi-model, so it can work as a graph database using the Gremlin language It can work as a Table database using the Azure Table Storage API So there may be some integrations out there that use those It's important to remember that compared to Couchbase and many other document databases, DocumentDb is very new, so features will come in time. Similarly, compared to Oracle and SQL Server, document databases in general are relatively new, so there are new features And innovations happening every year
  • #70: Documentdb.com link still works as of 7/18/2017 Even though the name has been changed
  • #71: Hosted by couchbase, but we have guests from all different companies to talk about nosql We recently had Kirill Gavrylyuk from the DocumentDb team on an episode, so check that out
  • #72: Start the animation
  • #74: Mongo: Features N1QL, XDCR, Full Text Search, Mobile & Sync. Memory-first architecture and proven, easy scaling. CouchDb: Couchbase started as a whole new piece of software that was basically a combination of memcache and CouchDb a long time ago, but has grown far beyond that. Couchbase isn’t a fork or vice versa. They share an acronym and they are both NoSQL. Like MySQL and SQL Server, for instance. Open source apache license for community edition, enterprise edition on a faster release schedule, some advanced features, and support license. Couchbase is software you can run in the cloud on a VM or on your own data center. CosmosDb is a manage cloud service, but there is a emulator you can run locally.