[SPARK-18045][SQL][TESTS] Move HiveDataFrameAnalyticsSuite
to package sql
## What changes were proposed in this pull request? The testsuite `HiveDataFrameAnalyticsSuite` has nothing to do with HIVE, we should move it to package `sql`. The original test cases in that suite are splited into two existing testsuites: `DataFrameAggregateSuite` tests for the functions and ~~`SQLQuerySuite`~~`SQLQueryTestSuite` tests for the SQL statements. ## How was this patch tested? ~~Modified `SQLQuerySuite` in package `sql`.~~ Add query file for `SQLQueryTestSuite`. Author: jiangxingbo <jiangxb1987@gmail.com> Closes #15582 from jiangxb1987/group-analytics-test.
This commit is contained in:
parent
21c7539a52
commit
b158256c2e
|
@ -0,0 +1,13 @@
|
|||
CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES
|
||||
(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2)
|
||||
AS testData(a, b);
|
||||
|
||||
-- CUBE on overlapping columns
|
||||
SELECT a + b, b, SUM(a - b) FROM testData GROUP BY a + b, b WITH CUBE;
|
||||
|
||||
SELECT a, b, SUM(b) FROM testData GROUP BY a, b WITH CUBE;
|
||||
|
||||
-- ROLLUP on overlapping columns
|
||||
SELECT a + b, b, SUM(a - b) FROM testData GROUP BY a + b, b WITH ROLLUP;
|
||||
|
||||
SELECT a, b, SUM(b) FROM testData GROUP BY a, b WITH ROLLUP;
|
|
@ -0,0 +1,87 @@
|
|||
-- Automatically generated by SQLQueryTestSuite
|
||||
-- Number of queries: 5
|
||||
|
||||
|
||||
-- !query 0
|
||||
CREATE OR REPLACE TEMPORARY VIEW testData AS SELECT * FROM VALUES
|
||||
(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2)
|
||||
AS testData(a, b)
|
||||
-- !query 0 schema
|
||||
struct<>
|
||||
-- !query 0 output
|
||||
|
||||
|
||||
|
||||
-- !query 1
|
||||
SELECT a + b, b, SUM(a - b) FROM testData GROUP BY a + b, b WITH CUBE
|
||||
-- !query 1 schema
|
||||
struct<(a + b):int,b:int,sum((a - b)):bigint>
|
||||
-- !query 1 output
|
||||
2 1 0
|
||||
2 NULL 0
|
||||
3 1 1
|
||||
3 2 -1
|
||||
3 NULL 0
|
||||
4 1 2
|
||||
4 2 0
|
||||
4 NULL 2
|
||||
5 2 1
|
||||
5 NULL 1
|
||||
NULL 1 3
|
||||
NULL 2 0
|
||||
NULL NULL 3
|
||||
|
||||
|
||||
|
||||
-- !query 2
|
||||
SELECT a, b, SUM(b) FROM testData GROUP BY a, b WITH CUBE
|
||||
-- !query 2 schema
|
||||
struct<a:int,b:int,sum(b):bigint>
|
||||
-- !query 2 output
|
||||
1 1 1
|
||||
1 2 2
|
||||
1 NULL 3
|
||||
2 1 1
|
||||
2 2 2
|
||||
2 NULL 3
|
||||
3 1 1
|
||||
3 2 2
|
||||
3 NULL 3
|
||||
NULL 1 3
|
||||
NULL 2 6
|
||||
NULL NULL 9
|
||||
|
||||
|
||||
-- !query 3
|
||||
SELECT a + b, b, SUM(a - b) FROM testData GROUP BY a + b, b WITH ROLLUP
|
||||
-- !query 3 schema
|
||||
struct<(a + b):int,b:int,sum((a - b)):bigint>
|
||||
-- !query 3 output
|
||||
2 1 0
|
||||
2 NULL 0
|
||||
3 1 1
|
||||
3 2 -1
|
||||
3 NULL 0
|
||||
4 1 2
|
||||
4 2 0
|
||||
4 NULL 2
|
||||
5 2 1
|
||||
5 NULL 1
|
||||
NULL NULL 3
|
||||
|
||||
|
||||
-- !query 4
|
||||
SELECT a, b, SUM(b) FROM testData GROUP BY a, b WITH ROLLUP
|
||||
-- !query 4 schema
|
||||
struct<a:int,b:int,sum(b):bigint>
|
||||
-- !query 4 output
|
||||
1 1 1
|
||||
1 2 2
|
||||
1 NULL 3
|
||||
2 1 1
|
||||
2 2 2
|
||||
2 NULL 3
|
||||
3 1 1
|
||||
3 2 2
|
||||
3 NULL 3
|
||||
NULL NULL 9
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* 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 org.scalatest.BeforeAndAfterAll
|
||||
|
||||
import org.apache.spark.sql.{DataFrame, QueryTest, Row}
|
||||
import org.apache.spark.sql.functions._
|
||||
import org.apache.spark.sql.hive.test.TestHiveSingleton
|
||||
|
||||
// TODO ideally we should put the test suite into the package `sql`, as
|
||||
// `hive` package is optional in compiling, however, `SQLContext.sql` doesn't
|
||||
// support the `cube` or `rollup` yet.
|
||||
class HiveDataFrameAnalyticsSuite extends QueryTest with TestHiveSingleton with BeforeAndAfterAll {
|
||||
import spark.implicits._
|
||||
import spark.sql
|
||||
|
||||
private var testData: DataFrame = _
|
||||
|
||||
override def beforeAll() {
|
||||
super.beforeAll()
|
||||
testData = Seq((1, 2), (2, 2), (3, 4)).toDF("a", "b")
|
||||
testData.createOrReplaceTempView("mytable")
|
||||
}
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
try {
|
||||
spark.catalog.dropTempView("mytable")
|
||||
} finally {
|
||||
super.afterAll()
|
||||
}
|
||||
}
|
||||
|
||||
test("rollup") {
|
||||
checkAnswer(
|
||||
testData.rollup($"a" + $"b", $"b").agg(sum($"a" - $"b")),
|
||||
sql("select a + b, b, sum(a - b) from mytable group by a + b, b with rollup").collect()
|
||||
)
|
||||
|
||||
checkAnswer(
|
||||
testData.rollup("a", "b").agg(sum("b")),
|
||||
sql("select a, b, sum(b) from mytable group by a, b with rollup").collect()
|
||||
)
|
||||
}
|
||||
|
||||
test("cube") {
|
||||
checkAnswer(
|
||||
testData.cube($"a" + $"b", $"b").agg(sum($"a" - $"b")),
|
||||
sql("select a + b, b, sum(a - b) from mytable group by a + b, b with cube").collect()
|
||||
)
|
||||
|
||||
checkAnswer(
|
||||
testData.cube("a", "b").agg(sum("b")),
|
||||
sql("select a, b, sum(b) from mytable group by a, b with cube").collect()
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue