sainimal1ba-hue opened a new issue, #13372: URL: https://github.com/apache/seatunnel/issues/13372
State: Under Review ## Background Column default values are handled independently at each stage of the DDL pipeline: source parsing, the SeaTunnel column model, and sink DDL rendering. There is no shared definition of what a default means, so the outcome depends on which source and sink are paired. The discussion in #13217 shows the consequences. When the MySQL sink creates the target table automatically, the DEFAULT clauses are dropped and the defaults disappear without an error. Values such as now() can be written out as string literals. The same column can also map to different Java types depending on whether its default came through the catalog or through a CDC read. The design has been discussed in #13217 and on the dev mailing list ([DISCUSS] Column default values: typed contract for the DDL pipeline, archive: https://www.mail-archive.com/[email protected]/msg01346.html). ## Motivation Because the defaults disappear without producing an error, a table created by SeaTunnel can differ from the source schema without anyone noticing. The problem usually surfaces much later, when the replicated table already behaves differently from the original. Each connector currently interprets defaults on its own, so the same value can be handled correctly by one dialect and incorrectly by another. Using the same representation throughout the pipeline would prevent connectors from reinterpreting defaults, and would give the project one place to define which values are actually supported. ## Goals - A typed DefaultValue model in seatunnel-api, attached to the existing column representation, so a default has one meaning from source parsing to sink DDL. - A closed vocabulary for v1 (typed literals, explicit NULL, CURRENT_TIMESTAMP / CURRENT_TIME / CURRENT_DATE); values outside it are marked UNSUPPORTED rather than passed through. - Schema operations fail by default when a default can't be expressed on the target, with an option to drop the default and warn instead. - MySQL to MySQL as the first end-to-end pair. ## Non-Goals - Other source/sink pairs. v1 covers MySQL to MySQL; the model is designed so other connectors can adopt it afterwards. - Arbitrary SQL expressions or function calls as defaults. - Changes to the general catalog type mapping beyond what defaults require. ## Design The proposal adds a typed DefaultValue model in seatunnel-api. A default is either a typed literal (a value together with its SeaTunnel type), explicit NULL, one of the current-datetime tokens, or UNSUPPORTED carrying the original raw string. The model attaches to the existing column representation in CatalogTable, so a default is parsed once when it enters the pipeline and rendered once when the sink writes its DDL. Nothing in between works with raw strings. A central converter normalizes what sources provide: JDBC metadata defaults and CDC default fields (Debezium) go in, the typed model comes out. Sink dialects see only the typed model and produce their own DEFAULT syntax. Separating normalization from rendering is what removes the catalog-versus-CDC inconsistency, since the semantic value is settled before any dialect-specific code runs. The failure policy is FAIL by default, with DROP_AND_WARN as the opt-in for users who prefer the current lenient behavior. The option name and its exact placement in the configuration haven't been decided; they should follow existing conventions. The vocabulary is deliberately closed. Supporting a new kind of value later means adding one token and teaching the converter about it, rather than letting arbitrary SQL move through the pipeline. ## Compatibility, Deprecation, and Migration Plan The model itself is additive. The behavioral change is that jobs which currently lose defaults silently will fail with a clear message once the new policy applies; DROP_AND_WARN restores the previous behavior for those jobs. The change should be called out in the release notes. ## Test Plan - Converter tests over JDBC metadata defaults and CDC default fields, covering each v1 vocabulary case and the UNSUPPORTED path. - MySQL dialect rendering tests for every token type and both failure policies. - An integration test where MySQL to MySQL auto table creation produces a target table that keeps its DEFAULT clauses. ## Alternatives Considered - Passing raw default strings through unchanged. A dialect still has to quote or translate the value at some point, and that is where meaning gets lost, as the now() case shows. - Handling defaults inside each connector without a shared model. This is the current state, and it is why the same problem appears in different forms across connectors. - Normalizing to strings only and letting dialects parse them. It keeps the semantic interpretation inside dialect code, which is exactly the part the proposal moves out. ## References - Feature discussion: #13217 - Dev list thread: [DISCUSS] Column default values: typed contract for the DDL pipeline (https://www.mail-archive.com/[email protected]/msg01346.html) - STIP guide: https://seatunnel.apache.org/community/contribution_guide/STIP - STIP-36 covers schema evolution observability and decision logging and does not touch default-value semantics. Requesting a maintainer to add the design / STIP label. -- 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]
