CSI410 – Programming Assignment II (Solution)

$ 20.99
Category:

Description

• any missing or incomplete elements of the code
• any changes made to the original API
• the amount of time spent for this assignment
• suggestions or comments if any

Part 1. Operators and TupleArrayReader (30 points)
In this assignment, all of the relational operators support the following four methods (see Operator.java):
• hasNext(): determines whether or not the operator has the next output Tuple.
• next(): returns the next output Tuple.
• rewind(): rewinds the operator in order to retrieve all of the output Tuples again.
• outputSchema(): returns the output schema of the operator.
It should be noted that the Operator interface inherits the hasNext() and next() methods from the standard Java Iterator interface.
In this part, you need to complete the code in TupleArrayReader.java. Each TupleArrayReader outputs, given an array of Tuples, the Tuples in that array. The methods to complete are hasNext(), next(), and rewind(). Implemet these methods using the currentIndex member variable which is to remember the index of the next Tuple to retrieve/return during each iteration over the Tuples. When all of the above methods are implemented correctly, your code will pass the unit tests in TupleArrayReaderTest.java.
Part 2. Selection (50 points)
The constructor/methods to complete are as follows:
• outputSchema(): returns the output schema of the SelectionOperator. This output schema is the same as the input schema of the SelectionOperator. Consider using a method or a member variable provided by a super-type of SelectionOperator to get the input schema of the SelectionOperator.
• hasNext(): determines whether or not the SelectionOperator has the next output Tuple.
• next(): returns the next output Tuple.
• rewind(): rewinds the operator in order to retrieve all of the output Tuples again.
When all of the above methods are implemented correctly, your code will pass the unit tests in SelectionOperatorTest.
Part 3. Aggregation: AggregateOperator.java (5 points)
In this part, you need to complete AggregateOperator.java. An Aggregator groups all Tuples (by user-specified attributes) from an input Operator and outputs, for each group of Tuples, a Tuple that represents/summarizes that group of Tuples (e.g., for each location code, the minimum temperature). An AggregateOperator is an operator that uses an Aggregator and supports the basic iterator capabilities (hasNext() and next() methods).
This part requires implementing only the following method:
• createOutputSchema(AggregateFunction[] aggregateFunctions): constructs and then returns the output schema of the AggregageOperator. The output schema consists of the grouping attributes (e.g., Location) and additional attributes from AggregateFunctions (e.g., Maximum(Temperature)). This method needs to construct a new RelationSchema which requires an array storing the names of the attributes and another array storing the types of these attributes.
For the i-th grouping attribute, the name of that attribute can be obtained from groupingAttributeNames[i]. Given that attribute name, the type of the attribute can be obtained by using inputSchema.attributeIndex(String) and inputSchema.attributeType(int). For the i-th AggregateFunction, the name of that AggregateFunction can be obtained from aggregateFunctions[i].toString(). The type of that AggregateFunction can be obtained from aggregateFunctions[i].valueType().
When the above method is implemented correctly, your code will pass the unit tests in AggregateOperatorTest while showing the following output:
input schema : {ID=java . lang . Integer , Location=java . lang . Integer , Temperature=java . lang . Double} grouping attributes : [ Location ] aggregate functions : [ Minimum(Temperature )]
output schema : {Location=java . lang . Integer , Minimum(Temperature)=java . lang . Double}
The above output shows a situation where (i) the input schema has attributes ID, Location, and Temperature, (ii) the grouping attribute is Location, (iii) the aggregate function is Minimum(Temperature), and thus (iv) the output schema has attributes Location and Minimum(Temperature).
Part 4. Aggregation: Aggregator.java (10 points)
As mentioned in Part 3, an Aggregator groups all Tuples (by user-specified attributes) from an input Operator and outputs, for each group of Tuples, a Tuple that represents/summarizes that group of Tuples (e.g., for each location code, the minimum temperature). In this part, you need to implement the following costructor and method in Aggregator.java:
• Aggregator(Operator input, RelationSchema outputSchema, String[] groupingAttributeNames, Class<?>[] aggregateFunctionTypes, String[] aggregationAttributeNames): constructs an Aggregator. Given an input tuple t, the Aggregator needs to extract the values of the grouping attributes (e.g., Location value 0) and then finds the AggregateFunctions for that combination of grouping values (e.g., Minimum and Maximum that have been applied to the Temperature attribute from all Tuples whose Location value is 0). Then, the Aggregator needs to update all of these AggregateFunctions based on tuple t (e.g., update the minimum value if the Temperature value of t is smaller than the previous minimum). The above implementation approach requires space linear in the number of distinct groups. For the purposes of this assignment, you do not need to worry about the situations where there are too many groups to fit into the memory.
• iterator(): returns an iterator over the output Tuples of the Aggregator. The details of these output Tuples are explained above (refer to the output schema of the AggregageOperator).
When the above constructor and method are implemented correctly, your code will pass the unit tests in AggregatorTest.
Appendix A. Importing a Java Project

2. In the menu bar, choose “File” and then “Import”. Next, select “General” and “Existing Projects into Workspace”. Then, click the “Browse” button and select the “hdb query.zip” file contained in this assignment package.
3. Once the project is imported, you can choose TupleArrayReaderTest.java, SelectionOperatorTest.java, textttAggregateOperatorTest.java, or AggregatorTest.java and then run the program.

Reviews

There are no reviews yet.

Be the first to review “CSI410 – Programming Assignment II (Solution)”

Your email address will not be published. Required fields are marked *