def from_dict(cls, entity_dict): """ Creates an entity from a dict. Args: entity_dict: A dict representation of an entity. Returns: An EntityV2 object based on the entity dict. """ entity_proto = json_format.ParseDict( entity_dict, EntityV2Proto(), ignore_unknown_fields=True ) return cls.from_proto(entity_proto)
def to_proto(self) -> EntityV2Proto: """ Converts an entity object to its protobuf representation Returns: EntityV2Proto protobuf """ meta = EntityMetaProto( created_timestamp=self.created_timestamp, last_updated_timestamp=self.last_updated_timestamp, ) spec = EntitySpecProto( name=self.name, description=self.description, value_type=self.value_type.value, labels=self.labels, ) return EntityV2Proto(spec=spec, meta=meta)
def to_proto(self) -> EntityV2Proto: """ Converts an entity object to its protobuf representation. Returns: An EntityV2Proto protobuf. """ meta = EntityMetaProto() if self._created_timestamp: meta.created_timestamp.FromDatetime(self._created_timestamp) if self._last_updated_timestamp: meta.last_updated_timestamp.FromDatetime(self._last_updated_timestamp) spec = EntitySpecProto( name=self.name, description=self.description, value_type=self.value_type.value, labels=self.labels, join_key=self.join_key, ) return EntityV2Proto(spec=spec, meta=meta)