Skip to content

Commit 3a21e8d

Browse files
committed
[SPARK-14795][SQL] Remove the use of Hive's variable substitution
## What changes were proposed in this pull request? This patch builds on #12556 and completely removes the use of Hive's variable substitution. ## How was this patch tested? Covered by existing tests. Author: Reynold Xin <[email protected]> Closes #12561 from rxin/SPARK-14795.
1 parent 79008e6 commit 3a21e8d

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveSessionState.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import java.util.regex.Pattern
2121

2222
import org.apache.hadoop.hive.conf.HiveConf
2323
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
24-
import org.apache.hadoop.hive.ql.parse.VariableSubstitution
2524

2625
import org.apache.spark.sql._
2726
import org.apache.spark.sql.catalyst.analysis.Analyzer
@@ -109,7 +108,7 @@ private[hive] class HiveSessionState(ctx: SQLContext) extends SessionState(ctx)
109108
/**
110109
* Parser for HiveQl query texts.
111110
*/
112-
override lazy val sqlParser: ParserInterface = new HiveSqlParser(conf, hiveconf)
111+
override lazy val sqlParser: ParserInterface = new HiveSqlParser(conf)
113112

114113
/**
115114
* Planner that takes into account Hive-specific strategies.

sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,30 @@ package org.apache.spark.sql.hive.execution
2020
import scala.util.Try
2121

2222
import org.antlr.v4.runtime.Token
23-
import org.apache.hadoop.hive.conf.HiveConf
24-
import org.apache.hadoop.hive.ql.parse.VariableSubstitution
2523
import org.apache.hadoop.hive.serde.serdeConstants
2624

2725
import org.apache.spark.sql.catalyst.catalog._
2826
import org.apache.spark.sql.catalyst.parser._
2927
import org.apache.spark.sql.catalyst.parser.SqlBaseParser._
3028
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
3129
import org.apache.spark.sql.execution.SparkSqlAstBuilder
32-
import org.apache.spark.sql.internal.SQLConf
30+
import org.apache.spark.sql.internal.{SQLConf, VariableSubstitution}
3331

3432
/**
3533
* Concrete parser for HiveQl statements.
3634
*/
37-
class HiveSqlParser(conf: SQLConf, hiveconf: HiveConf) extends AbstractSqlParser {
35+
class HiveSqlParser(conf: SQLConf) extends AbstractSqlParser {
3836

3937
val astBuilder = new HiveSqlAstBuilder(conf)
4038

41-
lazy val substitutor = new VariableSubstitution
39+
private val substitutor = new VariableSubstitution(conf)
4240

4341
protected override def parse[T](command: String)(toResult: SqlBaseParser => T): T = {
44-
super.parse(substitutor.substitute(hiveconf, command))(toResult)
42+
super.parse(substitutor.substitute(command))(toResult)
4543
}
4644

4745
protected override def nativeCommand(sqlText: String): LogicalPlan = {
48-
HiveNativeCommand(substitutor.substitute(hiveconf, sqlText))
46+
HiveNativeCommand(substitutor.substitute(sqlText))
4947
}
5048
}
5149

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
512512
sql("SELECT key FROM ${hiveconf:tbl} ORDER BY key, value limit 1"),
513513
sql("SELECT key FROM src ORDER BY key, value limit 1").collect().toSeq)
514514

515-
sql("set hive.variable.substitute=false") // disable the substitution
515+
sql("set spark.sql.variable.substitute=false") // disable the substitution
516516
sql("set tbl2=src")
517517
intercept[Exception] {
518518
sql("SELECT key FROM ${hiveconf:tbl2} ORDER BY key, value limit 1").collect()
519519
}
520520

521-
sql("set hive.variable.substitute=true") // enable the substitution
521+
sql("set spark.sql.variable.substitute=true") // enable the substitution
522522
checkAnswer(
523523
sql("SELECT key FROM ${hiveconf:tbl2} ORDER BY key, value limit 1"),
524524
sql("SELECT key FROM src ORDER BY key, value limit 1").collect().toSeq)

0 commit comments

Comments
 (0)