Exemple #1
0
    def run(self, metadata):
        '''
            RETURN: {
                    'value': [(ID, NAME)],              # ID = ['user', 3]
                    'query': {
                        'whereclause': [col.in_(*primary_keys)],
                        'column': [col],
                        'group_by': [col]
                    },
                    'axis_mapping': axis_map.column_mapping(result),
                    'delta':0
                }
        '''
        if self.sublevels[0].name=='all':
            return [{
                'value': [([str(self.level)], str(self.level), False)],
                'query': {
                    'column': [sqlalchemy.literal('all')],
                },
                'axis_mapping': axis_map.column_static(False),
                'delta':0,
            }]


        # Make these 2 commands working in all cases:
        # return self._run_transform(metadata)
        # return self._run_star(metadata)
        
        if self.object.table_id<>self.object.dimension_id.cube_id.table_id: # Add a condition on the object
            result = self._run_transform(metadata)
        else:
            result = self._run_star(metadata)
        return result
Exemple #2
0
    def _run_star(self, metadata):
        """
            Compute axis values, and transform the main query in the same way
            to add this branch of the star for this subset. The mappers
            reassign to values.
        """
        print '*** Start ***'
        table, result,result_mapping, result_axis = self._compute_axis(metadata, True)
        result_axis.setdefault('where_clause', [])
        #
        # The result to be applied to the main query object
        #
        result = {
            'value': result,
            'query': {
#               'whereclause': result_axis.get('where_clause',[]),
                'column': result_axis.get('column', []),
                'group_by': result_axis.get('column', [])
            },
            ##
            ## How to use group of axis_mapping ?
            ##
            'axis_mapping': axis_map.column_static(False),
            'delta':0,
        }
        return [result]
Exemple #3
0
    def _run_transform(self, metadata):
        """
            Compute axis values, and transform the main query according to axis
            values for this subset. The main query slicer is transformed to a
            single condition like: foreign_key in (...) and reapplied to axis
            values.
        """

        table, axis, mapping, result_axis = self._compute_axis(metadata, True)
        table2 = common.table_get(metadata, self.object.dimension_id.cube_id.table_id)
        sql_table = sqlalchemy.Table(self.object.table_id.column_link_id.table_id.table_db_name,metadata)
        col = common.col_get(sql_table, self.object.table_id.column_link_id)

        #
        # The result to be applied to the main query object
        #

        result = []
        for a in axis:
            k = tuple(list(a)[0][1:])
            mapping_axis = filter(lambda m: tuple(list(m)[:-1])==k, mapping)
            primary_keys = map(lambda x:list(x)[-1], mapping_axis)
            # To convert everything in to the string so that no conversion needed at later stage 
            # This is for the elements to be displayed in the rows and columns
            for i in range(len(a[0])):
                if a[0][i]:
                    if isinstance(a[0][i],int):
                        a[0][i] = str(a[0][i])
                    elif isinstance(a[0][i],float):
                        a[0][i] = str(int(a[0][i]))
                else:
                    a[0][i] = '/'
            a = list(a)
            if isinstance(a[-1],int):
                a[-1] = str(a[-1])
            elif isinstance(a[-1],float):
                a[-1] = str(int(a[-1]))
            a = tuple(a)
            primary_keys = map(lambda x: str(x),primary_keys)
            result.append( {
                'value': [a],
                'query': {
                          
                    'whereclause': [col.in_(primary_keys)],#.extend(result_axis['where_clause']),
                    'column': [sqlalchemy.literal('transform')],
                },
                'axis_mapping': axis_map.column_static(False),
                'delta':0,
            })
        return result