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

Code before:
    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


class LoggerOperatorSchemaExporter(OperatorSchemaExporter):
    """Operator schema exporter implementation that uses the Ray export event logger.

    This exporter writes operator schema to log files using Ray's export event system.
    """

    def __init__(self, logger: logging.Logger):
        """Initialize with a configured export event logger.

        Args:
            logger: The export event logger to use for writing events.
        """
        self._export_logger = logger

    def export_operator_schema(self, operator_schema: OperatorSchema) -> None:
        """Export operator schema using the export event logger.

        Args:
            operator_schema: OperatorSchema object containing operator event details.
        """
        operator_schema_proto = operator_schema_to_proto(operator_schema)

Review comment (suggestion):
```suggestion
            A schema exporter instance if enabled, none otherwise.
```

Code after:


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


class LoggerOperatorSchemaExporter(OperatorSchemaExporter):
    """Operator schema exporter implementation that uses the Ray export event logger.

    This exporter writes operator schema to log files using Ray's export event system.
    """

    def __init__(self, logger: logging.Logger):
        """Initialize with a configured export event logger.

        Args:
            logger: The export event logger to use for writing events.
        """
        self._export_logger = logger

    def export_operator_schema(self, operator_schema: OperatorSchema) -> None:
        """Export operator schema using the export event logger.

        Args:
            operator_schema: OperatorSchema object containing operator event details.
        """
        operator_schema_proto = operator_schema_to_proto(operator_schema)
        self._export_logger.send_event(operator_schema_proto)