Skip to content

feat(dataset): add collectAllKeys option for full CSV export (#2945)#3007

Merged
janbuchar merged 4 commits intoapify:masterfrom
Bhanu-Chauhan-uoa:feat/collect-all-keys-export
Jun 16, 2025
Merged

feat(dataset): add collectAllKeys option for full CSV export (#2945)#3007
janbuchar merged 4 commits intoapify:masterfrom
Bhanu-Chauhan-uoa:feat/collect-all-keys-export

Conversation

@Bhanu-Chauhan-uoa
Copy link
Contributor

What Changed

This PR adds support for a new option in Dataset.exportToCSV():

collectAllKeys?: boolean
When set to true, this option ensures that all unique keys across all dataset items are included in the exported CSV header, rather than only using the keys from the first item.

Motivation

Fixes #2945.
When datasets contain heterogeneous objects (e.g., items with different fields), using only the first item’s keys results in incomplete exports. This change allows full field coverage.

Implementation Details

  • Added collectAllKeys?: boolean to the DatasetExportToOptions interface.

  • Modified the export logic to:

    • Gather keys across all items using Array.from(new Set(...)) when the option is true.

    • Fall back to the default behavior otherwise.

    • Handle empty dataset case gracefully.

Test Coverage

Added a test in dataset.test.ts to verify:

Export includes all fields (id, name, age) from multiple items with varying structures.

@Coder-Chauhan
Copy link
Contributor

Hi! 👋 Just checking in to see if there's anything more I can do on this PR or if any changes are needed. Thanks for reviewing when you get a chance!

Copy link
Contributor

@janbuchar janbuchar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

Copy link
Member

@B4nan B4nan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the formatting (just run yarn format)

@Bhanu-Chauhan-uoa Bhanu-Chauhan-uoa requested a review from B4nan June 16, 2025 11:27
@Bhanu-Chauhan-uoa
Copy link
Contributor Author

Hi! The changes are now ready and reviewed. Could someone please approve the CI so the workflow can run? Thanks in advance!

@janbuchar janbuchar merged commit 3b629da into apify:master Jun 16, 2025
10 checks passed
barjin added a commit that referenced this pull request Aug 13, 2025
Ports the `collectAllKeys` option from #3007 to the `BasicCrawler.exportData` method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an Option to allow the export of all Fields to CSV

4 participants