aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
diff options
context:
space:
mode:
Diffstat (limited to 'sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala108
1 files changed, 100 insertions, 8 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
index c958eac266..cdd404d699 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
@@ -24,6 +24,7 @@ import org.apache.spark.AccumulatorSuite
import org.apache.spark.sql.catalyst.analysis.UnresolvedException
import org.apache.spark.sql.catalyst.expressions.SortOrder
import org.apache.spark.sql.catalyst.plans.logical.Aggregate
+import org.apache.spark.sql.catalyst.util.StringUtils
import org.apache.spark.sql.execution.aggregate
import org.apache.spark.sql.execution.joins.{BroadcastHashJoin, CartesianProduct, SortMergeJoin}
import org.apache.spark.sql.functions._
@@ -56,12 +57,13 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
test("show functions") {
def getFunctions(pattern: String): Seq[Row] = {
- val regex = java.util.regex.Pattern.compile(pattern)
- sqlContext.sessionState.functionRegistry.listFunction()
- .filter(regex.matcher(_).matches()).map(Row(_))
+ StringUtils.filterPattern(sqlContext.sessionState.functionRegistry.listFunction(), pattern)
+ .map(Row(_))
}
- checkAnswer(sql("SHOW functions"), getFunctions(".*"))
- Seq("^c.*", ".*e$", "log.*", ".*date.*").foreach { pattern =>
+ checkAnswer(sql("SHOW functions"), getFunctions("*"))
+ Seq("^c*", "*e$", "log*", "*date*").foreach { pattern =>
+ // For the pattern part, only '*' and '|' are allowed as wildcards.
+ // For '*', we need to replace it to '.*'.
checkAnswer(sql(s"SHOW FUNCTIONS '$pattern'"), getFunctions(pattern))
}
}
@@ -87,6 +89,14 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
"Function: abcadf not found.")
}
+ test("SPARK-14415: All functions should have own descriptions") {
+ for (f <- sqlContext.sessionState.functionRegistry.listFunction()) {
+ if (!Seq("cube", "grouping", "grouping_id", "rollup", "window").contains(f)) {
+ checkExistence(sql(s"describe function `$f`"), false, "To be added.")
+ }
+ }
+ }
+
test("SPARK-6743: no columns from cache") {
Seq(
(83, 0, 38),
@@ -1656,7 +1666,7 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
val e2 = intercept[AnalysisException] {
sql("select interval 23 nanosecond")
}
- assert(e2.message.contains("cannot recognize input near"))
+ assert(e2.message.contains("No interval can be constructed"))
}
test("SPARK-8945: add and subtract expressions for interval type") {
@@ -1817,12 +1827,12 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
val e1 = intercept[AnalysisException] {
sql("select * from in_valid_table")
}
- assert(e1.message.contains("Table not found"))
+ assert(e1.message.contains("Table or View not found"))
val e2 = intercept[AnalysisException] {
sql("select * from no_db.no_table").show()
}
- assert(e2.message.contains("Table not found"))
+ assert(e2.message.contains("Table or View not found"))
val e3 = intercept[AnalysisException] {
sql("select * from json.invalid_file")
@@ -2228,6 +2238,88 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
assert(error.getMessage contains "grouping__id is deprecated; use grouping_id() instead")
}
+ test("grouping and grouping_id in having") {
+ checkAnswer(
+ sql("select course, year from courseSales group by cube(course, year)" +
+ " having grouping(year) = 1 and grouping_id(course, year) > 0"),
+ Row("Java", null) ::
+ Row("dotNET", null) ::
+ Row(null, null) :: Nil
+ )
+
+ var error = intercept[AnalysisException] {
+ sql("select course, year from courseSales group by course, year" +
+ " having grouping(course) > 0")
+ }
+ assert(error.getMessage contains
+ "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup")
+ error = intercept[AnalysisException] {
+ sql("select course, year from courseSales group by course, year" +
+ " having grouping_id(course, year) > 0")
+ }
+ assert(error.getMessage contains
+ "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup")
+ error = intercept[AnalysisException] {
+ sql("select course, year from courseSales group by cube(course, year)" +
+ " having grouping__id > 0")
+ }
+ assert(error.getMessage contains "grouping__id is deprecated; use grouping_id() instead")
+ }
+
+ test("grouping and grouping_id in sort") {
+ checkAnswer(
+ sql("select course, year, grouping(course), grouping(year) from courseSales" +
+ " group by cube(course, year) order by grouping_id(course, year), course, year"),
+ Row("Java", 2012, 0, 0) ::
+ Row("Java", 2013, 0, 0) ::
+ Row("dotNET", 2012, 0, 0) ::
+ Row("dotNET", 2013, 0, 0) ::
+ Row("Java", null, 0, 1) ::
+ Row("dotNET", null, 0, 1) ::
+ Row(null, 2012, 1, 0) ::
+ Row(null, 2013, 1, 0) ::
+ Row(null, null, 1, 1) :: Nil
+ )
+
+ checkAnswer(
+ sql("select course, year, grouping_id(course, year) from courseSales" +
+ " group by cube(course, year) order by grouping(course), grouping(year), course, year"),
+ Row("Java", 2012, 0) ::
+ Row("Java", 2013, 0) ::
+ Row("dotNET", 2012, 0) ::
+ Row("dotNET", 2013, 0) ::
+ Row("Java", null, 1) ::
+ Row("dotNET", null, 1) ::
+ Row(null, 2012, 2) ::
+ Row(null, 2013, 2) ::
+ Row(null, null, 3) :: Nil
+ )
+
+ var error = intercept[AnalysisException] {
+ sql("select course, year from courseSales group by course, year" +
+ " order by grouping(course)")
+ }
+ assert(error.getMessage contains
+ "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup")
+ error = intercept[AnalysisException] {
+ sql("select course, year from courseSales group by course, year" +
+ " order by grouping_id(course, year)")
+ }
+ assert(error.getMessage contains
+ "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup")
+ error = intercept[AnalysisException] {
+ sql("select course, year from courseSales group by cube(course, year)" +
+ " order by grouping__id")
+ }
+ assert(error.getMessage contains "grouping__id is deprecated; use grouping_id() instead")
+ }
+
+ test("filter on a grouping column that is not presented in SELECT") {
+ checkAnswer(
+ sql("select count(1) from (select 1 as a) t group by a having a > 0"),
+ Row(1) :: Nil)
+ }
+
test("SPARK-13056: Null in map value causes NPE") {
val df = Seq(1 -> Map("abc" -> "somestring", "cba" -> null)).toDF("key", "value")
withTempTable("maptest") {