Github user xuanyuanking commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22467#discussion_r218835749
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/ParquetPartitioningTest.scala 
---
    @@ -0,0 +1,253 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive
    +
    +import java.io.File
    +
    +import org.apache.spark.sql._
    +import org.apache.spark.sql.hive.test.TestHiveSingleton
    +import org.apache.spark.sql.test.SQLTestUtils
    +import org.apache.spark.util.Utils
    +
    +// The data where the partitioning key exists only in the directory 
structure.
    +case class ParquetData(intField: Int, stringField: String)
    +// The data that also includes the partitioning key
    +case class ParquetDataWithKey(p: Int, intField: Int, stringField: String)
    +
    +case class StructContainer(intStructField: Int, stringStructField: String)
    +
    +case class ParquetDataWithComplexTypes(
    +    intField: Int,
    +    stringField: String,
    +    structField: StructContainer,
    +    arrayField: Seq[Int])
    +
    +case class ParquetDataWithKeyAndComplexTypes(
    +    p: Int,
    +    intField: Int,
    +    stringField: String,
    +    structField: StructContainer,
    +    arrayField: Seq[Int])
    +
    +/**
    + * A collection of tests for parquet data with various forms of 
partitioning.
    + */
    +abstract class ParquetPartitioningTest extends QueryTest with SQLTestUtils 
with TestHiveSingleton {
    +  import testImplicits._
    +
    +  var partitionedTableDir: File = null
    +  var normalTableDir: File = null
    +  var partitionedTableDirWithKey: File = null
    +  var partitionedTableDirWithComplexTypes: File = null
    +  var partitionedTableDirWithKeyAndComplexTypes: File = null
    +
    +  override def beforeAll(): Unit = {
    +    super.beforeAll()
    +    partitionedTableDir = Utils.createTempDir()
    +    normalTableDir = Utils.createTempDir()
    +
    +    (1 to 10).foreach { p =>
    +      val partDir = new File(partitionedTableDir, s"p=$p")
    +      sparkContext.makeRDD(1 to 10)
    +        .map(i => ParquetData(i, s"part-$p"))
    +        .toDF()
    +        .write.parquet(partDir.getCanonicalPath)
    +    }
    +
    +    sparkContext
    +      .makeRDD(1 to 10)
    +      .map(i => ParquetData(i, s"part-1"))
    +      .toDF()
    +      .write.parquet(new File(normalTableDir, "normal").getCanonicalPath)
    +
    +    partitionedTableDirWithKey = Utils.createTempDir()
    +
    +    (1 to 10).foreach { p =>
    +      val partDir = new File(partitionedTableDirWithKey, s"p=$p")
    +      sparkContext.makeRDD(1 to 10)
    +        .map(i => ParquetDataWithKey(p, i, s"part-$p"))
    +        .toDF()
    +        .write.parquet(partDir.getCanonicalPath)
    +    }
    +
    +    partitionedTableDirWithKeyAndComplexTypes = Utils.createTempDir()
    +
    +    (1 to 10).foreach { p =>
    +      val partDir = new File(partitionedTableDirWithKeyAndComplexTypes, 
s"p=$p")
    +      sparkContext.makeRDD(1 to 10).map { i =>
    +        ParquetDataWithKeyAndComplexTypes(
    +          p, i, s"part-$p", StructContainer(i, f"${i}_string"), 1 to i)
    +      }.toDF().write.parquet(partDir.getCanonicalPath)
    +    }
    +
    +    partitionedTableDirWithComplexTypes = Utils.createTempDir()
    +
    +    (1 to 10).foreach { p =>
    +      val partDir = new File(partitionedTableDirWithComplexTypes, s"p=$p")
    +      sparkContext.makeRDD(1 to 10).map { i =>
    +        ParquetDataWithComplexTypes(i, s"part-$p", StructContainer(i, 
f"${i}_string"), 1 to i)
    +      }.toDF().write.parquet(partDir.getCanonicalPath)
    +    }
    +  }
    +
    +  override protected def afterAll(): Unit = {
    +    try {
    +      partitionedTableDir.delete()
    +      normalTableDir.delete()
    +      partitionedTableDirWithKey.delete()
    +      partitionedTableDirWithComplexTypes.delete()
    +      partitionedTableDirWithKeyAndComplexTypes.delete()
    +    } finally {
    +      super.afterAll()
    +    }
    +  }
    +
    +  /**
    +   * Drop named tables if they exist
    + *
    --- End diff --
    
    nit for the indent.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to