def setUp(self):
        self.students = [
          ('id', 'name', 'age', 'major'),
          (1, 'Brian', 30, 'eng'),
          (2, 'Jason', 33, 'econ'),
          (3, 'Christie', 28, 'accounting'),
          (4, 'Gayle', 33, 'edu'),
          (5, 'Carolyn', 33, 'econ'),
          (6, 'Michael', 65, 'law'),
          (7, 'Lori', 62, 'business')
        ]
        self.major_gpas = [
          ('id', 'major', 'gpa'),
          (1, 'eng', 4),
          (2, 'econ', 2),
          (3, 'accounting', 3),
          (4, 'edu', 4.5),
          (6, 'law', 5),
          (7, 'business', 4)
        ]
        self._input1 = Scan([ii for ii in self.students])
        self._input2 = Scan([ii for ii in self.major_gpas])

        # join students with the average gpa for their major
        self.theta = lambda _row1, _row2: _row1[3] == _row2[1]

        self.expected_joins = [
          (1, 'Brian', 30, 'eng', 1, 'eng', 4),
          (2, 'Jason', 33, 'econ', 2, 'econ', 2),
          (3, 'Christie', 28, 'accounting', 3, 'accounting', 3),
          (4, 'Gayle', 33, 'edu', 4, 'edu', 4.5),
          (5, 'Carolyn', 33, 'econ', 2, 'econ', 2),
          (6, 'Michael', 65, 'law', 6, 'law', 5),
          (7, 'Lori', 62, 'business', 7, 'business', 4)
        ]
예제 #2
0
    def test_sort_merge_join(self):
        expected_joins = [
            ('3', 'Christie', '28', 'accounting', '3', 'accounting', '3'),
            ('7', 'Lori', '62', 'business', '7', 'business', '4'),
            ('2', 'Jason', '33', 'econ', '2', 'econ', '2'),
            ('5', 'Carolyn', '33', 'econ', '2', 'econ', '2'),
            ('4', 'Gayle', '33', 'edu', '4', 'edu', '4.5'),
            ('1', 'Brian', '30', 'eng', '1', 'eng', '4'),
            ('6', 'Michael', '65', 'law', '6', 'law', '5'),
        ]

        theta = lambda _row1, _row2: _row1[3] == _row2[1]
        projection1 = lambda r: r[3]
        projection2 = lambda r: r[1]

        result = list(
            execute(
                tree([
                    SortMergeJoin(theta, projection1, projection2),
                    [Sort(projection1), [Scan(self._data, pop_headers=True)]],
                    [
                        Sort(projection2),
                        [Scan(self.majors_gpa, pop_headers=True)]
                    ],
                ])))

        self.assertEquals(result, expected_joins)
예제 #3
0
 def setUp(self):
     self._data = [('id', 'name', 'age', 'major'), (1, 'Brian', 30, 'eng'),
                   (2, 'Jason', 33, 'econ'),
                   (3, 'Christie', 28, 'accounting'),
                   (4, 'Gayle', 33, 'edu'), (5, 'Carolyn', 33, 'econ'),
                   (6, 'Michael', 65, 'law'), (7, 'Lori', 62, 'business')]
     self._input = Scan((ii for ii in self._data))
     self._projector = lambda _row: [_row[1]]
예제 #4
0
    def test_next(self):
        instance = Scan(self.values)

        self.assertEquals(next(instance), self.values[0])

        self.assertEquals(next(instance), self.values[1])

        self.assertEquals(next(instance), instance.EOF)
예제 #5
0
    def test_tree__one(self):
        scan_node = Scan(self._data)
        result = tree([scan_node])
        expected = scan_node
        self.assertEquals(result, expected)

        result = scan_node._inputs
        expected = []
        self.assertEquals(result, expected)
예제 #6
0
 def test_eof(self):
     main = tree([
         Count(),
         [
             Projection(lambda a: a),
             [Scan([1, 2, 3], pop_headers=False)],
         ],
     ])
     self.assertEquals(next(main), (3, ))
     result = next(main)
     self.assertEquals(result, Count.EOF)
예제 #7
0
 def test_next(self):
     result = list(
         execute(
             tree([
                 Count(),
                 [
                     Projection(lambda a: a),
                     [Scan(self._data, pop_headers=True)],
                 ],
             ])))
     expected = [(7, )]
     self.assertEquals(result, expected)
예제 #8
0
    def test_tree__two(self):
        selection_node = Selection(lambda a: a)
        scan_node = Scan(self._data)

        result = tree([selection_node, [scan_node]])
        expected = selection_node
        self.assertEquals(result, expected)

        self.assertIn(
            scan_node,
            selection_node._inputs,
        )
        self.assertEquals(len(selection_node._inputs), 1)
예제 #9
0
    def test_nested_loop_join(self):
        expected_joins = [
            ('1', 'Brian', '30', 'eng', '1', 'eng', '4'),
            ('2', 'Jason', '33', 'econ', '2', 'econ', '2'),
            ('3', 'Christie', '28', 'accounting', '3', 'accounting', '3'),
            ('4', 'Gayle', '33', 'edu', '4', 'edu', '4.5'),
            ('5', 'Carolyn', '33', 'econ', '2', 'econ', '2'),
            ('6', 'Michael', '65', 'law', '6', 'law', '5'),
            ('7', 'Lori', '62', 'business', '7', 'business', '4')
        ]

        theta = lambda _row1, _row2: _row1[3] == _row2[1]

        result = list(
            execute(
                tree([
                    NestedLoopJoin(theta),
                    [Scan(self._data, pop_headers=True)],
                    [Scan(self.majors_gpa, pop_headers=True)],
                ])))

        self.assertEquals(result, expected_joins)
예제 #10
0
    def test_tree__nested(self):
        projection_node = Projection(lambda a: a)
        selection_node = Selection(lambda a: a)
        scan_node = Scan([1, 2, 3])

        result = tree([projection_node, [selection_node, [scan_node]]])

        self.assertEquals(result, projection_node)

        self.assertIn(
            selection_node,
            projection_node._inputs,
        )
        self.assertEquals(len(projection_node._inputs), 1)

        self.assertIn(
            scan_node,
            selection_node._inputs,
        )
        self.assertEquals(len(selection_node._inputs), 1)
예제 #11
0
 def test_close(self):
     instance = Scan(self.values)
     self.assertEquals(instance.__close__(), None)
예제 #12
0
 def test_init(self):
     instance = Scan(self.values)
     self.assertEquals(instance.values, self.values)