Пример #1
0
    def test_simple_multiple(self):
        ra = 'gamma {operator} gammatwin {operator} gammaprime;'.format(
            operator=self.ra_operator)

        root_list = TreeBRD(self.grammar).build(instring=ra,
                                                schema=self.schema)
        root_name = id(root_list[0])
        child_name = id(root_list[0].left)
        root_list = root_list[0].post_order()
        actual = sql_translator.translate(root_list, use_bag_semantics=True)

        expected = [
            'SELECT gamma.g1, gamma.g2 FROM gamma',
            'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin',
            'SELECT g1, g2 FROM (SELECT gamma.g1, gamma.g2 FROM gamma '
            '{operator} ALL '
            'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin) AS _{name1}'.
            format(operator=self.sql_operator,
                   name1=child_name,
                   name2=root_name),
            'SELECT gammaprime.g1, gammaprime.g2 FROM gammaprime',
            'SELECT g1, g2 FROM ('
            'SELECT g1, g2 FROM '
            '(SELECT gamma.g1, gamma.g2 FROM gamma '
            '{operator} ALL '
            'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin) AS _{name1} '
            '{operator} ALL '
            'SELECT gammaprime.g1, gammaprime.g2 FROM gammaprime) AS _{name2}'.
            format(operator=self.sql_operator,
                   name1=child_name,
                   name2=root_name)
        ]
        self.assertEqual(expected, actual)
Пример #2
0
    def test_simple_multiple(self):
        ra = 'gamma {operator} gammatwin {operator} gammaprime;'.format(operator=self.ra_operator)

        root_list = TreeBRD(self.grammar).build(instring=ra, schema=self.schema)
        root_name = id(root_list[0])
        child_name = id(root_list[0].left)
        root_list = root_list[0].post_order()
        actual = sql_translator.translate(root_list, use_bag_semantics=True)

        expected = ['SELECT gamma.g1, gamma.g2 FROM gamma',
                    'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin',

                    'SELECT g1, g2 FROM (SELECT gamma.g1, gamma.g2 FROM gamma '
                    '{operator} ALL '
                    'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin) AS _{name1}'
                        .format(operator=self.sql_operator, name1=child_name, name2=root_name),

                    'SELECT gammaprime.g1, gammaprime.g2 FROM gammaprime',

                    'SELECT g1, g2 FROM ('
                    'SELECT g1, g2 FROM '
                    '(SELECT gamma.g1, gamma.g2 FROM gamma '
                    '{operator} ALL '
                    'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin) AS _{name1} '
                    '{operator} ALL '
                    'SELECT gammaprime.g1, gammaprime.g2 FROM gammaprime) AS _{name2}'
                        .format(operator=self.sql_operator, name1=child_name, name2=root_name)]
        self.assertEqual(expected, actual)
Пример #3
0
 def test_project_simple(self):
     ra = '\\project_{{g2}} (gamma {operator} gammatwin);'.format(operator=self.ra_operator)
     root_list = TreeBRD(self.grammar).build(instring=ra, schema=self.schema)
     name = id(root_list[0].child)
     actual = sql_translator.translate(root_list, use_bag_semantics=True)
     expected = ['SELECT g2 FROM '
                 '(SELECT gamma.g1, gamma.g2 FROM gamma '
                 '{operator} ALL '
                 'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin) '
                 'AS _{name}'
                     .format(operator=self.sql_operator, name=name)]
     self.assertEqual(expected, actual)
Пример #4
0
    def test_rename_attributes(self):
        ra = '\\rename_{{g(a, b)}} (gamma {operator} gammatwin);'.format(operator=self.ra_operator)

        root_list = TreeBRD(self.grammar).build(instring=ra, schema=self.schema)
        name = id(root_list[0].child)
        actual = sql_translator.translate(root_list, use_bag_semantics=True)

        expected = ['SELECT g.a, g.b FROM '
                    '(SELECT g1, g2 FROM (SELECT gamma.g1, gamma.g2 FROM gamma '
                    '{operator} ALL '
                    'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin) AS _{name}) '
                    'AS g(a, b)'.format(operator=self.sql_operator, name=name)]
        self.assertEqual(expected, actual)
Пример #5
0
 def test_project_simple(self):
     ra = '\\project_{{g2}} (gamma {operator} gammatwin);'.format(
         operator=self.ra_operator)
     root_list = TreeBRD(self.grammar).build(instring=ra,
                                             schema=self.schema)
     name = id(root_list[0].child)
     actual = sql_translator.translate(root_list, use_bag_semantics=True)
     expected = [
         'SELECT g2 FROM '
         '(SELECT gamma.g1, gamma.g2 FROM gamma '
         '{operator} ALL '
         'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin) '
         'AS _{name}'.format(operator=self.sql_operator, name=name)
     ]
     self.assertEqual(expected, actual)
Пример #6
0
    def test_rename_attributes(self):
        ra = '\\rename_{{g(a, b)}} (gamma {operator} gammatwin);'.format(
            operator=self.ra_operator)

        root_list = TreeBRD(self.grammar).build(instring=ra,
                                                schema=self.schema)
        name = id(root_list[0].child)
        actual = sql_translator.translate(root_list, use_bag_semantics=True)

        expected = [
            'SELECT g.a, g.b FROM '
            '(SELECT g1, g2 FROM (SELECT gamma.g1, gamma.g2 FROM gamma '
            '{operator} ALL '
            'SELECT gammatwin.g1, gammatwin.g2 FROM gammatwin) AS _{name}) '
            'AS g(a, b)'.format(operator=self.sql_operator, name=name)
        ]
        self.assertEqual(expected, actual)