@@ -91,4 +91,54 @@ class InsertIntoHiveTableSuite extends QueryTest {
9191
9292 sql(" DROP TABLE hiveTableWithMapValue" )
9393 }
94+
95+ test(" Insert ArrayType.containsNull == false" ) {
96+ val schema = StructType (Seq (
97+ StructField (" a" , ArrayType (StringType , containsNull = false ))))
98+ val rowRDD = TestHive .sparkContext.parallelize((1 to 100 ).map(i => Row (Seq (s " value $i" ))))
99+ val schemaRDD = applySchema(rowRDD, schema)
100+ schemaRDD.registerTempTable(" tableWithArrayValue" )
101+ sql(" CREATE TABLE hiveTableWithArrayValue(a Array <STRING>)" )
102+ sql(" INSERT OVERWRITE TABLE hiveTableWithArrayValue SELECT a FROM tableWithArrayValue" )
103+
104+ checkAnswer(
105+ sql(" SELECT * FROM hiveTableWithArrayValue" ),
106+ rowRDD.collect().toSeq)
107+
108+ sql(" DROP TABLE hiveTableWithArrayValue" )
109+ }
110+
111+ test(" Insert MapType.valueContainsNull == false" ) {
112+ val schema = StructType (Seq (
113+ StructField (" m" , MapType (StringType , StringType , valueContainsNull = false ))))
114+ val rowRDD = TestHive .sparkContext.parallelize(
115+ (1 to 100 ).map(i => Row (Map (s " key $i" -> s " value $i" ))))
116+ val schemaRDD = applySchema(rowRDD, schema)
117+ schemaRDD.registerTempTable(" tableWithMapValue" )
118+ sql(" CREATE TABLE hiveTableWithMapValue(m Map <STRING, STRING>)" )
119+ sql(" INSERT OVERWRITE TABLE hiveTableWithMapValue SELECT m FROM tableWithMapValue" )
120+
121+ checkAnswer(
122+ sql(" SELECT * FROM hiveTableWithMapValue" ),
123+ rowRDD.collect().toSeq)
124+
125+ sql(" DROP TABLE hiveTableWithMapValue" )
126+ }
127+
128+ test(" Insert StringType.fields.exists(_.nullable == false)" ) {
129+ val schema = StructType (Seq (
130+ StructField (" s" , StructType (Seq (StructField (" f" , StringType , nullable = false ))))))
131+ val rowRDD = TestHive .sparkContext.parallelize(
132+ (1 to 100 ).map(i => Row (Row (s " value $i" ))))
133+ val schemaRDD = applySchema(rowRDD, schema)
134+ schemaRDD.registerTempTable(" tableWithStructValue" )
135+ sql(" CREATE TABLE hiveTableWithStructValue(s Struct <f: STRING>)" )
136+ sql(" INSERT OVERWRITE TABLE hiveTableWithStructValue SELECT s FROM tableWithStructValue" )
137+
138+ checkAnswer(
139+ sql(" SELECT * FROM hiveTableWithStructValue" ),
140+ rowRDD.collect().toSeq)
141+
142+ sql(" DROP TABLE hiveTableWithStructValue" )
143+ }
94144}
0 commit comments