SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
Hybrid data models:
relational + JSON
Shane K Johnson
Senior Director of Product Marketing
MariaDB Corporation
About me
I’m not a morning person,
but I like breakfast.
About me
I’m not a NoSQL person,
but I like JSON.
What’s the point?
What’s the point?
What’s the point?
If a movie can be both
science fiction and
western…
A data model can be comprised of
structured and semi-structured data.
JSON
Relational
Flexibility
Simplicity
Ubiquity
Data integrity
Transactions
Reliability
What’s the difference?
Structured data is externally described
Semi-structured data is self described
Structured and semi-structured data
with relational + JSON
Structured Semi-structured
Structured and semi-structured data
with relational + JSON
Structure data described by
the schema
Structured described
by the data
Creating and querying
JSON documents
Example #1: definition
CREATE TABLE IF NOT EXISTS products (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
type VARCHAR(1) NOT NULL,
name VARCHAR(40) NOT NULL,
format VARCHAR(20) NOT NULL,
price FLOAT(5, 2) NOT NULL,
attr JSON NOT NULL);
Example #2: create
INSERT INTO products (type, name, format, price, attr) VALUES
('M', 'Aliens', 'Blu-ray', 13.99,'{"video": {"resolution": "1080p", "aspectRatio": "1.85:1"},
"cuts": [{"name": "Theatrical", "runtime": 138}, {"name": "Special Edition", "runtime":
155}], "audio": ["DTS HD", "Dolby Surround"]}');
INSERT INTO products (type, name, format, price, attr) VALUES
('B', 'Foundation', 'Paperback', 7.99, '{"author": "Isaac Asimov", "page_count": 296}');
Example #3: read field
SELECT name, format, price,
JSON_VALUE(attr, '$.video.aspectRatio') AS aspect_ratio
FROM products
WHERE type = 'M';
name format price aspect_ratio
Aliens Blu-ray 13.99 1.85:1
Example #4: null field
SELECT type, name, format, price,
JSON_VALUE(attr,$.video.aspectRatio') AS aspect_ratio
FROM products;
type name format price aspect_ratio
M Aliens Blu-ray 13.99 1.85:1
B Foundation Paperback 7.99 NULL
Example #5: contains field
SELECT name, format, price,
JSON_VALUE(attr, '$.video.aspectRatio') AS aspect_ratio
FROM products
WHERE type = 'M' AND
JSON_CONTAINS_PATH(attr, 'one', '$.video.resolution') = 1;
name format price aspect_ratio
Aliens Blu-ray 13.99 1.85:1
Example #6: contains value
SELECT id, name, format, price
FROM products
WHERE type = 'M' AND
JSON_CONTAINS(attr, '"DTS HD"', '$.audio') = 1;
name format price aspect_ratio
Aliens Blu-ray 13.99 1.85:1
Example #7: read array
SELECT name, format, price,
JSON_QUERY(attr, '$.audio') AS audio
FROM products
WHERE type = 'M';
name format price audio
Aliens Blu-ray 13.99 [
"DTS HD",
"Dolby Surround"
]
Example #8: read array element
SELECT name, format, price,
JSON_VALUE(attr, '$.audio[0]') AS default_audio
FROM products
WHERE type = 'M';
name format price audio
Aliens Blu-ray 13.99 DTS HD
Example #9: read object
SELECT name, format, price,
JSON_QUERY(attr, '$.video') AS video
FROM products
WHERE type = 'M';
name format price video
Aliens Blu-ray 13.99 {
"resolution": "1080p",
"aspectRatio": "1.85:1"
}
Example #10: read objects
SELECT name,
JSON_QUERY(attr, '$.audio') AS audio,
JSON_QUERY(attr, '$.video') AS video
FROM products
WHERE type = 'M';
name audio video
Aliens [
"DTS HD",
"Dolby Surround"
]
{
"resolution": "1080p",
"aspectRatio": "1.85:1"
}
Example #11: field equals
SELECT id, name, format, price
FROM products
WHERE type = 'M' AND
JSON_VALUE(attr, '$.video.resolution') = '1080p';
name format price aspect_ratio
Aliens Blu-ray 13.99 1.85:1
Example #12: indexing (1/2)
ALTER TABLE products ADD COLUMN
video_resolution VARCHAR(5) AS (JSON_VALUE(attr, '$.video.resolution')) VIRTUAL;
EXPLAIN SELECT name, format, price
FROM products
WHERE video_resolution = '1080p';
id select_type table type possible_keys
1 SIMPLE products ALL NULL
Example #13: indexing (2/2)
CREATE INDEX resolutions ON products(video_resolution);
EXPLAIN SELECT name, format, price
FROM products
WHERE video_resolution = '1080p';
id select_type table ref possible_keys
1 SIMPLE products ref resolutions
Modifying JSON documents
Example #14: insert field
UPDATE products
SET attr = JSON_INSERT(attr, '$.disks', 1)
WHERE id = 1;
name format price disks
Aliens Blu-ray 13.99 1
SELECT name, format, price,
JSON_VALUE(attr, '$.disks') AS disks
FROM products
WHERE type = 'M';
Example #15: insert array
UPDATE products
SET attr =JSON_INSERT(attr, '$.languages',
JSON_ARRAY('English', 'French'))
WHERE id = 1;
SELECT name, format, price,
JSON_QUERY(attr, '$.languages')
AS languages
FROM products
WHERE type = 'M';
name format price languages
Aliens Blu-ray 13.99 [
"English",
"French"
]
Example #16: add array element
UPDATE products
SET attr = JSON_ARRAY_APPEND(attr,
'$.languages', 'Spanish')
WHERE id = 1;
SELECT name, format, price,
JSON_QUERY(attr, '$.languages')
AS languages
FROM products
WHERE type = 'M';
name format price languages
Aliens Blu-ray 13.99 [
"English",
"French",
"Spanish"
]
Example #17: remove array element
UPDATE products
SET attr = JSON_REMOVE(attr,
'$.languages[0]')
WHERE id = 1;
SELECT name, format, price,
JSON_QUERY(attr, '$.languages')
AS languages
FROM products
WHERE type = 'M';
name format price languages
Aliens Blu-ray 13.99 [
"French",
"Spanish"
]
Creating JSON documents
from relational data
Example #18: relational to JSON (new)
SELECT JSON_OBJECT('name', name, 'format', format, 'price', price) AS data
FROM products
WHERE type = 'M';
data
{
"name": "Tron",
"format": "Blu-ray",
"price": 29.99
}
Example #19: relational + JSON (new)
SELECT JSON_OBJECT('name', name, 'format', format, 'price', price, 'resolution',
JSON_VALUE(attr, '$.video.resolution')) AS data
FROM products
WHERE type = 'M';
data
{
"name": "Aliens",
"format": "Blu-ray",
"price": 13.99,
"resolution": "1080p"
}
Example #20: relational + JSON (merge)
SELECT JSON_MERGE(
JSON_OBJECT(
'name', name,
'format', format),
attr) AS data
FROM products
WHERE type = 'M';
data
{
"name": "Tron",
"format": "Blu-ray",
"video": {
"resolution": "1080p",
"aspectRatio": "1.85:1"},
"cuts": [
{"name": "Theatrical", "runtime": 138},
{"name": "Special Edition", "runtime": 155}],
"audio": [
"DTS HD",
"Dolby Surround"]}
Enforcing data integrity with
JSON documents
Example #21: constraints (1/2)
ALTER TABLE products ADD CONSTRAINT check_attr
CHECK (
type != 'M' or (type = 'M' and
JSON_TYPE(JSON_QUERY(attr, '$.video')) = 'OBJECT' and
JSON_TYPE(JSON_QUERY(attr, '$.cuts')) = 'ARRAY' and
JSON_TYPE(JSON_QUERY(attr, '$.audio')) = 'ARRAY' and
JSON_TYPE(JSON_VALUE(attr, '$.disks')) = 'INTEGER' and
JSON_EXISTS(attr, '$.video.resolution') = 1 and
JSON_EXISTS(attr, '$.video.aspectRatio') = 1 and
JSON_LENGTH(JSON_QUERY(attr, '$.cuts')) > 0 and
JSON_LENGTH(JSON_QUERY(attr, '$.audio')) > 0));
Example #21: constraints (1/2)
INSERT INTO products (type, name, format, price, attr) VALUES
('M', 'Tron', 'Blu-ray', 29.99, '{"video": {"aspectRatio": "2.21:1"}, "cuts": [{"name": "Theatrical",
"runtime": 96}], "audio": ["DTS HD", "Dolby Digital"], "disks": 1}');
ERROR 4025 (23000): CONSTRAINT `check_attr` failed for `test`.`products`
no resolution field!
Example #22: constraints (2/2)
INSERT INTO products (type, name, format, price, attr) VALUES
('M', 'Tron', 'Blu-ray', 29.99, '{"video": {"resolution": "1080p", "aspectRatio": "2.21:1"}, "cuts":
[{"name": "Theatrical", "runtime": 96}], "audio": ["DTS HD", "Dolby Digital"], "disks": "one"}');
ERROR 4038 (HY000): Syntax error in JSON text in argument 1 to function 'json_type' at
position 1
"one" is not a number!
One more thing…
What’s semi-structured can
become structured…
id name price attributes
1 Aliens 17.99 {"video": {
"resolution": "1080p",
"aspectRatio": "2.35:1",}}
2 Event Horizon 9.75 {"video": {
"resolution": "1080p",
"aspectRatio": "2.34:1"}}
3 Pandorum 11.49 {"video": {
"resolution": "1080p",
"aspectRatio": "2.35:1"}}
Create “virtual” columns for
permanent fields
id name price resolution attributes
1 Aliens 17.99 1080p {"video": {
"resolution": "1080p",
"aspectRatio": "2.35:1",}}
2 Event Horizon 9.75 1080p {"video": {
"resolution": "1080p",
"aspectRatio": "2.34:1"}}
3 Pandorum 11.49 1080p {"video": {
"resolution": "1080p",
"aspectRatio": "2.35:1"}}
Replace virtual columns with columns
id name price resolution ratio attributes
1 Aliens 17.99 1080p 2.35:1 {"video": {
"aspectRatio": "2.35:1",}}
2 Event Horizon 9.75 1080p 2.34:1 {"video": {
"aspectRatio": "2.34:1"}}
3 Pandorum 11.49 1080p 2.35:1 {"video": {
"aspectRatio": "2.35:1"}}
Create virtual columns using functions to create
default values for new attributes
id name price resolution ratio 3d attributes
4 Sunshine 9.99 1080p 2.38:1 false {"video": {}}
5 The Darkest Hour 34.99 1080p 2.40:1 true {"video": {
"3d": true}}
IFNULL(JSON_VALUE(attr, '$.video.3d'), false)
Questions?
Check out the JSON microsite:
mariadb.com/database/topics/json
Check out the JSON white paper:
goo.gl/sw34cx
Try it out!
What’s next?
Thank you

Contenu connexe

Tendances

Walking Skeleton
Walking SkeletonWalking Skeleton
Walking Skeletonhepphep
 
Repository Pattern with c# and Entity Framework
Repository Pattern with c# and Entity FrameworkRepository Pattern with c# and Entity Framework
Repository Pattern with c# and Entity FrameworkImtiaj Ahammad
 
Leveraging Cloud Transformation to Build a DevOps Culture | AWS Public Sector...
Leveraging Cloud Transformation to Build a DevOps Culture | AWS Public Sector...Leveraging Cloud Transformation to Build a DevOps Culture | AWS Public Sector...
Leveraging Cloud Transformation to Build a DevOps Culture | AWS Public Sector...Amazon Web Services
 
Customer Experience in a SaaS business
Customer Experience in a SaaS businessCustomer Experience in a SaaS business
Customer Experience in a SaaS businessAditya Nag
 
Radical Agility with Autonomous Teams and Microservices in the Cloud
Radical Agility with Autonomous Teams and Microservices in the CloudRadical Agility with Autonomous Teams and Microservices in the Cloud
Radical Agility with Autonomous Teams and Microservices in the CloudZalando Technology
 
Slide DevSecOps Microservices
Slide DevSecOps Microservices Slide DevSecOps Microservices
Slide DevSecOps Microservices Hendri Karisma
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the bookCyrille Martraire
 
Domain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesDomain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesRadosław Maziarka
 
Sample Investots Pitch Deck.pdf
Sample Investots Pitch Deck.pdfSample Investots Pitch Deck.pdf
Sample Investots Pitch Deck.pdfEkaaPitch
 
Drive business outcomes using Azure Devops
Drive business outcomes using Azure DevopsDrive business outcomes using Azure Devops
Drive business outcomes using Azure DevopsBelatrix Software
 
The Paved PaaS to Microservices at Netflix (IAS2017 Nanjing)
The Paved PaaS to Microservices at Netflix (IAS2017 Nanjing)The Paved PaaS to Microservices at Netflix (IAS2017 Nanjing)
The Paved PaaS to Microservices at Netflix (IAS2017 Nanjing)Yunong Xiao
 
Agoda open stack in a large scale deployment
Agoda open stack in a large scale deploymentAgoda open stack in a large scale deployment
Agoda open stack in a large scale deploymentSharkrit JOBBO
 
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...SlideTeam
 
EastWest Ageas Life Insurance – Insurer Transformation Award 2023
EastWest Ageas Life Insurance – Insurer Transformation Award 2023EastWest Ageas Life Insurance – Insurer Transformation Award 2023
EastWest Ageas Life Insurance – Insurer Transformation Award 2023The Digital Insurer
 
DDD SoCal: Decompose your monolith: Ten principles for refactoring a monolith...
DDD SoCal: Decompose your monolith: Ten principles for refactoring a monolith...DDD SoCal: Decompose your monolith: Ten principles for refactoring a monolith...
DDD SoCal: Decompose your monolith: Ten principles for refactoring a monolith...Chris Richardson
 
The Guerrilla Guide to Game Code
The Guerrilla Guide to Game CodeThe Guerrilla Guide to Game Code
The Guerrilla Guide to Game CodeGuerrilla
 

Tendances (20)

Walking Skeleton
Walking SkeletonWalking Skeleton
Walking Skeleton
 
ISO-26262-Webinar.pptx
ISO-26262-Webinar.pptxISO-26262-Webinar.pptx
ISO-26262-Webinar.pptx
 
Repository Pattern with c# and Entity Framework
Repository Pattern with c# and Entity FrameworkRepository Pattern with c# and Entity Framework
Repository Pattern with c# and Entity Framework
 
Leveraging Cloud Transformation to Build a DevOps Culture | AWS Public Sector...
Leveraging Cloud Transformation to Build a DevOps Culture | AWS Public Sector...Leveraging Cloud Transformation to Build a DevOps Culture | AWS Public Sector...
Leveraging Cloud Transformation to Build a DevOps Culture | AWS Public Sector...
 
Customer Experience in a SaaS business
Customer Experience in a SaaS businessCustomer Experience in a SaaS business
Customer Experience in a SaaS business
 
Radical Agility with Autonomous Teams and Microservices in the Cloud
Radical Agility with Autonomous Teams and Microservices in the CloudRadical Agility with Autonomous Teams and Microservices in the Cloud
Radical Agility with Autonomous Teams and Microservices in the Cloud
 
Slide DevSecOps Microservices
Slide DevSecOps Microservices Slide DevSecOps Microservices
Slide DevSecOps Microservices
 
Introducing DevOps
Introducing DevOpsIntroducing DevOps
Introducing DevOps
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
 
Azure DevOps - Azure Guatemala Meetup
Azure DevOps - Azure Guatemala MeetupAzure DevOps - Azure Guatemala Meetup
Azure DevOps - Azure Guatemala Meetup
 
Domain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesDomain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and Microservices
 
Acp policies
Acp policiesAcp policies
Acp policies
 
Sample Investots Pitch Deck.pdf
Sample Investots Pitch Deck.pdfSample Investots Pitch Deck.pdf
Sample Investots Pitch Deck.pdf
 
Drive business outcomes using Azure Devops
Drive business outcomes using Azure DevopsDrive business outcomes using Azure Devops
Drive business outcomes using Azure Devops
 
The Paved PaaS to Microservices at Netflix (IAS2017 Nanjing)
The Paved PaaS to Microservices at Netflix (IAS2017 Nanjing)The Paved PaaS to Microservices at Netflix (IAS2017 Nanjing)
The Paved PaaS to Microservices at Netflix (IAS2017 Nanjing)
 
Agoda open stack in a large scale deployment
Agoda open stack in a large scale deploymentAgoda open stack in a large scale deployment
Agoda open stack in a large scale deployment
 
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...
Devops Strategy Roadmap Lifecycle Ppt Powerpoint Presentation Slides Complete...
 
EastWest Ageas Life Insurance – Insurer Transformation Award 2023
EastWest Ageas Life Insurance – Insurer Transformation Award 2023EastWest Ageas Life Insurance – Insurer Transformation Award 2023
EastWest Ageas Life Insurance – Insurer Transformation Award 2023
 
DDD SoCal: Decompose your monolith: Ten principles for refactoring a monolith...
DDD SoCal: Decompose your monolith: Ten principles for refactoring a monolith...DDD SoCal: Decompose your monolith: Ten principles for refactoring a monolith...
DDD SoCal: Decompose your monolith: Ten principles for refactoring a monolith...
 
The Guerrilla Guide to Game Code
The Guerrilla Guide to Game CodeThe Guerrilla Guide to Game Code
The Guerrilla Guide to Game Code
 

Similaire à Hybrid Data Models - Relational + JSON

Moving to hybrid relational/JSON data models
Moving to hybrid relational/JSON data modelsMoving to hybrid relational/JSON data models
Moving to hybrid relational/JSON data modelsMariaDB plc
 
Hyrbid Data Models (relational + json)
Hyrbid Data Models (relational + json)Hyrbid Data Models (relational + json)
Hyrbid Data Models (relational + json)MariaDB plc
 
Somewhere between schema and schemaless
Somewhere between schema and schemalessSomewhere between schema and schemaless
Somewhere between schema and schemalessMariaDB plc
 
M|18 Somewhere Between Schema and Schemaless
M|18 Somewhere Between Schema and SchemalessM|18 Somewhere Between Schema and Schemaless
M|18 Somewhere Between Schema and SchemalessMariaDB plc
 
Wie man Datenbankinfrastrukturen in Containern zum Laufen bringt
Wie man Datenbankinfrastrukturen in Containern zum Laufen bringtWie man Datenbankinfrastrukturen in Containern zum Laufen bringt
Wie man Datenbankinfrastrukturen in Containern zum Laufen bringtMariaDB plc
 
How to Handle NoSQL with a Relational Database
How to Handle NoSQL with a Relational DatabaseHow to Handle NoSQL with a Relational Database
How to Handle NoSQL with a Relational DatabaseDATAVERSITY
 
AWS Innovate 2020 - Cómo crear aplicaciones inteligentes con inteligencia art...
AWS Innovate 2020 - Cómo crear aplicaciones inteligentes con inteligencia art...AWS Innovate 2020 - Cómo crear aplicaciones inteligentes con inteligencia art...
AWS Innovate 2020 - Cómo crear aplicaciones inteligentes con inteligencia art...Amazon Web Services LATAM
 
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)Pamela Fox
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptLaurence Svekis ✔
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31Mahmoud Samir Fayed
 
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBMongoDB
 
Poetry with R -- Dissecting the code
Poetry with R -- Dissecting the codePoetry with R -- Dissecting the code
Poetry with R -- Dissecting the codePeter Solymos
 
Easy Path to Machine Learning (2019)
Easy Path to Machine Learning (2019)Easy Path to Machine Learning (2019)
Easy Path to Machine Learning (2019)wesley chun
 
Baton rouge - sql vs no sql and azure data factory
Baton rouge - sql vs no sql and azure data factoryBaton rouge - sql vs no sql and azure data factory
Baton rouge - sql vs no sql and azure data factoryDiponkar Paul
 
SQL vs. NoSQL and Moving data by Azure Data Factory
SQL vs. NoSQL and Moving data by Azure Data FactorySQL vs. NoSQL and Moving data by Azure Data Factory
SQL vs. NoSQL and Moving data by Azure Data FactoryDiponkar Paul
 
When Relational Isn't Enough: Neo4j at Squidoo
When Relational Isn't Enough: Neo4j at SquidooWhen Relational Isn't Enough: Neo4j at Squidoo
When Relational Isn't Enough: Neo4j at SquidooGil Hildebrand
 
The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212Mahmoud Samir Fayed
 
Constance et qualité du code dans une équipe - Rémi Prévost
Constance et qualité du code dans une équipe - Rémi PrévostConstance et qualité du code dans une équipe - Rémi Prévost
Constance et qualité du code dans une équipe - Rémi PrévostWeb à Québec
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)Pedro Rodrigues
 

Similaire à Hybrid Data Models - Relational + JSON (20)

Moving to hybrid relational/JSON data models
Moving to hybrid relational/JSON data modelsMoving to hybrid relational/JSON data models
Moving to hybrid relational/JSON data models
 
Hyrbid Data Models (relational + json)
Hyrbid Data Models (relational + json)Hyrbid Data Models (relational + json)
Hyrbid Data Models (relational + json)
 
Somewhere between schema and schemaless
Somewhere between schema and schemalessSomewhere between schema and schemaless
Somewhere between schema and schemaless
 
M|18 Somewhere Between Schema and Schemaless
M|18 Somewhere Between Schema and SchemalessM|18 Somewhere Between Schema and Schemaless
M|18 Somewhere Between Schema and Schemaless
 
Wie man Datenbankinfrastrukturen in Containern zum Laufen bringt
Wie man Datenbankinfrastrukturen in Containern zum Laufen bringtWie man Datenbankinfrastrukturen in Containern zum Laufen bringt
Wie man Datenbankinfrastrukturen in Containern zum Laufen bringt
 
How to Handle NoSQL with a Relational Database
How to Handle NoSQL with a Relational DatabaseHow to Handle NoSQL with a Relational Database
How to Handle NoSQL with a Relational Database
 
AWS Innovate 2020 - Cómo crear aplicaciones inteligentes con inteligencia art...
AWS Innovate 2020 - Cómo crear aplicaciones inteligentes con inteligencia art...AWS Innovate 2020 - Cómo crear aplicaciones inteligentes con inteligencia art...
AWS Innovate 2020 - Cómo crear aplicaciones inteligentes con inteligencia art...
 
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)
 
JavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScriptJavaScript Objects and OOP Programming with JavaScript
JavaScript Objects and OOP Programming with JavaScript
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31
 
Fast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDBFast REST APIs Development with MongoDB
Fast REST APIs Development with MongoDB
 
Poetry with R -- Dissecting the code
Poetry with R -- Dissecting the codePoetry with R -- Dissecting the code
Poetry with R -- Dissecting the code
 
Easy Path to Machine Learning (2019)
Easy Path to Machine Learning (2019)Easy Path to Machine Learning (2019)
Easy Path to Machine Learning (2019)
 
Baton rouge - sql vs no sql and azure data factory
Baton rouge - sql vs no sql and azure data factoryBaton rouge - sql vs no sql and azure data factory
Baton rouge - sql vs no sql and azure data factory
 
SQL vs. NoSQL and Moving data by Azure Data Factory
SQL vs. NoSQL and Moving data by Azure Data FactorySQL vs. NoSQL and Moving data by Azure Data Factory
SQL vs. NoSQL and Moving data by Azure Data Factory
 
When Relational Isn't Enough: Neo4j at Squidoo
When Relational Isn't Enough: Neo4j at SquidooWhen Relational Isn't Enough: Neo4j at Squidoo
When Relational Isn't Enough: Neo4j at Squidoo
 
The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212The Ring programming language version 1.10 book - Part 22 of 212
The Ring programming language version 1.10 book - Part 22 of 212
 
Constance et qualité du code dans une équipe - Rémi Prévost
Constance et qualité du code dans une équipe - Rémi PrévostConstance et qualité du code dans une équipe - Rémi Prévost
Constance et qualité du code dans une équipe - Rémi Prévost
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
 

Plus de DATAVERSITY

Architecture, Products, and Total Cost of Ownership of the Leading Machine Le...
Architecture, Products, and Total Cost of Ownership of the Leading Machine Le...Architecture, Products, and Total Cost of Ownership of the Leading Machine Le...
Architecture, Products, and Total Cost of Ownership of the Leading Machine Le...DATAVERSITY
 
Data at the Speed of Business with Data Mastering and Governance
Data at the Speed of Business with Data Mastering and GovernanceData at the Speed of Business with Data Mastering and Governance
Data at the Speed of Business with Data Mastering and GovernanceDATAVERSITY
 
Exploring Levels of Data Literacy
Exploring Levels of Data LiteracyExploring Levels of Data Literacy
Exploring Levels of Data LiteracyDATAVERSITY
 
Building a Data Strategy – Practical Steps for Aligning with Business Goals
Building a Data Strategy – Practical Steps for Aligning with Business GoalsBuilding a Data Strategy – Practical Steps for Aligning with Business Goals
Building a Data Strategy – Practical Steps for Aligning with Business GoalsDATAVERSITY
 
Make Data Work for You
Make Data Work for YouMake Data Work for You
Make Data Work for YouDATAVERSITY
 
Data Catalogs Are the Answer – What is the Question?
Data Catalogs Are the Answer – What is the Question?Data Catalogs Are the Answer – What is the Question?
Data Catalogs Are the Answer – What is the Question?DATAVERSITY
 
Data Catalogs Are the Answer – What Is the Question?
Data Catalogs Are the Answer – What Is the Question?Data Catalogs Are the Answer – What Is the Question?
Data Catalogs Are the Answer – What Is the Question?DATAVERSITY
 
Data Modeling Fundamentals
Data Modeling FundamentalsData Modeling Fundamentals
Data Modeling FundamentalsDATAVERSITY
 
Showing ROI for Your Analytic Project
Showing ROI for Your Analytic ProjectShowing ROI for Your Analytic Project
Showing ROI for Your Analytic ProjectDATAVERSITY
 
How a Semantic Layer Makes Data Mesh Work at Scale
How a Semantic Layer Makes  Data Mesh Work at ScaleHow a Semantic Layer Makes  Data Mesh Work at Scale
How a Semantic Layer Makes Data Mesh Work at ScaleDATAVERSITY
 
Is Enterprise Data Literacy Possible?
Is Enterprise Data Literacy Possible?Is Enterprise Data Literacy Possible?
Is Enterprise Data Literacy Possible?DATAVERSITY
 
The Data Trifecta – Privacy, Security & Governance Race from Reactivity to Re...
The Data Trifecta – Privacy, Security & Governance Race from Reactivity to Re...The Data Trifecta – Privacy, Security & Governance Race from Reactivity to Re...
The Data Trifecta – Privacy, Security & Governance Race from Reactivity to Re...DATAVERSITY
 
Emerging Trends in Data Architecture – What’s the Next Big Thing?
Emerging Trends in Data Architecture – What’s the Next Big Thing?Emerging Trends in Data Architecture – What’s the Next Big Thing?
Emerging Trends in Data Architecture – What’s the Next Big Thing?DATAVERSITY
 
Data Governance Trends - A Look Backwards and Forwards
Data Governance Trends - A Look Backwards and ForwardsData Governance Trends - A Look Backwards and Forwards
Data Governance Trends - A Look Backwards and ForwardsDATAVERSITY
 
Data Governance Trends and Best Practices To Implement Today
Data Governance Trends and Best Practices To Implement TodayData Governance Trends and Best Practices To Implement Today
Data Governance Trends and Best Practices To Implement TodayDATAVERSITY
 
2023 Trends in Enterprise Analytics
2023 Trends in Enterprise Analytics2023 Trends in Enterprise Analytics
2023 Trends in Enterprise AnalyticsDATAVERSITY
 
Data Strategy Best Practices
Data Strategy Best PracticesData Strategy Best Practices
Data Strategy Best PracticesDATAVERSITY
 
Who Should Own Data Governance – IT or Business?
Who Should Own Data Governance – IT or Business?Who Should Own Data Governance – IT or Business?
Who Should Own Data Governance – IT or Business?DATAVERSITY
 
Data Management Best Practices
Data Management Best PracticesData Management Best Practices
Data Management Best PracticesDATAVERSITY
 
MLOps – Applying DevOps to Competitive Advantage
MLOps – Applying DevOps to Competitive AdvantageMLOps – Applying DevOps to Competitive Advantage
MLOps – Applying DevOps to Competitive AdvantageDATAVERSITY
 

Plus de DATAVERSITY (20)

Architecture, Products, and Total Cost of Ownership of the Leading Machine Le...
Architecture, Products, and Total Cost of Ownership of the Leading Machine Le...Architecture, Products, and Total Cost of Ownership of the Leading Machine Le...
Architecture, Products, and Total Cost of Ownership of the Leading Machine Le...
 
Data at the Speed of Business with Data Mastering and Governance
Data at the Speed of Business with Data Mastering and GovernanceData at the Speed of Business with Data Mastering and Governance
Data at the Speed of Business with Data Mastering and Governance
 
Exploring Levels of Data Literacy
Exploring Levels of Data LiteracyExploring Levels of Data Literacy
Exploring Levels of Data Literacy
 
Building a Data Strategy – Practical Steps for Aligning with Business Goals
Building a Data Strategy – Practical Steps for Aligning with Business GoalsBuilding a Data Strategy – Practical Steps for Aligning with Business Goals
Building a Data Strategy – Practical Steps for Aligning with Business Goals
 
Make Data Work for You
Make Data Work for YouMake Data Work for You
Make Data Work for You
 
Data Catalogs Are the Answer – What is the Question?
Data Catalogs Are the Answer – What is the Question?Data Catalogs Are the Answer – What is the Question?
Data Catalogs Are the Answer – What is the Question?
 
Data Catalogs Are the Answer – What Is the Question?
Data Catalogs Are the Answer – What Is the Question?Data Catalogs Are the Answer – What Is the Question?
Data Catalogs Are the Answer – What Is the Question?
 
Data Modeling Fundamentals
Data Modeling FundamentalsData Modeling Fundamentals
Data Modeling Fundamentals
 
Showing ROI for Your Analytic Project
Showing ROI for Your Analytic ProjectShowing ROI for Your Analytic Project
Showing ROI for Your Analytic Project
 
How a Semantic Layer Makes Data Mesh Work at Scale
How a Semantic Layer Makes  Data Mesh Work at ScaleHow a Semantic Layer Makes  Data Mesh Work at Scale
How a Semantic Layer Makes Data Mesh Work at Scale
 
Is Enterprise Data Literacy Possible?
Is Enterprise Data Literacy Possible?Is Enterprise Data Literacy Possible?
Is Enterprise Data Literacy Possible?
 
The Data Trifecta – Privacy, Security & Governance Race from Reactivity to Re...
The Data Trifecta – Privacy, Security & Governance Race from Reactivity to Re...The Data Trifecta – Privacy, Security & Governance Race from Reactivity to Re...
The Data Trifecta – Privacy, Security & Governance Race from Reactivity to Re...
 
Emerging Trends in Data Architecture – What’s the Next Big Thing?
Emerging Trends in Data Architecture – What’s the Next Big Thing?Emerging Trends in Data Architecture – What’s the Next Big Thing?
Emerging Trends in Data Architecture – What’s the Next Big Thing?
 
Data Governance Trends - A Look Backwards and Forwards
Data Governance Trends - A Look Backwards and ForwardsData Governance Trends - A Look Backwards and Forwards
Data Governance Trends - A Look Backwards and Forwards
 
Data Governance Trends and Best Practices To Implement Today
Data Governance Trends and Best Practices To Implement TodayData Governance Trends and Best Practices To Implement Today
Data Governance Trends and Best Practices To Implement Today
 
2023 Trends in Enterprise Analytics
2023 Trends in Enterprise Analytics2023 Trends in Enterprise Analytics
2023 Trends in Enterprise Analytics
 
Data Strategy Best Practices
Data Strategy Best PracticesData Strategy Best Practices
Data Strategy Best Practices
 
Who Should Own Data Governance – IT or Business?
Who Should Own Data Governance – IT or Business?Who Should Own Data Governance – IT or Business?
Who Should Own Data Governance – IT or Business?
 
Data Management Best Practices
Data Management Best PracticesData Management Best Practices
Data Management Best Practices
 
MLOps – Applying DevOps to Competitive Advantage
MLOps – Applying DevOps to Competitive AdvantageMLOps – Applying DevOps to Competitive Advantage
MLOps – Applying DevOps to Competitive Advantage
 

Dernier

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

Hybrid Data Models - Relational + JSON

  • 1. Hybrid data models: relational + JSON Shane K Johnson Senior Director of Product Marketing MariaDB Corporation
  • 2. About me I’m not a morning person, but I like breakfast.
  • 3. About me I’m not a NoSQL person, but I like JSON.
  • 6. What’s the point? If a movie can be both science fiction and western…
  • 7. A data model can be comprised of structured and semi-structured data.
  • 9. What’s the difference? Structured data is externally described Semi-structured data is self described
  • 10. Structured and semi-structured data with relational + JSON Structured Semi-structured
  • 11. Structured and semi-structured data with relational + JSON Structure data described by the schema Structured described by the data
  • 13. Example #1: definition CREATE TABLE IF NOT EXISTS products ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, type VARCHAR(1) NOT NULL, name VARCHAR(40) NOT NULL, format VARCHAR(20) NOT NULL, price FLOAT(5, 2) NOT NULL, attr JSON NOT NULL);
  • 14. Example #2: create INSERT INTO products (type, name, format, price, attr) VALUES ('M', 'Aliens', 'Blu-ray', 13.99,'{"video": {"resolution": "1080p", "aspectRatio": "1.85:1"}, "cuts": [{"name": "Theatrical", "runtime": 138}, {"name": "Special Edition", "runtime": 155}], "audio": ["DTS HD", "Dolby Surround"]}'); INSERT INTO products (type, name, format, price, attr) VALUES ('B', 'Foundation', 'Paperback', 7.99, '{"author": "Isaac Asimov", "page_count": 296}');
  • 15. Example #3: read field SELECT name, format, price, JSON_VALUE(attr, '$.video.aspectRatio') AS aspect_ratio FROM products WHERE type = 'M'; name format price aspect_ratio Aliens Blu-ray 13.99 1.85:1
  • 16. Example #4: null field SELECT type, name, format, price, JSON_VALUE(attr,$.video.aspectRatio') AS aspect_ratio FROM products; type name format price aspect_ratio M Aliens Blu-ray 13.99 1.85:1 B Foundation Paperback 7.99 NULL
  • 17. Example #5: contains field SELECT name, format, price, JSON_VALUE(attr, '$.video.aspectRatio') AS aspect_ratio FROM products WHERE type = 'M' AND JSON_CONTAINS_PATH(attr, 'one', '$.video.resolution') = 1; name format price aspect_ratio Aliens Blu-ray 13.99 1.85:1
  • 18. Example #6: contains value SELECT id, name, format, price FROM products WHERE type = 'M' AND JSON_CONTAINS(attr, '"DTS HD"', '$.audio') = 1; name format price aspect_ratio Aliens Blu-ray 13.99 1.85:1
  • 19. Example #7: read array SELECT name, format, price, JSON_QUERY(attr, '$.audio') AS audio FROM products WHERE type = 'M'; name format price audio Aliens Blu-ray 13.99 [ "DTS HD", "Dolby Surround" ]
  • 20. Example #8: read array element SELECT name, format, price, JSON_VALUE(attr, '$.audio[0]') AS default_audio FROM products WHERE type = 'M'; name format price audio Aliens Blu-ray 13.99 DTS HD
  • 21. Example #9: read object SELECT name, format, price, JSON_QUERY(attr, '$.video') AS video FROM products WHERE type = 'M'; name format price video Aliens Blu-ray 13.99 { "resolution": "1080p", "aspectRatio": "1.85:1" }
  • 22. Example #10: read objects SELECT name, JSON_QUERY(attr, '$.audio') AS audio, JSON_QUERY(attr, '$.video') AS video FROM products WHERE type = 'M'; name audio video Aliens [ "DTS HD", "Dolby Surround" ] { "resolution": "1080p", "aspectRatio": "1.85:1" }
  • 23. Example #11: field equals SELECT id, name, format, price FROM products WHERE type = 'M' AND JSON_VALUE(attr, '$.video.resolution') = '1080p'; name format price aspect_ratio Aliens Blu-ray 13.99 1.85:1
  • 24. Example #12: indexing (1/2) ALTER TABLE products ADD COLUMN video_resolution VARCHAR(5) AS (JSON_VALUE(attr, '$.video.resolution')) VIRTUAL; EXPLAIN SELECT name, format, price FROM products WHERE video_resolution = '1080p'; id select_type table type possible_keys 1 SIMPLE products ALL NULL
  • 25. Example #13: indexing (2/2) CREATE INDEX resolutions ON products(video_resolution); EXPLAIN SELECT name, format, price FROM products WHERE video_resolution = '1080p'; id select_type table ref possible_keys 1 SIMPLE products ref resolutions
  • 27. Example #14: insert field UPDATE products SET attr = JSON_INSERT(attr, '$.disks', 1) WHERE id = 1; name format price disks Aliens Blu-ray 13.99 1 SELECT name, format, price, JSON_VALUE(attr, '$.disks') AS disks FROM products WHERE type = 'M';
  • 28. Example #15: insert array UPDATE products SET attr =JSON_INSERT(attr, '$.languages', JSON_ARRAY('English', 'French')) WHERE id = 1; SELECT name, format, price, JSON_QUERY(attr, '$.languages') AS languages FROM products WHERE type = 'M'; name format price languages Aliens Blu-ray 13.99 [ "English", "French" ]
  • 29. Example #16: add array element UPDATE products SET attr = JSON_ARRAY_APPEND(attr, '$.languages', 'Spanish') WHERE id = 1; SELECT name, format, price, JSON_QUERY(attr, '$.languages') AS languages FROM products WHERE type = 'M'; name format price languages Aliens Blu-ray 13.99 [ "English", "French", "Spanish" ]
  • 30. Example #17: remove array element UPDATE products SET attr = JSON_REMOVE(attr, '$.languages[0]') WHERE id = 1; SELECT name, format, price, JSON_QUERY(attr, '$.languages') AS languages FROM products WHERE type = 'M'; name format price languages Aliens Blu-ray 13.99 [ "French", "Spanish" ]
  • 31. Creating JSON documents from relational data
  • 32. Example #18: relational to JSON (new) SELECT JSON_OBJECT('name', name, 'format', format, 'price', price) AS data FROM products WHERE type = 'M'; data { "name": "Tron", "format": "Blu-ray", "price": 29.99 }
  • 33. Example #19: relational + JSON (new) SELECT JSON_OBJECT('name', name, 'format', format, 'price', price, 'resolution', JSON_VALUE(attr, '$.video.resolution')) AS data FROM products WHERE type = 'M'; data { "name": "Aliens", "format": "Blu-ray", "price": 13.99, "resolution": "1080p" }
  • 34. Example #20: relational + JSON (merge) SELECT JSON_MERGE( JSON_OBJECT( 'name', name, 'format', format), attr) AS data FROM products WHERE type = 'M'; data { "name": "Tron", "format": "Blu-ray", "video": { "resolution": "1080p", "aspectRatio": "1.85:1"}, "cuts": [ {"name": "Theatrical", "runtime": 138}, {"name": "Special Edition", "runtime": 155}], "audio": [ "DTS HD", "Dolby Surround"]}
  • 35. Enforcing data integrity with JSON documents
  • 36. Example #21: constraints (1/2) ALTER TABLE products ADD CONSTRAINT check_attr CHECK ( type != 'M' or (type = 'M' and JSON_TYPE(JSON_QUERY(attr, '$.video')) = 'OBJECT' and JSON_TYPE(JSON_QUERY(attr, '$.cuts')) = 'ARRAY' and JSON_TYPE(JSON_QUERY(attr, '$.audio')) = 'ARRAY' and JSON_TYPE(JSON_VALUE(attr, '$.disks')) = 'INTEGER' and JSON_EXISTS(attr, '$.video.resolution') = 1 and JSON_EXISTS(attr, '$.video.aspectRatio') = 1 and JSON_LENGTH(JSON_QUERY(attr, '$.cuts')) > 0 and JSON_LENGTH(JSON_QUERY(attr, '$.audio')) > 0));
  • 37. Example #21: constraints (1/2) INSERT INTO products (type, name, format, price, attr) VALUES ('M', 'Tron', 'Blu-ray', 29.99, '{"video": {"aspectRatio": "2.21:1"}, "cuts": [{"name": "Theatrical", "runtime": 96}], "audio": ["DTS HD", "Dolby Digital"], "disks": 1}'); ERROR 4025 (23000): CONSTRAINT `check_attr` failed for `test`.`products` no resolution field!
  • 38. Example #22: constraints (2/2) INSERT INTO products (type, name, format, price, attr) VALUES ('M', 'Tron', 'Blu-ray', 29.99, '{"video": {"resolution": "1080p", "aspectRatio": "2.21:1"}, "cuts": [{"name": "Theatrical", "runtime": 96}], "audio": ["DTS HD", "Dolby Digital"], "disks": "one"}'); ERROR 4038 (HY000): Syntax error in JSON text in argument 1 to function 'json_type' at position 1 "one" is not a number!
  • 40. What’s semi-structured can become structured… id name price attributes 1 Aliens 17.99 {"video": { "resolution": "1080p", "aspectRatio": "2.35:1",}} 2 Event Horizon 9.75 {"video": { "resolution": "1080p", "aspectRatio": "2.34:1"}} 3 Pandorum 11.49 {"video": { "resolution": "1080p", "aspectRatio": "2.35:1"}}
  • 41. Create “virtual” columns for permanent fields id name price resolution attributes 1 Aliens 17.99 1080p {"video": { "resolution": "1080p", "aspectRatio": "2.35:1",}} 2 Event Horizon 9.75 1080p {"video": { "resolution": "1080p", "aspectRatio": "2.34:1"}} 3 Pandorum 11.49 1080p {"video": { "resolution": "1080p", "aspectRatio": "2.35:1"}}
  • 42. Replace virtual columns with columns id name price resolution ratio attributes 1 Aliens 17.99 1080p 2.35:1 {"video": { "aspectRatio": "2.35:1",}} 2 Event Horizon 9.75 1080p 2.34:1 {"video": { "aspectRatio": "2.34:1"}} 3 Pandorum 11.49 1080p 2.35:1 {"video": { "aspectRatio": "2.35:1"}}
  • 43. Create virtual columns using functions to create default values for new attributes id name price resolution ratio 3d attributes 4 Sunshine 9.99 1080p 2.38:1 false {"video": {}} 5 The Darkest Hour 34.99 1080p 2.40:1 true {"video": { "3d": true}} IFNULL(JSON_VALUE(attr, '$.video.3d'), false)
  • 45. Check out the JSON microsite: mariadb.com/database/topics/json Check out the JSON white paper: goo.gl/sw34cx Try it out! What’s next?