예제 #1
0
    def test_optimize_distinct(self):
        """
        Unoptimized:
            Selector._select({'col1': ['values']}, col2='xyz').distinct()

        Optimized:
            Selector._select_distinct({'col1': ['values']}, col2='xyz')
        """
        unoptimized = (
            (getattr, (RESULT_TOKEN, '_select'), {}),
            (RESULT_TOKEN, ({
                'col1': ['values']
            }, ), {
                'col2': 'xyz'
            }),
            (_sqlite_distinct, (RESULT_TOKEN, ), {}),
        )
        optimized = Query._optimize(unoptimized)

        expected = (
            (getattr, (RESULT_TOKEN, '_select_distinct'), {}),
            (RESULT_TOKEN, ({
                'col1': ['values']
            }, ), {
                'col2': 'xyz'
            }),
        )
        self.assertEqual(optimized, expected)
예제 #2
0
    def test_optimize_aggregation(self):
        """
        Unoptimized:
            Selector._select({'col1': ['values']}, col2='xyz').sum()

        Optimized:
            Selector._select_aggregate('SUM', {'col1': ['values']}, col2='xyz')
        """
        unoptimized = (
            (getattr, (RESULT_TOKEN, '_select'), {}),
            (RESULT_TOKEN, ({
                'col1': ['values']
            }, ), {
                'col2': 'xyz'
            }),
            (_apply_to_data, (
                _sqlite_sum,
                RESULT_TOKEN,
            ), {}),
        )
        optimized = Query._optimize(unoptimized)

        expected = (
            (getattr, (RESULT_TOKEN, '_select_aggregate'), {}),
            (RESULT_TOKEN, (
                'SUM',
                {
                    'col1': ['values']
                },
            ), {
                'col2': 'xyz'
            }),
        )
        self.assertEqual(optimized, expected)