@@ -252,10 +252,12 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
252252 }
253253 }
254254
255- private def createDataSourceTable (
255+ private def checkSchemaInCreatedDataSourceTable (
256256 path : File ,
257257 userSpecifiedSchema : Option [String ],
258- userSpecifiedPartitionCols : Option [String ]): (StructType , Seq [String ]) = {
258+ userSpecifiedPartitionCols : Option [String ],
259+ expectedSchema : StructType ,
260+ expectedPartitionCols : Seq [String ]): Unit = {
259261 var tableSchema = StructType (Nil )
260262 var partCols = Seq .empty[String ]
261263
@@ -278,7 +280,8 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
278280 tableSchema = DDLUtils .getSchemaFromTableProperties(tableMetadata)
279281 partCols = DDLUtils .getPartitionColumnsFromTableProperties(tableMetadata)
280282 }
281- (tableSchema, partCols)
283+ assert(tableSchema == expectedSchema)
284+ assert(partCols == expectedPartitionCols)
282285 }
283286
284287 test(" Create partitioned data source table without user specified schema" ) {
@@ -291,13 +294,12 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
291294 withTempPath { pathToPartitionedTable =>
292295 df.write.format(" parquet" ).partitionBy(" num" )
293296 .save(pathToPartitionedTable.getCanonicalPath)
294- val (tableSchema, partCols) =
295- createDataSourceTable(
296- pathToPartitionedTable,
297- userSpecifiedSchema = None ,
298- userSpecifiedPartitionCols = partitionCols)
299- assert(tableSchema == new StructType ().add(" str" , StringType ).add(" num" , IntegerType ))
300- assert(partCols == Seq (" num" ))
297+ checkSchemaInCreatedDataSourceTable(
298+ pathToPartitionedTable,
299+ userSpecifiedSchema = None ,
300+ userSpecifiedPartitionCols = partitionCols,
301+ expectedSchema = new StructType ().add(" str" , StringType ).add(" num" , IntegerType ),
302+ expectedPartitionCols = Seq (" num" ))
301303 }
302304 }
303305 }
@@ -312,13 +314,12 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
312314 withTempPath { pathToPartitionedTable =>
313315 df.write.format(" parquet" ).partitionBy(" num" )
314316 .save(pathToPartitionedTable.getCanonicalPath)
315- val (tableSchema, partCols) =
316- createDataSourceTable(
317- pathToPartitionedTable,
318- userSpecifiedSchema = Option (" num int, str string" ),
319- userSpecifiedPartitionCols = partitionCols)
320- assert(tableSchema == new StructType ().add(" num" , IntegerType ).add(" str" , StringType ))
321- assert(partCols.mkString(" , " ) == partitionCols.getOrElse(" " ))
317+ checkSchemaInCreatedDataSourceTable(
318+ pathToPartitionedTable,
319+ userSpecifiedSchema = Option (" num int, str string" ),
320+ userSpecifiedPartitionCols = partitionCols,
321+ expectedSchema = new StructType ().add(" num" , IntegerType ).add(" str" , StringType ),
322+ expectedPartitionCols = partitionCols.map(Seq (_)).getOrElse(Seq .empty[String ]))
322323 }
323324 }
324325 }
@@ -332,13 +333,12 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
332333 Seq (Option (" inexistentColumns" ), None ).foreach { partitionCols =>
333334 withTempPath { pathToNonPartitionedTable =>
334335 df.write.format(" parquet" ).save(pathToNonPartitionedTable.getCanonicalPath)
335- val (tableSchema, partCols) =
336- createDataSourceTable(
337- pathToNonPartitionedTable,
338- userSpecifiedSchema = None ,
339- userSpecifiedPartitionCols = partitionCols)
340- assert(tableSchema == new StructType ().add(" num" , IntegerType ).add(" str" , StringType ))
341- assert(partCols.isEmpty)
336+ checkSchemaInCreatedDataSourceTable(
337+ pathToNonPartitionedTable,
338+ userSpecifiedSchema = None ,
339+ userSpecifiedPartitionCols = partitionCols,
340+ expectedSchema = new StructType ().add(" num" , IntegerType ).add(" str" , StringType ),
341+ expectedPartitionCols = Seq .empty[String ])
342342 }
343343 }
344344 }
@@ -352,13 +352,12 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
352352 Seq (Option (" num" ), None ).foreach { partitionCols =>
353353 withTempPath { pathToNonPartitionedTable =>
354354 df.write.format(" parquet" ).save(pathToNonPartitionedTable.getCanonicalPath)
355- val (tableSchema, partCols) =
356- createDataSourceTable(
357- pathToNonPartitionedTable,
358- userSpecifiedSchema = Option (" num int, str string" ),
359- userSpecifiedPartitionCols = partitionCols)
360- assert(tableSchema == new StructType ().add(" num" , IntegerType ).add(" str" , StringType ))
361- assert(partCols.mkString(" , " ) == partitionCols.getOrElse(" " ))
355+ checkSchemaInCreatedDataSourceTable(
356+ pathToNonPartitionedTable,
357+ userSpecifiedSchema = Option (" num int, str string" ),
358+ userSpecifiedPartitionCols = partitionCols,
359+ expectedSchema = new StructType ().add(" num" , IntegerType ).add(" str" , StringType ),
360+ expectedPartitionCols = partitionCols.map(Seq (_)).getOrElse(Seq .empty[String ]))
362361 }
363362 }
364363 }
0 commit comments