dhirschfeld commented on issue #34554:
URL: https://github.com/apache/arrow/issues/34554#issuecomment-1996620231
Seems to work, though I'm not sure how efficient it is :/
```python
def rename_columns(schema: pa.Schema, **name_mapping) -> pa.RecordBatch:
return pa.schema(
field.with_name(name_mapping.get(field.name, field.name))
for field in schema
)
def append_filename(ds: pa.dataset.Dataset) -> pa.dataset.Dataset:
scanner = ds.scanner(columns=ds.schema.names + ['__filename'])
schema = rename_columns(scanner.projected_schema, __filename='filename')
batches = (
pa.RecordBatch.from_arrays(batch.columns, schema=schema)
for batch in scanner.to_batches()
)
return pa.dataset.dataset(list(batches))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]