transformColumnDef modifies a column definition for DuckLake compatibility. SERIAL is rewritten to plain integer types; GENERATED STORED and DEFAULT (which would silently produce NULL data on a lake catalog) are stripped. Unenforceable column constraints (PK/UNIQUE/CHECK/FK) are stripped.
(col *pg_query.ColumnDef, result *Result)
| 204 | // (which would silently produce NULL data on a lake catalog) are stripped. |
| 205 | // Unenforceable column constraints (PK/UNIQUE/CHECK/FK) are stripped. |
| 206 | func (t *DDLTransform) transformColumnDef(col *pg_query.ColumnDef, result *Result) bool { |
| 207 | changed := false |
| 208 | |
| 209 | // SERIAL/BIGSERIAL: no backing sequence on a lake catalog -> ids silently NULL. |
| 210 | if col.TypeName != nil { |
| 211 | if serialTypeName(col.TypeName) != "" { |
| 212 | if t.policy.RewriteSerial && t.convertSerialType(col.TypeName) { |
| 213 | changed = true |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | // Remove unsupported column constraints |
| 219 | if len(col.Constraints) > 0 { |
| 220 | newConstraints := make([]*pg_query.Node, 0) |
| 221 | for _, c := range col.Constraints { |
| 222 | constraint := c.GetConstraint() |
| 223 | if constraint == nil { |
| 224 | newConstraints = append(newConstraints, c) |
| 225 | continue |
| 226 | } |
| 227 | // Unenforceable constraints (PK/UNIQUE/CHECK/FK/EXCLUSION): strip. |
| 228 | if t.policy.ConstraintHandling == backend.StripConstraints && t.isUnsupportedColumnConstraint(constraint) { |
| 229 | changed = true |
| 230 | continue |
| 231 | } |
| 232 | // GENERATED ALWAYS AS (...) STORED: computed value would be silently NULL. |
| 233 | if constraint.Contype == pg_query.ConstrType_CONSTR_GENERATED { |
| 234 | if t.policy.StripVolatileDefaults { |
| 235 | changed = true |
| 236 | continue |
| 237 | } |
| 238 | } |
| 239 | // DEFAULT <expression>/now(): the default would be silently dropped (NULL). |
| 240 | // Literal int/float/string and DEFAULT NULL are not "unsupported" here and |
| 241 | // are passed through to the engine. |
| 242 | if constraint.Contype == pg_query.ConstrType_CONSTR_DEFAULT && t.isUnsupportedDefault(constraint.RawExpr) { |
| 243 | if t.policy.StripVolatileDefaults { |
| 244 | changed = true |
| 245 | continue |
| 246 | } |
| 247 | } |
| 248 | newConstraints = append(newConstraints, c) |
| 249 | } |
| 250 | col.Constraints = newConstraints |
| 251 | } |
| 252 | |
| 253 | return changed |
| 254 | } |
| 255 | |
| 256 | // convertSerialType converts SERIAL types to INTEGER types |
| 257 | func (t *DDLTransform) convertSerialType(typeName *pg_query.TypeName) bool { |
no test coverage detected