Document Store Implementation
New folder/data.txt
B: 390 C: 5 D: 1 F: 127700 F: 108200 C: 1 I: 66 H: 44 B: 990 E: 13 H: 41 F: 121200 F: 149600 H: 67 F: 99200 B: 510 E: 47 D: 1 I: 21 B: 650 I: 76 F: 173600 C: 1 F: 127200 G: 1 I: 86 B: 100 D: 2 E: 15 C: 3 F: 151900 G: 1 E: 19 H: 47 D: 2 C: 1 H: 38 E: 44 B: 820 G: 1 C: 2 E: 40 F: 153700 H: 68 B: 470 B: 220 H: 56 H: 25 D: 1 C: 1 C: 5 E: 50 B: 640 E: 39 I: 46 B: 470 D: 2 H: 66 I: 21 F: 124000 H: 62 F: 126300 C: 5 B: 570 E: 32 G: 1 H: 36 E: 37 G: 1 H: 40 I: 96 F: 54900 G: 2 I: 31 D: 1 B: 620 F: 172700 C: 4 I: 91 F: 146900 D: 2 C: 2 B: 900 G: 1 G: 2 C: 1 H: 24 F: 175200 I: 91 H: 51 E: 37 C: 1 H: 68 E: 41 I: 81 B: 870 D: 1 H: 62 F: 95300 C: 3 E: 10 G: 1 D: 2 F: 153100 D: 1 C: 4 E: 40 I: 71 H: 78 G: 2 F: 67400 D: 1 B: 920 I: 41 E: 19 C: 1 D: 2 B: 220 D: 1 C: 5 F: 133700 H: 33 B: 550 D: 2 H: 86 E: 5 I: 46 C: 4 B: 420 H: 96 G: 1 D: 1 E: 27 E: 31 C: 3 G: 2 H: 43 G: 2 C: 4 H: 76 I: 56 F: 133700 C: 5 E: 50 B: 510 B: 190 E: 1 D: 1 I: 86 C: 5 D: 1 C: 4 I: 1 D: 2 C: 4 B: 480 E: 35 I: 11 B: 280 F: 178400 C: 5 G: 2 B: 440 F: 135000 D: 2 C: 2 D: 2 G: 2 I: 91 F: 52600 E: 8 H: 77 I: 31 G: 1 D: 1 B: 610 C: 2 H: 38 G: 2 I: 61 H: 83 C: 2 F: 77400 F: 130800 G: 2 E: 50 H: 71 E: 7 B: 870 I: 56 H: 72 C: 5 F: 158100 E: 16 F: 160300 H: 20 B: 830 C: 4 G: 1 B: 600 D: 2 C: 3 I: 41 B: 720 C: 1 D: 2 I: 6 E: 29 H: 34 B: 800 I: 91 D: 2 F: 127600 H: 65 C: 4 F: 116300 H: 24 G: 1 I: 16 E: 50 C: 5 G: 2 E: 4 H: 61 I: 41 F: 132900 B: 990 I: 76 E: 35 D: 1 H: 82 G: 1 H: 70 B: 530 E: 14 C: 5 I: 61 E: 4 D: 1 I: 1 B: 670 H: 26 G: 2 E: 22 E: 2 H: 70 F: 87600 B: 200 C: 3 E: 16 D: 1 H: 73 I: 21 C: 4 F: 73500 H: 72 D: 1 F: 70200 I: 6 F: 74300 D: 1 E: 44 F: 75000 D: 2 I: 41 D: 1 C: 3 D: 1 G: 1 E: 22 I: 31 C: 2 C: 4 E: 38 F: 145100 G: 2 F: 153000 B: 760 D: 2 G: 2 I: 91 G: 2 E: 25 D: 2 G: 1 C: 1 E: 38 B: 370 E: 2 H: 52 G: 1 I: 71 B: 950 I: 96 D: 1 F: 105200 B: 300 C: 4 E: 35 E: 16 F: 89400 B: 930 D: 1 H: 42 I: 81 E: 26 C: 4 G: 1 G: 2 I: 56 H: 66 E: 33 F: 168500 C: 4 F: 53700 I: 41 D: 2 D: 2 C: 4 B: 540 I: 36 D: 2 B: 900 E: 49 H: 41 F: 148000 H: 54 F: 178200 I: 86 F: 155400 E: 9 B: 620 E: 50 H: 65 D: 2 I: 1 H: 56 C: 1 H: 48 D: 2 E: 8 B: 490 G: 2 C: 5 F: 174900 G: 1 H: 61 F: 166500 D: 2 C: 2 I: 26 H: 40 B: 630 C: 5 H: 96 I: 11 C: 5 F: 159500 F: 157700 D: 1 E: 50 H: 71 C: 1 E: 28 B: 140 D: 1 G: 2 I: 1 E: 39 B: 160 D: 2 C: 5 H: 80 C: 5 E: 4 D: 1 I: 31 B: 810 F: 166600 E: 31 C: 5 I: 76 D: 2 B: 730 E: 13 G: 2 I: 36 G: 2 F: 166700 I: 66 F: 199500 E: 7 H: 66 K: 10 E: 15 D: 1 B: 150 K: 20 E: 21 C: 4 F: 110400 B: 240 D: 1 H: 21 E: 8 F: 83700 G: 1 I: 76 H: 89 E: 31 C: 4 C: 4 H: 38 D: 1 E: 47 I: 41 G: 1 H: 38 C: 1 F: 91900 E: 45 E: 46 H: 22 D: 2 B: 350 G: 2 F: 103800 I: 21 F: 99600 B: 270 D: 1 D: 2 F: 110300 G: 1 C: 5 E: 18 F: 68600 H: 21 B: 480 F: 93900 B: 970 D: 1 G: 2 B: 430 E: 45 I: 56 C: 2 F: 172100 I: 61 E: 44 B: 170 D: 2 B: 280 I: 66 H: 29 D: 1 G: 2 H: 27 D: 1 B: 610 G: 2 E: 7 C: 1 G: 1 F: 121800 G: 2 H: 52 E: 44 B: 700 I: 51 E: 42 H: 18 B: 390 F: 155600 E: 22 D: 2 E: 9 G: 1 F: 127600 I: 41 I: 41 H: 35 B: 790 G: 2 C: 2 B: 800 H: 35 E: 12 D: 1 C: 3 H: 89 F: 162900 G: 1 D: 1 I: 21 H: 20 F: 123800 I: 71 D: 2 G: 1 G: 2 F: 182100 B: 570 I: 81 C: 1 E: 4 H: 59 C: 5 H: 45 I: 21 J: 500 G: 1 B: 960 C: 5 D: 2 E: 1 D: 2 F: 118500 H: 61 G: 2 I: 61 B: 250 E: 47 C: 4 D: 2 F: 182000 B: 800 D: 2 H: 83 E: 41 G: 1 F: 156000 D: 1 C: 3 G: 2 I: 11 D: 2 F: 112300 C: 1 D: 2 E: 16 H: 33 G: 2 C: 5 E: 29 G: 2 E: 33 G: 2 C: 4 F: 145300 H: 49 B: 760 I: 31 E: 6 F: 185600 D: 1 I: 76 G: 1 F: 195100 E: 50 E: 31 G: 1 I: 26 B: 480 C: 3 G: 2 F: 130800 D: 1 C: 4 I: 56 F: 108400 G: 1 B: 520 E: 44 I: 36 C: 2 D: 2 G: 2 E: 26 G: 2 J: 600 D: 1 I: 96 B: 720 G: 2 F: 168400 C: 2 I: 91 H: 56 C: 1 E: 24 B: 750 H: 18 D: 1 B: 360 E: 1 F: 108400 I: 66 G: 1 C: 5 F: 134200 H: 43 I: 81 C: 3 E: 38 B: 580 G: 2 I: 41 C: 5 I: 56 D: 2 G: 1 E: 47 B: 770 F: 57500 C: 4 G: 1 I: 66 F: 115700 H: 90 E: 13 C: 3 D: 1 F: 49900 F: 106800 B: 150 I: 21 D: 2 H: 63 C: 1 H: 41 G: 2 E: 44 D: 2 F: 43900 I: 76 D: 1 E: 5 H: 70 F: 141100 I: 21 E: 49 D: 1 C: 1 B: 320 C: 4 D: 1 E: 30 E: 47 D: 1 C: 5 E: 28 D: 2 F: 147400 C: 4 H: 96 B: 270 G: 1 E: 30 D: 1 B: 180 B: 820 J: 700 C: 3 I: 11 I: 51 D: 2 H: 49 E: 36 I: 56 G: 1 H: 76 F: 107200 E: 20 I: 46 I: 6 G: 1 C: 5 D: 2 F: 151300 I: 41 H: 28 H: 21 G: 2 F: 62200 H: 51 G: 1 E: 48 C: 3 B: 110 H: 18 I: 16 F: 100200 I: 56 E: 19 D: 1 C: 4 E: 28 I: 56 F: 195500 I: 61 G: 2 B: 170 E: 31 C: 1 G: 2 B: 320 C: 3 D: 2 F: 154700 E: 37 E: 15 B: 800 C: 1 E: 45 C: 3 D: 2 G: 1 B: 370 E: 41 F: 184800 D: 1 F: 190300 D: 1 C: 5 E: 5 E: 45 F: 47600 D: 2 C: 3 G: 2 C: 1 H: 81 E: 18 F: 166200 H: 96 I: 51 F: 87400 B: 230 D: 1 H: 87 E: 14 F: 91300 I: 16 E: 4 I: 41 D: 1 G: 2 F: 81500 I: 61 E: 42 F: 76300 H: 76 B: 730 F: 183600 B: 650 G: 1 H: 79 F: 121800 C: 1 D: 1 E: 9 D: 1 C: 2 B: 570 F: 95700 H: 75 F: 89800 C: 1 I: 6 B: 990 E: 17 F: 129300 D: 1 E: 20 F: 176700 I: 91 D: 2 E: 26 B: 410 B: 950 C: 3 H: 62 D: 1 I: 71 C: 2 E: 13 G: 1 C: 2 E: 40 F: 171500 D: 1 I: 36 C: 2 I: 61 F: 174100 E: 12 C: 2 B: 800 G: 1 I: 1 D: 2 D: 2 E: 4 C: 1 F: 121300 E: 17 D: 2 G: 1 F: 42500 G: 1 I: 76 G: 2 D: 1 B: 840 C: 5 E: 26 F: 159000 G: 1 B: 350 E: 3 B: 460 H: 22 E: 18 C: 4 D: 1 I: 1 F: 68500 I: 91 E: 43 B: 280 G: 2 I: 36 H: 20 C: 4 F: 188200 H: 91 D: 1 F: 186500 C: 3 G: 2
New folder/Document 1.pdf
CS 301 Final Exam Project
Implement Document Store Queries
Fall 2020 Updated: 11/13 @ 7:16 am
Due Date - Monday, Dec. 7
Sample Data File - SampleData.txt Sample Queries - queries copy.txt Solutions to Queries - Solutions Queries.txt
For this assignment you are to write a program to implement the operations required
to process and execute NoSQL queries on a preexisting file of data. The data in the
file corresponds to a collection in a database. In order to process the query, you will
have to parse the query to identify which operations it is requesting, perform the
operations on the specified documents and display the results. You must write the
code to implement two operations similar to those in MongoDB: a select operation
and a sort operation. You cannot run these queries using a database management
system, instead you are implementing some of the software yourself for a NoSQL
DBS.
You may use the programming language of your choice. You may use any library EXCEPT you must implement the actual FIND and SORT operations yourself. This means you are to implement the project and the selection operations needed for FIND. Also, do not use a built in sort function.You may implement any sort algorithm you want.
Data: The data will be stored in a file named data.txt. In the data file each line represents a different document. Since this is a NoSQL database, the names of each
field are included in the data along with the value of the field.
• The fields may be stored in a different order for each document. Each field is
formatted as fieldname: value
• The field name is followed by a colon and a space, and fields are separated by a
space.
• Assume all values for every field are integer.
• You should generate an ID field for each document. This system generated ID
will be named A.
• All fields will be exactly one character long and will be one of the alphabetic
characters from the capital letters B through W.
Example of possible input data for collection final: B: 555 V: 1 C: 5 C: 10 V: 1 M: 555 B: 777 H: 20
M: 555 V: 2 C: 6 H: 20 V: 1 M: 555 B: 222
You can store the data anyway you choose for your collection. You are writing the
DBMS, so do what you want to the data in order to process the query.
Queries: There will be a series of queries for you to process from an input file called
final.txt. You MUST assume this as the name of the file. The NoSQL queries for this
project are similar to MongoDB but they have a completely different syntax. You will
implement the two operations FIND and SORT.
Operation - FIND FIND: returns values to fields specified for documents that satisfy the specified
condition(s).
• The query is formatted to appear on multiple lines.
• The first line of such input is a keyword FIND.
• The second line and subsequent lines of the input are the conditions. • The final line for the query contains the projections, in other words, the fields
to be displayed
Conditions: fieldName ComparisonOp integer There will be zero or more select conditions with each select condition on a separate
line.
• A document can only be included in the result if it satisfies all of the
conditions. That means if a field that appears in a condition does not exist in
the document, then that document does not appeaer in the result.
• If there are zero conditions then a line will contain an Y. Zero conditions means
include all documents.
• The comparisonOp can only be one of these three: =, < or >.
• There will be spaces separating each fieldName, ComparisonOP and
value. Examples are H = 67 G = 7
Projections: fieldName fieldName fieldName The list of fieldnames to be displayed appear on the last line of the query. The field
names are separated by spaces.
• If all of the fields of the document are to be displayed, then the line will contain
a Z and only the letter Z.
• The names of the fields can appear in any order.
• Unlike Mongo DB, the ID field, named A, is only included if specified. If a
document does not have a field in the fieldName list, but it has other fields
appearing in the list, then it should be included in the result.
The end of a query will be denoted with a ; preceded by a space. There will not be any blank lines in the final.txt or data.txt files.
FIND H = 67 G > 7 A M K S G ; FIND Y Z ;
The last FIND query above returns the entire collection, e.g., all fields for all
documents including the id, which has the fieldname of A.
Output: For each document satisfying the conditions, output each field name ending
with a colon, a space, and the value for the field.
• Separate fields with a space.
• The fields should be displayed in the same order as they appear in the
document, so the fields may not be in the same order as the fieldName list.
• Keep a count for each query executed and print the number of the query before
you display the results.
Example queries and their results: FIND M = 555 C H ; //Query 1 C: 10 H: 20 C: 6 H: 20
FIND H = 20 M = 555 Z ; //Query 2 A: 2 C: 10 V: 1 M: 555 B: 777 H: 20 A: 4 H: 20 V: 1 M: 555 B: 222
FIND Y Z ; //Query 3 A: 001 B: 555 V: 1 C: 5 A: 002 C: 10 V: 1 M: 555 B: 777 H: 20
A: 003 M: 555 V: 2 C: 6 A: 004 H: 20 V: 1 M: 555 B: 222
• If no documents satisfy the specified condition, output nothing.
• If the first line of the input for a query is not the keyword FIND or SORT print
an error.
• Since this is a NoSQL DB, there should not be an error generated if there is no
match for the name of a field. Instead:
o If a field specified in a condition does not exist in the entire
collection, it evaluates to a false so no output is produced.
o If a field in a projection does not exist in a document,
ignore it in the output. If other fields listed do exist, then
list those in the output.
Example queries and their results: FIND T = 6 U ; //returns nothing, if there is no T field and/or no U field
Operation - SORT SORT: Returns the documents sorted on the specified fieldname.
• The query is formatted to appear on multiple lines.
• The first line of such input is a keyword SORT.
• The second line is the field on which the documents will be sorted.
Sorting field is fieldName = order Where order is 1 for ascending and -1 for descending
SORT A = -1 ;
• Only one field will be specified per SORT operation
• Display the entire document
Output: Documents listed in reverse sorted order Example: SORT A = -1 ;
A: 4 H: 20 V: 1 M: 555 B: 222 A: 3 M: 555 V: 2 C: 6 A: 2 C: 10 V: 1 M: 555 B: 777 H: 20 A: 1 B: 555 V: 1 C: 5
• If a document does not have the sort field, do NOT include it in the
output. This is different from MongoDB which includes documents with missing sorting fields, but includes the missing sorting fields as { } in the output.
• If no documents contain the sort field, return nothing. Obviously, you cannot
sort the documents on a field that does not exist.
New folder/queries copy.txt
FIND B = 550 Z ; FIND B = 550 A F H ; FND B = 55 A ; FIND I > 91 B < 500 I B ; FIND Y K ; SORT J = -1 ; FIND B = 2 Z ;
New folder/Solutions Queries.txt
A: 33 D: 1 C: 5 F: 133700 H: 33 B: 550 A: 33 F: 133700 H: 33 Error I: 96 B: 300 K: 10 K: 20 A: 186 B: 820 J: 700 A: 160 E: 26 G: 2 J: 600 A: 141 C: 5 H: 45 I: 21 J: 500 Empty Output