30
CS162 Discussion Notes March 31, 2011 Jorge Ortiz

CS162 Discussion Notes

Embed Size (px)

DESCRIPTION

CS162 Discussion Notes. March 31, 2011 Jorge Ortiz. Paul A. Strassmann , George Mason University Rightscale.com Kirk Anne, SUNY Geneseo Randy Katz, UC Berkeley. Acknowledgements. Outline. Cloud computing What is it? Virtualization Hypervisor configurations Amazon EC2 - PowerPoint PPT Presentation

Citation preview

Page 1: CS162 Discussion Notes

CS162 Discussion Notes

March 31, 2011Jorge Ortiz

Page 2: CS162 Discussion Notes

ACKNOWLEDGEMENTSPaul A. Strassmann, George Mason UniversityRightscale.comKirk Anne, SUNY GeneseoRandy Katz, UC Berkeley

Page 3: CS162 Discussion Notes

Outline

• Cloud computing– What is it?

• Virtualization– Hypervisor configurations

• Amazon EC2• Relational databases

– Entity relationship diagrams• Data models

– Imperative versus declarative• SQL

Page 4: CS162 Discussion Notes

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

Page 5: CS162 Discussion Notes
Page 6: CS162 Discussion Notes

Data Centers

6

Google’sContainerizedDatacenter

MicrosoftChicagoDatacenter

Page 7: CS162 Discussion Notes

What runs on these machines?

• All types of applications!• How can we make best

use of the resources?

Page 8: CS162 Discussion Notes

Virtualization (2)

Page 9: CS162 Discussion Notes

Virtualization (3)

Page 10: CS162 Discussion Notes

Amazon EC2 Architecture

Page 11: CS162 Discussion Notes

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

Page 12: CS162 Discussion Notes

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

Page 13: CS162 Discussion Notes

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

Page 14: CS162 Discussion Notes

Creating tables with CREATE

• Generic form

CREATE TABLE tablename (column_name data_type attributes…,column_name data_type attributes…,…

)

• Table and column names can’t have spaces or be “reserved words” like TABLE, CREATE, etc.

Page 15: CS162 Discussion Notes

Phone Book/Contact TableCREATE TABLE contacts (

Name VARCHAR(40),Address VARCHAR(60),Company VARCHAR(60),Phone VARCHAR(11),URL VARCHAR(80),Age INT,Height FLOAT,Birthday DATE,WhenEntered TIMESTAMP

);Plan your tables very carefully!

Once created, they are difficult to change!

Page 16: CS162 Discussion Notes

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)

Page 17: CS162 Discussion Notes

Adding data with INSERT

• Generic Form

INSERT INTO tablename (column_name,…)VALUES (value,…)

Page 18: CS162 Discussion Notes

Inserting a record into ‘contacts’

INSERT INTO contacts (contactid,name,address,company,phone,url,age,height,birthday,whenentered)

VALUES(1,‘Joe’,’123 Any St.’,’ABC’,’800-555-1212’,‘http://abc.com’,30,1.9,’6/14/1972’,now());

Page 19: CS162 Discussion Notes

Inserting a partial record

INSERT INTO contacts (contactid,name,phone)VALUES (2,’Jane’,’212-555-1212’);

Page 20: CS162 Discussion Notes

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 tableINSERT contacts (contactid,name,phone)VALUES (nextval(‘contactidseq’),’Jack’,

‘716-555-1212’);

Page 21: CS162 Discussion Notes

Viewing data with SELECT

• Generic FormSELECT column,… FROM table,…

WHERE condition GROUP BY group_by_expressionHAVING 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

Page 22: CS162 Discussion Notes

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.

Page 23: CS162 Discussion Notes

Refining selections with WHERE

• The WHERE “subclause” allows you to select records based on a condition.

• SELECT * FROM contactsWHERE 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

Page 24: CS162 Discussion Notes

Additional selections

• The “LIKE” condition– Allows you to look at strings that are alike

• SELECT * FROM contactsWHERE 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”

Page 25: CS162 Discussion Notes

Removing data with DELETE

• Generic Form

DELETE FROM table WHERE condition;

DELETE FROM contacts WHERE age<13;

Page 26: CS162 Discussion Notes

Modifying data with UPDATE

• Generic Form

UPDATE table SET column=expression WHERE condition;

UPDATE contacts SET company=‘AOL’

WHERE company=‘Time Warner’;

Page 27: CS162 Discussion Notes

Destroying tables with DROP

• Generic Form

DROP TABLE tablename;

DROP TABLE contacts;

Page 28: CS162 Discussion Notes

Joining together tables• SELECT name,phone,zip FROM people,

phonenumbers, address WHERE people.addressid=address.addressid AND people.id=phonenumbers.id;

People

Id Name AddressID

1 Joe 1

2 Jane 2

3 Chris 3

Address

AddressID Company Address Zip

1 ABC 123 12345

2 XYZ 456 14454

3 PDQ 789 14423

PhoneNumbers

PhoneID Id Phone

1 1 5532

2 1 2234

3 1 3211

4 2 3421

5 3 2341

6 3 6655

Page 29: CS162 Discussion Notes

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

Page 30: CS162 Discussion Notes

Important links

• http://aws.amazon.com/documentation/ec2/• http://www.mysql.com/