Skip to content

Commit 5ab6e9f

Browse files
adrian-wangmarmbrus
authored andcommitted
[SPARK-6202] [SQL] enable variable substitution on test framework
Author: Daoyuan Wang <[email protected]> Closes apache#4930 from adrian-wang/testvs and squashes the following commits: 2ce590f [Daoyuan Wang] add explicit function types b1d68bf [Daoyuan Wang] only substitute for parseSql 9c4a950 [Daoyuan Wang] add a comment explaining 18fb481 [Daoyuan Wang] enable variable substitute on test framework
1 parent 328daf6 commit 5ab6e9f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/test/TestHive.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import java.util.{Set => JavaSet}
2323
import org.apache.hadoop.hive.ql.exec.FunctionRegistry
2424
import org.apache.hadoop.hive.ql.io.avro.{AvroContainerInputFormat, AvroContainerOutputFormat}
2525
import org.apache.hadoop.hive.ql.metadata.Table
26+
import org.apache.hadoop.hive.ql.parse.VariableSubstitution
2627
import org.apache.hadoop.hive.ql.processors._
2728
import org.apache.hadoop.hive.serde2.RegexSerDe
2829
import org.apache.hadoop.hive.serde2.`lazy`.LazySimpleSerDe
@@ -153,8 +154,13 @@ class TestHiveContext(sc: SparkContext) extends HiveContext(sc) {
153154

154155
val describedTable = "DESCRIBE (\\w+)".r
155156

157+
val vs = new VariableSubstitution()
158+
159+
// we should substitute variables in hql to pass the text to parseSql() as a parameter.
160+
// Hive parser need substituted text. HiveContext.sql() does this but return a DataFrame,
161+
// while we need a logicalPlan so we cannot reuse that.
156162
protected[hive] class HiveQLQueryExecution(hql: String)
157-
extends this.QueryExecution(HiveQl.parseSql(hql)) {
163+
extends this.QueryExecution(HiveQl.parseSql(vs.substitute(hiveconf, hql))) {
158164
def hiveExec(): Seq[String] = runSqlHive(hql)
159165
override def toString: String = hql + "\n" + super.toString
160166
}

0 commit comments

Comments
 (0)