Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

supporting fields with NULL types as sql NullType #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ object SchemaConverters {
case LONG => SchemaType(LongType, nullable = false)
case FIXED => SchemaType(BinaryType, nullable = false)
case ENUM => SchemaType(StringType, nullable = false)
case NULL => SchemaType(NullType, nullable = false)

case RECORD =>
val fields = avroSchema.getFields.asScala.map { f =>
Expand Down Expand Up @@ -150,7 +151,7 @@ object SchemaConverters {
(item: AnyRef) => if (item == null) null else item.toString
// Byte arrays are reused by avro, so we have to make a copy of them.
case (IntegerType, INT) | (BooleanType, BOOLEAN) | (DoubleType, DOUBLE) |
(FloatType, FLOAT) | (LongType, LONG) =>
(FloatType, FLOAT) | (LongType, LONG) | (NullType, NULL) | (NullType, STRING) =>
identity
case (BinaryType, FIXED) =>
(item: AnyRef) =>
Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/com/databricks/spark/avro/AvroSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ class AvroSuite extends FunSuite with BeforeAndAfterAll {
dataFileWriter.flush()
dataFileWriter.close()

intercept[IncompatibleSchemaException] {
spark.read.avro(s"$dir.avro")
}
val df = spark.read.avro(s"$dir.avro")
assert(df.count() == 1)
}
}

Expand Down