SlideShare a Scribd company logo
Querying NoSQL with SQL
HAVINGYour JSON Cake and SELECTing it too
Matthew D. Groves, @mgroves
TITANIUM SPONSORS
Platinum Sponsors
Gold Sponsors
©2017 Couchbase Inc. 3
Agenda
Why NoSQL?
JSON Data Modeling
SQL for JSON
Ecosystem and convergence
©2017 Couchbase Inc. 4
Where am I?
• KCDC (Kansas City Developer Conference)
• http://kcdc.info
©2017 Couchbase Inc. 5
Who am I?
• Matthew D. Groves
• DeveloperAdvocate 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. 7
Major Enterprises Across Industries are Adopting NoSQL
CommunicationsTechnology
Travel & Hospitality Media &
Entertainment
E-Commerce &
DigitalAdvertising
Retail & Apparel
Games & GamingFinance &
Business Services
©2017 Couchbase Inc. 8
Why NoSQL?
©2017 Couchbase Inc. 9
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. 10
NoSQL Landscape
• Get by key(s)
• Set by key(s)
• Replace by key(s)
• Delete by key(s)
• Map/Reduce
Document
• Couchbase
• MongoDB
• DynamoDB
• DocumentDB
©2017 Couchbase Inc. 11
Why NoSQL? Scalability
©2017 Couchbase Inc. 12
Why NoSQL? Scalability
©2017 Couchbase Inc. 13
Why NoSQL? Flexibility
©2017 Couchbase Inc. 14
Why NoSQL? Performance
©2017 Couchbase Inc. 15
Why NoSQL? Availability
©2017 Couchbase Inc. 16
JSON Data Modeling
©2017 Couchbase Inc. 17
Models for Representing Data
Data Concern Relational Model JSON Document Model
Rich Structure
Relationships
Value Evolution
Structure
Evolution
©2017 Couchbase Inc. 18
Properties of Real-World Data
©2017 Couchbase Inc. 19
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
©2017 Couchbase Inc. 21
CustomerID Name DOB
CBL2015 Jane Smith 1990-01-30
Table: Customer {
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Purchases" : [
{
"item" : "laptop",
"amount" : 1499.99,
"date" : "2019-03",
}
]
}
Customer DocumentKey: CBL2015
CustomerID Item Amount Date
CBL2015 laptop 1499.99 2019-03
Table: Purchases
CustomerID Name DOB
CBL2015 Jane Smith 1990-01-30
Table: Customer {
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Purchases" : [
{
"item" : "laptop",
"amount" : 1499.99,
"date" : "2019-03",
},
{
"item" : "phone",
"amount" : 99.99,
"date" : "2018-12"
}
]
}
Customer DocumentKey: CBL2015
CustomerID Item Amount Date
CBL2015 laptop 1499.99 2019-03
CBL2015 phone 99.99 2018-12
Table: Purchases
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-...",
"expiry" : "2019-03"
}, ...
],
"Connections" : [
{
"ConnId" : "XYZ987",
"Name" : "Joe Smith"
},
{
"ConnId" : ”SKR007",
"Name" : ”Sam Smith"
}
}
Customer DocumentKey: CBL2015
©2017 Couchbase Inc. 24
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"cardnum" : "5827-2842…",
"expiry" : "2019-03",
"cardType" : "visa",
"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
Custome
rID
Name DOB Cardnum Expiry CardType
CBL2015 Jane
Smith
1990-01-30 5827-
2842…
2019-03 visa
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
ConnectionsPurchases
{
"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. 26
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. 27
SQL for JSON
©2017 Couchbase Inc. 28
Why SQL for JSON?
©2017 Couchbase Inc. 29
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. 30
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. 31
©2017 Couchbase Inc. 32
route_5966 ← key
{
"type": "route", ← document type identifier
"airlineid": "airline_24", ← foreign key
"sourceairport": "MCO",
"destinationairport": "SEA",
"equipment": "737",
"schedule": [
{"day": 1, "utc": "13:25:00", "flight": "AA788"},
{"day": 4, "utc": "13:25:00", "flight": "AA419"},
{"day": 5, "utc": "13:25:00", "flight": "AA519"}
]
}
©2017 Couchbase Inc. 33
airline_24 ← key
{
"active": "Y",
"callsign": "AMERICAN",
"country": "United States",
"iata": "AA",
"icao": "AAL",
"name": "American Airlines",
"type": "airline" ← document type identifier
}
©2017 Couchbase Inc. 34
SELECT: JOIN
©2017 Couchbase Inc. 35
SELECT: Aggregation
©2017 Couchbase Inc. 36
SELECT: Aggregation
MIN
MAX
SUM
COUNT
AVG
ARRAY_AGG [ DISTINCT ]
©2017 Couchbase Inc. 37
SELECT: UNION, UNION ALL, INTERSECT, EXCEPT
©2017 Couchbase Inc. 38
USE KEYS
©2017 Couchbase Inc. 39
UNNEST (aka JOIN)
©2017 Couchbase Inc. 40
UNNEST (aka JOIN)
©2017 Couchbase Inc. 41
UNNEST (aka JOIN)
©2017 Couchbase Inc. 42
UNNEST (aka JOIN)
©2017 Couchbase Inc. 46
Composability
JOIN, NEST, and UNNEST
can be chained in any combination
©2017 Couchbase Inc. 47
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. 49
ResultSet
©2017 Couchbase Inc. 50
{
"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. 51
N1QL (Couchbase)
©2017 Couchbase Inc. 52
SQL (DocumentDb CosmosDb)
 https://www.documentdb.com/sql/demo
©2017 Couchbase Inc. 53
SQL CosmosDb SQL
SQL standard JSON stuff
©2017 Couchbase Inc. 54
Demo: N1QL
©2017 Couchbase Inc. 55
Other JSON "Stuff"
©2014 Couchbase, Inc. 55
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. 56
DataTypes in JSON
N1QL supports all JSON data types
 Numbers
 Strings
 Booleans
 Null
 Arrays
 Objects
©2017 Couchbase Inc. 59
Data Modification Statements
INSERT INTO `orders` (KEY, VALUE)
VALUES ("mykey", {"field1":482, "field2":3, "field3":4});
UPDATE `order`
SET field4 = "ABC987"
WHERE field1 = 482 AND field2 = 3 AND field3 = 4
DELETE FROM `neworder`
WHERE fieldX = 291 AND
fieldY = 3482 AND
fieldZ = 2483
JSON literals can be used in any
expression
©2017 Couchbase Inc. 60
Index Statements
 CREATE INDEX ON …
 DROP INDEX …
 EXPLAIN …
https://dzone.com/articles/index-first-and-query-faster
©2017 Couchbase Inc. 62
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. 63
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. 64
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. 65
SQL for JSON
SQL++
N1QL
http://tinyurl.com/UCSDsql
©2017 Couchbase Inc. 66
Couchbase Analytics (CBAS) and SQL++
©2017 Couchbase Inc. 67
©2017 Couchbase Inc. 68
Industry is Choosing SQL to Query JSON
©2017 Couchbase Inc. 69
JSON in SQL Server
©2017 Couchbase Inc. 74
Try SQL for JSON
http://tiny.cc/n1ql
http://tiny.cc/cosmosdb
©2017 Couchbase Inc. 75
Podcast
https://blog.couchbase.com/tag/podcast/
Free event:
Couchbase Day Kansas City
August 15th
http://tiny.cc/cbkc
©2017 Couchbase Inc. 77
Couchbase, everybody!
©2017 Couchbase Inc. 78
Where do you find us?
• blog.couchbase.com
• @couchbasedev
• @mgroves
• http://tiny.cc/cbkc
©2017 Couchbase Inc. 79
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?
©2017 Couchbase Inc. 80
CouchDB and Couchbase
< Back
memcached
©2017 Couchbase Inc. 81
MongoDB vs Couchbase
• Memory first architecture
• Master-master architecture
• Auto-sharding
• N1QL
• FullText Search
• Mobile & Sync
< Back
©2017 Couchbase Inc. 82
Licensing
Couchbase Server Community
• Open source (Apache 2)
• Binary release is one release behind Enterprise
• Free to use in dev/test/qa/prod
• Forum support only
Couchbase Server Enterprise
• Mostly open source (Apache 2)
• Some features not available on Community (XDCRTLS, MDS, Rack Zone, etc)
• Free to use in dev/test/qa
• Need commercial license for prod
• Paid support provided
< Back
©2017 Couchbase Inc. 83
Managed Cloud Service (DBaaS)?
No.
< Back

More Related Content

PPTX
Querying NoSQL with SQL - MIGANG - July 2017
PPTX
Bringing SQL to NoSQL: Rich, Declarative Query for NoSQL
PPTX
N1QL workshop: Indexing & Query turning.
PPTX
Tuning for Performance: indexes & Queries
PPTX
Understanding N1QL Optimizer to Tune Queries
PPTX
Introducing N1QL: New SQL Based Query Language for JSON
PDF
MongoDB .local Munich 2019: Still Haven't Found What You Are Looking For? Use...
PPTX
Creating a Single View: Data Design and Loading Strategies
Querying NoSQL with SQL - MIGANG - July 2017
Bringing SQL to NoSQL: Rich, Declarative Query for NoSQL
N1QL workshop: Indexing & Query turning.
Tuning for Performance: indexes & Queries
Understanding N1QL Optimizer to Tune Queries
Introducing N1QL: New SQL Based Query Language for JSON
MongoDB .local Munich 2019: Still Haven't Found What You Are Looking For? Use...
Creating a Single View: Data Design and Loading Strategies

What's hot (17)

PPTX
Utilizing Arrays: Modeling, Querying and Indexing
KEY
MongoDB, PHP and the cloud - php cloud summit 2011
PPTX
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
PDF
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
PDF
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
PPTX
From SQL to NoSQL: Structured Querying for JSON
PPTX
How to leverage what's new in MongoDB 3.6
PDF
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
PDF
Deciphering Explain Output
PDF
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
PPTX
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
PDF
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
PDF
Mongodbworkshop I: get started
PDF
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
PDF
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
PDF
MongoDB Europe 2016 - Graph Operations with MongoDB
PPTX
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
Utilizing Arrays: Modeling, Querying and Indexing
MongoDB, PHP and the cloud - php cloud summit 2011
Creating a Single View Part 2: Loading Disparate Source Data and Creating a S...
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
From SQL to NoSQL: Structured Querying for JSON
How to leverage what's new in MongoDB 3.6
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
Deciphering Explain Output
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
Mongodbworkshop I: get started
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
MongoDB Europe 2016 - Graph Operations with MongoDB
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
Ad

Similar to Querying NoSQL with SQL - KCDC - August 2017 (20)

PPTX
SQL for JSON: Rich, Declarative Querying for NoSQL Databases and Applications 
PPTX
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
PPTX
JSON Data Modeling - GDG Indy - April 2020
PPTX
Query in Couchbase. N1QL: SQL for JSON
PPTX
NoSQL Data Modeling using Couchbase
PPTX
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
PPTX
Json data modeling june 2017 - pittsburgh tech fest
PPTX
NoSQL’s biggest secret: NoSQL never went away
PDF
Data Modeling and Relational to NoSQL
PPTX
Putting the SQL Back in NoSQL - October 2022 - All Things Open
PPTX
N1QL+GSI: Language and Performance Improvements in Couchbase 5.0 and 5.5
PPTX
JSON Data Modeling - July 2018 - Tulsa Techfest
PDF
JSON Data Modeling in Document Database
PPTX
Querying Nested JSON Data Using N1QL and Couchbase
PDF
Three Things You Need to Know About Document Data Modeling in NoSQL
PPTX
N1QL: What's new in Couchbase 5.0
PDF
NoSQL's biggest lie: SQL never went away - Martin Esmann
PPTX
Deep dive into N1QL: SQL for JSON: Internals and power features.
PPTX
Couchbase Data Platform | Big Data Demystified
PPTX
Couchbase N1QL: Language & Architecture Overview.
SQL for JSON: Rich, Declarative Querying for NoSQL Databases and Applications 
Querying NoSQL with SQL: HAVING Your JSON Cake and SELECTing it too
JSON Data Modeling - GDG Indy - April 2020
Query in Couchbase. N1QL: SQL for JSON
NoSQL Data Modeling using Couchbase
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Json data modeling june 2017 - pittsburgh tech fest
NoSQL’s biggest secret: NoSQL never went away
Data Modeling and Relational to NoSQL
Putting the SQL Back in NoSQL - October 2022 - All Things Open
N1QL+GSI: Language and Performance Improvements in Couchbase 5.0 and 5.5
JSON Data Modeling - July 2018 - Tulsa Techfest
JSON Data Modeling in Document Database
Querying Nested JSON Data Using N1QL and Couchbase
Three Things You Need to Know About Document Data Modeling in NoSQL
N1QL: What's new in Couchbase 5.0
NoSQL's biggest lie: SQL never went away - Martin Esmann
Deep dive into N1QL: SQL for JSON: Internals and power features.
Couchbase Data Platform | Big Data Demystified
Couchbase N1QL: Language & Architecture Overview.
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 ...

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectroscopy.pptx food analysis technology
Chapter 3 Spatial Domain Image Processing.pdf
Review of recent advances in non-invasive hemoglobin estimation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
Encapsulation theory and applications.pdf

Querying NoSQL with SQL - KCDC - August 2017

  • 1. Querying NoSQL with SQL HAVINGYour JSON Cake and SELECTing it too Matthew D. Groves, @mgroves
  • 3. ©2017 Couchbase Inc. 3 Agenda Why NoSQL? JSON Data Modeling SQL for JSON Ecosystem and convergence
  • 4. ©2017 Couchbase Inc. 4 Where am I? • KCDC (Kansas City Developer Conference) • http://kcdc.info
  • 5. ©2017 Couchbase Inc. 5 Who am I? • Matthew D. Groves • DeveloperAdvocate for Couchbase • @mgroves onTwitter • Podcast and blog: http://crosscuttingconcerns.com • “I am not an expert, but I am an enthusiast.” – Alan Stevens
  • 6. Querying NoSQL with SQL HAVINGYour JSON Cake and SELECTing it too Matthew D. Groves, @mgroves
  • 7. ©2017 Couchbase Inc. 7 Major Enterprises Across Industries are Adopting NoSQL CommunicationsTechnology Travel & Hospitality Media & Entertainment E-Commerce & DigitalAdvertising Retail & Apparel Games & GamingFinance & Business Services
  • 8. ©2017 Couchbase Inc. 8 Why NoSQL?
  • 9. ©2017 Couchbase Inc. 9 NoSQL Landscape Document • Couchbase • MongoDB • DynamoDB • DocumentDB Graph • OrientDB • Neo4J • DEX • GraphBase Key-Value • Couchbase • Riak • BerkeleyDB • Redis Wide Column • Hbase • Cassandra • Hypertable
  • 10. ©2017 Couchbase Inc. 10 NoSQL Landscape • Get by key(s) • Set by key(s) • Replace by key(s) • Delete by key(s) • Map/Reduce Document • Couchbase • MongoDB • DynamoDB • DocumentDB
  • 11. ©2017 Couchbase Inc. 11 Why NoSQL? Scalability
  • 12. ©2017 Couchbase Inc. 12 Why NoSQL? Scalability
  • 13. ©2017 Couchbase Inc. 13 Why NoSQL? Flexibility
  • 14. ©2017 Couchbase Inc. 14 Why NoSQL? Performance
  • 15. ©2017 Couchbase Inc. 15 Why NoSQL? Availability
  • 16. ©2017 Couchbase Inc. 16 JSON Data Modeling
  • 17. ©2017 Couchbase Inc. 17 Models for Representing Data Data Concern Relational Model JSON Document Model Rich Structure Relationships Value Evolution Structure Evolution
  • 18. ©2017 Couchbase Inc. 18 Properties of Real-World Data
  • 19. ©2017 Couchbase Inc. 19 Modeling Data in RelationalWorld Billing ConnectionsPurchases Contacts Customer
  • 20. CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30” } Customer DocumentKey: CBL2015
  • 21. ©2017 Couchbase Inc. 21 CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Purchases" : [ { "item" : "laptop", "amount" : 1499.99, "date" : "2019-03", } ] } Customer DocumentKey: CBL2015 CustomerID Item Amount Date CBL2015 laptop 1499.99 2019-03 Table: Purchases
  • 22. CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Purchases" : [ { "item" : "laptop", "amount" : 1499.99, "date" : "2019-03", }, { "item" : "phone", "amount" : 99.99, "date" : "2018-12" } ] } Customer DocumentKey: CBL2015 CustomerID Item Amount Date CBL2015 laptop 1499.99 2019-03 CBL2015 phone 99.99 2018-12 Table: Purchases
  • 23. 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-...", "expiry" : "2019-03" }, ... ], "Connections" : [ { "ConnId" : "XYZ987", "Name" : "Joe Smith" }, { "ConnId" : ”SKR007", "Name" : ”Sam Smith" } } Customer DocumentKey: CBL2015
  • 24. ©2017 Couchbase Inc. 24 { "Name" : "Jane Smith", "DOB" : "1990-01-30", "cardnum" : "5827-2842…", "expiry" : "2019-03", "cardType" : "visa", "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 Custome rID Name DOB Cardnum Expiry CardType CBL2015 Jane Smith 1990-01-30 5827- 2842… 2019-03 visa 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 ConnectionsPurchases
  • 25. { "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
  • 26. ©2017 Couchbase Inc. 26 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
  • 27. ©2017 Couchbase Inc. 27 SQL for JSON
  • 28. ©2017 Couchbase Inc. 28 Why SQL for JSON?
  • 29. ©2017 Couchbase Inc. 29 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
  • 30. ©2017 Couchbase Inc. 30 Goal of Query for JSON Give developers and enterprises an expressive, powerful, and complete language for querying, transforming, and manipulating JSON data.
  • 32. ©2017 Couchbase Inc. 32 route_5966 ← key { "type": "route", ← document type identifier "airlineid": "airline_24", ← foreign key "sourceairport": "MCO", "destinationairport": "SEA", "equipment": "737", "schedule": [ {"day": 1, "utc": "13:25:00", "flight": "AA788"}, {"day": 4, "utc": "13:25:00", "flight": "AA419"}, {"day": 5, "utc": "13:25:00", "flight": "AA519"} ] }
  • 33. ©2017 Couchbase Inc. 33 airline_24 ← key { "active": "Y", "callsign": "AMERICAN", "country": "United States", "iata": "AA", "icao": "AAL", "name": "American Airlines", "type": "airline" ← document type identifier }
  • 34. ©2017 Couchbase Inc. 34 SELECT: JOIN
  • 35. ©2017 Couchbase Inc. 35 SELECT: Aggregation
  • 36. ©2017 Couchbase Inc. 36 SELECT: Aggregation MIN MAX SUM COUNT AVG ARRAY_AGG [ DISTINCT ]
  • 37. ©2017 Couchbase Inc. 37 SELECT: UNION, UNION ALL, INTERSECT, EXCEPT
  • 38. ©2017 Couchbase Inc. 38 USE KEYS
  • 39. ©2017 Couchbase Inc. 39 UNNEST (aka JOIN)
  • 40. ©2017 Couchbase Inc. 40 UNNEST (aka JOIN)
  • 41. ©2017 Couchbase Inc. 41 UNNEST (aka JOIN)
  • 42. ©2017 Couchbase Inc. 42 UNNEST (aka JOIN)
  • 43. ©2017 Couchbase Inc. 46 Composability JOIN, NEST, and UNNEST can be chained in any combination
  • 44. ©2017 Couchbase Inc. 47 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
  • 45. ©2017 Couchbase Inc. 49 ResultSet
  • 46. ©2017 Couchbase Inc. 50 { "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
  • 47. ©2017 Couchbase Inc. 51 N1QL (Couchbase)
  • 48. ©2017 Couchbase Inc. 52 SQL (DocumentDb CosmosDb)  https://www.documentdb.com/sql/demo
  • 49. ©2017 Couchbase Inc. 53 SQL CosmosDb SQL SQL standard JSON stuff
  • 50. ©2017 Couchbase Inc. 54 Demo: N1QL
  • 51. ©2017 Couchbase Inc. 55 Other JSON "Stuff" ©2014 Couchbase, Inc. 55 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
  • 52. ©2017 Couchbase Inc. 56 DataTypes in JSON N1QL supports all JSON data types  Numbers  Strings  Booleans  Null  Arrays  Objects
  • 53. ©2017 Couchbase Inc. 59 Data Modification Statements INSERT INTO `orders` (KEY, VALUE) VALUES ("mykey", {"field1":482, "field2":3, "field3":4}); UPDATE `order` SET field4 = "ABC987" WHERE field1 = 482 AND field2 = 3 AND field3 = 4 DELETE FROM `neworder` WHERE fieldX = 291 AND fieldY = 3482 AND fieldZ = 2483 JSON literals can be used in any expression
  • 54. ©2017 Couchbase Inc. 60 Index Statements  CREATE INDEX ON …  DROP INDEX …  EXPLAIN … https://dzone.com/articles/index-first-and-query-faster
  • 55. ©2017 Couchbase Inc. 62 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
  • 56. ©2017 Couchbase Inc. 63 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
  • 57. ©2017 Couchbase Inc. 64 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)
  • 58. ©2017 Couchbase Inc. 65 SQL for JSON SQL++ N1QL http://tinyurl.com/UCSDsql
  • 59. ©2017 Couchbase Inc. 66 Couchbase Analytics (CBAS) and SQL++
  • 61. ©2017 Couchbase Inc. 68 Industry is Choosing SQL to Query JSON
  • 62. ©2017 Couchbase Inc. 69 JSON in SQL Server
  • 63. ©2017 Couchbase Inc. 74 Try SQL for JSON http://tiny.cc/n1ql http://tiny.cc/cosmosdb
  • 64. ©2017 Couchbase Inc. 75 Podcast https://blog.couchbase.com/tag/podcast/
  • 65. Free event: Couchbase Day Kansas City August 15th http://tiny.cc/cbkc
  • 66. ©2017 Couchbase Inc. 77 Couchbase, everybody!
  • 67. ©2017 Couchbase Inc. 78 Where do you find us? • blog.couchbase.com • @couchbasedev • @mgroves • http://tiny.cc/cbkc
  • 68. ©2017 Couchbase Inc. 79 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?
  • 69. ©2017 Couchbase Inc. 80 CouchDB and Couchbase < Back memcached
  • 70. ©2017 Couchbase Inc. 81 MongoDB vs Couchbase • Memory first architecture • Master-master architecture • Auto-sharding • N1QL • FullText Search • Mobile & Sync < Back
  • 71. ©2017 Couchbase Inc. 82 Licensing Couchbase Server Community • Open source (Apache 2) • Binary release is one release behind Enterprise • Free to use in dev/test/qa/prod • Forum support only Couchbase Server Enterprise • Mostly open source (Apache 2) • Some features not available on Community (XDCRTLS, MDS, Rack Zone, etc) • Free to use in dev/test/qa • Need commercial license for prod • Paid support provided < Back
  • 72. ©2017 Couchbase Inc. 83 Managed Cloud Service (DBaaS)? No. < Back

Editor's Notes

  • #3: Please make sure to visit the sponsors and say thank you. They make this great event possible. Couchbase is here too, if you have questions or just want to talk databases, please come on by!
  • #4: 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
  • #8: 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 Marriott is using Couchbase, so you may be interacting with it right now
  • #9: 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
  • #10: 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.
  • #11: 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”
  • #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: 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]
  • #14: 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.
  • #15: 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]
  • #16: 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
  • #17: Let’s talk about data modeling a bit, because storing data in JSON Is different that storing in tables.
  • #18: 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
  • #19: 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)
  • #20: 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.
  • #21: Let’s see how to represent customer data in JSON. The primary (CustomerID) becomes the DocumentKey Column name-Column value becomes KEY-VALUE pair.
  • #22: 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.
  • #23: Value evolution Simply add additional array element or update a value.
  • #24: 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
  • #25: 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.
  • #26: 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.
  • #27: Reference slide
  • #29: 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)
  • #30: 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
  • #31: SQL is meant for normalized data so what do we do when we have denormalized data, like JSON documents?
  • #32: So let’s look at how SQL for JSON should work I’m going to use a different model as an example: Travel data. Specifically airlines and routes. I want users to be able to find flights between given destinations On a specific day, etc The data I’m looking at is actually a sample data set that ships with Couchbase Called the “travel sample” bucket It has airlines, routes, airports, and landmarks, but we’re only going to look at airlines and routes today.
  • #33: Here is a sample route document Notice it has a source and destination It also has a “type”, which I won’t need but I may in the future Notice it has an airlineid field, which is kinda like a foreign key It has a schedule field, which is an array. In relational, this would typically Be 3 rows in another table, but it’s denormalized into a single document
  • #34: Here’s an airline sample document It’s flat data, but it contains the name of the airline It also has a “type” field that I also don’t need today but might in the future, or I might need for other use cases
  • #35: Go fast over these, since it’s just SQL
  • #36: Go fast over these, since it’s just SQL
  • #37: ARRAY_AGG – array of the non MISSING values in the group, including nulls ARRAY_AGG can optionally use DISTINCT
  • #38: Go fast over these, since it’s just SQL
  • #39: USE is like WHERE for document keys Direct primary key lookup bypassing index scans Ideal for hash-distributed datastore Available in SELECT, UPDATE, DELETE
  • #40: 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
  • #41: 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
  • #42: 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
  • #43: 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
  • #44: 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
  • #45: 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
  • #46: 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
  • #47: I didn’t cover NEST, but it’s another type of JOIN
  • #48: 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
  • #49: Go fast over these, since it’s just SQL
  • #50: 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
  • #51: 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.
  • #53: 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)
  • #54: 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!
  • #56: 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
  • #57: 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)
  • #58: 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
  • #59: 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
  • #60: JSON in, JSON out
  • #61: 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
  • #62: 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
  • #63: 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
  • #64: Reference/summary slide
  • #65: This chart is not exhaustive, but I think it identifies key points of difference Sprocs on CosmosDb are in Javascript, not SQL
  • #66: 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
  • #67: 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.
  • #69: JSON support in SQL IBM Informix Oracle PostgreSQL MySQL All the sql vendors are introducing JSON features
  • #70: 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
  • #72: 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
  • #73: 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
  • #74: No ODBC driver afaik (yet) But there are some interesting APIs being provided by CosmosDb 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
  • #75: Documentdb.com link still works as of 7/18/2017 Even though the name has been changed
  • #76: 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 We've had guests on to talk about Raven, Marten, Mongo, Cassandra, Realm, etc
  • #78: Start the animation
  • #80: 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.
  • #81: Couchbase is the company, Couchbase Server is the software So imagine if Mongo and Redis companies formed a new company named RedMongo, and a new database combining Redis and Mongo together called RedMongo Server
  • #82: Memory first: integrated cache, you don't need to put redis on top of couchbase Master-master: easier scaling, better scaling Auto-sharding: we call vBuckets, you don't have to come up with a sharding scheme, it's done by crc32 N1QL: SQL, mongo has a more limited query language and it's not SQL-like Full Text Search: Using the bleve search engine, language aware FTS capabilities built in Mobile & sync: Mongo has nothing like the offline-first and sync capabilities couchbase offers Mongo DOES have a DbaaS cloud provider
  • #83: Everything I've shown you today is available in Community edition The only N1QL feature I can think of not in Community is INFER The Enterprise features you probably don't need unless you are Enterprise developer.
  • #84: Not yet. We've been talking about it at least as long as I've been with Couchbase. It's partly a technical problem, may need additional features for multi-tenant. It's partly (mostly) a business problem. Would this be worth it? Couchbase IS in the Azure and AWS marketplaces, and there are some wizards to make config easy, but it runs on your VMs.