@@ -94,7 +94,7 @@ public void TestCreateDataFrame()
9494
9595 // Calling CreateDataFrame(IEnumerable<string> _) without schema
9696 {
97- var data = new List < string > ( new string [ ] { "Alice" , "Bob" } ) ;
97+ var data = new string [ ] { "Alice" , "Bob" , null } ;
9898 StructType schema = SchemaWithSingleColumn ( new StringType ( ) ) ;
9999
100100 DataFrame df = _spark . CreateDataFrame ( data ) ;
@@ -103,7 +103,16 @@ public void TestCreateDataFrame()
103103
104104 // Calling CreateDataFrame(IEnumerable<int> _) without schema
105105 {
106- var data = new List < int > ( new int [ ] { 1 , 2 } ) ;
106+ var data = new int [ ] { 1 , 2 } ;
107+ StructType schema = SchemaWithSingleColumn ( new IntegerType ( ) , false ) ;
108+
109+ DataFrame df = _spark . CreateDataFrame ( data ) ;
110+ ValidateDataFrame ( df , data . Select ( a => new object [ ] { a } ) , schema ) ;
111+ }
112+
113+ // Calling CreateDataFrame(IEnumerable<int?> _) without schema
114+ {
115+ var data = new int ? [ ] { 1 , 2 , null } ;
107116 StructType schema = SchemaWithSingleColumn ( new IntegerType ( ) ) ;
108117
109118 DataFrame df = _spark . CreateDataFrame ( data ) ;
@@ -112,7 +121,16 @@ public void TestCreateDataFrame()
112121
113122 // Calling CreateDataFrame(IEnumerable<double> _) without schema
114123 {
115- var data = new List < double > ( new double [ ] { 1.2 , 2.3 } ) ;
124+ var data = new double [ ] { 1.2 , 2.3 } ;
125+ StructType schema = SchemaWithSingleColumn ( new DoubleType ( ) , false ) ;
126+
127+ DataFrame df = _spark . CreateDataFrame ( data ) ;
128+ ValidateDataFrame ( df , data . Select ( a => new object [ ] { a } ) , schema ) ;
129+ }
130+
131+ // Calling CreateDataFrame(IEnumerable<double?> _) without schema
132+ {
133+ var data = new double ? [ ] { 1.2 , 2.3 , null } ;
116134 StructType schema = SchemaWithSingleColumn ( new DoubleType ( ) ) ;
117135
118136 DataFrame df = _spark . CreateDataFrame ( data ) ;
@@ -121,19 +139,29 @@ public void TestCreateDataFrame()
121139
122140 // Calling CreateDataFrame(IEnumerable<bool> _) without schema
123141 {
124- var data = new List < bool > ( new bool [ ] { true , false } ) ;
142+ var data = new bool [ ] { true , false } ;
143+ StructType schema = SchemaWithSingleColumn ( new BooleanType ( ) , false ) ;
144+
145+ DataFrame df = _spark . CreateDataFrame ( data ) ;
146+ ValidateDataFrame ( df , data . Select ( a => new object [ ] { a } ) , schema ) ;
147+ }
148+
149+ // Calling CreateDataFrame(IEnumerable<bool?> _) without schema
150+ {
151+ var data = new bool ? [ ] { true , false , null } ;
125152 StructType schema = SchemaWithSingleColumn ( new BooleanType ( ) ) ;
126153
127154 DataFrame df = _spark . CreateDataFrame ( data ) ;
128155 ValidateDataFrame ( df , data . Select ( a => new object [ ] { a } ) , schema ) ;
129156 }
130-
157+
131158 // Calling CreateDataFrame(IEnumerable<Date> _) without schema
132159 {
133160 var data = new Date [ ]
134161 {
135162 new Date ( 2020 , 1 , 1 ) ,
136- new Date ( 2020 , 1 , 2 )
163+ new Date ( 2020 , 1 , 2 ) ,
164+ null
137165 } ;
138166 StructType schema = SchemaWithSingleColumn ( new DateType ( ) ) ;
139167
@@ -151,7 +179,8 @@ public void TestCreateDataFrameWithTimestamp()
151179 var data = new Timestamp [ ]
152180 {
153181 new Timestamp ( 2020 , 1 , 1 , 0 , 0 , 0 , 0 ) ,
154- new Timestamp ( 2020 , 1 , 2 , 15 , 30 , 30 , 0 )
182+ new Timestamp ( 2020 , 1 , 2 , 15 , 30 , 30 , 0 ) ,
183+ null
155184 } ;
156185 StructType schema = SchemaWithSingleColumn ( new TimestampType ( ) ) ;
157186
@@ -172,8 +201,9 @@ private void ValidateDataFrame(
172201 /// Returns a single column schema of the given datatype.
173202 /// </summary>
174203 /// <param name="dataType">Datatype of the column</param>
204+ /// <param name="isNullable">Indicates if values of the column can be null</param>
175205 /// <returns>Schema as StructType</returns>
176- private StructType SchemaWithSingleColumn ( DataType dataType ) =>
177- new StructType ( new [ ] { new StructField ( "_1" , dataType ) } ) ;
206+ private StructType SchemaWithSingleColumn ( DataType dataType , bool isNullable = true ) =>
207+ new StructType ( new [ ] { new StructField ( "_1" , dataType , isNullable ) } ) ;
178208 }
179209}
0 commit comments