Exemplo n.º 1
0
 def __init__(self, title, folder=None, reference=None,
              schemaReference=None, dataType=None, datetime=False, format=None):
     self.title = to_title(title)
     self.folder = to_identifier(folder)
     self.folder_title = to_title(folder)
     self.reference = to_identifier(reference)
     self.schemaReference = to_identifier(schemaReference)
     self.dataType = dataType
     self.datetime = datetime
     self.format = format
Exemplo n.º 2
0
 def __init__(
     self, title, folder=None, reference=None, schemaReference=None,
     dataType=None, datetime=False, references_cp=None
 ):
     self.title = to_title(title)
     self.folder = to_identifier(folder)
     self.folder_title = to_title(folder)
     self.reference = to_identifier(reference)
     self.schemaReference = to_identifier(schemaReference)
     self.dataType = dataType
     self.datetime = datetime
     # an attribute useful for labels,
     # to know if they reference a connection point
     self.references_cp = references_cp
Exemplo n.º 3
0
 def __init__(self,
              title,
              folder=None,
              reference=None,
              schemaReference=None,
              dataType=None,
              datetime=False,
              format=None):
     self.title = to_title(title)
     self.folder = to_identifier(folder)
     self.folder_title = to_title(folder)
     self.reference = to_identifier(reference)
     self.schemaReference = to_identifier(schemaReference)
     self.dataType = dataType
     self.datetime = datetime
     self.format = format
Exemplo n.º 4
0
    def get_maql(self):
        maql = []

        maql.append("""
# THIS IS MAQL SCRIPT THAT GENERATES PROJECT LOGICAL MODEL.
# SEE THE MAQL DOCUMENTATION AT http://developer.gooddata.com/api/maql-ddl.html FOR MORE DETAILS

# CREATE DATASET. DATASET GROUPS ALL FOLLOWING LOGICAL MODEL ELEMENTS TOGETHER.
CREATE DATASET {dataset.%s} VISUAL(TITLE "%s");
""" % (to_identifier(self.schema_name), to_title(self.schema_name)))

        attribute_folders, fact_folders = self.get_folders()
        if attribute_folders or fact_folders:
            maql.append('# CREATE THE FOLDERS THAT GROUP ATTRIBUTES AND FACTS')
            for folder, folder_title in attribute_folders:
                maql.append('CREATE FOLDER {dim.%s} VISUAL(TITLE "%s") TYPE ATTRIBUTE;' \
                            % (folder, folder_title))
            maql.append('')
            for folder, folder_title in fact_folders:
                maql.append('CREATE FOLDER {ffld.%s} VISUAL(TITLE "%s") TYPE FACT;' \
                            % (folder, folder_title))
            maql.append('')

        maql.append('# CREATE ATTRIBUTES.\n# ATTRIBUTES ARE CATEGORIES THAT ARE USED FOR SLICING AND DICING THE NUMBERS (FACTS)')

        column_list = self.get_columns()

        for column in column_list:
            if isinstance(column, (Attribute, ConnectionPoint))\
                or (isinstance(column, Date) and not column.schemaReference):
                maql.append(column.get_maql())

        maql.append('# CREATE FACTS\n# FACTS ARE NUMBERS THAT ARE AGGREGATED BY ATTRIBUTES.')
        for column in column_list:
            if isinstance(column, Fact):
                maql.append(column.get_maql())

        maql.append('# CREATE DATE FACTS\n# DATES ARE REPRESENTED AS FACTS\n# DATES ARE ALSO CONNECTED TO THE DATE DIMENSIONS')
        for column in column_list:
            if isinstance(column, Date) and column.schemaReference:
                maql.append(column.get_maql())

        maql.append('# CREATE REFERENCES\n# REFERENCES CONNECT THE DATASET TO OTHER DATASETS')
        for column in column_list:
            if isinstance(column, Reference):
                maql.append(column.get_maql())


        for column in column_list:
            default_set = False
            if isinstance(column, Label):
                maql.append(column.get_maql())
                if not default_set:
                    maql.append(column.get_maql_default())
                    default_set = True

        cp = False
        for column in column_list:
            if isinstance(column, ConnectionPoint):
                cp = True
                maql.append('# ADD LABEL TO CONNECTION POINT')
                maql.append(column.get_original_label_maql())

        # TODO: not sure where this came from in Department example, wild guess only!
        if not cp:
            '''#maql.append('ALTER ATTRIBUTE {attr.%s.%s} ADD LABELS {label.%s.%s} VISUAL(TITLE "%s") AS {f_%s.nm_%s};'\
                    % (to_identifier(self.schema_name), to_identifier(self.schema_name),
                       to_identifier(self.schema_name), to_identifier(self.schema_name),
                       to_title(self.schema_name), to_identifier(self.schema_name),
                       to_identifier(self.schema_name)))
            '''
            maql.append('CREATE ATTRIBUTE {attr.%s.factsof} VISUAL(TITLE "Records of %s") AS KEYS {f_%s.id} FULLSET;'\
                    % (to_identifier(self.schema_name), to_title(self.schema_name), to_identifier(self.schema_name)))
            maql.append('ALTER DATASET {dataset.%s} ADD {attr.%s.factsof};'\
                    % (to_identifier(self.schema_name), to_identifier(self.schema_name)))
        maql.append("""# SYNCHRONIZE THE STORAGE AND DATA LOADING INTERFACES WITH THE NEW LOGICAL MODEL
SYNCHRONIZE {dataset.%s};
""" % to_identifier(self.schema_name))

        return '\n'.join(maql)
Exemplo n.º 5
0
    def get_maql(self):
        maql = []

        maql.append("""
# THIS IS MAQL SCRIPT THAT GENERATES PROJECT LOGICAL MODEL.
# SEE THE MAQL DOCUMENTATION AT http://developer.gooddata.com/api/maql-ddl.html FOR MORE DETAILS

# CREATE DATASET. DATASET GROUPS ALL FOLLOWING LOGICAL MODEL ELEMENTS TOGETHER.
CREATE DATASET {dataset.%s} VISUAL(TITLE "%s");
""" % (to_identifier(self.schema_name), to_title(self.schema_name)))

        attribute_folders, fact_folders = self.get_folders()
        if attribute_folders or fact_folders:
            maql.append('# CREATE THE FOLDERS THAT GROUP ATTRIBUTES AND FACTS')
            for folder, folder_title in attribute_folders:
                maql.append('CREATE FOLDER {dim.%s} VISUAL(TITLE "%s") TYPE ATTRIBUTE;' \
                            % (folder, folder_title))
            maql.append('')
            for folder, folder_title in fact_folders:
                maql.append('CREATE FOLDER {ffld.%s} VISUAL(TITLE "%s") TYPE FACT;' \
                            % (folder, folder_title))
            maql.append('')

        maql.append('# CREATE ATTRIBUTES.\n# ATTRIBUTES ARE CATEGORIES THAT ARE USED FOR SLICING AND DICING THE NUMBERS (FACTS)')

        column_list = self.get_columns()

        for column in column_list:
            if isinstance(column, (Attribute, ConnectionPoint))\
                or (isinstance(column, Date) and not column.schemaReference):
                maql.append(column.get_maql())

        maql.append('# CREATE FACTS\n# FACTS ARE NUMBERS THAT ARE AGGREGATED BY ATTRIBUTES.')
        for column in column_list:
            if isinstance(column, Fact):
                maql.append(column.get_maql())

        maql.append('# CREATE DATE FACTS\n# DATES ARE REPRESENTED AS FACTS\n# DATES ARE ALSO CONNECTED TO THE DATE DIMENSIONS')
        for column in column_list:
            if isinstance(column, Date) and column.schemaReference:
                maql.append(column.get_maql())

        maql.append('# CREATE REFERENCES\n# REFERENCES CONNECT THE DATASET TO OTHER DATASETS')
        for column in column_list:
            if isinstance(column, Reference):
                maql.append(column.get_maql())

        default_set = False
        for column in column_list:
            if isinstance(column, Label):
                maql.append(column.get_maql())
                if not default_set:
                    maql.append(column.get_maql_default())
                    default_set = True

        cp = False
        for column in column_list:
            if isinstance(column, ConnectionPoint):
                cp = True
                maql.append(column.get_original_label_maql())

        # TODO: not sure where this came from in Department example, wild guess only!
        if not cp:
            maql.append('ALTER ATTRIBUTE {attr.%s.%s} ADD LABELS {label.%s.%s} VISUAL(TITLE "%s") AS {f_%s.nm_%s};'\
                    % (to_identifier(self.schema_name), to_identifier(self.schema_name),
                       to_identifier(self.schema_name), to_identifier(self.schema_name),
                       to_title(self.schema_name), to_identifier(self.schema_name),
                       to_identifier(self.schema_name)))

        maql.append("""# SYNCHRONIZE THE STORAGE AND DATA LOADING INTERFACES WITH THE NEW LOGICAL MODEL
SYNCHRONIZE {dataset.%s};
""" % to_identifier(self.schema_name))

        return '\n'.join(maql)