Exemplo n.º 1
0
def create_avro_schema(
    schema_json,
    schema_elements=None,
    topic_name=None,
    namespace=None,
    source=None,
    status=models.AvroSchemaStatus.READ_AND_WRITE,
    base_schema_id=None,
    created_at=None
):
    topic = get_or_create_topic(
        topic_name,
        namespace_name=namespace,
        source_name=source
    )

    avro_schema = models.AvroSchema.create(
        session,
        avro_schema_json=schema_json,
        topic_id=topic.id,
        status=status,
        base_schema_id=base_schema_id,
        created_at=created_at
    )
    schema_elements = (
        schema_elements or
        AvroSchema.create_schema_elements_from_json(schema_json)
    )
    for schema_element in schema_elements:
        schema_element.avro_schema_id = avro_schema.id
        session.add(schema_element)
    session.flush()

    return avro_schema
Exemplo n.º 2
0
def _create_avro_schema(
    avro_schema_json,
    source_id,
    topic_id,
    status=models.AvroSchemaStatus.READ_AND_WRITE,
    base_schema_id=None
):
    avro_schema_elements = models.AvroSchema.create_schema_elements_from_json(
        avro_schema_json
    )

    avro_schema = models.AvroSchema(
        avro_schema_json=avro_schema_json,
        topic_id=topic_id,
        status=status,
        base_schema_id=base_schema_id
    )
    session.add(avro_schema)
    session.flush()

    for avro_schema_element in avro_schema_elements:
        avro_schema_element.avro_schema_id = avro_schema.id
        session.add(avro_schema_element)

    session.flush()
    _add_meta_attribute_mappings(avro_schema.id, source_id)
    return avro_schema
Exemplo n.º 3
0
def create_note(reference_type, reference_id, note_text, last_updated_by):
    note = models.Note(reference_type=reference_type,
                       reference_id=reference_id,
                       note=note_text,
                       last_updated_by=last_updated_by)
    session.add(note)
    session.flush()
    return note
Exemplo n.º 4
0
def create_source_category(source_id, category):
    source_category = models.SourceCategory(
        source_id=source_id,
        category=category
    )
    session.add(source_category)
    session.flush()
    return source_category
Exemplo n.º 5
0
def _update_schema_status(schema_id, status):
    session.query(
        models.AvroSchema
    ).filter(
        models.AvroSchema.id == schema_id
    ).update(
        {'status': status}
    )
    session.flush()
Exemplo n.º 6
0
 def delete_topics(cls, source_id):
     topics = session.query(
         models.Topic
     ).filter(
         models.Topic.source_id == source_id
     ).all()
     for topic in topics:
         session.delete(topic)
     session.flush()
Exemplo n.º 7
0
def _add_meta_attribute_mappings(schema_id, source_id):
    mappings = []
    for meta_attr_schema_id in meta_attr_logic.get_meta_attributes_by_source(
            source_id):
        new_mapping = SchemaMetaAttributeMapping(
            schema_id=schema_id, meta_attr_schema_id=meta_attr_schema_id)
        session.add(new_mapping)
        mappings.append(new_mapping)
    session.flush()
    return mappings
Exemplo n.º 8
0
def create_note(reference_type, reference_id, note_text, last_updated_by):
    note = models.Note(
        reference_type=reference_type,
        reference_id=reference_id,
        note=note_text,
        last_updated_by=last_updated_by
    )
    session.add(note)
    session.flush()
    return note
Exemplo n.º 9
0
def create_refresh(source_id, offset, batch_size, priority, filter_condition,
                   avg_rows_per_second_cap):
    refresh = models.Refresh(source_id=source_id,
                             offset=offset,
                             batch_size=batch_size,
                             priority=priority,
                             filter_condition=filter_condition,
                             avg_rows_per_second_cap=avg_rows_per_second_cap)
    session.add(refresh)
    session.flush()
    return refresh
Exemplo n.º 10
0
def _create_topic(topic_name, source_id, contains_pii, cluster_type):
    """Create a topic named `topic_name` in the given source.
    It returns a newly created topic. If a topic with the same
    name already exists, an exception is thrown
    """
    topic = models.Topic(name=topic_name,
                         source_id=source_id,
                         contains_pii=contains_pii,
                         cluster_type=cluster_type)
    session.add(topic)
    session.flush()
    return topic
Exemplo n.º 11
0
def _add_meta_attribute_mappings(schema_id, source_id):
    mappings = []
    for meta_attr_schema_id in meta_attr_logic.get_meta_attributes_by_source(
        source_id
    ):
        new_mapping = SchemaMetaAttributeMapping(
            schema_id=schema_id,
            meta_attr_schema_id=meta_attr_schema_id
        )
        session.add(new_mapping)
        mappings.append(new_mapping)
    session.flush()
    return mappings
Exemplo n.º 12
0
def _create_topic(topic_name, source_id, contains_pii, cluster_type):
    """Create a topic named `topic_name` in the given source.
    It returns a newly created topic. If a topic with the same
    name already exists, an exception is thrown
    """
    topic = models.Topic(
        name=topic_name,
        source_id=source_id,
        contains_pii=contains_pii,
        cluster_type=cluster_type
    )
    session.add(topic)
    session.flush()
    return topic
Exemplo n.º 13
0
    def create(cls, session, **kwargs):
        """Create this entity in the database.  Note this function will call
        `session.flush()`, so do not use this function if there are other
        operations that need to happen before the flush is called.

        Args:
            session (:class:yelp_conn.session.YelpConnScopedSession) global
                session manager used to provide sessions.
            kwargs (dict): pairs of model attributes and their values.

        Returns:
            :class:schematizer.models.[cls]: object that is newly created in
            the database.
        """
        entity = cls(**kwargs)
        session.add(entity)
        session.flush()
        return entity
Exemplo n.º 14
0
def create_refresh(
        source_id,
        offset,
        batch_size,
        priority,
        filter_condition,
        avg_rows_per_second_cap
):
    refresh = models.Refresh(
        source_id=source_id,
        offset=offset,
        batch_size=batch_size,
        priority=priority,
        filter_condition=filter_condition,
        avg_rows_per_second_cap=avg_rows_per_second_cap
    )
    session.add(refresh)
    session.flush()
    return refresh
Exemplo n.º 15
0
def _create_avro_schema(avro_schema_json,
                        source_id,
                        topic_id,
                        status=models.AvroSchemaStatus.READ_AND_WRITE,
                        base_schema_id=None):
    avro_schema_elements = models.AvroSchema.create_schema_elements_from_json(
        avro_schema_json)

    avro_schema = models.AvroSchema(avro_schema_json=avro_schema_json,
                                    topic_id=topic_id,
                                    status=status,
                                    base_schema_id=base_schema_id)
    session.add(avro_schema)
    session.flush()

    for avro_schema_element in avro_schema_elements:
        avro_schema_element.avro_schema_id = avro_schema.id
        session.add(avro_schema_element)

    session.flush()
    _add_meta_attribute_mappings(avro_schema.id, source_id)
    return avro_schema
Exemplo n.º 16
0
def create_source_category(source_id, category):
    source_category = models.SourceCategory(source_id=source_id,
                                            category=category)
    session.add(source_category)
    session.flush()
    return source_category
Exemplo n.º 17
0
 def create_in_db(cls, name, namespace):
     source = cls.create(name, namespace)
     session.add(source)
     session.flush()
     return source
Exemplo n.º 18
0
def _update_schema_status(schema_id, status):
    session.query(models.AvroSchema).filter(
        models.AvroSchema.id == schema_id).update({'status': status})
    session.flush()