Ejemplo n.º 1
0
def build_factor_list(factor):
    factor_name_list = factor.name.split(".")
    factor_list = []
    for name in factor_name_list:
        factor = Factor()
        factor.name = name
        factor_list.append(factor)
    return factor_list
Ejemplo n.º 2
0
def convert_business_fields_to_factors(business_fields_dict: Dict[str,
                                                                  ModelField]):
    factors = []
    for key, businessField in business_fields_dict.items():
        factor = Factor()
        factor.factorName = businessField.name
        factor.type = businessField.type
        factors.append(factor)

    return factors
def __build_presto_fields(factors):
    # presto_fields = [{"name": "_id", "type": "ObjectId", "hidden": True},
    #                  {"name": "insert_time", "type": "timestamp", "hidden": False},
    #                  {"name": "update_time", "type": "timestamp", "hidden": False}]
    for factor in factors:
        factor = Factor.parse_obj(factor)
        field = {"name": factor.name, "type": __convert_presto_type(factor.type), "hidden": False}
        presto_fields.append(field)

    return presto_fields
def crate_topic_by_raw_data_schema(schema, topic_list, mapping_list):
    factor_list = []
    node: schema
    topic: Topic = Topic(
        **{
            'topic_id': get_surrogate_key(),
            'name': '',
            'topic_type': '',
            'factors': []
        })
    mapping: {}
    # 遍历tree, 创建mapping和topic
    node = schema
    entity = node.data_entity

    # 每个node上的data_entity对应一个topic,data_entity上的一个attr对应一个factor
    topic.name = entity.name
    topic.topic_type = 'test'
    attr_list = entity.attrs
    mapping = Mapping(
        **{
            'mapping_id': get_surrogate_key(),
            'source_entity_id': entity.entity_id,
            'source_entity_name': entity.name,
            'target_topic_id': topic.topicId,
            'target_topic_name': entity.name,
            'mapping_detail_list': []
        })
    mapping_detail_list = []
    for attr in attr_list:
        factor: Factor = Factor(**{
            'id': get_surrogate_key(),
            'name': '',
            'type': ''
        })
        factor.name = attr.name
        factor.type = attr.type
        factor_list.append(factor)
        mapping_detail = MappingDetail(**{
            'source_attr': attr,
            'target_factor': factor
        })
        mapping_detail_list.append(mapping_detail)

    topic.factors = factor_list
    topic_list.append(topic)
    mapping.mapping_detail_list = mapping_detail_list
    mapping_list.append(mapping)
    if len(node.childs) == 0:
        return
    else:
        for node in node.childs:
            crate_topic_by_raw_data_schema(node, topic_list, mapping_list)
    return mapping_list
Ejemplo n.º 5
0
def build_factors(factors: list, parent: str, model_schema: ModelSchema,
                  model_schema_set: ModelSchemaSet):
    for key, value in model_schema.businessFields.items():
        if value.type == "array" or value.type == "dict":
            if parent == "":
                build_factors(factors, key, model_schema_set.schemas[key],
                              model_schema_set)
            else:
                build_factors(factors, parent + "." + key,
                              model_schema_set.schemas[key], model_schema_set)
        else:
            factor = Factor()
            if parent != "":
                factor.name = parent + "." + key
                factor.label = parent + "." + key
            else:
                factor.name = key
                factor.label = key
            factor.type = value.type
            factor.factorId = get_surrogate_key()
            factors.append(factor)