Repository: ray-project/ray
File: python/ray/data/_internal/operator_schema_exporter.py (Python)

Code before:
    Returns:
        The protobuf message representing the operator schema.
    """

    from ray.core.generated.export_dataset_operator_schema_pb2 import (
        ExportDatasetOperatorSchema as ProtoOperatorSchema,
    )

    # Create the protobuf message
    proto_operator_schema = ProtoOperatorSchema(
        operator_uuid=operator_schema.operator_uuid,
        schema_fields=operator_schema.schema_fields,
    )

    return proto_operator_schema


def get_operator_schema_exporter() -> "OperatorSchemaExporter":
    """Get the operator schema exporter instance.

    Returns:
        The operator schema exporter instance.
    """
    return LoggerOperatorSchemaExporter.create_if_enabled()


class OperatorSchemaExporter(ABC):
    """Abstract base class for operator schema exporters.

    Implementations of this interface can export Ray Data operator schema to various
    destinations like log files, databases, or monitoring systems.
    """

    @abstractmethod
    def export_operator_schema(self, operator_schema: OperatorSchema) -> None:
        """Export operator schema to the destination.

        Args:
            operator_schema: OperatorSchema object containing operator schema details.
        """
        pass

    @classmethod
    @abstractmethod
    def create_if_enabled(cls) -> Optional["OperatorSchemaExporter"]:
        """Create an schema exporter instance if the export functionality is enabled.

        Returns:
            An schema exporter instance if enabled, none otherwise.
        """
        pass

Review comment (suggestion):
You probably know best, but wondering when we would need this because I can't forsee if we'll need multiple `OperatorSchemaExporter`

Code after:
        The protobuf message representing the operator schema.
    """

    from ray.core.generated.export_dataset_operator_schema_pb2 import (
        ExportDatasetOperatorSchema as ProtoOperatorSchema,
    )

    # Create the protobuf message
    proto_operator_schema = ProtoOperatorSchema(
        operator_uuid=operator_schema.operator_uuid,
        schema_fields=operator_schema.schema_fields,
    )

    return proto_operator_schema


def get_operator_schema_exporter() -> Optional["LoggerOperatorSchemaExporter"]:
    """Get the operator schema exporter instance.

    Returns:
        The operator schema exporter instance.
    """
    return LoggerOperatorSchemaExporter.create_if_enabled()


class OperatorSchemaExporter(ABC):
    """Abstract base class for operator schema exporters.

    Implementations of this interface can export Ray Data operator schema to various
    destinations like log files, databases, or monitoring systems.
    """

    @abstractmethod
    def export_operator_schema(self, operator_schema: OperatorSchema) -> None:
        """Export operator schema to the destination.

        Args:
            operator_schema: OperatorSchema object containing operator schema details.
        """
        pass

    @classmethod
    @abstractmethod
    def create_if_enabled(cls) -> Optional["OperatorSchemaExporter"]:
        """Create a schema exporter instance if the export functionality is enabled.

        Returns:
            A schema exporter instance if enabled, none otherwise.
        """
        pass