-
-
Notifications
You must be signed in to change notification settings - Fork 28
feat: Support unnest function for array expansion in type inference #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 7fc74d9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
WalkthroughAdds support for the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/generate/src/ast-describe.ts (1)
810-851: Solid implementation with correct unnest semantics.The
unwraphelper correctly handles:
- Recursive array unwrapping for multidimensional arrays
- Union type simplification (removing outer null from nullable arrays while preserving inner nulls)
- PostgreSQL array type name normalization (stripping underscore prefix)
The null filtering logic on Line 837 is particularly well-designed:
!hasArray || !(t.kind === "type" && t.value === "null")ensures thatdate[] | nullunwraps toDate(outer null removed), whileARRAY[1, NULL]unwraps to1 | null(inner null preserved).💡 Optional: Add explanatory comment for null filtering logic
Consider adding a brief comment above Line 837 to document the intentional behavior:
const unwrapped = type.value + // Remove outer null (array itself being null) but preserve inner nulls (null elements within array) .filter((t) => !hasArray || !(t.kind === "type" && t.value === "null")) .map(unwrap);This would help future maintainers understand the distinction between outer and inner nullability.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.changeset/slimy-walls-prove.mdpackages/generate/src/ast-describe.tspackages/generate/src/generate.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/generate/src/ast-describe.ts (1)
packages/ast-types/src/index.ts (1)
FuncCall(1711-1723)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: check (17)
- GitHub Check: check (16)
🔇 Additional comments (3)
.changeset/slimy-walls-prove.md (1)
1-5: LGTM! Changeset documentation is clear and accurate.The changeset appropriately documents the new unnest function support with a minor version bump, and clearly describes the feature including multidimensional arrays and enums.
packages/generate/src/ast-describe.ts (1)
803-804: LGTM! Unnest function properly integrated.The new case correctly delegates to the dedicated handler, following the existing pattern for other special functions like
array_aggandjsonb_agg.packages/generate/src/generate.test.ts (1)
2512-2585: Excellent test coverage for unnest functionality!The test suite comprehensively validates unnest behavior across critical scenarios:
- Text arrays → unwrapped to base type
- Enum arrays → union of enum values preserved
- Multidimensional arrays → fully flattened to union of all elements
- Nullable arrays (
date[] | null) → outer null correctly removed- Arrays with null elements (
ARRAY[1, NULL]) → inner null correctly preservedThe test cases align perfectly with PostgreSQL unnest semantics and confirm the implementation handles the nuanced difference between outer (array-level) and inner (element-level) nullability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const firstArg = node.args?.at(0); | ||
| if (firstArg === undefined) { | ||
| return [{ name, type: context.toTypeScriptType({ name: "unknown" }) }]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Infer columns for all UNNEST arguments
getDescribedUnnestFunCall only inspects node.args?.at(0) and builds a single column from that one argument, so calls like SELECT * FROM unnest(arr1, arr2) or unnest(... ) WITH ORDINALITY will drop the additional returned columns in the inferred schema. That produces an incorrect column count and types for valid UNNEST usages involving multiple arrays, which will make the generated typings diverge from the actual query results.
Useful? React with 👍 / 👎.
Summary by CodeRabbit
New Features
✏️ Tip: You can customize this high-level summary in your review settings.