- Sai Divya Panditi - Priyanka Yechuri

Slides:



Advertisements
Similar presentations
B.Sc. Multimedia ComputingMedia Technologies Database Technologies.
Advertisements

State of Connecticut Core-CT Project Query 4 hrs Updated 1/21/2011.
MS Access: Database Concepts Instructor: Vicki Weidler.
MS Access Advanced Instructor: Vicki Weidler Assistant:
NoSQL Databases - CouchDB By Tom Sausner. Agenda Introduction Review of NoSQL storage options  CAP Theorem  Review categories of storage options CouchDB.
Linux Operations and Administration
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
Is Apache CouchDB for you?
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
CouchDB - Sai Divya Panditi - Priyanka Yechuri. Overview Introduction SQL vs CouchDB CouchDB Features CouchDB Core API Futon Security Application.
Moohanad Hassan Maedeh Pishvaei. Introduction Open Source Apache foundation project Relational DB: SQL Server CouchDB : JSON document-oriented DB (NoSQL)
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
A FIRST TOUCH ON NOSQL SERVERS: COUCHDB GENOVEVA VARGAS SOLAR, JAVIER ESPINOSA CNRS, LIG-LAFMIA, FRANCE
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
1 © Donald F. Ferguson, All rights reserved.Modern Internet Service Oriented Application Development – Lecture 2: REST Details and Patterns Some.
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
Web Technologies Lecture 10 Web services. From W3C – A software system designed to support interoperable machine-to-machine interaction over a network.
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
REST API Design. Application API API = Application Programming Interface APIs expose functionality of an application or service that exists independently.
2 Copyright © 2008, Oracle. All rights reserved. Building the Physical Layer of a Repository.
Emdeon Office Batch Management Services This document provides detailed information on Batch Import Services and other Batch features.
Fundamental of Database Systems
Introduction to Mongo DB(NO SQL data Base)
Database and Cloud Security
DHTML.
ASP.NET Programming with C# and SQL Server First Edition
NO SQL for SQL DBA Dilip Nayak & Dan Hess.
and Big Data Storage Systems
Introduction To DBMS.
DBMS & TPS Barbara Russell MBA 624.
Business Directory REST API
Data Virtualization Tutorial: Introduction to SQL Script
Better RESTFul API – Best Practices
PGT(CS) ,KV JHAGRAKHAND
Using E-Business Suite Attachments
MongoDB Er. Shiva K. Shrestha ME Computer, NCIT
Data Virtualization Tutorial… CORS and CIS
Applied CyberInfrastructure Concepts Fall 2017
NOSQL.
Dineesha Suraweera.
CHAPTER 3 Architectures for Distributed Systems
PHP / MySQL Introduction
NOSQL databases and Big Data Storage Systems
Relational Algebra Chapter 4, Part A
Testing REST IPA using POSTMAN
CS 174: Server-Side Web Programming February 12 Class Meeting
Chapter 2 Database Environment Pearson Education © 2009.
WEB API.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Chapter 2 Database Environment Pearson Education © 2009.
Physical Database Design
Relational Algebra Chapter 4, Sections 4.1 – 4.2
MANAGING DATA RESOURCES
Data Model.
NoSQL Not Only SQL University of Kurdistan Faculty of Engineering
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Chapter 10 ADO.
Contents Preface I Introduction Lesson Objectives I-2
Introduction to Access
Chapter 8 Advanced SQL.
Database Management Systems
Developing and testing enterprise Java applications
CloudAnt: Database as a Service (DBaaS)
Chapter 2 Database Environment Pearson Education © 2009.
NoSQL & Document Stores
Chapter 2 Database Environment Pearson Education © 2009.
NoSQL databases An introduction and comparison between Mongodb and Mysql document store.
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

- Sai Divya Panditi - Priyanka Yechuri CouchDB - Sai Divya Panditi - Priyanka Yechuri

Overview Introduction SQL vs CouchDB CouchDB Features CouchDB Core API Futon Security Application

Overview Demo Code Advantages DisAdvantages Iris Couch Conclusion References

CAP theorem – Pick two Consistency All database clients see the same data, even with concurrent updates. Availability All database clients are able to access some version of the data. Partition tolerance The database can be split over multiple servers.

CAP theorem

Introduction Created By : Damien Katz Year : 2005 Language : Erlang License : Apache Software Foundation(2008)

Introduction... NoSQL Database .....Uses Map/Reduce queries written in javascript

Architecture

NoSQL Databases Schema-Free Distributed Open Source Horizontally Scalable Easy Replication Support

NoSQL Timeline

Document-Oriented DBMS Data is stored in documents ......and not in relations like an RDBMS

SQL vs CouchDB SQL CouchDB Relational Non-Relational Tables Documents with types Rows and Columns Document Fields SQL Query Engine Map / Reduce Engine

CouchDB Features Data Representation - Using JSON Interaction - Futon / CouchDB API Querying - Map / Reduce Design Documents - Application code(Language : Javascript) Documents can have attachments

JSON Stands for Javascript Object Notation Derived from Javascript scripting language Used for representing simple data structures and associative arrays

JSON..... Example: { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, "type": "fax", "number": "646 555-4567" } ] }

CouchDB Core API (Command Line Utility ) Server API Database API Document API Replication API

HTTP API Messages are self-described via HTTP Headers and HTTP Status Codes. URIs identify resources. HTTP Methods define operations on the resources.

HTTP Request Methods Method Description PUT GET POST DELETE COPY PUT requests are used to create new resources where the URI of the request is different to the resource that is to be created. GET requests are used to request data from the database. POST requests are used to update the existing data, at the same resource the URI is requested from. DELETE requests to delete databases and documents. Copies one resource to another resource.

HTTP Status Codes Status Code Description 200 (OK) 201 (Created) 304 (Not Modified) 400 (Bad Request) 404 (Not Found) 405 (Method Not Allowed) 409 (Conflict) 412 (Precondition Failed) 500 (Internal Server Error) The request was successfully processed. The document was successfully created. The document has not been modified since the last update. The syntax of the request was invalid. The request was not found. The request was made using an incorrect request method. The request failed because of a database conflict. could not create a database- a database with that name already exists. The request was invalid and failed, or an error occurred within the CouchDB server.

Curl Command - Server API Command to check if CouchDB is working at all? curl http://127.0.0.1:5984/ Response : {"couchdb":"Welcome","version":"0.10.1"}

Curl Command - Database API Command to get a list of Databases : curl -X GET http://127.0.0.1:5984/_all_dbs

Creating and retrieving Creating the database "albums": curl -X PUT http://localhost:5984/albums Creating the document "album1": curl -X PUT http://localhost:5984/albums/album1 -d @- { "artista": "Megadeth", "titulo": "Endgame", "anio": 2009 } <EOF> // en Windows es ^z y en Unix ^d Retrieving the created document: curl -X GET http://localhost:5984/albums/album1

Updating (1) For updating a document: Give the last version Otherwise an error (code 409) will be generated, as shown in the following example: curl -X PUT http://localhost:5984/albums/album1 -d @- { "artista": "Megadeth", "titulo": "Endgame", "anio": 2010 } ^z

Updating (2) The attribute "_rev" specifies the version that will be updated: curl -X PUT http://localhost:5984/albums/album1 -d @- { "_rev": "1-142438dc8c583cda2a1f292c62291215", "artista": "Megadeth", "titulo": "Endgame", "anio": 2010 } ^z

Deleting (1) Delete the document "album1": curl -X DELETE http://localhost:5984/albums/album1?rev=2- d05127b44500ec19a2e5a25adc610380 If you try to retrieve it, an error is generated: curl -X GET http://localhost:5984/albums/album1 {"error":"not_found","reason":"deleted"} You have access to the version generated by the deletion operation: curl -X GET http://localhost:5984/albums/album1?rev=3- fac16c94309ed5ff842ffa89cc6048b1 {"_id":"album1","_rev":"3- fac16c94309ed5ff842ffa89cc6048b1","_deleted":true}

Deleting (2) We purge the document from the database: curl -X POST -H "Content-Type: application/json" http://localhost:5984/albums/_purge -d @- { "album1": ["3-fac16c94309ed5ff842ffa89cc6048b1"] } We try to query the version again: curl -X GET http://localhost:5984/albums/album1?rev=3- fac16c94309ed5ff842ffa89cc6048b1 {"error":"not_found","reason":"missing"}

Any binary type can be stored by adding it to a document Attachments (1) Any binary type can be stored by adding it to a document Let us create again "album1": curl -X PUT http://localhost:5984/albums/album1 -d @- { "artista": "Megadeth", "titulo": "Endgame", "anio": 2010 } The method HTTP PUT is used for attaching a file to the document using the attribute "cover.jpg": curl -X PUT -H 'Content-Type: image/jpg' --data-binary @300px- Endgame_album_art.jpg http://localhost:5984/albums/album1/cover.jpg?rev="1- 8a015dd26403219af66f05542cb540b2"

On adding an attachment to a document its version number changes: Attachments (2) On adding an attachment to a document its version number changes: For adding an attachment it is imperative to specify the version number of the document object Whe an attachment is created, the special attribute "_attachments” is created The method GET enables the retrieval of the attachment through the corresponding attribute: curl -X GET http://localhost:5984/albums/album1/cover.jpg?rev="2- 31e1ce62601aac5b9de7059788361641" > tmp.jpg

Views are useful for many purposes: Filtering the documents in your database to find those relevant to a particular process. Extracting data from your documents and presenting it in a specific order. Building efficient indexes (B-Trees)to find documents by any value or structure that resides in them. Use these indexes to represent relationships among documents. Views you can make all sorts of calculations on the data in your documents. E.g., if documents represent your company’s financial transactions, a view can answer the question of what the spending was in the last week, month, or year.

Defining views (1) Views are based on the working model MapReduce: Map and reduce function are specified in javascript Built-in views are provided curl -X GET http://localhost:5984/albums/_al l_docs

Example: defining a view curl -X PUT http://localhost:5984/albums/_design/vistas1 -d @- { "language": "javascript", "views": { "por_anio": { "map": "function( doc ) { if( doc.anio ) { emit( doc.anio, 1 );}}", "reduce": "function( keys, values, rereduce ) {return sum( values );}" }

Reduce values retrieved without considering the keys: Example: using a view Reduce values retrieved without considering the keys: curl http://localhost:5984/albums/_design/vistas1/_view/por_anio curl -X GET http://localhost:5984/albums/_design/vistas1/_view/por_anio Reduce the values retrieved considering the values of the different keys: curl http://localhost:5984/albums/_design/vistas1/_view/por_anio?group=true

Futon Built-in admin interface Access to all CouchDB features Create and Destroy databases Create, View and Edit Documents Compose and run Map / Reduce Views Replicate a Database

Futon Interface Demo...

Design Documents Contains application code They are like normal json documents but prefixed by _design/ CouchDB looks for views and other application functions here...

Views Used for extracting data we need for a specific purpose Example : function(doc){ if(doc.Bname) { emit(doc.id,doc.Bname); }

View Functions... Map - single parameter - doc emit(key,value) - built-in function Results of emit() are sorted by key We query the views to produce the desired result When we query a view, it's run on every document in the database for which view is defined View result is stored in a B-tree

View Functions… B-tree for the view is built only once and all the subsequent queries will just read the B-tree instead of executing the map function again Used to find documents by any value or structure that resides in them Using the URI, we can retrieve the exact data we need. For Example : /books/_design/docs/_view/by_Bname?key="Circuits"

Map Functions For Example : Consider the following documents Bname : Oracle Category : CS Author : abc Edition : 2007 Document-2 id : 2 Bname : Networks Category : CS Author : xyz Edition : 2001 Document-3 id : 3 Bname : Circuits Category : Electronics Author : abcd Edition : 2004 Document-4 id : 4 Bname : AI Category : CS Author : pqrs Edition : 2010

Map Functions… Output : Key Value 1 Oracle 2 Networks 3 Circuits 4 AI

Map Functions… Map Function : map:function(doc) { emit(doc.Bname, doc.id); } Output : AI 4 Circuits 3 Networks 2 Oracle 1

Reduce Function This function operates on the sorted rows emitted by map view functions. Predefined Reduce Functions: _sum, _count etc. Example: function(keys,values){ return sum(values); //gives aggregate values }

Security Database Admins Validation Functions

Validation Function Uses the function validate_doc_update(). If the validation function raises an exception, the update is denied else the updates are accepted. Document validation is optional.

Who uses CouchDB?

Advantages / DisAdvantages Features Not easy to learn especially if the user is familiar with SQL Security is weak Temporary views on large datasets are very slow. Replication of large databases may fail Documents are quite large as the data is represented using “JSON” format

References CouchDB - The Definitive Guide , J. Chris Anderson, Jan Lehnardt & Noah Slater Beginning CouchDB, Joe Lennon

Thank You...