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/23 17:05]
jjones95 [Part 1: relation class with tests]
cs-236:relational-database [2018/10/18 15:53]
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). 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.''' ​The tests must be documented and justified: what does the test accomplish?+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.'''​
  
 * '''​Command line''':​ no command line arguments * '''​Command line''':​ no command line arguments
-* '''​Output''':​ A '''​pass'''/'''​fail'''​ report for each test. (For this project, each test case you create should pass.)+* '''​Output''':​ A '''​pass'''/'''​fail'''​ report for each test. (see below for further details on these tests) 
 + 
 +The only text that needs to be outputted to the console is the test number and whether it passed or not (but you may definitely output more!). The TAs will look at your code to make sure the test cases do what you say they are doing in the comments. They will also make sure you implemented the select, project, and rename functions.
  
-The pass-off is based on the quality ​of tests and whether ​or not the solution passes.+For this project, each test case you create should pass. The pass/fail report of a test is based on a comparison between ​the expected result and the actual result ​of each test. The comparison must be made automatically by your tester. This means that your tester must have the expected output in the code to compare with the actual output in an if-else statement; the actual output is the relation that is created after performing the select, project, and/or rename operations, while the expected output is what you calculate the relation should be after performing the operations. Common ways to check if they are equal include creating a method that tests if two relations have the same name, schema, ​and tuples; ​or creating a toString function for the relation class and comparing the strings for each relation. It is up to you how to do this, but what is not allowed is always outputting that each test passed without actually checking that the code does what it is supposed to do.
  
-The pass/fail report of a test is based on a comparison between ​the expected result ​and the actual result of each test. The comparison must be made automatically by your tester.+The pass-off is based on the quality of tests and whether or not the solution passes. If a test does not automatically compare actual and expected out as described above, it won't be countedIf more than one test case tests the same thing, only the first test case will be counted.
  
 ===Part 2: RDBMS-based Interpreter=== ===Part 2: RDBMS-based Interpreter===
Line 41: 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 138: 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 192: Line 229:
  
 ==FAQ== ==FAQ==
 +
 +'''​How should we refer to parts of a query?'''​
 +
 +Consider the query SNAP('​s',​X,​X,​Y)?​
 +* 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.
 +* X and Y are variables. Because X occurs more than once, a select must be performed.
  
 '''​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 ID if the ID has been seen previously (i.e., the special ​case to avoid having two identical IDs in the scheme. +Iterate through every parameter of the query and perform ​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 ​that remain ​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 a column rather than a constant. Also 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 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.
  
-Also, as a general rule that is always true, at any parameter, it is either a select operation ​or a delayed project/​rename operation. It is never both. +'''​What does the select operation ​do?'''​
  
-'''​Should project also re-order ​the tuple?'''​+The select operation finds tuples in a relation that meet certain criteria. It can do this in two different ways: 
 +# It can find all the tuples that have a constant in a certain column. 
 +# 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 output for the lab requires that tuples follow the order declared in the query. Although not apparent right now, consider what happens in a natural joinIn such an operation, the order becomes less clear. A project-method can ensure the tuples follow the correct order as part of its operation with some little thought and foresight. ​+'''​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?'''​ 
 + 
 +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?'''​ 
 + 
 +The output for the lab requires that tuples follow the order declared in the query. Although not apparent right now, the later labs will implement ​a natural join operation. ​In such an operation, the order becomes less clear. A project-method can ensure the tuples follow the correct order as part of its operation with some little thought and foresight.  
 + 
 +'''​What does the rename operation do?'''​ 
 + 
 +The rename operation changes the relation'​s schema. The resulting relation will have all the same tuples.
  
 '''​Should rename only change one attribute at a time or the entire attribute list at once?'''​ '''​Should rename only change one attribute at a time or the entire attribute list at once?'''​
  
 Renaming the entire attribute list at once is simpler and avoids any issues with replacing A with B and then replacing B with A on the relation with attributes (A,B). That said, the test inputs are careful to never create such a situation. ​ Renaming the entire attribute list at once is simpler and avoids any issues with replacing A with B and then replacing B with A on the relation with attributes (A,B). That said, the test inputs are careful to never create such a situation. ​
 +
 +'''​What should the select, project, and rename functions return?'''​
 +
 +These functions should create a new relation that reflects the changes made to the original relation. Then they return that new relation. These functions should not modify the original relations, as many queries could be made and it would not work if the original relation kept changing.
 +
 +Note that the new relation will always have the same name as the original relation, but the schema, number of tuples, and number of columns might change depending on the operation.
 ==Submission== ==Submission==
 Review the [[project-standards | project standards]] for creating a zip archive. Review the [[project-standards | project standards]] for creating a zip archive.
cs-236/relational-database.txt · Last modified: 2018/10/18 15:53 by pdiddy
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