JQL : The Java Query Language Darren Willis, David J Pearce, James Noble.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Equality Join R X R.A=S.B S : : Relation R M PagesN Pages Relation S Pr records per page Ps records per page.
Query Optimization CS634 Lecture 12, Mar 12, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Topic 15 Implementing and Using Stacks
CIT 590 Intro to Programming Java lecture 4. Agenda Types Collections – Arrays, ArrayLists, HashMaps Variable scoping Access modifiers – public, private,
Programming with Collections Collections in Java Using Arrays Week 9.
Stacks (Revised and expanded from CIT 591). What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on.
Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
T HE Q UERY C OMPILER Prepared by : Ankit Patel (226)
Query Processing Presented by Aung S. Win.
Grouping objects Collections and iterators. Main concepts to be covered Collections Loops Iterators.
A review session 2013-T2 Lecture 16 School of Engineering and Computer Science, Victoria University of Wellington COMP 103 Marcus Frean.
7-1 7 Contextual analysis  Aspects of contextual analysis  Scope checking  Type checking  Case study: Fun contextual analyser  Representing types.
CSE 143 Lecture 11 Maps Grammars slides created by Alyssa Harding
1 2. Program Construction in Java. 2.8 Searching.
CIS 280 Hashing and Hash Tables. Calendar Today: Hashing and Hash Tables Wednesday: Calculus due, work Friday: Cuckoo hashing and linear hashing Monday:
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 2.0.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Checking Equality of Reference Variables. Arrays and objects are both “reference” types n They are allocated a chunk of memory in the address space n.
Lecture 131 CS110 Lecture 13 Thursday, March 11, 2004 Announcements –hw5 due tonight –Spring break next week –hw6 due two weeks from tonight Agenda –questions.
Java.util.Vector Brian Toone 10/3/07 Updated 10/10/07.
Grouping objects Collections and iterators Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
CompSci Arrays  Aggregate data type  Deal with items of same type  Lists of words  Numbers  Analogies  Mailboxes in post office  CD racks.
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
1 Introduction to Hashing - Hash Functions Sections 5.1, 5.2, and 5.6.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
Data Structures & Algorithms
1 CS161 Introduction to Computer Science Topic #8.
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 1.0.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Lecture Objectives  To understand how Java implements a stack  To learn how to implement a stack using an underlying array or linked list  Implement.
The Java Query Language Darren Willis, David J. Pearce and James Noble Victoria University of Wellington, New Zealand.
GROUPING OBJECTS CITS1001. Lecture outline The ArrayList collection Process all items: the for-each loop 2.
Maps Nick Mouriski.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Take-Home Lab #02 CS1020 – DATA STRUCTURES AND ALGORITHMS 1 AY SEMESTER 2 1.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
CS 153: Concepts of Compiler Design September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Lecture 9:FXML and Useful Java Collections Michael Hsu CSULA.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
Computer Science Victoria University of Wellington Copyright: david streader, Victoria University of Wellington Simple Design COMP
Arrays Chapter 7.
CS314 – Section 5 Recitation 9
for-each PROS CONS easy to use access to ALL items one-by-one
Prepared by : Ankit Patel (226)
CS 536 / Fall 2017 Introduction to programming languages and compilers
Introduction to Functional Programming in Racket
Advanced Programming in Java
Road Map CS Concepts Data Structures Java Language Java Collections
Introduction to Database Systems
JQL : The Java Query Language
Introduction to Database Systems CSE 444 Lecture 23: Final Review
Coding Concepts (Basics)
Introduction to Functional Programming in Racket
Road Map - Quarter CS Concepts Data Structures Java Language
Road Map CS Concepts Data Structures Java Language Java Collections
CS100J Lecture 16 Previous Lecture This Lecture Programming concepts
Outline Software Development Activities
CS100J Lecture 16 Previous Lecture This Lecture Programming concepts
Introduction to Database Systems CSE 444 Lecture 23: Final Review
CS100A Lect. 12, 8 Oct More About Arrays
Presentation transcript:

JQL : The Java Query Language Darren Willis, David J Pearce, James Noble

Object Querying JQL is a simple extension for Java. JQL adds support for Object Querying. Object Querying helps us pick sets of objects from other sets. JQL can simplify working with collections.

Object Querying Without JQL: for(Object a : collection1) for(Object b : collection2) if(a.equals(b)) results.add(new Object[]{a,b}); With JQL: selectAll(Object a = collection1, Object b = collection2 :a.equals(b));

Hypothetical IM Client Session String name; send_msg(Msg); recv_msg(Msg); Window String name; int id; show_msg(Msg); enter_msg(); A Hypothetical Instant Messaging Client

Querying : Nested Loop We're joining the sets of Sessions and Windows. An easy way – the nested loop join: ArrayList results = new Arraylist(); for(Session s : sessions) for(Window w : windows) if(w.name.equals(s.name)) results.add(new Object[w,s]); This takes O(|sessions| * |windows|) time.

Querying : Hash Join Another join technique, from databases: ArrayList results = new ArrayList(); Hashtable nameIndex = new Hashtable(); for(Session s : sessions) nameIndex.put(s.name,s); } for(Window w : windows){ results.add(names.get(w.name)); } (This is a simplified version)

Joining Dilemma AB A B AB

JQL for Collection Operations results = selectAll(Session s = sessions, Window w = windows: s.name.equals(w.name)); Let the Query Evaluator take care of the details!

Domain Variable Sources Passing in a Domain Variable source selectAll(Window w = windows :w.ID == 5) Domain Variable Definition without a source selectAll(Window w : w.ID == 5)

Query Expressions w.ID == 5 w.ID == 5 && w.name == s.name w.ID > 5 && w.ID < 10 && w.name == s.name && s.isActive() &&...

Query Expressions  Method calls are allowed  Side effects are possible  These expressions do not short circuit So what else can we do with queries?

BinTree Aliasing

A Query Invariant assert null == selectA(BinTree a, BinTree b : (a != b && a.left == b.left) || (a != b && a.right == b.right)|| a.left == b.right); Uses Object Tracking to check all BinTrees.

Object Tracking public class GroupChat{ private List participants; public SomeClass(){ participants = new ArrayList();... } public void addChatter(String name){... participants.add(new Session(name));... } Object Tracker

Expression Ordering Queries get broken down along &&s w.ID == 5 && w.name == s.name Becomes two subqueries: w.ID = 5 w.name == s.name JQL arranges these into a query pipeline.

A Query Pipeline Sessions Windows w.name == s.name Temp. Results w.ID == 5 w.ID == 5 && w.name == s.name

Ordering the Pipeline There are two factors to consider: Cost -Very dependent on input sizes - Input sizes are dependent on selectivity… Selectivity - The proportion of results rejected by the stage - We estimate it based on the expression used: ==,, !=, aMethod() - Or, we can test it with sampling

Configuring Join Order Two strategies to decide Join Order:  Exhaustive Search - Good results but expensive - Requires searching n! possible orderings  Maximum Selectivity Heuristic - Less optimal order, less overhead.

Querying Performance Four versions of: selectAll(Integer a=as, Integer b=bs, Integer c=cs, Integer d=ds: a == b && b != c && c < d);

HANDOPT Implementation HashMap > map; map = new HashMap >( ); for(Integer i1 : array1) { ArrayList grp = map.get(i1); if(grp == null) { grp = new ArrayList (); map.put(i1,grp); } grp.add(i1); } ArrayList matches = new ArrayList (); Collections.sort(array4); for(Integer i2 : array2) { int b=i2; ArrayList grp = map.get(i2); if(grp != null) { for(Integer i1 : grp) {int a=i1; for(Integer i3 : array3) { int c=i3; if(b != c) { for(int x=array4.size();x!=0;x=x1){ int d=array4.get(x-1); if(c<d){ Object[] t = new Object[4]; t[0]=a; t[1]=b; t[2]=c; t[3]=d; matches.add(t); } else { break; } } return matches;

Performance Discussion selectAll(Integer a=as, Integer b=bs, Integer c=cs, Integer d=ds : a==b && b!=c && c < d); JQL's performance is pretty good! The average programmer is more likely to code HANDPOOR than HANDOPT.

Object Tracker Performance Object tracker overhead varies greatly.

Other Querying Systems C ω /LINQ(C#) Provide similar querying capabilities. Query-Based Debuggers QBD, DQBD by Lencevicius et al. Used querying and object tracking for debugging. Relational Databases Much prior work in query optimisation.

In Development/Consideration Caching Both simple, and incrementalised Other join methods Again, from databases – Merge, Sort, etc Tool Support Eclipse/Netbeans/etc

Conclusions  Queries are neat  They are a powerful, simple, useful abstraction.  JQL provides efficient and easy support for querying in Java.  For more information on JQL: