예제 #1
0
    def _check_required_grain(self, adhoc_datasources=None):
        """Integrity check for required_grain settings"""
        errors = []

        for metric in self.get_metrics(adhoc_fms=adhoc_datasources).values():
            if not metric.required_grain:
                continue

            for field in metric.required_grain:
                if not self.has_dimension(field, adhoc_fms=adhoc_datasources):
                    errors.append(
                        "Metric %s references unknown dimension %s in required_grain"
                        % (metric.name, field))

        for ds in self.get_field_managers(adhoc_fms=adhoc_datasources):
            for table in ds.metadata.tables.values():
                if not is_active(table):
                    continue

                for column in table.c:
                    if not is_active(column):
                        continue
                    if not column.zillion.required_grain:
                        continue

                    for field in column.zillion.required_grain:
                        if not self.has_dimension(field,
                                                  adhoc_fms=adhoc_datasources):
                            errors.append(
                                "Column %s->%s references unknown dimension %s in required_grain"
                                % (ds.name, column_fullname(column), field))

        return errors
예제 #2
0
    def _check_primary_key_dimensions(self, adhoc_datasources=None):
        """Integrity check for primary keys"""
        errors = []

        for ds in self.get_field_managers(adhoc_fms=adhoc_datasources):
            for table in ds.metadata.tables.values():
                if not is_active(table):
                    continue

                primary_key = table.zillion.primary_key
                table_dims = get_table_dimensions(self,
                                                  table,
                                                  adhoc_fms=adhoc_datasources)

                for pk_field in primary_key:
                    if not self.has_dimension(pk_field):
                        errors.append(
                            "Primary key field is not a dimension: %s" %
                            pk_field)
                    if pk_field not in table_dims:
                        errors.append(
                            "Primary key dimension %s is not in table %s" %
                            (pk_field, table.fullname))

        return errors
예제 #3
0
    def _check_fields_have_type(self, adhoc_datasources=None):
        """Integrity check for field types"""
        errors = []

        for ds in self.get_field_managers(adhoc_fms=adhoc_datasources):
            for table in ds.metadata.tables.values():
                if not is_active(table):
                    continue

                for column in table.c:
                    if not is_active(column):
                        continue

                    for field in column.zillion.get_field_names():
                        if not (self.has_metric(field,
                                                adhoc_fms=adhoc_datasources)
                                or self.has_dimension(
                                    field, adhoc_fms=adhoc_datasources)):
                            errors.append(
                                "Field %s for column %s->%s is not defined as a metric or dimension"
                                % (field, ds.name, column_fullname(column)))

        return errors
예제 #4
0
    def _check_incomplete_dimensions(self, adhoc_datasources=None):
        """Integrity check for incomplete_dimensions settings"""
        errors = []

        for ds in self.get_field_managers(adhoc_fms=adhoc_datasources):
            for table in ds.metadata.tables.values():
                if not is_active(table):
                    continue

                if not table.zillion.incomplete_dimensions:
                    continue

                for field in table.zillion.incomplete_dimensions:
                    if not self.has_dimension(field,
                                              adhoc_fms=adhoc_datasources):
                        errors.append(
                            "Table %s->%s references unknown dimension %s in incomplete_dimensions"
                            % (ds.name, table.fullname, field))

        return errors
예제 #5
0
def get_table_fields(table):
    """Get a list of field names supported by a table
    
    **Parameters:**
    
    * **table** - (*SQLAlchemy Table*) The table to get a list of supported
    fields for
    
    **Returns:**
    
    (*set*) - A set of field names
    
    """
    fields = set()
    for col in table.c:
        if not is_active(col):
            continue
        for field in col.zillion.get_field_names():
            fields.add(field)
    return fields
예제 #6
0
def get_table_field_column(table, field_name):
    """Return the column within a table that supports a given field
    
    **Parameters:**
    
    * **table** - (*Table*) SQLAlchemy table onject
    * **field_name** - (*str*) The name of a field supported by the table
    
    **Returns:**
    
    (*Column*) - A SQLAlchemy column object
    
    """
    for col in table.c:
        if not is_active(col):
            continue
        for field in col.zillion.get_field_names():
            if field == field_name:
                return col
    raise ZillionException("Field %s inactive or not found in table %s" %
                           (field_name, table.fullname))
예제 #7
0
def get_table_dimensions(fm, table, adhoc_fms=None):
    """Get a list of dimensions supported by a table
    
    **Parameters:**
    
    * **fm** - (*FieldManager*) An object supporting the FieldManager interface
    * **table** - (*SQLAlchemy Table*) The table to get a list of supported
    dimensions for
    * **adhoc_fms** - (*list, optional*) AdHoc FieldManagers relevant to this
    request
    
    **Returns:**
    
    (*set*) - A set of dimension names
    
    """
    dims = set()
    for col in table.c:
        if not is_active(col):
            continue
        for field in col.zillion.get_field_names():
            if fm.has_dimension(field, adhoc_fms=adhoc_fms):
                dims.add(field)
    return dims