def generate_version(self, connection: Connection, schema: SchemaEvent, name: ResourceName, template: ResourceTemplate) -> List[ResourceVersion]: versions = [] base = super(CanalResourceGenerator, self).generate_version(connection, schema, name, template)[0] for mode in self._mode: version = deepcopy(base) version.name = mode version.full_name = get_full_name(template.full_name, mode) fields = [] config = super(CanalResourceGenerator, self).generate_default_version_config( connection, schema, name, template) if mode == CanalMode.update: fields = self._generate_update_fields(schema, config) elif mode == CanalMode.upsert: fields = self._generate_upsert_fields() self._handle_time_field(fields) config.schema = [ResourceVersion.field2schema(x) for x in fields] version.config = dump_yaml(attr.asdict(config)) versions.append(version) return versions
def generate_resource_name(self, connection: Connection, schema: SchemaEvent) -> ResourceName: return ResourceName(name=schema.name, database=schema.database, connection_id=connection.id, schema_version_id=schema.id, latest_schema_id=schema.id, is_latest=True, full_name=get_full_name(connection.name, schema.database, schema.name))
def generate_resource_name(self, connection: Connection, schema: SchemaEvent) -> ResourceName: name = super(SystemConnectorGenerator, self).generate_resource_name(connection, schema) t_database, t_table = self.connector.get_transform_target_full_name( resource_name=name, connector=self.connector) name.database = t_database name.name = t_table name.full_name = get_full_name(connection.name, t_database, t_table) return name
def generate_template( self, connection: Connection, schema: SchemaEvent, resource_name: ResourceName) -> List[ResourceTemplate]: res = [] for x in self.support_type: temp = ResourceTemplate(name=x, type=x, is_system=True, full_name=get_full_name( resource_name.full_name, x), connection_id=connection.id, resource_name_id=resource_name.id, schema_version_id=schema.id) res.append(temp) return res
def generate_version(self, connection: Connection, schema: SchemaEvent, name: ResourceName, template: ResourceTemplate) -> List[ResourceVersion]: config = self.generate_default_version_config(connection, schema, name, template) config_str = dump_yaml(attr.asdict(config)) return [ ResourceVersion(name=ResourceVersion.latest_name(), full_name=get_full_name( template.full_name, ResourceVersion.latest_name()), is_system=True, is_latest=True, connection_id=connection.id, resource_name_id=name.id, template_id=template.id, schema_version_id=schema.id if schema else None, config=config_str) ]