Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs-236:relational-database [2017/10/26 00:22]
jrtyler [Part 1: relation class with tests]
cs-236:relational-database [2018/10/18 21:53] (current)
pdiddy [Part 2: RDBMS-based Interpreter]
Line 18: Line 18:
 * At least 4 of the 10 tests must mimic a datalog query in that they use a sequence of select, project, and rename to answer the query (as explained below in the FAQ). * At least 4 of the 10 tests must mimic a datalog query in that they use a sequence of select, project, and rename to answer the query (as explained below in the FAQ).
 * The tests must be testing either a select, project, rename, or a query; they may '''​not'''​ test if the relation you create is structured properly (i.e. proper sorting, no duplicates, etc.; while these things are important, they are not what should be tested). * The tests must be testing either a select, project, rename, or a query; they may '''​not'''​ test if the relation you create is structured properly (i.e. proper sorting, no duplicates, etc.; while these things are important, they are not what should be tested).
 +** Both types of selects must be implemented.
 * The tests must be documented and justified: what does the test accomplish? * The tests must be documented and justified: what does the test accomplish?
 ** Each test must be marked with comments explaining what operation is being performed and why. ** Each test must be marked with comments explaining what operation is being performed and why.
Line 51: Line 52:
 * '''​Output''':​ see the [[datalog-parser#​Output Specifications|output specifications]] and [[datalog-parser#​Examples | examples]] * '''​Output''':​ see the [[datalog-parser#​Output Specifications|output specifications]] and [[datalog-parser#​Examples | examples]]
  
-Part 2 is scored on a set of 10 private tests at submission. ​+Part 2 is scored on a set of private tests at submission. ​
 ==Examples== ==Examples==
  
Line 148: Line 149:
 dc(X,Y)? Yes(1) dc(X,Y)? Yes(1)
   X='​ralph',​ Y='​howard'​   X='​ralph',​ Y='​howard'​
 +</​code>​
 +
 +'''​Input'''​
 +<​code>​
 +Schemes:
 +  Student(name,​ age, class)
 +Facts:
 +  Student('​Sean','​21','​Sophomore'​).
 +  Student('​Arthur','​19','​Freshman'​).
 +  Student('​Sidney','​19','​Sophomore'​).
 +  Student('​Nicole','​23','​Senior'​).
 +Rules:
 +Queries:
 +  Student(A,'​19',​B)?​
 +  Student(M,​M,​M)?​
 +  Student('​Nicole',​howOld,'​Senior'​)?​
 +</​code>​
 +
 +'''​Output'''​
 +<​code>​
 +Student(A,'​19',​B)?​ Yes(2)
 +  A='​Arthur',​ B='​Freshman'​
 +  A='​Sidney',​ B='​Sophomore'​
 +Student(M,​M,​M)?​ No
 +Student('​Nicole',​howOld,'​Senior'​)?​ Yes(1)
 +  howOld='​23'​
 </​code>​ </​code>​
  
Line 215: Line 242:
 Here is a simple strategy to consider when deciding how to evaluate queries: Here is a simple strategy to consider when deciding how to evaluate queries:
 # Iterate through every parameter of the query and perform a select for every constant and every variable that has occurred before. It may be the case that no select takes place on a certain variable or any variable in a query, which is fine! # Iterate through every parameter of the query and perform a select for every constant and every variable that has occurred before. It may be the case that no select takes place on a certain variable or any variable in a query, which is fine!
-# Once all the select operations have been completed, project the relation to only include ​the columns ​that have original variables ​in the query (only the first instance of each variable, leaving out the columns that were selected for constants and the columns that were selected as the duplicate instances of variables)+# Once all the select operations have been completed, project the relation to include ​only columns ​with identifiers ​in the query (only the first instance of each variable, leaving out the columns that were selected for constants and the columns that were selected as the duplicate instances of variables)
 # After projecting, rename those attributes to their new names as given in the query. # After projecting, rename those attributes to their new names as given in the query.
 The functions must be called in this order: any selects, followed by a project, followed by a rename. While it is possible in some circumstances to do it in a different order, such attempts will often lead to errors, so you need to execute these functions in the proper order. The functions must be called in this order: any selects, followed by a project, followed by a rename. While it is possible in some circumstances to do it in a different order, such attempts will often lead to errors, so you need to execute these functions in the proper order.
Line 225: Line 252:
 # It can find all the tuples that have the same value in two columns (doesn'​t matter what that value is, as long as the two columns both have it). # It can find all the tuples that have the same value in two columns (doesn'​t matter what that value is, as long as the two columns both have it).
 The schema stays the same. The schema stays the same.
 +
 +'''​If the select operation finds when two columns have the same value, should it also find when two columns have different values?'''​
 +
 +No. If a query has two different variables in it, that does not mean the select must find tuples with different values in those columns. Consider the last query of the first example:
 +
 +<​code>​
 +SK(A,B)? Yes(3)
 +  A='​a',​ B='​c'​
 +  A='​b',​ B='​b'​
 +  A='​b',​ B='​c'​
 +</​code>​
 +
 +While A and B are different variables, the query still includes when the values are the same in the tuple (the second result where both A and B equal '​b'​).
  
 '''​What does the project operation do?'''​ '''​What does the project operation do?'''​
  
-The project operation changes the number and order of columns in a relation. The resulting relation will have either the same number or fewer columns. This affects the schema and all of the tuples in that relation.+The project operation changes the number and order of columns in a relation. The resulting relation will have either the same number ​of or fewer columns. This affects the schema and all of the tuples in that relation.
  
 '''​Why can the project operation also re-order the tuple?'''​ '''​Why can the project operation also re-order the tuple?'''​
cs-236/relational-database.1508977366.txt.gz ยท Last modified: 2017/10/26 00:22 by jrtyler
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0