|
38 | 38 |
|
39 | 39 | import org.apache.hadoop.conf.Configuration; |
40 | 40 | import org.apache.iceberg.CatalogUtil; |
| 41 | +import org.apache.iceberg.HasTableOperations; |
41 | 42 | import org.apache.iceberg.PartitionSpec; |
42 | 43 | import org.apache.iceberg.Schema; |
43 | 44 | import org.apache.iceberg.Table; |
@@ -197,6 +198,9 @@ private void applyCreateTable(CreateTableEvent event) { |
197 | 198 |
|
198 | 199 | private void applyDefaultValues( |
199 | 200 | Table table, org.apache.flink.cdc.common.schema.Schema cdcSchema) { |
| 201 | + if (getFormatVersion(table) < 3) { |
| 202 | + return; |
| 203 | + } |
200 | 204 | UpdateSchema updateSchema = null; |
201 | 205 | for (Column column : cdcSchema.getColumns()) { |
202 | 206 | Literal<?> defaultValue = |
@@ -240,8 +244,9 @@ private void applyAddColumnEventWithPosition(Table table, AddColumnEvent event) |
240 | 244 | Literal<?> defaultValue = |
241 | 245 | IcebergTypeUtils.parseDefaultValue( |
242 | 246 | addColumn.getDefaultValueExpression(), addColumn.getType()); |
243 | | - if (defaultValue != null) { |
| 247 | + if (defaultValue != null && getFormatVersion(table) >= 3) { |
244 | 248 | updateSchema.addColumn(columnName, icebergType, columnComment, defaultValue); |
| 249 | + updateSchema.updateColumnDefault(columnName, defaultValue); |
245 | 250 | } else { |
246 | 251 | updateSchema.addColumn(columnName, icebergType, columnComment); |
247 | 252 | } |
@@ -396,6 +401,13 @@ public Set<SchemaChangeEventType> getSupportedSchemaEvolutionTypes() { |
396 | 401 | SchemaChangeEventType.ALTER_COLUMN_TYPE); |
397 | 402 | } |
398 | 403 |
|
| 404 | + private int getFormatVersion(Table table) { |
| 405 | + if (table instanceof HasTableOperations) { |
| 406 | + return ((HasTableOperations) table).operations().current().formatVersion(); |
| 407 | + } |
| 408 | + return 2; |
| 409 | + } |
| 410 | + |
399 | 411 | @Override |
400 | 412 | public void close() { |
401 | 413 | catalog = null; |
|
0 commit comments