Skip to content

Conversation

@pyramation
Copy link
Collaborator

@pyramation pyramation commented Jul 1, 2025

Fix: resolve 15-16 transformer AST mismatch for create_view-281.sql

Summary

This PR fixes a critical AST transformation mismatch in the PostgreSQL 15-to-16 transformer that was causing the latest/postgres/create_view-281.sql test case to fail. The issue was related to how SYSTEM_USER references are transformed between PostgreSQL versions.

The root cause was that PostgreSQL 15 and 16 represent SYSTEM_USER differently in their ASTs:

  • PG15: Uses ColumnRef for direct references, RangeVar for table-like usage
  • PG16: Uses FuncCall with pg_catalog.system_user for both cases, or RangeFunction for table-like usage

The complex CREATE VIEW SQL statement contained multiple forms of SYSTEM_USER usage that required bidirectional transformation logic to handle all cases correctly.

Review & Testing Checklist for Human

  • Verify bidirectional transformation logic: The ColumnRefFuncCall and RangeVarRangeFunction transformations are complex. Review the logic in both directions to ensure they're consistent and handle edge cases.
  • Test the specific SQL query manually: Run the exact SQL from the failing test case through both PG15 and PG16 parsers to verify the transformation produces the expected AST.
  • Check for other SYSTEM_USER usage patterns: Search the codebase for other uses of SYSTEM_USER to ensure this fix doesn't break existing functionality.
  • Validate empty object handling: The {} as any change in the List method affects many AST nodes. Spot-check a few other transformer tests to ensure no regressions.

Diagram

%%{ init : { "theme" : "default" }}%%
graph TB
    subgraph "Test Infrastructure"
        A["transformer-errors.ts"]:::minor-edit
        B["latest-postgres-create_view.test.ts"]:::context
    end
    
    subgraph "Core Transformer"
        C["v15-to-v16.ts"]:::major-edit
        D["ColumnRef method"]:::major-edit
        E["FuncCall method"]:::major-edit
        F["RangeVar method"]:::major-edit
        G["List method"]:::minor-edit
        H["IndexStmt method"]:::minor-edit
    end
    
    subgraph "SQL Query"
        I["CREATE VIEW with SYSTEM_USER"]:::context
        J["Direct SYSTEM_USER references"]:::context
        K["SELECT * FROM SYSTEM_USER"]:::context
    end
    
    A --> C
    B --> C
    C --> D
    C --> E
    C --> F
    C --> G
    C --> H
    I --> J
    I --> K
    J --> D
    J --> E
    K --> F
    
    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit
        L3["Context/No Edit"]:::context
    end
    
    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • Session Info: Requested by Dan Lynch (@pyramation) - Devin Session
  • Regression Fix: I initially introduced a regression in IndexStmt by accidentally removing nulls_not_distinct handling, which I caught and fixed in a follow-up commit.
  • Testing: All 1070 test suites pass, including the previously failing create_view-281.sql test case.
  • Risk Assessment: This is a complex transformation with bidirectional logic that requires careful review. The changes affect core AST transformation methods used across many SQL patterns.

devin-ai-integration bot and others added 2 commits July 1, 2025 07:15
- Add SYSTEM_USER transformation handling in ColumnRef, FuncCall, and RangeVar methods
- Fix empty object handling in List transformation to use {} as any instead of { A_Const: {} }
- Remove skip entry for latest/postgres/create_view-281.sql test case

The transformer now correctly handles:
- PG15 ColumnRef with system_user -> PG16 FuncCall with pg_catalog.system_user
- PG15 FuncCall with pg_catalog.system_user -> PG16 ColumnRef with system_user
- PG15 RangeVar with system_user -> PG16 RangeFunction with nested FuncCall
- Empty objects in List items to match native PG16 AST output

Co-Authored-By: Dan Lynch <[email protected]>
- Restore nulls_not_distinct property transformation in IndexStmt method
- Fixes regression introduced in previous commit that broke CREATE INDEX tests
- Both create_view-281.sql and create_index tests now pass

Co-Authored-By: Dan Lynch <[email protected]>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit a574947 into main Jul 1, 2025
1 check passed
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