@Test public void testUpdateMissingColumn() { AssertHelpers.assertThrows("Should reject rename missing column", IllegalArgumentException.class, "missing column: col", () -> { UpdateSchema update = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID); update.updateColumn("col", Types.DateType.get()); } ); }
@Override public UpdateSchema updateColumn(String name, Type.PrimitiveType newType) { Types.NestedField field = schema.findField(name); Preconditions.checkArgument(field != null, "Cannot update missing column: %s", name); Preconditions.checkArgument(!deletes.contains(field.fieldId()), "Cannot update a column that will be deleted: %s", field.name()); if (field.type().equals(newType)) { return this; } Preconditions.checkArgument(TypeUtil.isPromotionAllowed(field.type(), newType), "Cannot change column type: %s: %s -> %s", name, field.type(), newType); int fieldId = field.fieldId(); Types.NestedField update = updates.get(fieldId); if (update != null) { updates.put(fieldId, Types.NestedField.of(fieldId, update.isOptional(), update.name(), newType, update.doc())); } else { updates.put(fieldId, Types.NestedField.of(fieldId, field.isOptional(), field.name(), newType, field.doc())); } return this; }
SchemaUpdate implements UpdateSchema { @Override public UpdateSchema updateColumn(String name, Type.PrimitiveType newType) { Types.NestedField field = schema.findField(name); Preconditions.checkArgument(field != null, "Cannot update missing column: %s", name); Preconditions.checkArgument(!deletes.contains(field.fieldId()), "Cannot update a column that will be deleted: %s", field.name()); if (field.type().equals(newType)) { return this; } Preconditions.checkArgument(TypeUtil.isPromotionAllowed(field.type(), newType), "Cannot change column type: %s: %s -> %s", name, field.type(), newType); int fieldId = field.fieldId(); Types.NestedField update = updates.get(fieldId); if (update != null) { updates.put(fieldId, Types.NestedField.of(fieldId, update.isOptional(), update.name(), newType, update.doc())); } else { updates.put(fieldId, Types.NestedField.of(fieldId, field.isOptional(), field.name(), newType, field.doc())); } return this; } }
SchemaUpdate implements UpdateSchema { @Override public UpdateSchema updateColumn(String name, Type.PrimitiveType newType) { Types.NestedField field = schema.findField(name); Preconditions.checkArgument(field != null, "Cannot update missing column: %s", name); Preconditions.checkArgument(!deletes.contains(field.fieldId()), "Cannot update a column that will be deleted: %s", field.name()); if (field.type().equals(newType)) { return this; } Preconditions.checkArgument(TypeUtil.isPromotionAllowed(field.type(), newType), "Cannot change column type: %s: %s -> %s", name, field.type(), newType); int fieldId = field.fieldId(); Types.NestedField update = updates.get(fieldId); if (update != null) { updates.put(fieldId, Types.NestedField.of(fieldId, update.isOptional(), update.name(), newType, update.doc())); } else { updates.put(fieldId, Types.NestedField.of(fieldId, field.isOptional(), field.name(), newType, field.doc())); } return this; } SchemaUpdate(TableOperations ops);   SchemaUpdate(Schema schema, int lastColumnId); }
SchemaUpdate implements UpdateSchema { @Override public UpdateSchema updateColumn(String name, Type.PrimitiveType newType) { Types.NestedField field = schema.findField(name); Preconditions.checkArgument(field != null, "Cannot update missing column: %s", name); Preconditions.checkArgument(!deletes.contains(field.fieldId()), "Cannot update a column that will be deleted: %s", field.name()); if (field.type().equals(newType)) { return this; } Preconditions.checkArgument(TypeUtil.isPromotionAllowed(field.type(), newType), "Cannot change column type: %s: %s -> %s", name, field.type(), newType); int fieldId = field.fieldId(); Types.NestedField update = updates.get(fieldId); if (update != null) { updates.put(fieldId, Types.NestedField.of(fieldId, update.isOptional(), update.name(), newType, update.doc())); } else { updates.put(fieldId, Types.NestedField.of(fieldId, field.isOptional(), field.name(), newType, field.doc())); } return this; } SchemaUpdate(TableOperations ops);   SchemaUpdate(Schema schema, int lastColumnId); @Override SchemaUpdate allowIncompatibleChanges(); @Override UpdateSchema addColumn(String name, Type type, String doc); @Override UpdateSchema addColumn(String parent, String name, Type type, String doc); @Override UpdateSchema addRequiredColumn(String name, Type type, String doc); @Override UpdateSchema addRequiredColumn(String parent, String name, Type type, String doc); @Override UpdateSchema deleteColumn(String name); @Override UpdateSchema renameColumn(String name, String newName); @Override UpdateSchema requireColumn(String name); @Override UpdateSchema makeColumnOptional(String name); @Override UpdateSchema updateColumn(String name, Type.PrimitiveType newType); @Override UpdateSchema updateColumnDoc(String name, String doc); @Override UpdateSchema moveFirst(String name); @Override UpdateSchema moveBefore(String name, String beforeName); @Override UpdateSchema moveAfter(String name, String afterName); UpdateSchema updateSchema(Schema newSchema); @Override Schema apply(); @Override void commit(); }
SchemaUpdate implements UpdateSchema { @Override public UpdateSchema updateColumn(String name, Type.PrimitiveType newType) { Types.NestedField field = schema.findField(name); Preconditions.checkArgument(field != null, "Cannot update missing column: %s", name); Preconditions.checkArgument(!deletes.contains(field.fieldId()), "Cannot update a column that will be deleted: %s", field.name()); if (field.type().equals(newType)) { return this; } Preconditions.checkArgument(TypeUtil.isPromotionAllowed(field.type(), newType), "Cannot change column type: %s: %s -> %s", name, field.type(), newType); int fieldId = field.fieldId(); Types.NestedField update = updates.get(fieldId); if (update != null) { updates.put(fieldId, Types.NestedField.of(fieldId, update.isOptional(), update.name(), newType, update.doc())); } else { updates.put(fieldId, Types.NestedField.of(fieldId, field.isOptional(), field.name(), newType, field.doc())); } return this; } SchemaUpdate(TableOperations ops);   SchemaUpdate(Schema schema, int lastColumnId); @Override SchemaUpdate allowIncompatibleChanges(); @Override UpdateSchema addColumn(String name, Type type, String doc); @Override UpdateSchema addColumn(String parent, String name, Type type, String doc); @Override UpdateSchema addRequiredColumn(String name, Type type, String doc); @Override UpdateSchema addRequiredColumn(String parent, String name, Type type, String doc); @Override UpdateSchema deleteColumn(String name); @Override UpdateSchema renameColumn(String name, String newName); @Override UpdateSchema requireColumn(String name); @Override UpdateSchema makeColumnOptional(String name); @Override UpdateSchema updateColumn(String name, Type.PrimitiveType newType); @Override UpdateSchema updateColumnDoc(String name, String doc); @Override UpdateSchema moveFirst(String name); @Override UpdateSchema moveBefore(String name, String beforeName); @Override UpdateSchema moveAfter(String name, String afterName); UpdateSchema updateSchema(Schema newSchema); @Override Schema apply(); @Override void commit();  }