rdblue commented on a change in pull request #1932:
URL: https://github.com/apache/iceberg/pull/1932#discussion_r542945011
##########
File path:
spark2/src/test/java/org/apache/iceberg/examples/SchemaEvolutionTest.java
##########
@@ -120,13 +161,25 @@ public void renameColumn() {
results.createOrReplaceTempView("table");
spark.sql("select * from table").show();
+ List<String> fields = Arrays.asList(spark.sql("select * from
table").schema().names());
+ assert (fields.contains("writer"));
+ assert (!fields.contains("author"));
Review comment:
This are good assertions to have, but they should be JUnit assertions
and not `assert`.
##########
File path:
spark2/src/test/java/org/apache/iceberg/examples/SchemaEvolutionTest.java
##########
@@ -84,29 +98,56 @@ public void before() throws IOException {
@Test
public void addColumnToSchema() {
- table.updateSchema().addColumn("publisher",
Types.StringType.get()).commit();
- Dataset<Row> df2 = spark.read().json(dataLocation + "new-books.json");
+ String fieldName = "publisher";
+ Schema schema = table.schema();
+ Assert.assertNull(schema.findField(fieldName));
+
+ table.updateSchema().addColumn(fieldName, Types.StringType.get()).commit();
+
+ Dataset<Row> df1 = spark.read()
+ .json(dataLocation + "books.json");
+ df1 = df1.withColumn(fieldName, new Column(Literal$.MODULE$.apply(null)))
+ .selectExpr("title", "price", "author", "cast(published as
timestamp)", "genre", "publisher");
+ Dataset<Row> df2 = spark.read().json(dataLocation + "new-books.json")
+ .selectExpr("title", "price", "author", "cast(published as
timestamp)", "genre", "publisher");
+ List<Row> expected = df1.union(df2)
+ .collectAsList();
+
+ // Append data
df2.select(df2.col("title"), df2.col("price").cast(DataTypes.IntegerType),
df2.col("author"), df2.col("published").cast(DataTypes.TimestampType),
df2.col("genre"), df2.col("publisher")).write()
.format("iceberg")
.mode("append")
.save(tableLocation.toString());
+
+ // Read iceberg table
+ Dataset<Row> iceberg = spark.read()
+ .format("iceberg")
+ .load(tableLocation.toString());
+
+ String error = QueryTest$.MODULE$.checkAnswer(iceberg, expected);
+ Assert.assertNull(error);
+
}
@Test
public void deleteColumnFromSchema() {
- table.updateSchema().deleteColumn("genre").commit();
+ List<Row> rows = spark.read()
+ .format("iceberg")
+ .load(tableLocation.toString())
+ .drop("genre").collectAsList();
+ table.updateSchema().deleteColumn("genre").commit();
table.refresh();
+
Dataset<Row> results = spark.read()
.format("iceberg")
.load(tableLocation.toString());
-
- results.createOrReplaceTempView("table");
- spark.sql("select * from table").show();
+
Assert.assertFalse(Arrays.asList(results.schema().names()).contains("genre"));
Review comment:
This is a good assertion to add.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]