示例#1
0
def view_schema(state):
    schema = mapping('view')
    schema.add(key('name', validator=chained(nonempty_string, database_name)))
    schema.add(key('label', validator=nonempty_string))
    schema.add(key('dimension', validator=dimension_or_dataset(state)))
    schema.add(
        key('drilldown', validator=dimension_or_not(state), missing=None))
    schema.add(mapping('cuts', validator=key_is_attribute(state), missing={}))
    return schema
示例#2
0
def view_schema(state):
    schema = mapping('view')
    schema.add(key('name', validator=chained(
            nonempty_string,
            database_name
        )))
    schema.add(key('label', validator=nonempty_string))
    schema.add(key('dimension', 
                   validator=dimension_or_dataset(state)))
    schema.add(key('drilldown', 
                   validator=dimension_or_not(state),
                   missing=None))
    schema.add(mapping('cuts', 
                       validator=key_is_attribute(state),
                       missing={}))
    return schema
示例#3
0
def source_schema():
    schema = mapping('source')
    schema.add(key('url', validator=chained(
        nonempty_string,
        valid_url
    )))
    return schema
def dataset_schema(state):
    schema = mapping('dataset')
    schema.add(key('name', validator=chained(
            nonempty_string,
            reserved_name,
            database_name,
            no_double_underscore
        ),
        preparer=lambda x: x.lower().strip() if x else None))
    schema.add(key('currency', validator=chained(
            valid_currency
        )))
    schema.add(key('category', validator=chained(
            valid_category
        )))
    schema.add(key('label', validator=chained(
            nonempty_string,
        )))
    schema.add(key('description', validator=chained(
            nonempty_string,
        )))
    schema.add(sequence('languages',
        key('language', validator=valid_language), 
        missing=[]))
    schema.add(sequence('territories',
        key('territory', validator=valid_country), 
        missing=[]))
    return schema
示例#5
0
def dataset_schema(state):
    schema = mapping('dataset')
    schema.add(
        key('name',
            validator=chained(nonempty_string, reserved_name, database_name,
                              no_double_underscore),
            preparer=lambda x: x.lower().strip() if x else None))

    return schema
示例#6
0
def dataset_schema(state):
    schema = mapping('dataset')
    schema.add(key('name', validator=chained(
            nonempty_string,
            reserved_name,
            database_name,
            no_double_underscore
        ),
        preparer=lambda x: x.lower().strip() if x else None))

    return schema
示例#7
0
def dimension_attribute_schema(name, state):
    schema = mapping(name,
                     validator=chained(
                         name_wrap(nonempty_string, name),
                         name_wrap(reserved_name, name),
                         name_wrap(database_name, name),
                     ))
    schema.add(key('column', validator=chained(nonempty_string, )))
    schema.add(
        key('datatype', validator=chained(nonempty_string, valid_datatype)))
    return schema
示例#8
0
def source_schema(state):
    schema = mapping('source')
    schema.add(key('name', validator=chained(
            nonempty_string
        ),
        preparer=lambda x: x.lower().strip() if x else None))

    schema.add(key('url', validator=chained(
            validURL
        ),
        preparer=lambda x: x.strip() if x else None))

    return schema
示例#9
0
def source_schema(state):
    schema = mapping('source')
    schema.add(
        key('name',
            validator=chained(nonempty_string),
            preparer=lambda x: x.lower().strip() if x else None))

    schema.add(
        key('url',
            validator=chained(validURL),
            preparer=lambda x: x.strip() if x else None))

    return schema
示例#10
0
def dimension_attribute_schema(name, state):
    schema = mapping(name, validator=chained(
        name_wrap(nonempty_string, name),
        name_wrap(reserved_name, name),
        name_wrap(database_name, name),
        ))
    schema.add(key('column', validator=chained(
            nonempty_string,
        )))
    schema.add(key('datatype', validator=chained(
            nonempty_string,
            valid_datatype
        )))
    return schema
示例#11
0
def compound_dimension_schema(name, state):
    schema = property_schema(name, state)

    attributes = mapping('attributes',
                         validator=chained(
                             compound_attributes_include_name,
                             compound_attributes_include_label,
                             compound_attribute_name_is_id_type,
                             compound_attribute_label_is_string_type))
    for attribute in state.dimension_attributes(name):
        attributes.add(dimension_attribute_schema(attribute, state))
    schema.add(attributes)

    return schema
示例#12
0
def compound_dimension_schema(name, state):
    schema = property_schema(name, state)

    attributes = mapping('attributes',
        validator=chained(
            compound_attributes_include_name,
            compound_attributes_include_label,
            compound_attribute_name_is_id_type,
            compound_attribute_label_is_string_type
        ))
    for attribute in state.dimension_attributes(name):
        attributes.add(dimension_attribute_schema(attribute, state))
    schema.add(attributes)

    return schema
示例#13
0
def property_schema(name, state):
    """ This is validation which is common to all properties,
    i.e. both dimensions and measures. """
    schema = mapping(name,
                     validator=chained(
                         name_wrap(nonempty_string, name),
                         name_wrap(reserved_name, name),
                         name_wrap(database_name, name),
                         name_wrap(no_entry_namespace_overlap, name),
                         no_dimension_id_overlap(name, state)))
    schema.add(key('label', validator=chained(nonempty_string, )))
    schema.add(key('type', validator=chained(nonempty_string, )))
    schema.add(
        key('description', validator=chained(nonempty_string, ), missing=None))
    return schema
示例#14
0
def mapping_schema(state):
    schema = mapping('mapping',
                     validator=chained(require_time_dimension,
                                       require_amount_dimension,
                                       require_one_key_column,
                                       must_be_compound_dimension('to'),
                                       must_be_compound_dimension('from')))
    for name, meta in state.mapping_items:
        type_schema = {
            'measure': measure_schema,
            'value': attribute_dimension_schema,
            'attribute': attribute_dimension_schema,
            'date': date_schema,
        }.get(meta.get('type'), compound_dimension_schema)
        schema.add(type_schema(name, state))
    return schema
示例#15
0
def mapping_schema(state):
    schema = mapping('mapping', validator=chained(
        require_time_dimension,
        require_amount_dimension,
        require_one_key_column,
        must_be_compound_dimension('to'),
        must_be_compound_dimension('from')
        ))
    for name, meta in state.mapping_items:
        type_schema = {
            'measure': measure_schema,
            'value': attribute_dimension_schema,
            'attribute': attribute_dimension_schema,
            'date': date_schema,
            }.get(meta.get('type'),
                  compound_dimension_schema)
        schema.add(type_schema(name, state))
    return schema
示例#16
0
def property_schema(name, state):
    """ This is validation which is common to all properties,
    i.e. both dimensions and measures. """
    schema = mapping(name, validator=chained(
        name_wrap(nonempty_string, name),
        name_wrap(reserved_name, name),
        name_wrap(database_name, name),
        name_wrap(no_entry_namespace_overlap, name),
        no_dimension_id_overlap(name, state)
        ))
    schema.add(key('label', validator=chained(
            nonempty_string,
        )))
    schema.add(key('type', validator=chained(
            nonempty_string,
        )))
    schema.add(key('description', validator=chained(
            nonempty_string,
        ), missing=None))
    return schema
示例#17
0
def source_schema():
    schema = mapping('source')
    schema.add(key('url', validator=chained(nonempty_string, valid_url)))
    return schema