Skip to content

Add standard Ruby collection methods to Result and Row#159

Open
wpfleger96 wants to merge 2 commits intorinsed-org:masterfrom
wpfleger96:wpfleger/add-result-collection-methods
Open

Add standard Ruby collection methods to Result and Row#159
wpfleger96 wants to merge 2 commits intorinsed-org:masterfrom
wpfleger96:wpfleger/add-result-collection-methods

Conversation

@wpfleger96
Copy link

@wpfleger96 wpfleger96 commented Dec 24, 2025

This PR adds standard Ruby collection methods for query results: empty?, dig, key?, and fetch. A recent BigQuery to Snowflake migration revealed these methods were missing; Result includes Enumerable but lacks empty?, while Row has [] access but no safe nested access or column existence checks.

Implementation:

  • Add Result#empty? to check if result set has no rows
  • Add Row#dig for safe nested value access (useful for VARIANT/JSON columns)
  • Add Row#key?/has_key? to check column existence
  • Add Row#fetch with default values and block support
  • All methods maintain case-insensitive column access

- Add Result#empty? for checking empty result sets
- Add Row#dig for safe nested value access (useful for VARIANT/JSON columns)
- Add Row#to_h for explicit hash conversion
- Add Row#key?/has_key? for column existence checks
- Add Row#fetch for access with default values or error handling
- Add unit tests (28 test cases, no Snowflake required)

Addresses missing methods discovered during BigQuery to Snowflake migration.
@wpfleger96 wpfleger96 force-pushed the wpfleger/add-result-collection-methods branch from 1b44870 to 2080bb5 Compare January 7, 2026 22:55
@reidnimz
Copy link
Contributor

reidnimz commented Jan 7, 2026

Thanks @wpfleger96 - I'll try to steal some time and take a look through this in the next week or so, much appreciated!

@wpfleger96
Copy link
Author

@reidnimz 😅 I think the tests are failing bc GH Actions is blocking secrets since I opened this PR from a fork

Copy link
Contributor

@reidnimz reidnimz left a comment

Choose a reason for hiding this comment

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

Good addition, thanks @wpfleger96! Just a couple of minor things.

You're right, I forgot with the secrets, it's not going to work on a branch. But, I'll run it locally quick before confirming and then I'll try and get a release out today or tomorrow.

1. removed custom unnecessary to_h method implementation (and update CHANGELOG accordingly)
2. Add happy path test for Row#fetch
3. Added test cases for Row#key? since it's part of the API
@wpfleger96 wpfleger96 requested a review from reidnimz January 22, 2026 16:28
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.

2 participants