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

    https://github.com/apache/spark/pull/15515#discussion_r84986887
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/PartitionProviderCompatibilitySuite.scala
 ---
    @@ -0,0 +1,138 @@
    +/*
    + * 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.metrics.source.HiveCatalogMetrics
    +import org.apache.spark.sql.{AnalysisException, QueryTest}
    +import org.apache.spark.sql.hive.test.TestHiveSingleton
    +import org.apache.spark.sql.internal.SQLConf
    +import org.apache.spark.sql.test.SQLTestUtils
    +
    +class PartitionProviderCompatibilitySuite
    +  extends QueryTest with TestHiveSingleton with SQLTestUtils {
    +
    +  private def setupPartitionedDatasourceTable(tableName: String, dir: 
File): Unit = {
    +    // TODO(ekl) make these mixed-case fields once support for that is 
fixed
    +    spark.range(5).selectExpr("id as fieldone", "id as partcol1", "id as 
partcol2").write
    +      .partitionBy("partcol1", "partcol2")
    +      .mode("overwrite")
    +      .parquet(dir.getAbsolutePath)
    +
    +    spark.sql(s"""
    +      |create table $tableName (fieldone long, partcol1 int, partcol2 int)
    +      |using parquet
    +      |options (path "${dir.getAbsolutePath}")
    +      |partitioned by (partcol1, partcol2)""".stripMargin)
    +  }
    +
    +  private def verifyIsLegacyTable(tableName: String): Unit = {
    +    val unsupportedCommands = Seq(
    +      s"ALTER TABLE $tableName ADD PARTITION (partcol=1)",
    +      s"ALTER TABLE $tableName RENAME PARTITION (partcol=1)",
    +      s"ALTER TABLE $tableName DROP PARTITION (partcol=1)",
    +      s"TRUNCATE TABLE $tableName PARTITION (partcol=1)",
    +      s"DESCRIBE $tableName PARTITION (partcol1=1)",
    +      s"SHOW PARTITIONS $tableName")
    +
    +    withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> "true") {
    +      for (cmd <- unsupportedCommands) {
    +        val e = intercept[AnalysisException] {
    +          spark.sql(s"show partitions $tableName")
    +        }
    +        assert(e.getMessage.contains("partition metadata is not stored in 
the Hive metastore"), e)
    +      }
    +    }
    +  }
    +
    +  test("convert partition provider to hive with repair table") {
    +    withTable("test") {
    +      withTempDir { dir =>
    +        withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> 
"false") {
    +          setupPartitionedDatasourceTable("test", dir)
    +          assert(spark.sql("select * from test").count() == 5)
    +        }
    +        withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> 
"true") {
    +          verifyIsLegacyTable("test")
    +          spark.sql("msck repair table test")
    +          spark.sql("show partitions test").count()  // check we are a new 
table
    +
    +          // sanity check table performance
    +          HiveCatalogMetrics.reset()
    +          assert(spark.sql("select * from test where partcol1 < 
2").count() == 2)
    +          assert(HiveCatalogMetrics.METRIC_PARTITIONS_FETCHED.getCount() 
== 2)
    +          assert(HiveCatalogMetrics.METRIC_FILES_DISCOVERED.getCount() == 
2)
    +        }
    +      }
    +    }
    +  }
    +
    +  test("when partition management is enabled, new tables have partition 
provider hive") {
    +    withTable("test") {
    +      withTempDir { dir =>
    +        withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> 
"true") {
    +          setupPartitionedDatasourceTable("test", dir)
    +          spark.sql("show partitions test").count()  // check we are a new 
table
    +          assert(spark.sql("select * from test").count() == 0)  // needs 
repair
    +          spark.sql("msck repair table test")
    +          assert(spark.sql("select * from test").count() == 5)
    +        }
    +      }
    +    }
    +  }
    +
    +  test("when partition management is disabled, new tables have no 
partition provider") {
    +    withTable("test") {
    +      withTempDir { dir =>
    +        withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> 
"false") {
    +          setupPartitionedDatasourceTable("test", dir)
    +          verifyIsLegacyTable("test")
    +          assert(spark.sql("select * from test").count() == 5)
    +        }
    +      }
    +    }
    +  }
    +
    +  test("when partition management is disabled, we preserve the old 
behavior even for new tables") {
    +    withTable("test") {
    +      withTempDir { dir =>
    +        withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> 
"true") {
    +          setupPartitionedDatasourceTable("test", dir)
    +          spark.sql("show partitions test").count()  // check we are a new 
table
    +          spark.sql("refresh table test")
    +          assert(spark.sql("select * from test").count() == 0)
    +        }
    +        // disabled
    +        withSQLConf(SQLConf.HIVE_MANAGE_FILESOURCE_PARTITIONS.key -> 
"false") {
    +          val e = intercept[AnalysisException] {
    +            spark.sql(s"show partitions test")
    +          }
    +          assert(e.getMessage.contains("filesource partition management is 
disabled"))
    +          spark.sql("refresh table test")
    +          assert(spark.sql("select * from test").count() == 5)
    --- End diff --
    
    You'll get the old cached results. I think this is kind of fair since 
otherwise we'd have to include the flag value in the cache key, which would be 
kind of odd.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to