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

    https://github.com/apache/spark/pull/7070#discussion_r33705001
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/parquet/ParquetSchemaMergeConfigSuite.scala
 ---
    @@ -0,0 +1,64 @@
    +/*
    + * 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.parquet
    +
    +import org.apache.spark.sql.{SQLConf, QueryTest}
    +import org.apache.spark.sql.test.TestSQLContext
    +import org.scalatest.BeforeAndAfterAll
    +
    +case class ParquetData2(int2Field: Int, string2Field: String)
    +
    +
    +class ParquetSchemaMergeConfigSuite  extends QueryTest with ParquetTest 
with BeforeAndAfterAll {
    +  val sqlContext = TestSQLContext
    +  val defaultPartitionName = "__HIVE_DEFAULT_PARTITION__"
    +  case class ParquetData2(int2Field: Int, string2Field: String)
    +
    +  private val originalConf = sqlContext.conf
    +                          .getConf(SQLConf.PARQUET_MERGE_SCHEMA_ENABLED)
    +
    +  override def afterAll(): Unit = {
    +    sqlContext.conf.setConf(SQLConf.PARQUET_MERGE_SCHEMA_ENABLED, 
originalConf)
    +  }
    +
    +
    +  test("Disable SchemaMerge") {
    +    sqlContext.conf.setConf(SQLConf.PARQUET_MERGE_SCHEMA_ENABLED, false)
    +    withTempDir { base =>
    +      val parquetFile1 = makePartitionDir(base, defaultPartitionName, 
"lala" -> 1)
    +      makeParquetFile( (1 to 10).map(i => ParquetData(i, i.toString)), 
parquetFile1)
    +      val parquetFile2 = makePartitionDir(base, defaultPartitionName, 
"lala" -> 2)
    +      makeParquetFile( (1 to 10).map(i => ParquetData2(i, i.toString)), 
parquetFile2)
    +      assert( sqlContext.read.parquet(parquetFile1.toString, 
parquetFile2.toString)
    +                .columns.size == 3)
    +    }
    +  }
    +
    +  test("Enable SchemaMerge") {
    +    sqlContext.conf.setConf(SQLConf.PARQUET_MERGE_SCHEMA_ENABLED, true)
    +    withTempDir { base =>
    +      val parquetFile1 = makePartitionDir(base, defaultPartitionName, 
"lala" -> 1)
    +      makeParquetFile( (1 to 10).map(i => ParquetData(i, i.toString)), 
parquetFile1)
    +      val parquetFile2 = makePartitionDir(base, defaultPartitionName, 
"lala" -> 2)
    +      makeParquetFile( (1 to 10).map(i => ParquetData2(i, i.toString)), 
parquetFile2)
    +      assert( sqlContext.read.parquet(parquetFile1.toString, 
parquetFile2.toString)
    +        .columns.size == 5)
    +    }
    +  }
    --- End diff --
    
    As I commented above, you don't need a case class to generate a DataFrame. 
For example, these two test cases can be simplified to:
    
    ```scala
    test("Enabling/disabling schema merging") {
      def testSchemaMerging(expectedColumnNumber: Int): Unit {
        withTempDir { dir =>
          val basePath = dir.getCanonicalPath
          sqlContext.range(0, 10).toDF("a").write.parquet(new Path(basePath, 
"foo=1").toString)
          sqlContext.range(0, 10).toDF("b").write.parquet(new Path(basePath, 
"foo=2").toString)
          assert(sqlContext.read.parquet(basePath).columns.length === 
expectedColumnNumber)
        }
      }
    
      withSQLConf(SQLConf.PARQUET_SCHEMA_MERGING_ENABLED.key -> "true") {
        testSchemaMerging(3)
      }
    
      withSQLConf(SQLConf.PARQUET_SCHEMA_MERGING_ENABLED.key -> "false") {
        testSchemaMerging(2)
      }
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to