“n1ql” a rich query language for couchbase: presented by don pinto, couchbase
TRANSCRIPT
“N1QL” A Rich Query Language For Couchbase Don Pinto Sr. Product Manager, Couchbase
Agenda • Rich data • Compare relational and N1QL data model • Mission • Resources • Q&A • Demo
The Real World
Couchbase Server
General purpose
Elas-c scalability Consistent high performance
Always available Flexible, global deployment
Enterprise grade administra-on
Real -me big data
Data mobility
Developer focused
The Most complete, scalable & highest performing NoSQL database
Couchbase Server
Couchbase offers a full range of Data Management solu5ons
High Availability Cache
Key Value Document Mobile device
SSN: 400 658 9993 Pass: ******
A Basic Data Model § Tables, schemas, constraints
§ Prevailing model for 30+ years
A Rich Data Model
8
Person
Name
DOB
Billing
Connec5ons
Purchases
Jane Smith
Product
Jan-‐30-‐1990
Human Machine
§ Structure and richness of real-world data
§ Drivers: Big Data, agility
§ Enabler: JSON — convenient, standard
9
Basic Data Model Rich Data Model
Technology q Rela-onal v Document
Building blocks
§ Flat tables ü Rich objects
Developer impact
§ Real world must be translated
§ Objects must be assembled
§ Data must be uniform
§ Change must be an excep-on
ü Real world can be reflected
ü Objects can be represented
ü Data can be uniform or varied
ü Change can be a norm
Query language q SQL v N1QL — SQL and more
Comparing the data models
10
JSON: Rich Data SQL: Expressive Power N1NF
N1QL
N1QL: Query Language for Rich Data
Defining N1QL
11
Ø Power for Big Data Applica5ons § Ability to index and query rich data at scale § Power of Couchbase extended to querying
Ø Joy for Developers § Freedom, flexibility, alignment, produc-vity § Best of both — SQL and rich data
Ø Value for Customers § Query technology for a new era § Enabler for applica-ons of the future
What does N1QL achieve?
12
Reading Data
SELECT Projec-on
DISTINCT De-‐duplica-on
FROM Sourcing
JOIN INNER, LEFT OUTER
WHERE Filtering
GROUP BY Aggrega-on — HAVING, MIN, MAX, SUM, AVG, COUNT [ DISTINCT ]
ORDER BY Sor-ng
LIMIT, OFFSET Paging
UNION*, INTERSECT*, EXCEPT* Set operators
EXPLAIN Analyzing and tuning query execu-on plans
N1QL Features - Reads *Upcoming
13
Wri5ng Data
CREATE INDEX Create a Couchbase view index or secondary index*
DROP INDEX Drop an index
INSERT* INSERT using VALUES or SELECT
UPDATE* UPDATE…WHERE, with document-‐level atomicity
DELETE* DELETE FROM…WHERE, with document-‐level atomicity
MERGE* MERGE with INSERT or UPDATE, depending on match
N1QL Features - Writes
*Upcoming
14
Expressions
Literals Primi-ves [ 0, ‘hello’, TRUE ]
NULL
Operators
Arithme-c [ +, -‐, *, /, % ]
Logical [ AND, OR, NOT ]
Comparison [ <, <=, =, !=, >=, >, BETWEEN, IS NULL ]
Papern matching [ LIKE ]
Condi-onal [ CASE ]
Scalar func-ons
Numeric [ trigonometric, ROUND, TRUNC, … ]
String [ UPPER, LOWER, TRIM, SUBSTR, … ]
Date [ string and numeric dates, NOW, date arithme-c*, … ]
Aggregate func-ons MIN, MAX, SUM, AVG, COUNT [ DISTINCT ]
Subqueries* Subqueries are full expressions
N1QL Features - Expressions *Upcoming
15
Nested Data
Mul--‐valued apributes Arrays as apributes
Nested objects Mul--‐level nes-ng of objects; path naviga-on
NEST Collec-ng second term into nested array [ INNER, LEFT OUTER ]
UNNEST Flapening nested array [ INNER, LEFT OUTER ]
Collec-on operators Mapping, filtering, predicate, indexing, and slicing operators
Collec-on func-ons Sort, Reverse, Dis-nct, Append, Concatenate, Contains…
Collec-on aggrega-on* MIN, MAX, SUM, AVG, COUNT [ DISTINCT ]
Deep traversal* Finding or collec-ng of matching elements WITHIN any depth
Array and deep update* UPDATE of matching elements IN arrays and WITHIN any depth
Construc-on Dynamic construc-on of objects, arrays, and their combina-ons
*Upcoming
Rich Data Features - Nesting
Heterogeneous Data
Heterogeneous inputs Input data of varying structure and type
Heterogeneous results Results of varying structure and type
Raw projec-on Support for non-‐tuple, non-‐object results
Schema inference* Inference of result structure and types, based on result expressions
Missing apributes IS [ NOT ] MISSING and other operators and func-ons
Apribute removal* UPDATE…UNSET to remove apributes
Total ordering* Comparison and ordering for all values, across all types
Implicit types* § Type-‐encoding func-ons + expression indexes*
§ For example, range scans on dates
Closure JSON in, JSON out
Features for Rich Data — Heterogeneity
16
*Upcoming
17
Distributed Data
Key-‐value access § KEYS available in SELECT, UPDATE, DELETE
§ KEYS used in JOIN, NEST, subqueries*, MERGE*
Document metadata § META func-on to access ID, TTL, CAS, FLAGS…
LIMIT on UPDATE & DELETE* § LIMIT available in write statements
Features for Distributed Data
*Upcoming
18
j
Ø query.couchbase.com § Downloads § Tutorial § Documenta-on § Blogs § Webinars § Forum
Ø @N1QL § Follow us § Engage
Resources
Thank you!
@NoSQLDon | [email protected]