M Database

52
M Database Dima Kassab & Luis Ibanez SUNY Albany - 2013 Distributed under the Creative Commons by Attribution 3.0 License

description

M Database. Dima Kassab & Luis Ibanez SUNY Albany - 2013. Distributed under the Creative Commons by Attribution 3.0 License. Trees are Everything !. People are Trees Too !. First. Person. Name. Last. Street Name. Address. Street Number. City. Phone. Area Code. Number. email. - PowerPoint PPT Presentation

Transcript of M Database

Page 1: M Database

M DatabaseDima Kassab & Luis Ibanez

SUNY Albany - 2013

Distributed under the Creative Commons by Attribution 3.0 License

Page 2: M Database

Trees are Everything !

Page 3: M Database

People are Trees Too !Person Name

Address

First

Last

Street Name

Street Number

CityPhone

Area Code

Numberemail

name

domain

Page 4: M Database

Trees are Flexible

Sparse Data

Page 5: M Database

Relational Limits

Given Enough Time,

all Fields are Optional

Page 6: M Database

Relational Limits

First Last Street Number Street Name Phone email

John Smith 13 Pine 555-1234 [email protected]

Sara Johns 17 Lake 555-4321 [email protected]

Jen Stewart 34 Bison 333-5566 [email protected]

Mike Franklin 67 Blacksmith 222-7788 [email protected]

Martha Newton 134 Mapple 111-9977 [email protected]

Julia Sanders 23 Salmon 432-1267 [email protected]

Page 7: M Database

Relational Limits

First Last Street Number Street Name Phone email

John Smith 13 Pine 555-1234 [email protected]

Sara Johns 17 Lake 555-4321 [email protected]

Jen Stewart 34 Bison 333-5566 [email protected]

Mike Franklin 67 Blacksmith 222-7788 [email protected]

Martha Newton 134 Mapple 111-9977 [email protected]

Julia Sanders 23 Salmon 432-1267 [email protected]

Work ? Home ? Cell ?

Page 8: M Database

Relational Limits

First Last Street Number Street Name Phone email

John Smith 13 Pine 555-1234 [email protected]

Sara Johns 17 Lake 555-4321 [email protected]

Jen Stewart 34 Bison 333-5566 [email protected]

Mike Franklin 67 Blacksmith 222-7788 [email protected]

Martha Newton 134 Mapple 111-9977 [email protected]

Julia Sanders 23 Salmon 432-1267 [email protected]

Work ? Personal ? School ?

Page 9: M Database

Relational Limits

First Last Street Number Street Name Phone email

John Smith 13 Pine 555-1234 [email protected]

Sara Johns 17 Lake 555-4321 [email protected]

Jen Stewart 34 Bison 333-5566 [email protected]

Mike Franklin 67 Blacksmith 222-7788 [email protected]

Martha Newton 134 Mapple 111-9977 [email protected]

Julia Sanders 23 Salmon 432-1267 [email protected]

Maiden Name ? Married Name ? Divorced ?

Page 10: M Database

Relational Limits

Given Enough Time,

all Fields are Optional

Page 11: M Database

Hierarchical Databases

Things are Differentin a world of Trees

Page 12: M Database

Hierarchical Structures

Only those fieldswith data

are created

Page 13: M Database

Multi-Dimensional Arrays

set ^person("name","first")="John"set ^person("name","last")="Smith"set ^person("address","street","name")="Pine"set ^person("address","street","number")="13"set ^person("address","city")="Boston"set ^person("phone","area code")="555"set ^person("phone","number")="1234"set ^person("email","name")="johnsmith"set ^person("email","domain")="gmail.com"

Page 14: M Database

Hands On.

Let's do This !

Page 15: M Database

Join the Party

Log into the Server

Page 16: M Database

Join the Party

Click Here if INF-202

Click Here if INF-362

Page 17: M Database

Join the Party - INF 202

ssh-add -K ~/.ssh/inf_202_spring_2013_student_key

Open your SSH Key

chocolate

Page 18: M Database

Join the Party - INF 202

ssh -p 9744 [email protected]

put YOUR username here

Page 19: M Database

Once in the Server...

Continue here

Once you log into the Server

Page 20: M Database

Set up your EnvironmentUsing favorite text editor (Vim or Nano), open your file:

vim ~/.bashrc

Go to the end of the file, and add the line:

source /INF362-EWD/gtm/setup/add_to_bashrc.txt

save the file, quit the text editor

and from the command line do:

source ~/.bashrc

Page 21: M Database

GT.M is Open Source

gtm

Open the GT.M Interpreter

Just type this in the command line

Page 22: M Database

Look at the Data in a Tree

GTM>zwrite ^person(*)

Look at the "^person" tree

This is the GT.M Prompt

One and Only one Space

Page 23: M Database

Insert Data

GTM>set ^person("username")=""

Add yourself to the "^person" tree

This is the GT.M Prompt

One and only ONE space

YOURusername

Page 24: M Database

Insert Data

GTM>set ^person("username")=""

Add yourself to the "^person" tree

By Assigning an Empty stringwe create a node in the tree

Page 25: M Database

Insert Data

GTM>set ^person("username","name","first")="Luis" GTM>set ^person("username","name","last")="Ibanez"

Add your Name : First, Last

User YOUR name here

YOURusername

Page 26: M Database

Watch the Tree Grow !

GTM>zwrite ^person(*)

Look at the "^person" tree

Page 27: M Database

Watch the Tree Grow !

GTM>zwrite ^person("username",*)

Look at your portion of the "^person" tree

YOURusername

Page 28: M Database

Must Have more Data !

GTM>set ^person("username","food","apple")="" GTM>set ^person("username","food","broccoli")="" GTM>set ^person("username","food","chocolate")=""

Add your Favorite Food Items

YOURusername

Page 29: M Database

Must Have more Data !

GTM>set ^person("username","food","apple")="" GTM>set ^person("username","food","broccoli")="" GTM>set ^person("username","food","chocolate")=""

Add your Favorite Food Items

MultipleValues !!

Page 30: M Database

Terminal Nodes

GTM>set ^person("username","name","first")="Luis"

When the Value is Unique: use the End

GTM>set ^person("username","food","apple")=""

When the Value is Multiple: use the Index

Page 31: M Database

Terminal Nodes

When the Value is Unique: use the End

When the Value is Multiple: use the Index

Seriously !

This is important !

Page 32: M Database

Watch the Tree Grow !

GTM>zwrite ^person(*)

Look at the "^person" tree

Page 33: M Database

Your Turn !

Practice

Page 34: M Database

Your Turn !

You like varioustypes of Apples

(red, yellow, green)How would you enter them

in the database ?

Page 35: M Database

Taking over the World ! (202)

GTM>set ^place("asia")="Informative Revolver" GTM>set ^place("europe")="Starving Students" GTM>set ^place("africa")="Stacked like Pancakes" GTM>set ^place("america")="Mammoth Number 9"

Assigning Continents

Each TBL Team : Create your Continent

Page 36: M Database

GTM>set ^place("asia")="Amazing As" GTM>set ^place("europe")="Mellow United Nations" GTM>set ^place("africa")="PRO 2013" GTM>set ^place("america")="Yummy Tacos" GTM>set ^place("australia")=""

Taking over the World ! (362)

Assigning Continents

Each TBL Team : Create your Continent

Page 37: M Database

Taking over the World !

GTM>set ^place("asia","japan")="Steve" GTM>set ^place("asia","korea")="Mary" GTM>set ^place("asia","vietnam")="John"

Creating and Assigning Countries

Each Student in the TBL Team: Create your Country in that Continent

Page 38: M Database

GTM>set ^place("asia","japan","tokyo")="" GTM>set ^place("asia","japan","kyoto")="" GTM>set ^place("asia","japan","osaka")=""

Taking over the World !

Creating Cities

Each Student in the TBL Team: Create FIVE Cities in that Country

Page 39: M Database

GTM>set ^place("asia","japan","tokyo","human")=5000 GTM>set ^place("asia","japan","tokyo","zombie")=400

Taking over the World !

Tracking Zombies

Each Student in the TBL Team: Assign an estimated Human and Zombie

Population to her/his Cities

Page 40: M Database

Watch the Zoombies !

GTM>zwrite ^place(*)

Look at the "^place" tree

Page 41: M Database

Watch the Zombies !

GTM>zwrite ^place("asia",*)

Look at the "^place" sub-trees

GTM>zwrite ^place("asia","china",*)

Look at the sub-tree of YOUR country entry

Page 42: M Database

Walking in a Tree

Visiting the Data

Page 43: M Database

GTM>set i=$order(^place("")) GTM>write i GTM>set i=$order(^place(i)) write i GTM>set i=$order(^place(i)) write i GTM>set i=$order(^place(i)) write i

Taking over the World !

Start with one step

The $order() function returns the next value of a given index

Page 44: M Database

Your Turn

Write the expressions that will walk down the Countries of your Continent

Write the expressions that will walk down the Cities of your Country

Page 45: M Database

Repetition is Boring

Tired of Typing ?

It's time to master the:

for loop

Page 46: M Database

GTM>set i=""GTM>for set i=$order(^place(i)) write i,! quit:i=""

Taking over the World !

Start with initializing the index: i

TWOSpaces

ONESpace

ONESpace

ONESpace

Page 47: M Database

GTM>set i=""GTM>for set i=$order(^place(i)) write i,! quit:i=""

Taking over the World !

What have we done !?

This means:Forever !

This gets the next index

This means:Quit if (i="")

Page 48: M Database

GTM>s i=""GTM>f s i=$o(^place(i)) w i,! q:i=""

LOL BRB

Why to type words when we can just do letters...

This means:Forever !

This gets the next index

This means:Quit if (i="")

Page 49: M Database

GTM>s i="" f s i=$o(^place(i)) w i,! q:i=""

Be the One !

Why to use two lines, when we can do ONE !

TWOSpaces

ONESpace

ONESpace

ONESpace

ONESpace

ONESpace

Page 50: M Database

HINT: write $order(^place("asia","")

Your Turn

Write a FOR loop that listsall the Countries in your Continent

EmptyIndex

Page 51: M Database

HINT: write $order(^place("asia","china","")

Your Turn

Write a FOR loop that listsall the Cities in your Country

EmptyIndex

Page 52: M Database

Welcome to M !

The END

for now...