NoSQL Slides by Roni Licher and Shoval Lagziel , Spring 2017

Slides:



Advertisements
Similar presentations
Completeness and Expressiveness. תזכורת למערכת ההוכחה של לוגיקה מסדר ראשון : אקסיומות 1. ) ) (( 2. )) ) (( )) ( ) ((( 3. ))) F( F( ( 4. ) v) ( ) v ((
Advertisements

Neo4j. План Cypher – Создание – Запросы Neo4j embedded in Java Немного о релизации (Neo4j Internals) – Native Graph Processing – Native Graph Storage.
מבוא למדעי המחשב לתעשייה וניהול
1 Formal Specifications for Complex Systems (236368) Tutorial #4 Refinement in Z: data refinement; operations refinement; their combinations.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts סכימה לדוגמא.
אקסס מבוא למערכות מידע.
חורף - תשס " ג DBMS, Design1 שימור תלויות אינטואיציה : כל תלות פונקציונלית שהתקיימה בסכמה המקורית מתקיימת גם בסכמה המפורקת. מטרה : כאשר מעדכנים.
פרויקט מחקרי בנושא יחס הזהב ואסתטיקה של מנשקים ARD מנחה : פרופ ' נעם טרקטינסקי מנחה אקדמי : פרופ ' יובל אלוביץ ' מגישים : אפרת דוד ארסני קרופניק.
חורף - תשס " ג DBMS, צורות נורמליות 1 צורה נורמלית שלישית - 3NF הגדרה : תהי R סכמה רלציונית ותהי F קבוצת תלויות פונקציונליות מעל R. R היא ב -3NF.
1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site : T.A. :Emilia Katz.
1 Formal Specifications for Complex Systems (236368) Tutorial #5 Refinement in Z: data refinement; operations refinement; their combinations.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
תכנות תרגול 6 שבוע : תרגיל שורש של מספר מחושב לפי הסדרה הבאה : root 0 = 1 root n = root n-1 + a / root n-1 2 כאשר האיבר ה n של הסדרה הוא קירוב.
1 Formal Specifications for Complex Systems (236368) Tutorial #1 Course site : T.A. :Emilia Katz.
א " ב, מילים, ושפות הפקולטה למדעי המחשב אוטומטים ושפות פורמליות ( ) תרגיל מספר 1.
טיב פני שטח (טפ"ש) טיב פני שטח- רמת החלקות של המשטח.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts SQL n מבנה שאילתה n פונקציות צבירה.
מערכים עד היום כדי לייצג 20 סטודנטים נאלצנו להגדיר עד היום כדי לייצג 20 סטודנטים נאלצנו להגדיר int grade1, grade2, …, grade20; int grade1, grade2, …, grade20;
עקרון ההכלה וההדחה.
יחס סדר חלקי.
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב' Templates תבניות.
תחשיב היחסים (הפרדיקטים)
Markov Decision Processes (MDP) תומר באום Based on ch. 14 in “Probabilistic Robotics” By Thrun et al. ב"הב"ה.
11 Introduction to Programming in C - Fall 2010 – Erez Sharvit, Amir Menczel 1 Introduction to Programming in C תרגול
WEB OF SCIENCE. WEB OF SCIENCE  Science Citation Index ExpandedTM  Social Sciences Citation Index®  Art & Humanities Citation Index®
Database Systems NoSQL. Source:
Presentation by Gil Perry Supervised by Amos Fiat 1.
COMP5338 – Advanced Data Models
פיתוח מערכות מידע Class diagrams Aggregation, Composition and Generalization.
1 מבוא למדעי המחשב הרצאה 21: Queue, Iterator & Iterable.
File Systems Motivation SQL (Structured Query Language) MapReduce 1 תרגול 1.
2003B Q5 Suppliers(sid, sname, city) Select sid from suppliers where city=‘jerusalem’ or sname like ‘%Smith’ Select sid from suppliers where city=‘jerusalem’
April 2002 Information Systems Design John Ogden & John Wordsworth 1 Database Design SQL (1) John Wordsworth Department of Computer Science The University.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Neo4j: GRAPH DATABASE 27 March, 2017
מספרים אקראיים ניתן לייצר מספרים אקראיים ע"י הפונקציה int rand(void);
Programming Arrays.
מבוא למדעי המחשב לתעשייה וניהול
Tirgul 12 Trees 1.
DOGMA: A Disk-Oriented Graph Matching Algorithm for RDF Databases
Structured Query Language
PPL Lecture 3 Slides by Yaron Gonen,
Chapter 3 Introduction to SQL(3)
Databases : More about SQL
Every Good Graph Starts With
Formal Specifications for Complex Systems (236368) Tutorial #1
Graph Database.
Database Systems - Technion
SQL: Structured Query Language DML- Queries Lecturer: Dr Pavle Mogin
SQL בסיסי – הגדרה אינדוקטיבית
Structured Query Language
תירגול 14: מבני נתונים דינאמיים
עבודה עם נתונים באמצעות ADO.NET
חלק 3: מבוא ל- XPath XML Path Language Spring 2005.
מבוא למדעי המחשב הרצאה 1: מבוא כללי מי אני, שעות הקבלה:
ממשקים - interfaces איך לאפשר "הורשה מרובה".
בעיות נוספות ב-NPC.
Marina Kogan Sadetsky –
תרגול 11 NP complete.
Engineering Programming A
למה רמת פרמי צריכה להיות קבועה בחומר שנמצא בשווי משקל?
ירושה הגדרת קשר Is A.
מחסנית ותור Stacks and Queues.
Computer Programming תרגול 3 Summer 2016
Engineering Programming A
Christopher Thielen, Lead Application Developer, DSS IT
Instructor: Zhe He Department of Computer Science
Database Management Systems
Database Management Systems
Presentation transcript:

NoSQL Slides by Roni Licher and Shoval Lagziel , Spring 2017 הדגמות במקביל להצגת שקופיות Slides by Roni Licher and Shoval Lagziel , Spring 2017 236363- DBMS

מסד נתונים גרפי, לחשוב אחרת! Connected information is everywhere in our world. Neo4j was build to efficiently store, handle and query highly connected elements in your data model. With a powerful and flexible data model you can represent your real-world, variably structured information without a loss of richness. The property graph model is easy to understand and handle, especially for object oriented and relational developers.

מסד נתונים גרפי, לחשוב אחרת! Node- יש לו labelים ותכונות שהם key:value Edge- קשת, יכולה להיות מכוונת או לא יש לה סוג, ויכולה להכיל תכונות Connected information is everywhere in our world. Neo4j was build to efficiently store, handle and query highly connected elements in your data model. With a powerful and flexible data model you can represent your real-world, variably structured information without a loss of richness. The property graph model is easy to understand and handle, especially for object oriented and relational developers.

236363- DBMS, שפות שאילתא: Datalog Neo4j מסד נתונים גרפי ממומש בJava ובScala Open –Source הפיתוח החל ב2003 נפוץ מאוד כיום מתאים מאוד כאשר המידע הוא מקושר 236363- DBMS, שפות שאילתא: Datalog

ebay

Neo4j and Cypher 4j Neo4j מסד הנתונים הגרפי שפת שאילתא עבור Neo4j (במסד נתונים רלציוני יש לנו את SQL)

236363- DBMS, שפות שאילתא: Datalog יצירת תוכן בCypher על ידי הפקודה CREATE יצירת Node עם property, והחזרה שלו CREATE (n { name: 'Andres' }) יצירת Node עם Label: CREATE (n:Person) לדוגמא יצירת Node עם label וproperties: CREATE (n:Person { name: 'Andres', title: 'Developer' }) כדי להחזיר את הNode שנוצר ניתן להוסיף RETURN n אביב 2016 236363- DBMS, שפות שאילתא: Datalog

236363- DBMS, שפות שאילתא: Datalog יצירת תוכן בCypher ניתן ליצור Nodes עם Relationships: CREATE (database:Database {name:"Neo4j"})-[r:SAYS]->(message:Message {name:"Hello World!"}) return database,message,r ניתן גם ליצור קשר בין שני Node שכבר קיימים, נראה זאת מאוחר יותר. אביב 2016 236363- DBMS, שפות שאילתא: Datalog

מבנה שאילתא בCypher MATCH [Nodes and relationships] WHERE [Boolean filter statement] RETURN [DISTINCT] [statements [AS alias]] ORDER BY [Properties] [ASC\DESC] SKIP [Number] LIMIT [Number]

דוגמא לשאילתא שליפת כל הקודקודים מסוגDatabase עם השם Neo4j. Type = Database Name = 'Neo4j' MATCH (a : Database) WHERE a.name = 'Neo4j' RETURN a

שליפת קשרים שליפת כל הקשרים מסוג SAYS שמחברים בין Database לבין Message. Type = Database Type = Message SAYS MATCH (a:Database)-[r:SAYS]->(b:Message) RETURN a,r,b

שימושים אפשריים בMatch עבור Nodes: (a) (a:Ntype) (a { prop:’value’ } ) (a:Ntype { prop:’value’ } )

שימושים אפשריים בMatch עבור Relationships: (a)--(b) (a)-->(b) (a)<--(b) (a)-->() (a)-[r]->(b) (a)-[:Rtype]->(b) (a)-[:R1|:R2]->(b) (a)-[r:Rtype]->(b) יכולים להיות גם יותר משני Nodes (a)-->(b)<--(c), (a)-->(b)-->(c) עבור מסלולים p = (a)-->(b) MATCH (a:Database)-->(b:Message) RETURN a,b MATCH (a:Database)--() RETURN a

שימושים אפשריים בMatch עבור Relationships לפי מרחק: (a)-[:Rtype*2]->(b) – 2 hops of type Rtype. (a)-[:Rtype* ]->(b) – any number of hops of type Rtype. (a)-[:Rtype*2..10]-> (b) – 2-10 hops of Rtype. (a)-[:Rtype* ..10]-> (b) – 1-10 hops of Rtype. (a)-[:Rtype*2.. ]-> (b) – at least 2 hops of Rtype

יצירת קשר בין Nodeים קיימים ניתן ליצור Relationship בין Nodeים שקיימים כבר: MATCH (a:Person),(b:Person) WHERE a.name = 'Node A' AND b.name = 'Node B' CREATE (a)-[r:RELTYPE]->(b) RETURN r MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r CREATE (a:Person {name:'Shoval'}), (b:Person {name:'Dvir'}), (c:Person {name:'Benny'}) return a,b,c MATCH (a:Person),(b:Person) WHERE a.name = 'Shoval' AND b.name = 'Dvir' CREATE (a)-[r:Workswith]->(b),(b)-[r2:Workswith]->(a) RETURN a,b MATCH (a:Person),(b:Person) WHERE a.name = 'Shoval' AND b.name = 'Benny' CREATE (a)-[r:Workswith]->(b),(b)-[r2:Workswith]->(a) RETURN a,b Match (a) return a Match (a:Person {name:'Dvir'})-[:Workswith]-(b) Return DISTINCT b Match (a:Person {name:'Dvir'})-[:Workswith*..2]-(b) Return DISTINCT b אביב 2016 236363- DBMS, שפות שאילתא: Datalog

=,<>,<,>,>=,<=, =~ (Regex), אופרטורים בCypher אופרטורים מתמטיים: +, -, *, /,%, ^ (power) השוואה: =,<>,<,>,>=,<=, =~ (Regex), IS NULL , IS NOT NULL אופרטורים לוגיים: AND, OR, XOR, NOT עבור מחרוזות: STARTS WITH, ENDS WITH, CONTAINS שרשור עם + עבור אוספים: IN לבדיקה האם איבר נמצא באוסף

WHERE WHERE others.name IN ['Andres', 'Peter'] WHERE user.age IN range (18,30) WHERE n.name =~ 'Tob.*‘ WHERE n.name =~ '(?i)ANDR.*‘ - (case insensitive) WHERE (n)-->() WHERE NOT (n)-->() WHERE exists(a.name) WHERE b.name? = 'Bob' (Returns all nodes where name = 'Bob' plus all nodes without a name property) Match (a) WHERE a.name=~'Sho[a-z]*' return a Match (a) WHERE exists(a.name) return a

פעולות על אוספים MATCH (user) RETURN count(user) RETURN count(DISTINCT user.name) RETURN collect(user.name) Collection from the values, ignores NULL. RETURN avg(user.age) Average numerical values. Similar functions are sum, min, max. Match (a:Person{name:'Dvir'})-->() RETURN a, count(*) Match (a:Person{name:'Shoval'})-->()

פונקציות בCypher On paths: On collections: MATCH shortestPath( (a)-[*]-(b) ) MATCH allShortestPath( (a)-[*]-(b) ) Length(path) – The path length or 0 if not exists. RETURN relationships(p) - Returns all relationships in a path. On collections: WHERE ANY (x IN a.array WHERE x = "one“ ) – at least one WHERE ALL (x IN nodes(p) WHERE x.age > 30) – all elements WHERE SINGLE (x IN nodes(p) WHERE var.eyes = "blue") – Only one * nodes(p) – nodes of the path p MATCH p=shortestPath( (a{name:'Dvir'})-[*]-(b{name:'Benny'}) ) RETURN length(p) On collections: RETURN a.array, filter(x IN a.array WHERE length(x)= 3) FILTER - returns the elements in a collection that comply to a predicate. WHERE ANY (x IN a.array WHERE x = "one“ ) – at least one WHERE ALL (x IN nodes(p) WHERE x.age > 30) – all elements WHERE SINGLE (x IN nodes(p) WHERE var.eyes = "blue") – Only one * nodes(p) – nodes of the path p

236363- DBMS, שפות שאילתא: Datalog SET מאפשר לנו לשנות או לתת properties MATCH (n { name: 'Andres' }) SET n.position = 'Developer', n.surname = 'Taylor‘ מאפשר לנו להעתיק את כל התכונות מNode אחר לאחר MATCH (at { name: 'Andres' }),(pn { name: 'Peter' }) SET at = pn אביב 2016 236363- DBMS, שפות שאילתא: Datalog

236363- DBMS, שפות שאילתא: Datalog SET- המשך מאפשר לנו לתת labelים MATCH (n { name: 'Emil' }) SET n :Swedish:Israeli RETURN n אביב 2016 236363- DBMS, שפות שאילתא: Datalog

With מאפשר לנו לבצע מניפולציה על המידע לפני שהוא עובר לביצוע בהמשך חלקי השאילתא שימושים: הגבלת מספר הרשומות שמועברת הלאה לMATCH אחרים – על ידי שימוש בORDER BY וLIMIT פילטור על ערכים מקובצים על ידי ביצועWhere לאחר מכן

With - דוגמא מה מוחזר משאילתא זו? MATCH (david { name: "David" })--(otherPerson)-->() WITH otherPerson, count(*) AS foaf WHERE foaf > 1 RETURN otherPerson מה מוחזר משאילתא זו? האנשים שמחוברים לדוד שיש להם יותר מקשת אחת יוצאת Similar to SQL GROUP BY

236363- DBMS, שפות שאילתא: Datalog DELETE ניתן למחוק Nodes/Relationships על ידי DELETE. MATCH (n:Person) DELETE n מחיקת Node עם הRelationships המחוברים אליו: MATCH (n { name: 'Andres' }) DETACH DELETE n באותו האופן ניתן למחוק גם Relationships על ידי שימוש מתאים בMATCH. אביב 2016 236363- DBMS, שפות שאילתא: Datalog

Vintage tutorials questions dname dcity pname pcity frequents drinker pub likes serves beer bname btype

Vintage tutorials questions באלו ערים מגישים בירה שיוסי אוהב? MATCH (:drinker { dname: “Yossi" })-[:likes]->(:beer)<-[:serves]-(p :pub) RETURN p.pcity מי הם השתיינים שבכל פאב יש בירה שהם אוהבים? MATCH (p : pub) WITH collect(p) as Pubs MATCH (d : drinker) WHERE ALL (p in Pubs WHERE (p)-[:serves]->(:beer)<-[:likes]-(d) ) RETURN d drinker pub frequents serves beer likes dname dcity pcity pname btype bname

Exam questions - Win13-14 A MATCH (c:Course) Studies: מחבר בין Student לביןCourse ומכיל את התכונותsemester ו-grade. Teaches: מחבר בין Lecturer לביןCourse ומכיל את התכונות semester ו-classroom. א. כתבו שאילתת Cypher שמחזירה: שמות כל הסטודנטים שלמדו את כל המקצועות. MATCH (c:Course) WITH collect(c) AS courses MATCH (s:Student) WHERE ALL (x in courses WHERE (s)-[:Studies]->(x)) RETURN s.name

Exam questions - Win13-14 A Studies: מחבר בין Student לביןCourse ומכיל את התכונותsemester ו-grade. Teaches: מחבר ביןLecturer לביןCourse ומכיל את התכונותsemester ו-classroom. ב. כתבו שאילתת Cypher שמחזירה: שמות כל הסטודנטים שלמדו קורס כלשהו שלמד גם סטודנט בשם "Roy" או שאת הקורס למד גם סטודנט כלשהו שלמד קורס כלשהו שלמד גם סטודנט ששמו “Roy”. MATCH (s:Student)-[:Studies*2..4]- (:Student{Name:"Roy"}) RETURN DISTINCT s.name

Exam questions - Win13-14 B Studies: מחבר בין Student לביןCourse ומכיל את התכונותsemester ו-grade. Teaches: מחבר ביןLecturer לביןCourse ומכיל את התכונותsemester ו-classroom. א. נגדיר פונקציית מרחק בין שני סטודנטים שונים כדלקמן: 1. הסטודנטיםA ו-B הם במרחק 1 אם הם למדו קורס משותף. 2. הסטודנטיםA ו-B הם במרחק n>1 אם n הוא המספר הקטן ביותר כך שקיים סטודנט C כך ש-A במרחק n-1 מ-C ו-C במרחק 1 מ-B. 3. אם לא קיים n כזה נגדיר את המרחק להיות 0. כתבו שאילתתCypher שמחזירה: המרחק בין שני סטודנטים שתעודת הזהות שלהם היא 12345 ו-67890 MATCH p=shortestPath((s1:Student {ID:'12345'})-[:Studies*]-(s2:Student {ID:'67890'})) RETURN length(p)/2

Exam questions - Win13-14 B Studies: מחבר בין Student לביןCourse ומכיל את התכונותsemester ו-grade. Teaches: מחבר ביןLecturer לביןCourse ומכיל את התכונותsemester ו-classroom. ב. שמות כל המרצים שלימדו לפחות 3 מקצועות. (ניתן להניח שאין כפילויות בגרף) MATCH (l:Lecturer)-[:Teaches]->(c:Course) WITH l, count(c) as numcourses WHERE numcourses >= 3 RETURN l.name

Learn more… Check Neo4j online version: http://console.neo4j.org/

Learn more… Download Neo4j for free: http://neo4j.com/download/

Learn more… Read the Neo4j manual: http://neo4j.com/docs/stable/ Cypher tutorials: http://neo4j.com/developer/cypher-query-language/ More Neo4j developers tutorials: http://neo4j.com/developer/get-started/