Writes index file for records of a shard at given `sharded_index_path`. NOTE: Each record position (i.e shard_key in shard_keys) is stored as a string for better readability of the index files. The reader should parse the position from string using `RecordPosition.from_str()` method. Args:
(
sharded_index_path: epath.PathLike, record_keys: Sequence[Any]
)
| 157 | |
| 158 | |
| 159 | def _write_index_file( |
| 160 | sharded_index_path: epath.PathLike, record_keys: Sequence[Any] |
| 161 | ): |
| 162 | """Writes index file for records of a shard at given `sharded_index_path`. |
| 163 | |
| 164 | NOTE: Each record position (i.e shard_key in shard_keys) is stored as a |
| 165 | string for better readability of the index files. The reader should parse the |
| 166 | position from string using `RecordPosition.from_str()` method. |
| 167 | |
| 168 | Args: |
| 169 | sharded_index_path: Path to the sharded index path. |
| 170 | record_keys: Sequence of keys/indices of the records in the shard. |
| 171 | """ |
| 172 | # Store string representation of each record position. |
| 173 | # |
| 174 | # NOTE: This makes the index file more readable. Although the reader should |
| 175 | # parse the record position from a string. |
| 176 | index_info = {"index": [str(record_key) for record_key in record_keys]} |
| 177 | epath.Path(sharded_index_path).write_text(json.dumps(index_info)) |
| 178 | logging.info("Wrote index file to %s", os.fspath(sharded_index_path)) |
| 179 | |
| 180 | |
| 181 | class ExampleWriter: |
no test coverage detected