Exemple #1
0
class TestThetaJoin(TestSQL):
    grammar = ExtendedGrammar()

    def test_relation(self):
        ra = 'alpha \\join_{a1 = b1} beta;'
        expected = [
            'SELECT alpha.a1, alpha.a2, alpha.a3, '
            'beta.b1, beta.b2, beta.b3 FROM '
            '(SELECT alpha.a1, alpha.a2, alpha.a3 FROM alpha) AS alpha '
            'JOIN '
            '(SELECT beta.b1, beta.b2, beta.b3 FROM beta) AS beta '
            'ON a1 = b1'
        ]
        actual = self.translate(ra)
        self.assertEqual(expected, actual)

    def test_theta_join_then_join(self):
        ra = '(alpha \\join_{alpha.a1=beta.b1 and b3>50} beta) \\join gamma;'
        expected = [
            'SELECT alpha.a1, alpha.a2, alpha.a3, '
            'beta.b1, beta.b2, beta.b3, '
            'gamma.g1, gamma.g2 FROM '
            '(SELECT alpha.a1, alpha.a2, alpha.a3 FROM alpha) AS alpha '
            'JOIN '
            '(SELECT beta.b1, beta.b2, beta.b3 FROM beta) AS beta '
            'ON alpha.a1 = beta.b1 and b3 > 50 '
            'CROSS JOIN (SELECT gamma.g1, gamma.g2 FROM gamma) AS gamma'
        ]
        actual = self.translate(ra)
        self.assertEqual(expected, actual)
Exemple #2
0
class TestNaturalJoin(TestSQL):
    grammar = ExtendedGrammar()

    def test_relation_simple(self):
        ra = 'alpha \\natural_join alphatwin;'
        expected = [
            'SELECT alpha.a1, alpha.a2, alpha.a3 FROM '
            '(SELECT alpha.a1, alpha.a2, alpha.a3 FROM alpha) AS alpha '
            'NATURAL JOIN '
            '(SELECT alphatwin.a1, alphatwin.a2, alphatwin.a3 '
            'FROM alphatwin) AS alphatwin'
        ]
        actual = self.translate(ra)
        self.assertEqual(expected, actual)

    def test_three_relations(self):
        ra = 'alpha \\natural_join alphatwin \\natural_join alphaprime;'
        expected = [
            'SELECT alpha.a1, alpha.a2, alpha.a3, alphaprime.a4, '
            'alphaprime.a5 FROM '
            '(SELECT alpha.a1, alpha.a2, alpha.a3 FROM alpha) AS alpha '
            'NATURAL JOIN '
            '(SELECT alphatwin.a1, alphatwin.a2, alphatwin.a3 '
            'FROM alphatwin) AS alphatwin '
            'NATURAL JOIN '
            '(SELECT alphaprime.a1, alphaprime.a4, alphaprime.a5 '
            'FROM alphaprime) AS alphaprime'
        ]
        actual = self.translate(ra)
        self.assertEqual(expected, actual)
class TestNaturalJoin(TestSQLSequence):
    grammar = ExtendedGrammar()

    def test_relation_simple(self):
        ra = 'alpha \\natural_join alphatwin;'
        expected = [[
            'SELECT alpha.a1, alpha.a2, alpha.a3 FROM alpha',
            'SELECT alphatwin.a1, alphatwin.a2, alphatwin.a3 FROM alphatwin',
            'SELECT alpha.a1, alpha.a2, alpha.a3 FROM '
            '(SELECT alpha.a1, alpha.a2, alpha.a3 FROM alpha) AS alpha '
            'NATURAL JOIN '
            '(SELECT alphatwin.a1, alphatwin.a2, alphatwin.a3 '
            'FROM alphatwin) AS alphatwin'
        ]]
        actual = self.translate(ra)
        self.assertEqual(expected, actual)
class TestThetaJoin(TestSQLSequence):
    grammar = ExtendedGrammar()

    def test_relation(self):
        ra = 'alpha \\join_{a1 = b1} beta;'
        expected = [[
            'SELECT alpha.a1, alpha.a2, alpha.a3 FROM alpha',
            'SELECT beta.b1, beta.b2, beta.b3 FROM beta',
            'SELECT alpha.a1, alpha.a2, alpha.a3, '
            'beta.b1, beta.b2, beta.b3 FROM '
            '(SELECT alpha.a1, alpha.a2, alpha.a3 FROM alpha) AS alpha '
            'JOIN '
            '(SELECT beta.b1, beta.b2, beta.b3 FROM beta) AS beta '
            'ON a1 = b1'
        ]]
        actual = self.translate(ra)
        self.assertEqual(expected, actual)
class TestIntersection(TestSQLSequence, TestSet):
    grammar = ExtendedGrammar()
    ra_operator = '\\intersect'
    sql_operator = 'INTERSECT'
Exemple #6
0
 def setUp(self):
     self.parser = ExtendedGrammar()
     self.parse = self.parse_function(self.parser.statements)