(SQL NoSQL

2y ago
31 Views
2 Downloads
2.38 MB
33 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Grant Gall
Transcription

1Introduction to Data Management*** The“Online” Edition ***Lecture #24( SQL NoSQL)Instructor: Mike Careymjcarey@ics.uci.eduSQL1

Announcements Homework info: HW #8 (NoSQL) is the last one! Due next Wednesday (11 PM), Thursday (11PM) if late Warning: LOAD DATASET can be (path) finicky.SQL Endterm exam info: Non-cumulative and during class time next Friday (as usual) NoSQL lecture plans: Today: NoSQL & Big Data (a la AsterixDB) Refer to the Using SQL Primer and other docs on the Apache AsterixDB siteRead SQL For SQL Users from Couchbase, by Don Chamberlin (the Father of SQL!) Lots of useful info for moving from SQL to SQL ! (Setup script available here)2

Roadmap Check3

What is a NoSQL DB – why “not SQL”? Not from the DB world Distributed systems folks Also various startup companiesNoSQL Technologies From caches à persistent K/V use cases Apps needed massive scale-out OLTP (vs. parallel query DB) apps Simple, low-latency API – get/put by key Need a key K, but want no schema for value V Record-level atomicity, replica consistency varies In the context of this talk, NoSQL will not not mean Hadoop (or SQL on Hadoop) Graph databases or graph analytics platforms4

NoSQL Data (JSON-based)Collection(Orders){“id”: “123”,“Customer”:{ “custName”: “Fred”,“custCity”: “LA” }“total”: 25.97,“Items”: [{“product-sku”: 401,“qty”: 2,“price”: 9.99 },{“product-sku”: 544,“qty”: 1,“price”: 3.99 }]}Collection(Products){“sku”: 401,“name”: “Garfield T-Shirt”,“listPrice”: 9.99,“size”: “XL” },{“sku”: 544,“name”: “USB Charger”,“listPrice”: 5.99,“power”: “115V” }5

Current NoSQL (document DB) trends Popular examples: MongoDB, Couchbase Users now coveting the benefits of many DB goodies Secondary indexing and non-key access Declarative queries Aggregates and now (commonly small) joins World seems to be heading towards. BDMS (think scalable, OLTP-aimed, parallel/distributed DBMS) Declarative queries and query optimization, applied to schema-less data Return of (some, optional!) schema information6

Towards a Big Data Management System (BDMS)SemistructuredData ManagementBDMS Desiderata: ParallelDatabase SystemsAble to manage dataFlexible data modelFull query capabilityContinuous data ingestionEfficient and robust parallel runtimeCost proportional to task at handSupport “Big Data data types” 1st Generation“Big Data” Systems7

Apache AsterixDB (from UCI UCR)SQL (JSON, XML,CSV, )http://asterixdb.apache.org/8

Data Model: JSON (JavaScript Object "T. Hanks","address":{"street":"120 Harbor Blvd.","city":"Boston, "custid":"C35","order date":"2017-07-10","ship ]}{"custid":"C47","name":"S. Lauren","address":{"street":"17 Rue d'Antibes","city":"Cannes, ,"order ,"price":99.99}]}}}Data from D. Chamberlin. SQL for SQL Users: A Tutorial9

DataCustomersOrders.{{{"custid":"C37","name":"T. Hanks","address":{"street":"120 Harbor Blvd.","city":"Boston, "custid":"C35","order date":"2017-07-10","ship ]}{"custid":"C47","name":"S. Lauren","address":{"street":"17 Rue d'Antibes","city":"Cannes, ,"order ,"price":99.99}]}}}Data from D. Chamberlin. SQL for SQL Users: A Tutorial10

Data (Relational "name":"T. Hanks","address street":"120 Harbor Blvd.","address city":"Boston, MA","address ":"C35","order date":"2017-07-10","ship date":"2017-07-15"}{}{"custid":"C47","name":"S. Lauren","address street":"17 Rue d'Antibes","address city":"Cannes, France""address "C13","order date":"2017-10-13","ship ice":35.00}{"orderno":1008,CREATE TABLE Lineitems ("itemno":460,orderno INTEGER,"qty":20,itemno INTEGER,"price":99.99quantity INTEGER NOT NULL,}price DECIMAL(8,2) NOT NULL,PRIMARY KEY (orderno, itemno),FOREIGN KEY (orderno) REFERENCES Orders(orderno))11

Data (Relational "name":"T. Hanks","address street":"120 Harbor Blvd.","address city":"Boston, MA","address ":"C35","order date":"2017-07-10","ship date":"2017-07-15"}{}{"custid":"C47","name":"S. Lauren","address street":"17 Rue d'Antibes","address city":"Cannes, France""address "C13","order date":"2017-10-13","ship ce":9.99,"currency":"USD"}{}}CREATE TABLE Lineitems ({orderno INTEGER,itemno INTEGER,quantity INTEGER NOT NULL,price DECIMAL(8,2) NOT NULL,PRIMARY KEY (orderno, itemno),FOREIGN KEY (orderno) REFERENCES 12

Sloppy DataCustomersOrders.{{{"custid":"C37","name":"T. Hanks","address":{"street":"120 Harbor Blvd.","city":"Boston, "custid":"C35","order date":"2017-07-10","ship "price":9.99},{"itemno":195,"qty":4,"price":"if you have to ask ."}]}{"custid":"C47","name":"S. Lauren","address":{"street":"17 Rue d'Antibes","city":"Cannes, 3","order "price":99.99}}}}13

SQL : Just like SQL .SELECT nameFROM customersWHERE rating 650;[{"name": "M. Streep"},{"name": "T. Hanks"},{"name": "T. Cruise"}]14

Just like SQL .SELECT nameFROM customersWHERE rating 650;SELECT c.name,FROM customersWHERE c.custidAND c.custid[{"name": "R. Duvall","order date": "2017-09-02"},{"name": "R. Duvall","order date": "2017-04-29"}o.order dateAS c, orders AS o o.custid "C41";]15

Just like SQL .SELECT nameFROM customersWHERE rating 650;SELECT c.name,FROM customersWHERE c.custidAND c.custido.order dateAS c, orders AS o o.custid "C41";SELECT c.name, o.order dateFROM customers AS c LEFT OUTER JOIN orders AS oON c.custid o.custidWHERE c.custid "C41";16

Just like SQL .SELECT nameFROM customersWHERE rating 650;SELECT c.name,FROM customersWHERE c.custidAND c.custid[{"cnt": 1,"order date": "2017-10-13"},{"cnt": 1,"order date": "2017-09-13"},{"cnt": 1,"order date": "2017-09-02"}o.order dateAS c, orders AS o o.custid "C41";SELECT order date, count(*) AS cntFROM ordersGROUP BY order dateHAVING count(*) 0ORDER BY order date DESCLIMIT 3;]17

almost !SELECT name, order dateFROM customers, ordersWHERE customers.custid orders.custidAND rating 650;Cannot resolve ambiguous alias reference foridentifier rating (in line 4, at column 7)18

almost !SELECT name, order dateFROM customers, ordersWHERE customers.custid orders.custidAND rating 650;SELECT c.name,FROM customersWHERE c.custidAND c.rating[{"name": "T. Hanks","order date": "2017-08-30"},{"name": "T. Cruise","order date": "2017-05-01"},{"name": "T. Cruise","order date": "2017-10-13"},{"name": "T. Cruise","order date": "2017-09-13"}o.order dateAS c, orders AS o o.custid 650;]19

almost !SELECT name, order dateFROM customers, ordersWHERE customers.custid orders.custidAND rating 650;SELECT c.name,FROM customersWHERE c.custidAND c.ratingo.order dateAS c, orders AS o o.custid 650;SELECT *FROM customers AS c, orders AS oWHERE c.custid o.custidAND c.rating 650;[{"c": {"address": {"city": "Boston, MA","street": "120 Harbor Blvd.","zipcode": "02115"},"custid": "C37","name": "T. Hanks","rating": 750},"o": {"custid": "C37","items": [{"itemno": 460,"price": 99.98,"qty": 2}.20

SELECT VALUE: Added "VALUE"SELECT VALUE nameFROM customersWHERE rating 650;["M. Streep","T. Hanks","T. Cruise"]21

Added "VALUE"SELECT VALUE nameFROM customersWHERE rating 650;[{"CustomerName": "T. Hanks","OrderDate": "2017-08-30"},{"CustomerName": "T. Cruise","OrderDate": "2017-09-13"},{"CustomerName": "T. Cruise","OrderDate": "2017-05-01"},{"CustomerName": "T. Cruise","OrderDate": "2017-10-13"}SELECT VALUE {"CustomerName":c.name,"OrderDate":o.order date}FROM customers AS c, orders AS oWHERE c.custid o.custidAND c.rating 650;]22

Added "VALUE"SELECT VALUE nameFROM customersWHERE rating 650;SELECT VALUE {"CustomerName":c.name,"OrderDate":o.order date}FROM customers AS c, orders AS oWHERE c.custid o.custidAND c.rating 650;SELECT c.name AS CustomerName,o.order date AS OrderDateFROM customers AS c, orders AS oWHERE c.custid o.custidAND c.rating 650;23

Added "VALUE"SELECT VALUE nameFROM customersWHERE rating 650;SELECT VALUE {"CustomerName":c.name,"OrderDate":o.order date}FROM customers AS c, orders AS oWHERE c.custid o.custidAND c.rating 650;[{"Orders": [1006,1001],"CustomerName": "R. Duvall"}]SELECT VALUE {"CustomerName":c.name,"Orders":(SELECT VALUE o.orderno FROM orders AS oWHERE o.custid c.custid)}FROM customers AS cWHERE c.custid "C41";24

Quiz (Preview)Which query retrieves the names ofthe customers that have the highestrating?ASELECT nameFROM customersWHERE rating (SELECT MAX(rating) FROM customers);BSELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT VALUE MAX(c2.rating) FROM customers AS c2);CSELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT MAX(c2.rating) FROM customers AS c2);DSELECT VALUE c1.nameFROM customers AS c1WHERE c1.rating (SELECT VALUE MAX(c2.rating) FROM customers AS c2)[0];25

SQL Pitfalls and the value of VALUESELECT nameFROM customersWHERE rating (SELECT MAX(rating) FROM customers);Type mismatch: expected value of type multiset orarray, but got the value of type object (in line 4, atcolumn 28)26

SQL Pitfalls and the value of VALUESELECT nameFROM customers AS cWHERE rating (SELECT MAX(rating) FROM c);Type mismatch: expected value of type multiset orarray, but got the value of type object (in line 4, atcolumn 28)27

SQL Pitfalls and the value of VALUESELECT nameFROM customersWHERE rating (SELECT MAX(rating) FROM customers);[ ]SELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT MAX(c2.rating) FROM customers AS c2);28

SQL Pitfalls and the value of VALUESELECT nameFROM customersWHERE rating (SELECT MAX(rating) FROM customers);[ ]SELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT MAX(c2.rating) FROM customers AS c2);SELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT VALUE MAX(c2.rating) FROM customers AS c2);29

SQL Pitfalls and the value of VALUESELECT nameFROM customersWHERE rating (SELECT MAX(rating) FROM customers);["T. Cruise","T. Hanks"]SELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT MAX(c2.rating) FROM customers AS c2);SELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT VALUE MAX(c2.rating) FROM customers AS c2);SELECT VALUE c1.nameFROM customers AS c1WHERE c1.rating (SELECT VALUE MAX(c2.rating) FROM customers AS c2)[0];30

QuizWhich query retrieves the names ofthe customers that have the highestrating?ASELECT nameFROM customersWHERE rating (SELECT MAX(rating) FROM customers);BSELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT VALUE MAX(c2.rating) FROM customers AS c2);CSELECT c1.nameFROM customers AS c1WHERE c1.rating (SELECT MAX(c2.rating) FROM customers AS c2);DSELECT VALUE c1.nameFROM customers AS c1WHERE c1.rating (SELECT VALUE MAX(c2.rating) FROM customers AS c2)[0];31

More information about JSON, SQL , and AsterixDB Asterix project UCI/UCR research home Apache AsterixDB home http://asterixdb.apache.org/SQL Primer rojects/asterixdb/sqlpp/primer-sqlpp.htmlNavigate from CS122a wiki (HW) to get and install it.! Also, a few other resources and hints in the HW materials32

To be continued.33

4 NoSQL Technologies What is a NoSQL DB–why “not SQL”? Notfrom the DB world Distributed systems folks Also various startup companies From caches àpersistent K/V use cases Apps needed massive scale-out OLTP (vs. parallel query DB) apps Simple, low-latency API –get/put by key Need a keyK, but want n

Related Documents:

1. SQL Interface to RDB and NoSQL Database. To access both RDB and NoSQL databases, we provide a general SQL interface. It consists of a SQL query parser and Apache Phoenix to connect HBase as a NoSQL database to a SQL translator and a MySQL JDBC driver to an RDB connector. The application does not need to change the queries or manage NoSQL .

SQL vs NoSQL Performance Perhaps the most controversial comparison, NoSQL is regularly quoted as being faster than SQL. This isn't surprising; NoSQL's simpler denormalized store allows you to retrieve all information about a specific item in a single request. There's no need for related JOINs or complex SQL queries.

Welcome to SQL for Oracle NoSQL Database. This language provides a SQL-like interface to Oracle NoSQL Database. The SQL for Oracle NoSQL Database data model supports flat relational data, hierarchical typed (schema-full) data, and schema-less JSON data. SQL for Oracle NoSQL Database is designed to handle all such data seamlessly without any

towards NoSQL databases is the high cost of legacy RDBMS vendors versus NoSQL software. In general, NoSQL software is a fraction of what vendors such as IBM and Oracle charge for their databases. What Constitutes an Enterprise NoSQL Solution? What should a technology leader or decision-maker look for in a NoSQL offering that defines it as truly

NOSQL database iscalled the " Dynamo DB," which was designed and is being utilized by Amazon for its shopping basket. 4. COMPARISON OF SQL AND NOSQL DATABASE FEATURES In this section, a comparison of the features of the SQL and NOSQL databases will be discussed. This will includeThis hypothesis says that it is difficult to fulfill and ensure

SQL Server supports ANSI SQL, which is the standard SQL (Structured Query Language) language. However, SQL Server comes with its own implementation of the SQL language, T-SQL (Transact- SQL). T-SQL is a Microsoft propriety Language known as Transact-SQL. It provides further capab

MS SQL Server: MS SQL Server 2017, MS SQL Server 2016, MS SQL Server 2014, MS SQL Server 2012, MS SQL Server 2008 R2, 2008, 2008 (64 bit), 2008 Express, MS SQL Server 2005, 2005 (64 bit), 2005 Express, MS SQL Server 2000, 2000 (64 bit), 7.0 and mixed formats. To install the software, follow the steps: 1. Double-click Stellar Repair for MS SQL.exe.

Server 2005 , SQL Server 2008 , SQL Server 2008 R2 , SQL Server 2012 , SQL Server 2014 , SQL Server 2005 Express Edition , SQL Server 2008 Express SQL Server 2008 R2 Express , SQL Server 2012 Express , SQL Server 2014 Express .NET Framework 4.0, .NET Framework 2.0,