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/25 23:06]
jrtyler [FAQ]
cs-236:relational-database [2018/10/18 21:53] (current)
pdiddy [Part 2: RDBMS-based Interpreter]
Line 15: Line 15:
 Create a relation object that includes methods implementing select, project, and rename operations. The relation and its methods must follow the mathematical definitions described in class and in the textbook. For example, the operators must not produce relations which have duplicate tuples or duplicate names in the schema. Create a relation object that includes methods implementing select, project, and rename operations. The relation and its methods must follow the mathematical definitions described in class and in the textbook. For example, the operators must not produce relations which have duplicate tuples or duplicate names in the schema.
  
-Implement at least 10 tests to validate the select, project, and rename methodsAt 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 (in that order). 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. For the 4 tests that mimic a query, the comments must include the actual query that is being mimicked. Each of the tests must test something different; if one test case tests the same thing as another, it isn't telling you anything new, and therefore it won't be counted as one of the 10 tests.+Implement at least 10 tests to validate the select, project, and rename methods
 +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). 
 +** Both types of selects must be implemented. 
 +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. 
 +** For the 4 tests that mimic a query, the comments must include the '''​actual query''' ​that is being mimicked. 
 +*Each of the tests must test something different; if one test case tests the same thing as another, it isn't telling you anything new, and therefore it won't be counted as one of the 10 tests.
  
 Further, all the tests must be automatic; '''​automatic means the tests run without any user input and reports to the console the status of every test: pass or fail.'''​ Further, all the tests must be automatic; '''​automatic means the tests run without any user input and reports to the console the status of every test: pass or fail.'''​
Line 45: 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 142: 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 201: Line 234:
 Consider the query SNAP('​s',​X,​X,​Y)?​ Consider the query SNAP('​s',​X,​X,​Y)?​
 * SNAP is the name of the relation that pertains to this query. * SNAP is the name of the relation that pertains to this query.
 +* '​s',​ X, and Y are the parameters of this query.
 * '​s'​ is a constant. A select must be performed. * '​s'​ is a constant. A select must be performed.
 * X and Y are variables. Because X occurs more than once, a select must be performed. * X and Y are variables. Because X occurs more than once, a select must be performed.
Line 206: Line 240:
 '''​When should I select, project, or rename in a query?'''​ '''​When should I select, project, or rename in a query?'''​
  
-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: 
-Only do select operations as you traverse ​the parameters. The select ​will either be on a constant ​or it will be on an variable ​if that variable ​has been seen previously (i.e., the special ​case to avoid having two identical IDs in the scheme when the rename occurs). +Iterate through every parameter of the query and perform a select ​for every constant ​and every variable that has occurred beforeIt 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, ​then project to the original attributes ​(only the first instance of each variable, leaving out the constants and duplicate variables) ​and rename those attributes to their new names. +# 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) 
-The strategy implies that each select knows the list of IDs in the final project ​since it needs to check for duplicates to determine when to select on column rather than a constantAlso in this strategy, ​it may be the case that no select takes place on an ID parameter (which is just fine).  +# 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 renameWhile it is possible ​in some circumstances to do it in different ordersuch attempts will often lead to errorsso you need to execute these functions in the proper order.
-Also, as general rule that is always trueat any parameterit is either a select operation or a delayed project/​rename operation. It is never both+
  
 '''​What does the select operation do?'''​ '''​What does the select operation do?'''​
Line 219: 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.1508972789.txt.gz · Last modified: 2017/10/25 23:06 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