File tree Expand file tree Collapse file tree 4 files changed +49
-1
lines changed
java/org/apache/spark/sql/api/java
scala/org/apache/spark/sql/types/util
test/scala/org/apache/spark/sql/api/java Expand file tree Collapse file tree 4 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,11 @@ public abstract class DataType {
82
82
*/
83
83
public static final ShortType ShortType = new ShortType ();
84
84
85
+ /**
86
+ * Gets the NullType object.
87
+ */
88
+ public static final NullType NullType = new NullType ();
89
+
85
90
/**
86
91
* Creates an ArrayType by specifying the data type of elements ({@code elementType}).
87
92
* The field of {@code containsNull} is set to {@code true}.
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ package org .apache .spark .sql .api .java ;
19
+
20
+ /**
21
+ * The data type representing null and NULL values.
22
+ *
23
+ * {@code NullType} is represented by the singleton object {@link DataType#NullType}.
24
+ */
25
+ public class NullType extends DataType {
26
+ protected NullType () {}
27
+ }
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ protected[sql] object DataTypeConversions {
62
62
case IntegerType => JDataType .IntegerType
63
63
case LongType => JDataType .LongType
64
64
case ShortType => JDataType .ShortType
65
- case NullType => JDataType .StringType
65
+ case NullType => JDataType .NullType
66
66
67
67
case arrayType : ArrayType => JDataType .createArrayType(
68
68
asJavaDataType(arrayType.elementType), arrayType.containsNull)
Original file line number Diff line number Diff line change @@ -68,6 +68,22 @@ class JavaSQLSuite extends FunSuite {
68
68
javaSqlCtx.sql(" SELECT * FROM people" ).collect()
69
69
}
70
70
71
+ test(" schema with null from JavaBeans" ) {
72
+ val person = new PersonBean
73
+ person.setName(" Michael" )
74
+ person.setAge(29 )
75
+
76
+ val rdd = javaCtx.parallelize(person :: Nil )
77
+ val schemaRDD = javaSqlCtx.applySchema(rdd, classOf [PersonBean ])
78
+
79
+ schemaRDD.registerTempTable(" people" )
80
+ val nullRDD = javaSqlCtx.sql(" SELECT null FROM people" )
81
+ val structFields = nullRDD.schema.getFields()
82
+ assert(structFields.size == 1 )
83
+ assert(structFields(0 ).getDataType().isInstanceOf [NullType ])
84
+ assert(nullRDD.collect.head.row === Seq (null ))
85
+ }
86
+
71
87
test(" all types in JavaBeans" ) {
72
88
val bean = new AllTypesBean
73
89
bean.setStringField(" " )
You can’t perform that action at this time.
0 commit comments