-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
sql/hive/src/test/scala/org/apache/spark/sql/hive/api/java/JavaHiveQLSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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.api.java | ||
|
||
import scala.util.Try | ||
|
||
import org.scalatest.FunSuite | ||
|
||
import org.apache.spark.api.java.JavaSparkContext | ||
import org.apache.spark.sql.api.java.JavaSchemaRDD | ||
import org.apache.spark.sql.execution.ExplainCommand | ||
import org.apache.spark.sql.hive.test.TestHive | ||
import org.apache.spark.sql.test.TestSQLContext | ||
|
||
// Implicits | ||
import scala.collection.JavaConversions._ | ||
|
||
class JavaHiveQLSuite extends FunSuite { | ||
val javaCtx = new JavaSparkContext(TestSQLContext.sparkContext) | ||
|
||
// There is a little trickery here to avoid instantiating two HiveContexts in the same JVM | ||
val javaHiveCtx = new JavaHiveContext(javaCtx) { | ||
override val sqlContext = TestHive | ||
} | ||
|
||
test("SELECT * FROM src") { | ||
assert( | ||
javaHiveCtx.hql("SELECT * FROM src").collect().map(_.getInt(0)) === | ||
TestHive.sql("SELECT * FROM src").collect().map(_.getInt(0)).toSeq) | ||
} | ||
|
||
private val explainCommandClassName = | ||
classOf[ExplainCommand].getSimpleName.stripSuffix("$") | ||
|
||
def isExplanation(result: JavaSchemaRDD) = { | ||
val explanation = result.collect().map(_.getString(0)) | ||
explanation.size == 1 && explanation.head.startsWith(explainCommandClassName) | ||
} | ||
|
||
test("Query Hive native command execution result") { | ||
val tableName = "test_native_commands" | ||
|
||
assertResult(0) { | ||
javaHiveCtx.hql(s"DROP TABLE IF EXISTS $tableName").count() | ||
} | ||
|
||
assertResult(0) { | ||
javaHiveCtx.hql(s"CREATE TABLE $tableName(key INT, value STRING)").count() | ||
} | ||
|
||
javaHiveCtx.hql("SHOW TABLES").registerAsTable("show_tables") | ||
|
||
assert( | ||
javaHiveCtx | ||
.hql("SELECT result FROM show_tables") | ||
.collect() | ||
.map(_.getString(0)) | ||
.contains(tableName)) | ||
|
||
assertResult(Array(Array("key", "int", "None"), Array("value", "string", "None"))) { | ||
javaHiveCtx.hql(s"DESCRIBE $tableName").registerAsTable("describe_table") | ||
|
||
javaHiveCtx | ||
.hql("SELECT result FROM describe_table") | ||
.collect() | ||
.map(_.getString(0).split("\t").map(_.trim)) | ||
.toArray | ||
} | ||
|
||
assert(isExplanation(javaHiveCtx.hql( | ||
s"EXPLAIN SELECT key, COUNT(*) FROM $tableName GROUP BY key"))) | ||
|
||
TestHive.reset() | ||
} | ||
|
||
test("Exactly once semantics for DDL and command statements") { | ||
val tableName = "test_exactly_once" | ||
val q0 = javaHiveCtx.hql(s"CREATE TABLE $tableName(key INT, value STRING)") | ||
|
||
// If the table was not created, the following assertion would fail | ||
assert(Try(TestHive.table(tableName)).isSuccess) | ||
|
||
// If the CREATE TABLE command got executed again, the following assertion would fail | ||
assert(Try(q0.count()).isSuccess) | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
sql/hive/src/test/scala/org/apache/spark/sql/hive/api/java/JavaHiveSuite.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters