cloud-fan commented on a change in pull request #27851: [SPARK-31071][SQL]
Allow annotating non-null fields when encoding Java Beans
URL: https://github.com/apache/spark/pull/27851#discussion_r389503047
##########
File path:
sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java
##########
@@ -1504,6 +1574,54 @@ public void testSerializeNull() {
Assert.assertEquals(beans, ds2.collectAsList());
}
+ @Test
+ public void testNonNullField() {
+ NestedSmallBeanWithNonNullField bean1 = new
NestedSmallBeanWithNonNullField();
+ SmallBean smallBean = new SmallBean();
+ bean1.setNonNull_f(smallBean);
+ Map<String, SmallBean> map = new HashMap<>();
+ bean1.setChildMap(map);
+
+ Encoder<NestedSmallBeanWithNonNullField> encoder1 =
+ Encoders.bean(NestedSmallBeanWithNonNullField.class);
+ List<NestedSmallBeanWithNonNullField> beans1 = Arrays.asList(bean1);
+ Dataset<NestedSmallBeanWithNonNullField> ds1 = spark.createDataset(beans1,
encoder1);
+
+ StructType schema = ds1.schema();
+
Assert.assertFalse(schema.fields()[schema.fieldIndex("nonNull_f")].nullable());
Review comment:
how about `schema.apply("nonNull_f").nullable()`?
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]