
    &`iz                         d dl mZmZmZ d dlmZ d dlmZ  ed           G d d                      Z G d d	e          Z	d
S )    )AnyDictOptional)Block)	PublicAPIalpha)	stabilityc                   ^    e Zd ZdZdededededef
dZdeee	f         dededed	edefd
Z
dS )FilenameProvidera  Generates filenames when you write a :class:`~ray.data.Dataset`.

    Use this class to customize the filenames used when writing a Dataset.

    Some methods write each row to a separate file, while others write each block to a
    separate file. For example, :meth:`ray.data.Dataset.write_images` writes individual
    rows, and :func:`ray.data.Dataset.write_parquet` writes blocks of data. For more
    information about blocks, see :ref:`Data internals <datasets_scheduling>`.

    If you're writing each row to a separate file, implement
    :meth:`~FilenameProvider.get_filename_for_row`. Otherwise, implement
    :meth:`~FilenameProvider.get_filename_for_block`.

    Example:

        This snippet shows you how to encode labels in written files. For example, if
        `"cat"` is a label, you might write a file named `cat_000000_000000_000000.png`.

        .. testcode::

            import ray
            from ray.data.datasource import FilenameProvider

            class ImageFilenameProvider(FilenameProvider):

                def __init__(self, file_format: str):
                    self.file_format = file_format

                def get_filename_for_row(self, row, write_uuid, task_index, block_index, row_index):
                    return (
                        f"{row['label']}_{write_uuid}_{task_index:06}_{block_index:06}"
                        f"_{row_index:06}.{self.file_format}"
                    )

            ds = ray.data.read_parquet("s3://anonymous@ray-example-data/images.parquet")
            ds.write_images(
                "/tmp/results",
                column="image",
                filename_provider=ImageFilenameProvider("png")
            )
    block
write_uuid
task_indexblock_indexreturnc                     t           )aV  Generate a filename for a block of data.

        .. note::
            Filenames must be unique and deterministic for a given write UUID, and
            task and block index.

            A block consists of multiple rows and corresponds to a single output file.
            Each task might produce a different number of blocks.

        Args:
            block: The block that will be written to a file.
            write_uuid: The UUID of the write operation.
            task_index: The index of the write task.
            block_index: The index of the block *within* the write task.
        NotImplementedError)selfr   r   r   r   s        y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/data/datasource/filename_provider.pyget_filename_for_blockz'FilenameProvider.get_filename_for_block3   s
    $ "!    row	row_indexc                     t           )a  Generate a filename for a row.

        .. note::
            Filenames must be unique and deterministic for a given write UUID, and
            task, block, and row index.

            A block consists of multiple rows, and each row corresponds to a single
            output file. Each task might produce a different number of blocks, and each
            block might contain a different number of rows.

        .. tip::
            If you require a contiguous row index into the global dataset, use
            :meth:`~ray.data.Dataset.iter_rows`. This method is single-threaded and
            isn't recommended for large datasets.

        Args:
            row: The row that will be written to a file.
            write_uuid: The UUID of the write operation.
            task_index: The index of the write task.
            block_index: The index of the block *within* the write task.
            row_index: The index of the row *within* the block.
        r   )r   r   r   r   r   r   s         r   get_filename_for_rowz%FilenameProvider.get_filename_for_rowG   s
    < "!r   N)__name__
__module____qualname____doc__r   strintr   r   r   r    r   r   r   r      s        ( (T""(+"9<"KN"	" " " "("#s(^" " 	"
 " " 
" " " " " "r   r   c                       e Zd Z	 ddee         dee         fdZdedededed	ef
d
Zde	ee
f         dedededed	efdZded	efdZdS )_DefaultFilenameProviderNdataset_uuidfile_formatc                 "    || _         || _        d S )N_dataset_uuid_file_format)r   r%   r&   s      r   __init__z!_DefaultFilenameProvider.__init__i   s     *'r   r   r   r   r   r   c                 D    | d|dd|d}|                      |          S N_06_generate_filename)r   r   r   r   r   file_ids         r   r   z/_DefaultFilenameProvider.get_filename_for_blocko   s9      BB*BBB+BBB&&w///r   r   r   c                 L    | d|dd|dd|d}|                      |          S r-   r0   )r   r   r   r   r   r   r2   s          r   r   z-_DefaultFilenameProvider.get_filename_for_rowu   sD      QQ*QQQ+QQQ9QQQ&&w///r   r2   c                 d    d}| j         || j          dz  }||z  }| j        |d| j         z  }|S )N r.   .r(   )r   r2   filenames      r   r1   z+_DefaultFilenameProvider._generate_filename   sT    )4-0000HG(/D-///Hr   )NN)r   r   r   r   r    r+   r   r!   r   r   r   r   r1   r"   r   r   r$   r$   h   s        OS( ($SM(?G}( ( ( (00(+09<0KN0	0 0 0 0	0#s(^	0 	0 		0
 	0 	0 
	0 	0 	0 	0# #      r   r$   N)
typingr   r   r   ray.data.blockr   ray.util.annotationsr   r   r$   r"   r   r   <module>r;      s    & & & & & & & & & &             * * * * * * W]" ]" ]" ]" ]" ]" ]" ]"@    /     r   