Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ class ParquetIOSuite extends QueryTest with ParquetTest with SharedSQLContext {
}
}

test("SPARK-11694 Parquet logical types are not being tested properly") {
val parquetSchema = MessageTypeParser.parseMessageType(
"""message root {
| required int32 a(INT_8);
| required int32 b(INT_16);
| required int32 c(DATE);
| required int32 d(DECIMAL(1,0));
| required int64 e(DECIMAL(10,0));
|} + """.stripMargin)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the +?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I should get rid of this. I ran this test several times and added a PR. This is weird. Sorry.


withTempPath { location =>
val extraMetadata = Map.empty[String, String].asJava
val fileMetadata = new FileMetaData(parquetSchema, extraMetadata, "Spark")
val path = new Path(location.getCanonicalPath)
val footer = List(
new Footer(path, new ParquetMetadata(fileMetadata, Collections.emptyList()))
).asJava

ParquetFileWriter.writeMetadataFile(sparkContext.hadoopConfiguration, path, footer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that you've been using this trick multiple times in various test cases. There's a method ParquetTest.writeMetadata, which is very similar to the logic above. You may either modify that method or add an overloaded version of it to allow writing customized Parquet schema.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

val sparkTypes = sqlContext.read.parquet(path.toString).schema.map(_.dataType)

assert(sparkTypes ==
Seq(ByteType, ShortType, DateType, DecimalType(1, 0), DecimalType(10, 0)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use === instead of == for better assertion error message.

}
}

test("string") {
val data = (1 to 4).map(i => Tuple1(i.toString))
// Property spark.sql.parquet.binaryAsString shouldn't affect Parquet files written by Spark SQL
Expand Down