|
20 | 20 |
|
21 | 21 | import static org.apache.iceberg.Files.localInput; |
22 | 22 | import static org.assertj.core.api.Assertions.assertThat; |
| 23 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
23 | 24 |
|
24 | 25 | import java.io.File; |
25 | 26 | import java.io.IOException; |
@@ -272,6 +273,51 @@ public void testReadColumnFilter2() throws Exception { |
272 | 273 | scan, NUM_ROWS_PER_MONTH, 12 * NUM_ROWS_PER_MONTH, ImmutableList.of("timestamp")); |
273 | 274 | } |
274 | 275 |
|
| 276 | + @Test |
| 277 | + public void testThrowsUOEWhenNewColumnHasNoValue() throws Exception { |
| 278 | + rowsWritten = Lists.newArrayList(); |
| 279 | + tables = new HadoopTables(); |
| 280 | + |
| 281 | + Schema schema = |
| 282 | + new Schema( |
| 283 | + Types.NestedField.required(1, "a", Types.IntegerType.get()), |
| 284 | + Types.NestedField.optional(2, "b", Types.StringType.get()), |
| 285 | + Types.NestedField.required(3, "c", Types.DecimalType.of(12, 3))); |
| 286 | + |
| 287 | + PartitionSpec spec = PartitionSpec.builderFor(schema).build(); |
| 288 | + Table table1 = tables.create(schema, spec, tableLocation); |
| 289 | + |
| 290 | + // Add one record to the table |
| 291 | + GenericRecord rec = GenericRecord.create(schema); |
| 292 | + rec.setField("a", 1); |
| 293 | + rec.setField("b", "san diego"); |
| 294 | + rec.setField("c", new BigDecimal("1024.025")); |
| 295 | + List<GenericRecord> genericRecords = Lists.newArrayList(); |
| 296 | + genericRecords.add(rec); |
| 297 | + |
| 298 | + // Alter the table schema by adding a new, optional column. |
| 299 | + // Do not add any data for this new column in the one existing row in the table |
| 300 | + // and do not insert any new rows into the table. |
| 301 | + Table table = tables.load(tableLocation); |
| 302 | + table.updateSchema().addColumn("a1", Types.IntegerType.get()).commit(); |
| 303 | + |
| 304 | + // Select all columns, all rows from the table |
| 305 | + TableScan scan = table.newScan().select("*"); |
| 306 | + |
| 307 | + assertThatThrownBy( |
| 308 | + () -> { |
| 309 | + // Read the data. |
| 310 | + try (VectorizedTableScanIterable itr = |
| 311 | + new VectorizedTableScanIterable(scan, 1000, false)) { |
| 312 | + for (ColumnarBatch batch : itr) { |
| 313 | + // no-op |
| 314 | + } |
| 315 | + } |
| 316 | + }) |
| 317 | + .isInstanceOf(UnsupportedOperationException.class) |
| 318 | + .hasMessage("Unsupported vector: null"); |
| 319 | + } |
| 320 | + |
275 | 321 | /** |
276 | 322 | * The test asserts that {@link CloseableIterator#hasNext()} returned by the {@link ArrowReader} |
277 | 323 | * is idempotent. |
|
0 commit comments