CS162 Discussion Notes March 31, 2011 Jorge Ortiz
ACKNOWLEDGEMENTS Paul A. Strassmann, George Mason University Rightscale.com Kirk Anne, SUNY Geneseo Randy Katz, UC Berkeley
Outline Cloud computing – What is it? Virtualization – Hypervisor configurations Amazon EC2 Relational databases – Entity relationship diagrams Data models – Imperative versus declarative SQL
What is cloud computing? Cloud computing is Internet-based computing, whereby shared resources, software and information are provided to computers and other devices on-demand, like electricity – Wikipedia
Data Centers 6 Google’s Containerized Datacenter Microsoft Chicago Datacenter
What runs on these machines? All types of applications! How can we make best use of the resources?
Virtualization (2)
Virtualization (3)
Amazon EC2 Architecture
Applications Web applications Databases Compute-intensive jobs Client-Server applications – Project 3! Chat Server will be in the cloud Clients will be outside the cloud Application state stored in database
Parts of a database Record Attribute/Field Tables Records become “ rows ” Attributes/fields become “ columns ” Rules determine the relationship between the tables and tie the data together to form a database
Basic SQL Commands Creating tables with CREATE Adding data with INSERT Viewing data with SELECT Removing data with DELETE Modifying data with UPDATE Destroying tables with DROP
Creating tables with CREATE Generic form CREATE TABLE tablename ( column_name data_type attributes…, … ) Table and column names can ’ t have spaces or be “ reserved words ” like TABLE, CREATE, etc.
Phone Book/Contact Table CREATE TABLE contacts ( NameVARCHAR(40), Address VARCHAR(60), Company VARCHAR(60), Phone VARCHAR(11), URLVARCHAR(80), AgeINT, HeightFLOAT, BirthdayDATE, WhenEnteredTIMESTAMP ); Plan your tables very carefully! Once created, they are difficult to change!
Data Types Binary – Database specific binary objects (BLOB) Boolean – True/False values (BOOLEAN) Character – Fixed width (CHAR) or variable size (VARCHAR) Numeric – Integer (INT), Real (FLOAT), Money (MONEY) Temporal – Time (TIME), Date (DATE), Timestamp (TIMESTAMP)
Adding data with INSERT Generic Form INSERT INTO tablename (column_name,…) VALUES (value,…)
Inserting a record into ‘ contacts ’ INSERT INTO contacts (contactid,name,address,company,phone,url,a ge,height,birthday,whenentered) VALUES (1, ‘ Joe ’, ’ 123 Any St. ’, ’ ABC ’, ’ ’, ‘ ’,30,1.9, ’ 6/14/1972 ’, now());
Inserting a partial record INSERT INTO contacts (contactid,name,phone) VALUES (2, ’ Jane ’, ’ ’ );
Automatic key generation CREATE SEQUENCE contactidseq; Change the ContactID line in the CREATE TABLE to: ContactIDINT DEFAULT nextval( ‘ contactidseq ’ ) PRIMARY KEY Or when inserting into a table INSERT contacts (contactid,name,phone) VALUES (nextval( ‘ contactidseq ’ ), ’ Jack ’, ‘ ’ );
Viewing data with SELECT Generic Form SELECT column,… FROM table,… WHERE condition GROUP BY group_by_expression HAVING condition ORDER BY order_expression The most used command Probably the most complicated also If used improperly, can cause very long waits because complex computations
A few simple SELECTs SELECT * FROM contacts; – Display all records in the ‘ contacts ’ table SELECT contactid,name FROM contacts; – Display only the record number and names SELECT DISTINCT url FROM contacts; – Display only one entry for every value of URL.
Refining selections with WHERE The WHERE “ subclause ” allows you to select records based on a condition. SELECT * FROM contacts WHERE age<10; – Display records from contacts where age<10 SELECT * FROM contacts WHERE age BETWEEN 18 AND 35; – Display records where age is 18-35
Additional selections The “ LIKE ” condition – Allows you to look at strings that are alike SELECT * FROM contacts WHERE name LIKE ‘ J% ’ ; – Display records where the name starts with ‘ J ’ SELECT * FROM contacts WHERE url LIKE ‘ %.com ’ ; – Display records where url ends in “.com ”
Removing data with DELETE Generic Form DELETE FROM table WHERE condition; DELETE FROM contacts WHERE age<13;
Modifying data with UPDATE Generic Form UPDATE table SET column=expression WHERE condition; UPDATE contacts SET company= ‘ AOL ’ WHERE company= ‘ Time Warner ’ ;
Destroying tables with DROP Generic Form DROP TABLE tablename; DROP TABLE contacts;
Joining together tables SELECT name,phone,zip FROM people, phonenumbers, address WHERE people.addressid=address.addressid AND people.id=phonenumbers.id; People IdNameAddressID 1Joe1 2Jane2 3Chris3 Address AddressIDCompanyAddressZip 1ABC XYZ PDQ PhoneNumbers PhoneIDIdPhone
GROUP BY/HAVING The “ GROUP BY ” clause allows you to group results together with “ aggregate functions ” – AVG(), COUNT(), MAX(), MIN(), SUM() – COUNT DISTINCT HAVING allows you to search the GROUP BY results
Important links