From ade173c2397613b2649d6f61e8fe27c2d659d088 Mon Sep 17 00:00:00 2001 From: gatorsmile Date: Sat, 6 Aug 2016 21:27:41 -0700 Subject: [PATCH 1/4] fix --- .../sql/catalyst/catalog/SessionCatalog.scala | 2 +- .../apache/spark/sql/MetadataCacheSuite.scala | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala index fabab32592af..da12c20b7332 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala @@ -491,7 +491,7 @@ class SessionCatalog( // If the database is defined, this is definitely not a temp table. // If the database is not defined, there is a good chance this is a temp table. if (name.database.isEmpty) { - tempTables.get(name.table).foreach(_.refresh()) + tempTables.get(formatTableName(name.table)).foreach(_.refresh()) } } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/MetadataCacheSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/MetadataCacheSuite.scala index eacf254cd183..3dc6967bbc1d 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/MetadataCacheSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/MetadataCacheSuite.scala @@ -20,6 +20,7 @@ package org.apache.spark.sql import java.io.File import org.apache.spark.SparkException +import org.apache.spark.sql.internal.SQLConf import org.apache.spark.sql.test.SharedSQLContext /** @@ -85,4 +86,28 @@ class MetadataCacheSuite extends QueryTest with SharedSQLContext { assert(newCount > 0 && newCount < 100) }} } + + test("case sensitivity support in temporary view refresh") { + withSQLConf(SQLConf.CASE_SENSITIVE.key -> "false") { + withTempView("view_refresh") { + withTempPath { (location: File) => + // Create a Parquet directory + spark.range(start = 0, end = 100, step = 1, numPartitions = 3) + .write.parquet(location.getAbsolutePath) + + // Read the directory in + spark.read.parquet(location.getAbsolutePath).createOrReplaceTempView("view_refresh") + + // Delete a file + deleteOneFileInDirectory(location) + intercept[SparkException] {sql("select count(*) from view_refresh").first()} + + // Refresh and we should be able to read it again. + spark.catalog.refreshTable("vIeW_reFrEsH") + val newCount = sql("select count(*) from view_refresh").first().getLong(0) + assert(newCount > 0 && newCount < 100) + } + } + } + } } From f62fb19791f590a8110d6a7be65987b348dc167a Mon Sep 17 00:00:00 2001 From: gatorsmile Date: Sat, 6 Aug 2016 22:16:21 -0700 Subject: [PATCH 2/4] fix2 --- .../org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala index da12c20b7332..00c3db0aac1a 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala @@ -508,7 +508,7 @@ class SessionCatalog( * For testing only. */ private[catalog] def getTempTable(name: String): Option[LogicalPlan] = synchronized { - tempTables.get(name) + tempTables.get(formatTableName(name)) } // ---------------------------------------------------------------------------- From fb0dd0b03640c9456313d8b7a63203607940e683 Mon Sep 17 00:00:00 2001 From: gatorsmile Date: Sat, 6 Aug 2016 22:35:55 -0700 Subject: [PATCH 3/4] update the comment --- .../scala/org/apache/spark/sql/execution/SparkSqlParser.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala index 2bb686254cfd..8db77be5d99c 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala @@ -1212,7 +1212,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { * * For example: * {{{ - * CREATE [TEMPORARY] VIEW [IF NOT EXISTS] [db_name.]view_name + * CREATE [OR REPLACE] [TEMPORARY] VIEW [IF NOT EXISTS] [db_name.]view_name * [(column_name [COMMENT column_comment], ...) ] * [COMMENT view_comment] * [TBLPROPERTIES (property_name = property_value, ...)] From ad7470387ff178204285eb95cc64683b10204bae Mon Sep 17 00:00:00 2001 From: gatorsmile Date: Sun, 7 Aug 2016 22:01:26 -0700 Subject: [PATCH 4/4] address comments. --- .../test/scala/org/apache/spark/sql/MetadataCacheSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/MetadataCacheSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/MetadataCacheSuite.scala index 3dc6967bbc1d..98aa447fc056 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/MetadataCacheSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/MetadataCacheSuite.scala @@ -100,7 +100,7 @@ class MetadataCacheSuite extends QueryTest with SharedSQLContext { // Delete a file deleteOneFileInDirectory(location) - intercept[SparkException] {sql("select count(*) from view_refresh").first()} + intercept[SparkException](sql("select count(*) from view_refresh").first()) // Refresh and we should be able to read it again. spark.catalog.refreshTable("vIeW_reFrEsH")