Skip to content

Commit f57f15c

Browse files
author
Jacky Li
committed
add testcase
1 parent 578d167 commit f57f15c

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class SQLContext(@transient val sparkContext: SparkContext)
5858
self =>
5959

6060
@transient
61-
protected[sql] lazy val catalog: Catalog = new SimpleCatalog(true)
61+
protected[sql] lazy val catalog: Catalog = new SimpleCatalog(caseSensitive)
6262

6363
@transient
6464
protected[sql] lazy val functionRegistry: FunctionRegistry = new SimpleFunctionRegistry
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql.test
19+
20+
import org.apache.spark.{SparkConf, SparkContext}
21+
import org.apache.spark.sql.{SQLConf, SQLContext}
22+
23+
/** A case insensitive SQLContext that can be used for local testing. */
24+
object TestCaseInsensitiveSQLContext
25+
extends SQLContext(
26+
new SparkContext(
27+
"local[2]",
28+
"CaseInsensitiveSQLContext",
29+
new SparkConf().set(SQLConf.CASE_SENSITIVE, "false"))) {
30+
31+
/** Fewer partitions to speed up testing. */
32+
override private[spark] def numShufflePartitions: Int =
33+
getConf(SQLConf.SHUFFLE_PARTITIONS, "5").toInt
34+
}
35+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.sql
19+
20+
import java.util.TimeZone
21+
22+
import org.apache.spark.sql.test.TestCaseInsensitiveSQLContext
23+
import org.scalatest.BeforeAndAfterAll
24+
25+
/* Implicits */
26+
27+
import org.apache.spark.sql.test.TestCaseInsensitiveSQLContext._
28+
29+
object CaseInsensitiveTestData{
30+
case class StringData(s: String)
31+
val table = TestCaseInsensitiveSQLContext.sparkContext.parallelize(StringData("test") :: Nil)
32+
table.registerTempTable("caseInsensitiveTable")
33+
}
34+
35+
class SQLQueryCaseInsensitiveSuite extends QueryTest with BeforeAndAfterAll {
36+
CaseInsensitiveTestData
37+
38+
var origZone: TimeZone = _
39+
40+
override protected def beforeAll() {
41+
origZone = TimeZone.getDefault
42+
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
43+
}
44+
45+
override protected def afterAll() {
46+
TimeZone.setDefault(origZone)
47+
}
48+
49+
test("SPARK-4699 case sensitivity SQL query") {
50+
checkAnswer(sql("SELECT S FROM CASEINSENSITIVETABLE"), "test")
51+
}
52+
53+
}

0 commit comments

Comments
 (0)