nikitap-sg opened a new pull request, #13056:
URL: https://github.com/apache/seatunnel/pull/13056

   ### Purpose of this pull request
   
   PostgreSQL enum columns that are written through the JDBC sink fail when the 
enum name is mixed case and quoted, for example `"ChapterElementType"` or 
`"Role"[]`. The sink binds enum values with `setString`, so pgjdbc ends up 
looking up the type name in lowercase and fails with `Unknown type 
chapterelementtype`.
   
   This PR binds those values as typed `PGobject` values and keeps the quotes 
in the type name, so the driver resolves the exact type:
   
   - `PostgresJdbcRowConverter.toExternal` binds a STRING column whose source 
type is a user-defined type name with `PGobject.setType(...)`. Built-in names 
(`text`, `jsonb`, `numeric`, ...) keep the existing `setString` path.
   - Quoted identifiers are preserved in the type name, and an optional schema 
qualifier is stripped.
   - Enum arrays (`"Role"[]`) are written with `createArrayOf(elementType, 
values)`.
   - `PostgresCatalog` reads enum-array columns as `STRING_ARRAY_TYPE` with 
`format_type()` as the source type, so the array element type is available to 
the sink.
   
   This builds on #12588, which maps enum columns to STRING in the catalog and 
CDC path. #12588 does not cover writing these values back to a PostgreSQL sink.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A PostgreSQL sink can now write into existing enum columns, including 
mixed-case quoted enum names and enum arrays. Other column types are unchanged.
   
   | Case | before | after |
   |---|---|---|
   | JDBC sink, enum column named `"ChapterElementType"` | `Unknown type 
chapterelementtype` | written as enum |
   | JDBC sink, enum array `"Role"[]` | failed | written as enum array |
   | JDBC sink, `jsonb` column | `setString` | unchanged (`setString`, requires 
`stringtype=unspecified`) |
   
   ### How was this patch tested?
   
   - Added unit tests in `PostgresJdbcRowConverterTest`:
     - quoted mixed-case enum type is kept in `PGobject.setType`
     - quoted enum after a schema qualifier
     - unquoted enum name is bound as enum
     - `jsonb` stays on `setString`
     - quoted enum array uses `createArrayOf` with the quoted element type
   - Added unit tests in `PostgresCatalogBuildColumnTest` for the enum array 
catalog path and the `typcategory` / `typelem` SQL.
   
   Not yet run on this branch. CI will run the `connector-jdbc` unit tests.
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License 
Notice according
    New License Guide
   * [ ] If necessary, please update the documentation to describe the new 
feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If necessary, please update `incompatible-changes.md` to describe the 
incompatibility caused by this PR.
   * [ ] If you are contributing the connector code, please check that the 
following files are updated:
    1. Update plugin-mapping.properties and add new connector information in it
    2. Update the pom file of seatunnel-dist
    3. Add ci label in label-scope-conf
    4. Add e2e testcase in seatunnel-e2e
    5. Update connector plugin_config
   


-- 
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]

Reply via email to